annotate python/epoch2date.py @ 668:ef2762b1f7e8

note to self about fun tzinfo to fix in a year
author Jeff Hammel <k0scist@gmail.com>
date Thu, 17 Apr 2014 13:04:26 -0700
parents af95905ca177
children bcf5781b615e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
636
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
1 #!/usr/bin/env python
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
3
667
af95905ca177 STUB: python/epoch2date.py
Jeff Hammel <k0scist@gmail.com>
parents: 666
diff changeset
4 """
af95905ca177 STUB: python/epoch2date.py
Jeff Hammel <k0scist@gmail.com>
parents: 666
diff changeset
5 conversion between epoch and dates
af95905ca177 STUB: python/epoch2date.py
Jeff Hammel <k0scist@gmail.com>
parents: 666
diff changeset
6
af95905ca177 STUB: python/epoch2date.py
Jeff Hammel <k0scist@gmail.com>
parents: 666
diff changeset
7 https://docs.python.org/2/library/time.html
668
ef2762b1f7e8 note to self about fun tzinfo to fix in a year
Jeff Hammel <k0scist@gmail.com>
parents: 667
diff changeset
8 https://docs.python.org/2/library/datetime.html
ef2762b1f7e8 note to self about fun tzinfo to fix in a year
Jeff Hammel <k0scist@gmail.com>
parents: 667
diff changeset
9 http://bugs.python.org/issue7229
667
af95905ca177 STUB: python/epoch2date.py
Jeff Hammel <k0scist@gmail.com>
parents: 666
diff changeset
10 """
af95905ca177 STUB: python/epoch2date.py
Jeff Hammel <k0scist@gmail.com>
parents: 666
diff changeset
11
636
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
12 import argparse
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
13 import datetime
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
14 import os
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
15 import subprocess
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
16 import sys
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
17 import time
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
18
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
19 def main(args=sys.argv[1:]):
665
Jeff Hammel <k0scist@gmail.com>
parents: 636
diff changeset
20 """CLI"""
636
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
21
665
Jeff Hammel <k0scist@gmail.com>
parents: 636
diff changeset
22 # parse command line
636
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
23 parser = argparse.ArgumentParser(description=__doc__)
665
Jeff Hammel <k0scist@gmail.com>
parents: 636
diff changeset
24 parser.add_argument('seconds_since_epoch',
Jeff Hammel <k0scist@gmail.com>
parents: 636
diff changeset
25 type=float, nargs='?', default=time.time(),
Jeff Hammel <k0scist@gmail.com>
parents: 636
diff changeset
26 help="seconds since epoch input [DEFAULT: %(default)s]")
636
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
27 options = parser.parse_args(args)
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
28
665
Jeff Hammel <k0scist@gmail.com>
parents: 636
diff changeset
29 # produce a datetime
Jeff Hammel <k0scist@gmail.com>
parents: 636
diff changeset
30 dt = datetime.datetime.fromtimestamp(options.seconds_since_epoch)
Jeff Hammel <k0scist@gmail.com>
parents: 636
diff changeset
31 dt2 = datetime.datetime.utcfromtimestamp(options.seconds_since_epoch)
Jeff Hammel <k0scist@gmail.com>
parents: 636
diff changeset
32
Jeff Hammel <k0scist@gmail.com>
parents: 636
diff changeset
33 # output
666
fe6afbc1a38e STUB: python/epoch2date.py
Jeff Hammel <k0scist@gmail.com>
parents: 665
diff changeset
34 print ("{} seconds since epoch".format(options.seconds_since_epoch))
fe6afbc1a38e STUB: python/epoch2date.py
Jeff Hammel <k0scist@gmail.com>
parents: 665
diff changeset
35 print ("{} {}".format(dt, time.tzname[time.daylight]))
fe6afbc1a38e STUB: python/epoch2date.py
Jeff Hammel <k0scist@gmail.com>
parents: 665
diff changeset
36 print ("{} UTC".format(dt2))
636
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
37
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
38 if __name__ == '__main__':
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
39 main()