pst, pdt time 변환 업데이트

less than 1 minute read

역시 요구사항은 변화한다.

pst, pdt를 옵션에 따라 변환해 볼 수 있도록 다시 한 번 변경해보았다.

#!/usr/bin/python


import optparse
from datetime import datetime, timedelta

def main():
        p = optparse.OptionParser()
        p.add_option('--type', '-t', default="pdt")
        p.add_option('--time', '-i')
        options, arguments = p.parse_args()

        # check time type whether it is pst or pdt
        if options.type in ['pst', 'PST'] :
                hours_gap = timedelta(hours = 17)
        else :
                hours_gap = timedelta(hours = 16)

        # get time value from user
        if options.time == None :
                time = raw_input('Enter %s time in yyyymmddHHMMSS : ' % options.type)
        else :
                time = options.time

        # get converted time
        pxt_time = datetime.strptime(time, "%Y%m%d%H%M%S")
        converted_time = pxt_time + hours_gap

        print 'converted time(%s) : %s' % (options.type, converted_time)

if __name__ == '__main__':
        main()

Leave a Comment