annotate python/epoch2date.py @ 666:fe6afbc1a38e

STUB: python/epoch2date.py
author Jeff Hammel <k0scist@gmail.com>
date Thu, 17 Apr 2014 12:56:25 -0700
parents 93afa559ce77
children af95905ca177
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
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
4 import argparse
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
5 import datetime
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
6 import os
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
7 import subprocess
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
8 import sys
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
9 import time
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
10
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
11 def main(args=sys.argv[1:]):
665
Jeff Hammel <k0scist@gmail.com>
parents: 636
diff changeset
12 """CLI"""
636
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
13
665
Jeff Hammel <k0scist@gmail.com>
parents: 636
diff changeset
14 # parse command line
636
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
15 parser = argparse.ArgumentParser(description=__doc__)
665
Jeff Hammel <k0scist@gmail.com>
parents: 636
diff changeset
16 parser.add_argument('seconds_since_epoch',
Jeff Hammel <k0scist@gmail.com>
parents: 636
diff changeset
17 type=float, nargs='?', default=time.time(),
Jeff Hammel <k0scist@gmail.com>
parents: 636
diff changeset
18 help="seconds since epoch input [DEFAULT: %(default)s]")
636
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
19 options = parser.parse_args(args)
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
20
665
Jeff Hammel <k0scist@gmail.com>
parents: 636
diff changeset
21 # produce a datetime
Jeff Hammel <k0scist@gmail.com>
parents: 636
diff changeset
22 dt = datetime.datetime.fromtimestamp(options.seconds_since_epoch)
Jeff Hammel <k0scist@gmail.com>
parents: 636
diff changeset
23 dt2 = datetime.datetime.utcfromtimestamp(options.seconds_since_epoch)
Jeff Hammel <k0scist@gmail.com>
parents: 636
diff changeset
24
Jeff Hammel <k0scist@gmail.com>
parents: 636
diff changeset
25 # output
666
fe6afbc1a38e STUB: python/epoch2date.py
Jeff Hammel <k0scist@gmail.com>
parents: 665
diff changeset
26 print ("{} seconds since epoch".format(options.seconds_since_epoch))
fe6afbc1a38e STUB: python/epoch2date.py
Jeff Hammel <k0scist@gmail.com>
parents: 665
diff changeset
27 print ("{} {}".format(dt, time.tzname[time.daylight]))
fe6afbc1a38e STUB: python/epoch2date.py
Jeff Hammel <k0scist@gmail.com>
parents: 665
diff changeset
28 print ("{} UTC".format(dt2))
636
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
29
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
30 if __name__ == '__main__':
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
31 main()