annotate python/epoch2date.py @ 672:0eff3f3658ed

STUB: python/mountusb.py
author Jeff Hammel <k0scist@gmail.com>
date Mon, 05 May 2014 01:47:27 -0700
parents bcf5781b615e
children 1b8ea91f00a0
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
667
af95905ca177 STUB: python/epoch2date.py
Jeff Hammel <k0scist@gmail.com>
parents: 666
diff changeset
9 """
af95905ca177 STUB: python/epoch2date.py
Jeff Hammel <k0scist@gmail.com>
parents: 666
diff changeset
10
669
bcf5781b615e STUB: python/epoch2date.py
Jeff Hammel <k0scist@gmail.com>
parents: 668
diff changeset
11 # TODO: tz info
bcf5781b615e STUB: python/epoch2date.py
Jeff Hammel <k0scist@gmail.com>
parents: 668
diff changeset
12 #http://bugs.python.org/issue7229
bcf5781b615e STUB: python/epoch2date.py
Jeff Hammel <k0scist@gmail.com>
parents: 668
diff changeset
13 # http://stackoverflow.com/questions/13218506/how-to-get-system-timezone-setting-and-pass-it-to-pytz-timezone
bcf5781b615e STUB: python/epoch2date.py
Jeff Hammel <k0scist@gmail.com>
parents: 668
diff changeset
14
bcf5781b615e STUB: python/epoch2date.py
Jeff Hammel <k0scist@gmail.com>
parents: 668
diff changeset
15
636
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
16 import argparse
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
17 import datetime
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
18 import os
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
19 import subprocess
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
20 import sys
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
21 import time
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
22
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
23 def main(args=sys.argv[1:]):
665
Jeff Hammel <k0scist@gmail.com>
parents: 636
diff changeset
24 """CLI"""
636
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
25
665
Jeff Hammel <k0scist@gmail.com>
parents: 636
diff changeset
26 # parse command line
636
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
27 parser = argparse.ArgumentParser(description=__doc__)
665
Jeff Hammel <k0scist@gmail.com>
parents: 636
diff changeset
28 parser.add_argument('seconds_since_epoch',
Jeff Hammel <k0scist@gmail.com>
parents: 636
diff changeset
29 type=float, nargs='?', default=time.time(),
Jeff Hammel <k0scist@gmail.com>
parents: 636
diff changeset
30 help="seconds since epoch input [DEFAULT: %(default)s]")
636
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
31 options = parser.parse_args(args)
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
32
665
Jeff Hammel <k0scist@gmail.com>
parents: 636
diff changeset
33 # produce a datetime
Jeff Hammel <k0scist@gmail.com>
parents: 636
diff changeset
34 dt = datetime.datetime.fromtimestamp(options.seconds_since_epoch)
Jeff Hammel <k0scist@gmail.com>
parents: 636
diff changeset
35 dt2 = datetime.datetime.utcfromtimestamp(options.seconds_since_epoch)
Jeff Hammel <k0scist@gmail.com>
parents: 636
diff changeset
36
Jeff Hammel <k0scist@gmail.com>
parents: 636
diff changeset
37 # output
666
fe6afbc1a38e STUB: python/epoch2date.py
Jeff Hammel <k0scist@gmail.com>
parents: 665
diff changeset
38 print ("{} seconds since epoch".format(options.seconds_since_epoch))
fe6afbc1a38e STUB: python/epoch2date.py
Jeff Hammel <k0scist@gmail.com>
parents: 665
diff changeset
39 print ("{} {}".format(dt, time.tzname[time.daylight]))
fe6afbc1a38e STUB: python/epoch2date.py
Jeff Hammel <k0scist@gmail.com>
parents: 665
diff changeset
40 print ("{} UTC".format(dt2))
636
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
41
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
42 if __name__ == '__main__':
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
43 main()