Commit 7ad578de authored by Alexandre Boeglin's avatar Alexandre Boeglin

added createDateTimeFromMillis method: Returns a DateTime object, build from

the number of milliseconds since epoch.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@16080 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 76ffe82f
...@@ -362,3 +362,29 @@ def convertDateToHour(date=None): ...@@ -362,3 +362,29 @@ def convertDateToHour(date=None):
ordinal_reference_date = datetime.toordinal(reference_date) 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() hour = (ordinal_date - ordinal_reference_date) * number_of_hours_in_day + number_of_hours_in_day + date.hour()
return int(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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment