]> code.communitydata.science - rises_declines_wikia_code.git/blob - mediawiki_dump_tools/Mediawiki-Utilities/examples/timestamp.py
add copy of the GPL
[rises_declines_wikia_code.git] / mediawiki_dump_tools / Mediawiki-Utilities / examples / timestamp.py
1 """
2 Demonstrates some simple Timestamp operations
3 """
4 from mw import Timestamp
5
6 # Seconds since Unix Epoch
7 str(Timestamp(1234567890))
8 # > '20090213233130'
9
10 # Database format
11 int(Timestamp("20090213233130"))
12 # > 1234567890
13
14 # API format
15 int(Timestamp("2009-02-13T23:31:30Z"))
16 # > 1234567890
17
18 # Difference in seconds
19 Timestamp("2009-02-13T23:31:31Z") - Timestamp(1234567890)
20 # > 1
21
22 # strptime and strftime
23 Timestamp(1234567890).strftime("%Y foobar")
24 # > '2009 foobar'
25
26 str(Timestamp.strptime("2009 derp 10", "%Y derp %m"))
27 # > '20091001000000'

Community Data Science Collective || Want to submit a patch?