Mercurial > hg > config
changeset 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 | f8813ed3d015 |
children | f3c73873bcb5 |
files | python/epoch2date.py |
diffstat | 1 files changed, 17 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/python/epoch2date.py Tue May 06 15:18:40 2014 -0700 +++ b/python/epoch2date.py Thu May 08 13:36:24 2014 -0700 @@ -33,18 +33,27 @@ # parse command line parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('seconds_since_epoch', - type=float, nargs='?', default=time.time(), + type=float, nargs='*', default=time.time(), help="seconds since epoch input [DEFAULT: %(default)s]") + parser.add_argument('--utc', dest='display_utc', + action='store_true', default=False, + help="display UTC time only") options = parser.parse_args(args) - # produce a datetime - dt = datetime.datetime.fromtimestamp(options.seconds_since_epoch) - dt2 = datetime.datetime.utcfromtimestamp(options.seconds_since_epoch) + if isinstance(options.seconds_since_epoch, float): + options.seconds_since_epoch = [ options.seconds_since_epoch ] + + for s in options.seconds_since_epoch: - # output - print ("{} seconds since epoch".format(options.seconds_since_epoch)) - print ("{} {}".format(dt, time.tzname[time.daylight])) - print ("{} UTC".format(dt2)) + # produce a datetime + dt = datetime.datetime.fromtimestamp(s) + dt2 = datetime.datetime.utcfromtimestamp(s) + + # output + if not options.display_utc: + print ("{} seconds since epoch".format(s)) + print ("{} {}".format(dt, time.tzname[time.daylight])) + print ("{} UTC".format(dt2)) if __name__ == '__main__': main()