##// END OF EJS Templates
add IPython.utils.tz...
MinRK -
Show More
@@ -0,0 +1,46 b''
1 # encoding: utf-8
2 """
3 Timezone utilities
4
5 Just UTC-awareness right now
6 """
7
8 #-----------------------------------------------------------------------------
9 # Copyright (C) 2013 The IPython Development Team
10 #
11 # Distributed under the terms of the BSD License. The full license is in
12 # the file COPYING, distributed as part of this software.
13 #-----------------------------------------------------------------------------
14
15 #-----------------------------------------------------------------------------
16 # Imports
17 #-----------------------------------------------------------------------------
18
19 from datetime import tzinfo, timedelta, datetime
20
21 #-----------------------------------------------------------------------------
22 # Code
23 #-----------------------------------------------------------------------------
24 # constant for zero offset
25 ZERO = timedelta(0)
26
27 class tzUTC(tzinfo):
28 """tzinfo object for UTC (zero offset)"""
29
30 def utcoffset(self, d):
31 return ZERO
32
33 def dst(self, d):
34 return ZERO
35
36 UTC = tzUTC()
37
38 def utc_aware(unaware):
39 """decorator for adding UTC tzinfo to datetime's utcfoo methods"""
40 def utc_method(*args, **kwargs):
41 dt = unaware(*args, **kwargs)
42 return dt.replace(tzinfo=UTC)
43 return utc_method
44
45 utcfromtimestamp = utc_aware(datetime.utcfromtimestamp)
46 utcnow = utc_aware(datetime.utcnow)
General Comments 0
You need to be logged in to leave comments. Login now