comparison python/epoch2date.py @ 676:1e1bed921c08

allow multiple date ranges and display of UTC only
author Jeff Hammel <k0scist@gmail.com>
date Thu, 08 May 2014 13:36:24 -0700
parents 1b8ea91f00a0
children 7c4ee496794c
comparison
equal deleted inserted replaced
675:f8813ed3d015 676:1e1bed921c08
31 """CLI""" 31 """CLI"""
32 32
33 # parse command line 33 # parse command line
34 parser = argparse.ArgumentParser(description=__doc__) 34 parser = argparse.ArgumentParser(description=__doc__)
35 parser.add_argument('seconds_since_epoch', 35 parser.add_argument('seconds_since_epoch',
36 type=float, nargs='?', default=time.time(), 36 type=float, nargs='*', default=time.time(),
37 help="seconds since epoch input [DEFAULT: %(default)s]") 37 help="seconds since epoch input [DEFAULT: %(default)s]")
38 parser.add_argument('--utc', dest='display_utc',
39 action='store_true', default=False,
40 help="display UTC time only")
38 options = parser.parse_args(args) 41 options = parser.parse_args(args)
39 42
40 # produce a datetime 43 if isinstance(options.seconds_since_epoch, float):
41 dt = datetime.datetime.fromtimestamp(options.seconds_since_epoch) 44 options.seconds_since_epoch = [ options.seconds_since_epoch ]
42 dt2 = datetime.datetime.utcfromtimestamp(options.seconds_since_epoch)
43 45
44 # output 46 for s in options.seconds_since_epoch:
45 print ("{} seconds since epoch".format(options.seconds_since_epoch)) 47
46 print ("{} {}".format(dt, time.tzname[time.daylight])) 48 # produce a datetime
47 print ("{} UTC".format(dt2)) 49 dt = datetime.datetime.fromtimestamp(s)
50 dt2 = datetime.datetime.utcfromtimestamp(s)
51
52 # output
53 if not options.display_utc:
54 print ("{} seconds since epoch".format(s))
55 print ("{} {}".format(dt, time.tzname[time.daylight]))
56 print ("{} UTC".format(dt2))
48 57
49 if __name__ == '__main__': 58 if __name__ == '__main__':
50 main() 59 main()