1
2
3
4
5
6
7
8
9
10
11
12
13
14 """Time
15
16 Utilities for consistent manipulation of Dates and Time. All simple
17 code should migrate here, and without dependencies on anything other
18 than standard python libraries.
19
20 $Id:$"""
21
22 __version__ = "$$"[11:-2]
23
24 import time
25
27 if gmtSecondsSince1970 is None:
28 return time.time()
29 return int(gmtSecondsSince1970)
30
35
37 """
38 @param milliseconds:: UTC timestamp in milliseconds
39 """
40 return LocalDateTime(milliseconds / 1000)
41
42
46
48 """
49 @param milliseconds:: UTC timestamp in milliseconds
50 """
51 return isoDateTime(milliseconds / 1000)
52
56
57 -def USDate(gmtSecondsSince1970 = None):
60
62 return time.mktime(time.strptime(mdy, "%m/%d/%Y"))
63
67
68 -def HHMMSS(gmtSecondsSince1970 = None):
71
73 return "Saved at time: " + HHMMSS()
74
76 result = ':%02d' % (seconds % 60)
77 seconds /= 60
78 if seconds:
79 result = '%02d%s' % (seconds % 60, result)
80 seconds /= 60
81 if seconds:
82 result = '%02d:%s' % (seconds % 24, result)
83 seconds /= 24
84 if seconds:
85 result = '%d days %s' % (seconds, result)
86 return result
87
88
92
93
97
99 """
100 converts a iso time string that does not contain a timezone, ie.
101 YYYY-MM-DD HH:MM:SS, to a timestamp in seconds since 1970; uses the system
102 timezone
103 """
104 timeStr = value.replace('T', ' ')
105 timeTuple = time.strptime(timeStr, '%Y-%m-%d %H:%M:%S')
106 timestamp = time.mktime(timeTuple)
107 return timestamp
108