git://git.onelab.eu
/
sfa.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge branch 'senslab2' of ssh://git.f-lab.fr/git/sfa into senslab2
[sfa.git]
/
sfa
/
util
/
sfatime.py
diff --git
a/sfa/util/sfatime.py
b/sfa/util/sfatime.py
index
478c5be
..
34f4dce
100644
(file)
--- a/
sfa/util/sfatime.py
+++ b/
sfa/util/sfatime.py
@@
-13,7
+13,14
@@
the timezone, so that it's compatible with normal datetime.datetime objects.
For safety this can also handle inputs that are either timestamps, or datetimes
"""
For safety this can also handle inputs that are either timestamps, or datetimes
"""
-
+ # perpare the input for the checks below by
+ # casting strings ('1327098335') to ints
+ if isinstance(input, StringTypes):
+ try:
+ input = int(input)
+ except ValueError:
+ pass
+
if isinstance (input, datetime.datetime):
logger.warn ("argument to utcparse already a datetime - doing nothing")
return input
if isinstance (input, datetime.datetime):
logger.warn ("argument to utcparse already a datetime - doing nothing")
return input
@@
-34,7
+41,7
@@
def datetime_to_utc(input):
return time.gmtime(datetime_to_epoch(input))
def datetime_to_epoch(input):
return time.gmtime(datetime_to_epoch(input))
def datetime_to_epoch(input):
- return
time.mktime(input.timetuple(
))
+ return
int(time.mktime(input.timetuple()
))