[Pymoul-svn] SF.net SVN: pymoul: [161] pymoul/trunk/src/moul/time/dni.py
Status: Alpha
Brought to you by:
tiran
|
From: <ti...@us...> - 2007-02-12 17:19:23
|
Revision: 161
http://pymoul.svn.sourceforge.net/pymoul/?rev=161&view=rev
Author: tiran
Date: 2007-02-12 09:15:11 -0800 (Mon, 12 Feb 2007)
Log Message:
-----------
Better round()
Added method to calculate seconds to next bell
Modified Paths:
--------------
pymoul/trunk/src/moul/time/dni.py
Modified: pymoul/trunk/src/moul/time/dni.py
===================================================================
--- pymoul/trunk/src/moul/time/dni.py 2007-02-12 16:06:42 UTC (rev 160)
+++ pymoul/trunk/src/moul/time/dni.py 2007-02-12 17:15:11 UTC (rev 161)
@@ -34,10 +34,10 @@
>>> def compareDT(dt1, dt2):
... delta = td2sec(dt1 - dt2)
... # smaller than 5 seconds
-... if abs(delta) < 5:
+... if abs(delta) >0: # 1 off is fine
+... return delta
+... else:
... return True
-... else:
-... return delta
>>> dni = DniTime()
>>> dni.fromUTC(LEEFO_1_TABLE[1])
@@ -51,13 +51,20 @@
>>> other = datetime(2007, 2, 12, 13, 55, 10, 0, tzinfo=UTC)
>>> dni.fromUTC(other)
>>> dni.get()
-(9662, 9, 4, 4, 21, 24, 21)
+(9662, 9, 4, 4, 21, 24, 22)
>>> str(dni)
-'04:21:24:21, Leevotar 4, 9662'
+'04:21:24:22, Leevotar 4, 9662'
>>> compareDT(dni.toUTC(), other)
True
+>>> dni.bell
+24
+>>> dni.secondsToBell(25)
+2616
+>>> dni.secondsToBell(18)
+80964
+
"""
__author__ = "Christian Heimes"
__version__ = "$Id$"
@@ -185,17 +192,29 @@
if utc_dt is None:
utc_dt = utcnow()
sec = td2sec(utc_dt - BASE)
- prorahn = int(sec * FACTOR_PS)
+ prorahn = int(round(sec * FACTOR_PS))
self.set(hahr=BASE_HAHR, prorahn=prorahn)
def toUTC(self):
"""Convert to UTC datetime value
"""
hahr_sec = (self.hahr - BASE_HAHR) * SECONDS_PER_HAHR
- prorahn_sec = int(self._prorahn * FACTOR_SP)
+ prorahn_sec = int(round(self._prorahn * FACTOR_SP))
sec = hahr_sec + BASE_SEC + prorahn_sec
return UTC.localize(datetime.utcfromtimestamp(sec))
+ def secondsToBell(self, bell):
+ """Calculate seconds until bell
+ """
+ if bell < 1 or bell > 25:
+ raise ValueError("%s too large or small" % bell)
+ pro = self.prorahnOfYahr() # prorahn of day
+ probells = bell * 3125 # prorahn of start of bell
+ diff = probells - pro
+ if diff < 0:
+ diff = diff + 78125
+ return int(round(diff * FACTOR_SP))
+
def __str__(self):
"""00:00:00:00, Leefo 1, 9654
"""
@@ -228,10 +247,6 @@
self._addProrahn(value * 78125)
yahr = property(_getYahr, _setYahr)
- def _getBell(self):
- return (self.gahrtahvo // 5) % 25
- bell = property(_getBell)
-
def _getGahrtahvo(self):
return (self._prorahn // 15625) % 5
@valueCheck(int, 0, 5)
@@ -239,6 +254,10 @@
self._addProrahn(value * 15625)
gahrtahvo = property(_getGahrtahvo, _setGahrtahvo)
+ def _getBell(self):
+ return (self._prorahn // 3125) % 25
+ bell = property(_getBell)
+
def _getTahvo(self):
return (self._prorahn // 625) % 25
@valueCheck(int, 0, 25)
@@ -261,9 +280,15 @@
prorahn = property(_getProrahn, _setProrahn)
def _addProrahn(self, value):
- value = int(value)
+ value = int(round(value))
addhahr = value // PRORAHN_PER_HAHR
if addhahr:
self._hahr += addhahr
value = value - (addhahr * PRORAHN_PER_HAHR)
self._prorahn = value
+
+ def prorahnOfYahr(self):
+ """Get numbers of prorahntee since start of yahr
+ """
+ return (self.gahrtahvo * 15625 + self.tahvo * 625 +
+ self.gorahn * 25 + self.prorahn)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|