| OLD | NEW |
| 1 # copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved. | 1 # copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
| 2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr | 2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
| 3 # | 3 # |
| 4 # This file is part of logilab-common. | 4 # This file is part of logilab-common. |
| 5 # | 5 # |
| 6 # logilab-common is free software: you can redistribute it and/or modify it unde
r | 6 # logilab-common is free software: you can redistribute it and/or modify it unde
r |
| 7 # the terms of the GNU Lesser General Public License as published by the Free | 7 # the terms of the GNU Lesser General Public License as published by the Free |
| 8 # Software Foundation, either version 2.1 of the License, or (at your option) an
y | 8 # Software Foundation, either version 2.1 of the License, or (at your option) an
y |
| 9 # later version. | 9 # later version. |
| 10 # | 10 # |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 if isinstance(somedate, datetime): | 307 if isinstance(somedate, datetime): |
| 308 fields.update({'H': somedate.hour, | 308 fields.update({'H': somedate.hour, |
| 309 'M': somedate.minute, | 309 'M': somedate.minute, |
| 310 'S': somedate.second}) | 310 'S': somedate.second}) |
| 311 fmt = re.sub('%([YmdHMS])', r'%(\1)02d', fmt) | 311 fmt = re.sub('%([YmdHMS])', r'%(\1)02d', fmt) |
| 312 return unicode(fmt) % fields | 312 return unicode(fmt) % fields |
| 313 | 313 |
| 314 def utcdatetime(dt): | 314 def utcdatetime(dt): |
| 315 if dt.tzinfo is None: | 315 if dt.tzinfo is None: |
| 316 return dt | 316 return dt |
| 317 return datetime(*dt.utctimetuple()[:7]) | 317 return (dt.replace(tzinfo=None) - dt.utcoffset()) |
| 318 | 318 |
| 319 def utctime(dt): | 319 def utctime(dt): |
| 320 if dt.tzinfo is None: | 320 if dt.tzinfo is None: |
| 321 return dt | 321 return dt |
| 322 return (dt + dt.utcoffset() + dt.dst()).replace(tzinfo=None) | 322 return (dt + dt.utcoffset() + dt.dst()).replace(tzinfo=None) |
| 323 | 323 |
| 324 def datetime_to_seconds(date): | 324 def datetime_to_seconds(date): |
| 325 """return the number of seconds since the begining of the day for that date | 325 """return the number of seconds since the begining of the day for that date |
| 326 """ | 326 """ |
| 327 return date.second+60*date.minute + 3600*date.hour | 327 return date.second+60*date.minute + 3600*date.hour |
| 328 | 328 |
| 329 def timedelta_to_days(delta): | 329 def timedelta_to_days(delta): |
| 330 """return the time delta as a number of seconds""" | 330 """return the time delta as a number of seconds""" |
| 331 return delta.days + delta.seconds / (3600*24) | 331 return delta.days + delta.seconds / (3600*24) |
| 332 | 332 |
| 333 def timedelta_to_seconds(delta): | 333 def timedelta_to_seconds(delta): |
| 334 """return the time delta as a fraction of days""" | 334 """return the time delta as a fraction of days""" |
| 335 return delta.days*(3600*24) + delta.seconds | 335 return delta.days*(3600*24) + delta.seconds |
| OLD | NEW |