[Erp5-report] r16080 - /erp5/trunk/products/ERP5Type/DateUtils.py

nobody at svn.erp5.org nobody at svn.erp5.org
Wed Sep 5 17:28:59 CEST 2007


Author: alex
Date: Wed Sep  5 17:28:59 2007
New Revision: 16080

URL: http://svn.erp5.org?rev=16080&view=rev
Log:
added createDateTimeFromMillis method: Returns a DateTime object, build from
the number of milliseconds since epoch.

Modified:
    erp5/trunk/products/ERP5Type/DateUtils.py

Modified: erp5/trunk/products/ERP5Type/DateUtils.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/DateUtils.py?rev=16080&r1=16079&r2=16080&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/DateUtils.py (original)
+++ erp5/trunk/products/ERP5Type/DateUtils.py Wed Sep  5 17:28:59 2007
@@ -362,3 +362,29 @@
   ordinal_reference_date = datetime.toordinal(reference_date)
   hour = (ordinal_date - ordinal_reference_date) * number_of_hours_in_day + number_of_hours_in_day + date.hour()
   return int(hour)
+
+def createDateTimeFromMillis(millis):
+  """
+  Returns a DateTime object, build from the number of milliseconds since epoch.
+  Parameter should be a int or long.
+
+  This one should be used by solvers, as DateTime.__cmp__ actually only
+  compares the _millis parameter of the two DateTime objects.
+
+  This is currently not perfect: DateTime only supports creating a new object
+  from a floating point number of seconds since epoch, so a rounding issue is
+  still possible, that's why _millis is explicitely set to the same value
+  after the DateTime object has been created from (millis / 1000.)
+
+  A better way would be to compute (yr,mo,dy,hr,mn,sc,tz,t,d,s,millisecs) from
+  millis, and then create the DateTime object from it (see "elif ac == 11:" in
+  DateTime._parse_args).
+
+  Another solution would be a DateTime implementation that relies exclusively
+  on integer values internally.
+  """
+  millis = long(millis)
+  date = DateTime(millis / 1000.)
+  date._millis = millis
+  return date
+




More information about the Erp5-report mailing list