[Zope-Checkins] CVS: Zope/lib/python/DateTime - DateTime.py:1.77

Andreas Jung andreas@digicool.com
Thu, 7 Mar 2002 08:17:02 -0500


Update of /cvs-repository/Zope/lib/python/DateTime
In directory cvs.zope.org:/tmp/cvs-serv31506

Modified Files:
	DateTime.py 
Log Message:
added JulianDay() and week()


=== Zope/lib/python/DateTime/DateTime.py 1.76 => 1.77 ===
         return year,month,day,hour,minute,seconds,'GMT%+03d%02d' % (hour_off,min_off)
 
+    def JulianDay(self):
+        """
+        Return the Julian day according to
+        http://www.tondering.dk/claus/cal/node3.html#sec-calcjd
+        """
+        a = (14 - self._month)/12 #integer division, discard remainder
+        y = self._year + 4800 - a
+        m = self._month + (12*a) - 3
+        return self._day + (153*m+2)/5 + 365*y + y/4 - y/100 + y/400 - 32045
+
+    def week(self):
+        """
+        Return the week number according to ISO
+        see http://www.tondering.dk/claus/cal/node6.html#SECTION00670000000000000000
+        """
+        J = self.JulianDay()
+        d4 = (J + 31741 - (J % 7)) % 146097 % 36524 % 1461
+        L = d4/1460
+        d1 = (( d4 - L) % 365) + L
+        return d1/7 + 1
 
 
 class strftimeFormatter: