[Pymoul-svn] SF.net SVN: pymoul: [194] pymoul/trunk/src/moul/time/dni.py
Status: Alpha
Brought to you by:
tiran
From: <ti...@us...> - 2007-02-26 15:45:52
|
Revision: 194 http://pymoul.svn.sourceforge.net/pymoul/?rev=194&view=rev Author: tiran Date: 2007-02-26 07:45:48 -0800 (Mon, 26 Feb 2007) Log Message: ----------- Fixed bug in DniTime algorithm. Yahr and vailee start with 1 and not with 0 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-26 15:16:22 UTC (rev 193) +++ pymoul/trunk/src/moul/time/dni.py 2007-02-26 15:45:48 UTC (rev 194) @@ -23,8 +23,6 @@ official sources say that: 00:00:00:00, Leefo 1, 9654 DE = 10:35:18 UTC, April 21, 1998 CE ->>> from datetime import timedelta - >>> LEEFO_1_TABLE = [ ... datetime(1998, 4, 21, 10, 35, 18, 0, tzinfo=UTC), ... datetime(1999, 4, 21, 16, 24, 3, 0, tzinfo=UTC), @@ -36,9 +34,8 @@ >>> def compareDT(dt1, dt2): ... delta = td2sec(dt1 - dt2) -... # smaller than 5 seconds -... if abs(delta) >0: # 1 off is fine -... return delta +... if abs(delta) > 0: +... return dt1 - dt2 ... else: ... return True @@ -67,6 +64,16 @@ >>> dni.secondsToPahrtovo(18) 80964 +>>> dni = DniTime.fromDni(9655, 1, 1, 0, 0, 0, 0) +>>> compareDT(dni.toUTC(), LEEFO_1_TABLE[1]) +True +>>> dni.toUTC() +datetime.datetime(1999, 4, 21, 16, 24, 3, tzinfo=<UTC>) + +>>> dni = DniTime.fromDni(9662, 9, 4, 4, 21, 24, 22) +>>> compareDT(dni.toUTC(), other) +True + >>> CET = timezone('CET') >>> dni = DniTime.fromString("2007-02-12 14:55:10", tzinfo=CET) >>> str(dni) @@ -85,6 +92,7 @@ import sys from datetime import datetime +from datetime import timedelta from time import mktime from moul.time.utils import UNIX_0 @@ -122,7 +130,7 @@ BASE_GREGORIAN = datetime(1998, 4, 21, 10, 35, 18, 0, tzinfo=UTC) BASE_HAHR = 9654 FAHRAH_1 = -7656 # hahrtee fahrah 1 starts ~April 21st 7656 B.C -BASE_SEC = td2sec(BASE_GREGORIAN - UNIX_0) # WTF? no tottimestamp in datetime +#BASE_SEC = td2sec(BASE_GREGORIAN - UNIX_0) # WTF? no tottimestamp in datetime # factors HAHR_PER_HAHRTEE_FAHRAH = 625 # ~ 625 years @@ -210,8 +218,7 @@ """Constructor from D'ni time """ self = cls(_initialize=True) - self.set(hahr=0, vailee=0, yahr=0, gahrtahvo=0, tahvo=0, - gorahn=0, prorahn=0) + self.set(hahr, vailee, yahr, gahrtahvo, tahvo, gorahn, prorahn) return self @classmethod @@ -241,7 +248,7 @@ utc_dt = UTC.normalize(dt.astimezone(UTC)) return cls.fromUTC(utc_dt) - def set(self, hahr=0, vailee=0, yahr=0, gahrtahvo=0, tahvo=0, + def set(self, hahr=0, vailee=1, yahr=1, gahrtahvo=0, tahvo=0, gorahn=0, prorahn=0): self._hahr = 0 self._prorahn = 0 @@ -261,10 +268,11 @@ def toUTC(self): """Convert to UTC datetime value """ + #import pdb; pdb.set_trace() hahr_sec = (self.hahr - BASE_HAHR) * SECONDS_PER_HAHR prorahn_sec = int(round(self._prorahn * FACTOR_SP)) - sec = hahr_sec + BASE_SEC + prorahn_sec - return UTC.localize(datetime.utcfromtimestamp(sec)) + td = timedelta(days=0, seconds=hahr_sec + prorahn_sec) + return UTC.normalize(BASE_GREGORIAN + td) def secondsToPahrtovo(self, bell): """Calculate seconds until bell (pahr-to-vo) @@ -295,9 +303,9 @@ def _getVailee(self): return ((self._prorahn // PRORAHN_PER_VAILEE) % 10) +1 - @valueCheck(int, 0, 10) + @valueCheck(int, 1, 10) def _setVailee(self, value): - self._addProrahn(value * PRORAHN_PER_VAILEE) + self._addProrahn((value-1) * PRORAHN_PER_VAILEE) vailee = property(_getVailee, _setVailee) def getVaileeName(self): @@ -305,9 +313,9 @@ def _getYahr(self): return ((self._prorahn // PRORAHN_PER_YAHR) % 29) +1 - @valueCheck(int, 0, 29) + @valueCheck(int, 1, 29) def _setYahr(self, value): - self._addProrahn(value * PRORAHN_PER_YAHR) + self._addProrahn((value-1) * PRORAHN_PER_YAHR) yahr = property(_getYahr, _setYahr) def _getGahrtahvo(self): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |