def main(args): if args.index("--") == len(args) - 4: unit = args[-1] args = args[:-1] else: unit = "seconds" sdate1 = args[-2] sdate2 = args[-1] args = args[:-3] try: optlist, rest = getopt.getopt(args, 'c:') except getopt.GetoptError as err: print str(err) # will print something like "option -a not recognized" usage() sys.exit(2) calendar_type = 1 for o, a in optlist: if o == "-c": calendar_type = int(a) else: assert False, "unhandled option" cal = esm_calendar.calendar(calendar_type) date1 = esm_calendar.date(sdate1, cal) date2 = esm_calendar.date(sdate2, cal) print date1.time_between(date2, unit)
def main(args): sdate = args[-1] if "--" in args: args = args[:-2] else: args = args[:-1] try: optlist, rest = getopt.getopt(args, 'f:hms') except getopt.GetoptError as err: print str(err) # will print something like "option -a not recognized" usage() sys.exit(2) calendar_type = 1 cal = esm_calendar.calendar(calendar_type) date = esm_calendar.date(sdate, cal) printhours = printminutes = printseconds = False for o, a in optlist: if o == "-f": form = int(a) elif o == "-h": printhours = True elif o == "-m": printminutes = True elif o == "-s": printseconds = True else: assert False, "unhandled option" date.output(form, printhours, printminutes, printseconds)
def main(args): sdate1 = args[-2] sdate2 = args[-1] if "--" in args: args = args[:-3] else: args = args[:-2] try: optlist, rest = getopt.getopt(args, 'c:') except getopt.GetoptError as err: print str(err) # will print something like "option -a not recognized" usage() sys.exit(2) calendar_type = 1 for o, a in optlist: if o == "-c": calendar_type = int(a) else: assert False, "unhandled option" cal = esm_calendar.calendar(calendar_type) date1 = esm_calendar.date(sdate1, cal) date2 = esm_calendar.date(sdate2, cal) if date1 >= date2: date1.output() else: date2.output()
def main(args): year=int(args[-1]) if "--" in args: args=args[:-2] else: args=args[:-1] try: optlist, rest = getopt.getopt(args, 'c:') except getopt.GetoptError as err: print str(err) # will print something like "option -a not recognized" usage() sys.exit(2) calendar_type=1 for o,a in optlist: if o == "-c": calendar_type = int(a) else: assert False, "unhandled option" cal=esm_calendar.calendar(calendar_type) print(cal.leapyear(year))
def main(args): command = args[0] sdate = args[-1] if "--" in args: args = args[1:-2] else: args = args[1:-1] try: optlist, rest = getopt.getopt(args, 'c:Y:M:D:h:m:s:') except getopt.GetoptError as err: print str(err) # will print something like "option -a not recognized" usage() sys.exit(2) add_sub = [0, 0, 0, 0, 0, 0] calendar_type = 1 for o, a in optlist: if o == "-c": calendar_type = int(a) elif o == "-Y": add_sub[0] = int(a) elif o == "-M": add_sub[1] = int(a) elif o == "-D": add_sub[2] = int(a) elif o == "-h": add_sub[3] = int(a) elif o == "-m": add_sub[4] = int(a) elif o == "-s": add_sub[5] = int(a) else: assert False, "unhandled option" cal = esm_calendar.calendar(calendar_type) date = esm_calendar.date(sdate, cal) if command == "plus": date.add(add_sub) elif command == "minus": date.sub(add_sub) date.output()