-
Notifications
You must be signed in to change notification settings - Fork 7
/
extime-time.txt
38 lines (29 loc) · 1.68 KB
/
extime-time.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
= !ExtimeDotTime =
'''extime.Time''' lives in DivmodEpsilon ([http://divmod.org/trac/browser/trunk/Epsilon/epsilon browse the source]) - its a class that represents an instant or span of time - unambiguously and consistently, and provides some utility methods for converting to, from and between various representations. Values of [wiki:DivmodAxiom DivmodAxiom]'s timestamp attribute type are stored internally as {{{Time.asPOSIXTimestamp()}}}, and mapped to ExtimeDotTime instances when accessed from PythonLanguage.
{{{
#!python
from epsilon.extime import Time
from pytz import timezone
noon = Time.fromHumanly('noon')
print 'doc, be at the saloon at', noon.asHumanly()
# prints 'doc, be at the saloon at 12:00 pm'
print 'tim, be at the standards meeting at', noon.asISO8601TimeAndDate()
# prints 'tim, be at the standards meeting at 2005-10-27T12:00+00:00'
print 'hal, be at the holodeck at', noon.asPOSIXTimestamp()
# prints 'hal, be at the holodeck at 1130414400.0'
noonGMT = Time.fromHumanly('noon', tzinfo=timezone('GMT'))
noonEST = Time.fromHumanly('noon', tzinfo=timezone('EST'))
def getHourDifference(t1, t2):
(small, big) = sorted((t1, t2))
seconds = (big.asDatetime() - small.asDatetime()).seconds
return seconds / 60 ** 2
message = '''sam, the flight leaves from greenwich at %s, i guess that is
%s in new york. wow, %d hours apart, who would have thought'''
print message % (noonGMT.asHumanly(),
noonEST.asHumanly(),
getHourDifference(noonGMT, noonEST))
# will print:
# sam, the flight leaves from greenwich at 12:00 pm, i guess that is
# 05:00 pm in new york. wow, 5 hours apart, who would have thought
}}}
put more examples here.