1
2
3
4
5
6
7
8
9
10
11 """Time
12
13 Utilities for consistent manipulation of Dates and Time. All simple
14 code should migrate here, and without dependencies on anything other
15 than standard python libraries.
16
17 $Id:$"""
18
19 __version__ = "$$"[11:-2]
20
21 import time
22
24 if gmtSecondsSince1970 is None:
25 return time.time()
26 return int(gmtSecondsSince1970)
27
32
34 """
35 @param milliseconds:: UTC timestamp in milliseconds
36 """
37 return LocalDateTime(milliseconds / 1000)
38
39
43
45 """
46 @param milliseconds:: UTC timestamp in milliseconds
47 """
48 return isoDateTime(milliseconds / 1000)
49
53
54 -def USDate(gmtSecondsSince1970 = None):
57
59 return time.mktime(time.strptime(mdy, "%m/%d/%Y"))
60
64
65 -def HHMMSS(gmtSecondsSince1970 = None):
68
70 return "Saved at time: " + HHMMSS()
71
73 result = ':%02d' % (seconds % 60)
74 seconds /= 60
75 if seconds:
76 result = '%02d%s' % (seconds % 60, result)
77 seconds /= 60
78 if seconds:
79 result = '%02d:%s' % (seconds % 24, result)
80 seconds /= 24
81 if seconds:
82 result = '%d days %s' % (seconds, result)
83 return result
84
85
89
90
94
96 """
97 converts a iso time string that does not contain a timezone, ie.
98 YYYY-MM-DD HH:MM:SS, to a timestamp in seconds since 1970; uses the system
99 timezone
100 """
101 timeStr = value.replace('T', ' ')
102 timeTuple = time.strptime(timeStr, '%Y-%m-%d %H:%M:%S')
103 timestamp = time.mktime(timeTuple)
104 return timestamp
105