PK ~FF9 !// gtimes-0.1.data/scripts/timecalc#!/usr/bin/python # ############################### # # timecalc 0.7 # Code made by bgo@vedur.is # Iceland Met Office # 2015 # # ############################### """ In this program are the following functions in order: datestr(string): main(): """ import gtimes.timefunc as timefunc import gtimes.gpstime as gpstime import argparse, datetime #------------------------------------------------------------ def datestr(string): """ Formating check for -d option """ if type(string) != datetime.datetime: # more to contitions to come msg = "%r is not correctly formated" % string raise argparse.ArgumentTypeError(msg) return string def main(): """ command line script for general time and date calculations. can handle obscure GPS time formating. run: timecalc -h for help """ # date to use defaults to today ---- dstr="%Y-%m-%d" # Default input string outpstr="%a, %d. %b %Y" # Default output string #sday=datetime.date.today().strftime(dstr) sday=datetime.datetime.utcnow() dD_parser = argparse.ArgumentParser(description="Time conversion program",add_help=False) dD_parser.add_argument("-D", default=0, nargs='?', const=1, type=int, help="Number of days to shift the given day positive subracts, negativ adds" ) dD_parser.add_argument("-d", default=sday, help="Input date. The default format is ""%%Y-%%m-%%m""." + " The format can be modifed through the -f flag") dD_parser.add_argument("-f", default=dstr, type=str, help="Format of the string passed to -d. If absent, -d defaults to ""%%Y-%%m-%%-%%m""." + " Special formating: ""yearf"" -> fractional year ""w-dow"" -> GPS Week-Day of Week." + " See datetime documentation for formating") # parse what has -d, -f and -D to use as input for other options args, remaining_argv = dD_parser.parse_known_args() dstr=args.f # dealing with the input format. day = timefunc.toDatetime(args.d,args.f) day=day-datetime.timedelta(args.D) # applying the Day offset #---------------------------------------- parser= argparse.ArgumentParser(parents=[dD_parser],description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter,) # Year flag ------------------- group = parser.add_mutually_exclusive_group() group.add_argument("-o", type=str, help=" Output format for general formatting defaults to ""%%a, %%d. %%b %%Y""." + " See datetime documentation for the formating." + " for special formatting see other arguments") group.add_argument("-p", type=str, help="Second input date, will calculate the number of days between the input date from -d (or today) and the date given with -p." + "The default format is ""%%Y-%%m-%%m""." + " The format can be modifed through the -f flag") group.add_argument("-y", type=int, nargs='?', const=timefunc.shlyear(yyyy=day.year,change=True ), help= "Returns the Year in ""YYYY"" form. Special case: If the year is passed directly to -y it is converted to two/four digit form," + "depending on the input.") group.add_argument("-yy", action="store_true", help="Returns the Year from -d in two digit form (""YY""). " + "Current year is returned in two digit form if -d is omitted") group.add_argument("-yf", action="store_const", const=day, help="Return date from -d as fractional year. " + "Current date is returned if -d omitted") # flags for different output group.add_argument("-t", action="store_const", const=day, help= "Return a space seperated string of " + " (year, month, day of month, day of year, fractional year, GPS week, day of week sunday = 0 ... 6 = saturday) -> " + "(YYYY MM DD DOY YYYY.ddd WWWW DOW) ") group.add_argument("-j", action="store_const", const=day, help="Return the day of year") group.add_argument("-ny", action="store_const", const=day, help="Return the number of days in thye year") group.add_argument("-w", "--week", action="store_const", const=day, help="Return GPS week") group.add_argument("-u", "--dayofw", action="store_const", const=day, help="Return day of GPS week sunday = 0 ... 6 = saturday ") group.add_argument("-wd","--weekday", action="store_const", const=day, help="Return GPS week and day of GPS week sunday = 0 ... 6 = saturday ") group.add_argument("-i","--datet", action="store_const", const=day, help="Returns the calendar date and time") args = parser.parse_args(args=remaining_argv) #------------------------------ # printing out stuff depending on args if args.y != None: print timefunc.shlyear(yyyy=args.y,change=True) elif args.ny: print timefunc.DaysinYear(day.year) elif args.yy: print timefunc.shlyear(yyyy=day.year,change=True) elif args.yf: print timefunc.currYearfDate(refday=day) elif args.j: print timefunc.currDate(refday=args.j,string="%j") elif args.week: print timefunc.gpsWeekDay(refday=args.week)[0] elif args.dayofw: print timefunc.gpsWeekDay(refday=args.dayofw)[1] elif args.weekday: print "%d %03d" % timefunc.gpsWeekDay(refday=args.weekday) elif args.datet: print day.isoformat() elif args.t: print "%d %02d %02d %03d %4.5f %04d %d %d %02d %s" % timefunc.dateTuple(refday=args.t) elif args.o: print day.strftime(args.o) elif args.p: # dealing with the input format. day1 = timefunc.toDatetime(args.p,dstr) if dstr == "yearf": print (day - day1) else: print (day - day1).days else: print day.strftime(outpstr) if __name__=="__main__": main() PKp~ŠE(åØ88gtimes/__init__.py__import__('pkg_resources').declare_namespace(__name__) PKp~ŠEÏLkëê ê gtimes/gpstime.py""" A Python implementation of GPS related time conversions. Copyright 2002 by Bud P. Bruegger, Sistema, Italy mailto:bud@sistema.it http://www.sistema.it Modifications for GPS seconds by Duncan Brown PyUTCFromGpsSeconds added by Ben Johnson This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA GPS Time Utility functions This file contains a Python implementation of GPS related time conversions. The two main functions convert between UTC and GPS time (GPS-week, time of week in seconds, GPS-day, time of day in seconds). The other functions are convenience wrappers around these base functions. A good reference for GPS time issues is: http://www.oc.nps.navy.mil/~jclynch/timsys.html Note that python time types are represented in seconds since (a platform dependent Python) Epoch. This makes implementation quite straight forward as compared to some algorigthms found in the literature and on the web. """ __author__ = 'Benedikt G. Ofeigsson edited from Duncan Brown ' __date__ = '$Date: 2012/03/6' __version__ = '$Revision: 1.6 $'[11:-2] # $Source: /usr/local/cvs/lscsoft/glue/glue/gpstime.py,v $ import time, math, calendar, datetime, pytz from dateutil.tz import tzlocal secsInWeek = 604800 secsInDay = 86400 gpsEpoch = (1980, 1, 6, 0, 0, 0) # (year, month, day, hh, mm, ss) def dayOfWeek(year, month, day): """ Returns day of week: 0=Sun, 1=Mon, .., 6=Sat """ hr = 12 #make sure you fall into right day, middle is save t = time.mktime((year, month, day, hr, 0, 0, 0, 0, -1)) pyDow = time.localtime(t)[6] gpsDow = (pyDow + 1) % 7 return gpsDow def gpsWeek(year, month, day): """ Returns (full) gpsWeek for given date (in UTC) """ hr = 12 #make sure you fall into right day, middle is save return gpsFromUTC(year, month, day, hr, 0, 0)[0] def julianDay(year, month, day): "returns julian day=day since Jan 1 of year" hr = 12 #make sure you fall into right day, middle is save t = time.mktime((year, month, day, hr, 0, 0.0, 0, 0, -1)) julDay = time.localtime(t)[7] return julDay def mkUTC(year, month, day, hour, min, sec): """ Similar to python's mktime but for utc """ spec = [year, month, day, hour, min, sec] + [0, 0, 0] utc = time.mktime(spec) - time.timezone return utc def ymdhmsFromPyUTC(pyUTC): """ Returns tuple from a python time value in UTC """ ymdhmsXXX = time.gmtime(pyUTC) return ymdhmsXXX[:-3] def wtFromUTCpy(pyUTC, leapSecs=16): """ Convenience function: BGO 07.01.2013: changed the default leapsecond to 16 allows to use python UTC times and returns only week and tow""" ymdhms = ymdhmsFromPyUTC(pyUTC) wSowDSoD = apply(gpsFromUTC, ymdhms + (leapSecs,)) return wSowDSoD[0:2] def gpsFromUTC(year, month, day, hour, min, sec, leapSecs=16): """ Converts UTC to: gpsWeek, secsOfWeek, gpsDay, secsOfDay a good reference is: http://www.oc.nps.navy.mil/~jclynch/timsys.html This is based on the following facts (see reference above): GPS time is basically measured in (atomic) seconds since January 6, 1980, 00:00:00.0 (the GPS Epoch) The GPS week starts on Saturday midnight (Sunday morning), and runs for 604800 seconds. Currently, GPS time is 13 seconds ahead of UTC (see above reference). While GPS SVs transmit this difference and the date when another leap second takes effect, the use of leap seconds cannot be predicted. This routine is precise until the next leap second is introduced and has to be updated after that. BGO 07.01.2013: changed the default leapsecond to 16 SOW = Seconds of Week SOD = Seconds of Day Note: Python represents time in integer seconds, fractions are lost!!! """ secFract = sec % 1 epochTuple = gpsEpoch + (-1, -1, 0) t0 = time.mktime(epochTuple) t = time.mktime((year, month, day, hour, min, sec, -1, -1, 0)) # Note: time.mktime strictly works in localtime and to yield UTC, it should be # corrected with time.timezone # However, since we use the difference, this correction is unnecessary. # Warning: trouble if daylight savings flag is set to -1 or 1 !!! t = t + leapSecs tdiff = t - t0 gpsSOW = (tdiff % secsInWeek) + secFract gpsWeek = int(math.floor(tdiff/secsInWeek)) gpsDay = int(math.floor(gpsSOW/secsInDay)) gpsSOD = (gpsSOW % secsInDay) return (gpsWeek, gpsSOW, gpsDay, gpsSOD) def UTCFromGps(gpsWeek, SOW, leapSecs=16): """ Converts gps week and seconds to UTC BGO 07.01.2013: changed the default leapsecond to 16 see comments of inverse function! SOW = seconds of week gpsWeek is the full number (not modulo 1024) """ secFract = SOW % 1 epochTuple = gpsEpoch + (-1, -1, 0) t0 = time.mktime(epochTuple) - time.timezone #mktime is localtime, correct for UTC tdiff = (gpsWeek * secsInWeek) + SOW - leapSecs t = t0 + tdiff (year, month, day, hh, mm, ss, dayOfWeek, julianDay, daylightsaving) = time.gmtime(t) #use gmtime since localtime does not allow to switch off daylighsavings correction!!! return (year, month, day, hh, mm, ss + secFract) def GpsSecondsFromPyUTC( pyUTC, leapSecs=16 ): """ Converts the python epoch to gps seconds BGO 07.01.2013: changed the default leapsecond to 16 pyEpoch = the python epoch from time.time() """ t = t=gpsFromUTC(*ymdhmsFromPyUTC( pyUTC )) return int(t[0] * 60 * 60 * 24 * 7 + t[1]) def PyUTCFromGpsSeconds(gpsseconds): """ Converts gps seconds to the python epoch. That is, the time that would be returned from time.time() at gpsseconds. """ pyUTC #def gpsTimeFromUTC() #===== Tests ========================================= def testTimeStuff(): print "-"*20 print print "The GPS Epoch when everything began (1980, 1, 6, 0, 0, 0, leapSecs=0)" (w, sow, d, sod) = gpsFromUTC(1980, 1, 6, 0, 0, 0, leapSecs=0) print "**** week: %s, sow: %s, day: %s, sod: %s" % (w, sow, d, sod) print " and hopefully back:" print "**** %s, %s, %s, %s, %s, %s\n" % UTCFromGps(w, sow, leapSecs=0) print "The time of first Rollover of GPS week (1999, 8, 21, 23, 59, 47)" (w, sow, d, sod) = gpsFromUTC(1999, 8, 21, 23, 59, 47) print "**** week: %s, sow: %s, day: %s, sod: %s" % (w, sow, d, sod) print " and hopefully back:" print "**** %s, %s, %s, %s, %s, %s\n" % UTCFromGps(w, sow, leapSecs=14) print "Today is GPS week 1186, day 3, seems to run ok (2002, 10, 2, 12, 6, 13.56)" (w, sow, d, sod) = gpsFromUTC(2002, 10, 2, 12, 6, 13.56) print "**** week: %s, sow: %s, day: %s, sod: %s" % (w, sow, d, sod) print " and hopefully back:" print "**** %s, %s, %s, %s, %s, %s\n" % UTCFromGps(w, sow) def testJulD(): print '2002, 10, 11 -> 284 ==??== ', julianDay(2002, 10, 11) def testGpsWeek(): print '2002, 10, 11 -> 1187 ==??== ', gpsWeek(2002, 10, 11) def testDayOfWeek(): print '2002, 10, 12 -> 6 ==??== ', dayOfWeek(2002, 10, 12) print '2002, 10, 6 -> 0 ==??== ', dayOfWeek(2002, 10, 6) def testPyUtilties(): ymdhms = (2002, 10, 12, 8, 34, 12.3) print "testing for: ", ymdhms pyUtc = apply(mkUTC, ymdhms) back = ymdhmsFromPyUTC(pyUtc) print "yields : ", back #*********************** !!!!!!!! #assert(ymdhms == back) #! TODO: this works only with int seconds!!! fix!!! (w, t) = wtFromUTCpy(pyUtc) print "week and time: ", (w,t) #===== Main ========================================= if __name__ == "__main__": pass testTimeStuff() testGpsWeek() testJulD() testDayOfWeek() testPyUtilties() PK"K4H)êjd5d5gtimes/timefunc.py#!/usr/bin/python # ############################### # # timefunc.py 0.7 # Code made by bgo@vedur.is # Iceland Met Office # 2015 # # ############################### """ In this program are the following functions in order: TimetoYearf(year, month, day, hour=12, minute=0, sec=0): TimefromYearf(yearf, string=None): currDatetime(days=0,refday=datetime.datetime.today(),string=None): currDate(days=0,refday=datetime.datetime.today(),string=None,fromYearf=False): gpsWeekDay( days=0, refday=currDate() , fromYearf=False): currTime(string): DayofYear(days=0, year=None, month=None, day=None): DaysinYear( year=None ): yearDoy(yearf): currYearfDate( days=0, refday=datetime.date.today(), fromYearf=True ): currYear(): shlyear(yyyy=currYear(),change=True): dateTuple(days=0,refday=datetime.datetime.today(),string=None,fromYearf=False): datefgpsWeekDOW(gpsWeek,DOW,string=None,leapSecs=16): datefgpsWeekDoy(gpsWeek,Doy,string=None,leapSecs=16): toDatetime(dStr,fStr): _to_ordinalf(dt): """ import time, math, calendar, datetime, pytz import numpy as np #importing constants from gpstime. from gtimes.gpstime import secsInWeek, secsInDay, gpsEpoch, gpsFromUTC, UTCFromGps from dateutil.tz import tzlocal # Core functions --------------------------- def TimetoYearf(year, month, day, hour=12, minute=0, sec=0): """ converts time cal+time of day into fractional year. input: date: as year, month, day time: as hour, minute, sec (defaults to the middle of the day at 12 am) output: returns fractional year """ doy = DayofYear(0,year, month, day)-1 secofyear=doy*secsInDay + ( hour*60+minute )*60 + sec daysinyear=DaysinYear(year) secinyear=daysinyear*secsInDay yearf = year+secofyear/float(secinyear) return yearf def TimefromYearf(yearf, string=None): """ Returns a date and/or time according to a formated string derived from a fractional year. Intended to manipulate time format of gamit time series files which is in fractional years. Input: string: formated according to format codes that the C standard (1989 version) see documentation for datetime module. Example "%Y %m %d %H:%M:%S %f" year: fractional year. example 2012.55 Output: Returns time of the input year formated according to input string. """ # to integer year year = int(math.floor(yearf)) # converting to doy, hour, min, sec, microsec daysinyear = DaysinYear(year) dayf = (yearf-year)*daysinyear+1 doy = int(math.floor(dayf)) # day of year) fofday = dayf-doy Hour = int(math.floor( (fofday)*24)) # hour of day Min = int(math.floor( (fofday)*24*60 % 60)) # minute of hour fsec = fofday*24*60*60 % 60 Sec = int(math.floor(fsec)) # second of minute musec = int(math.floor((fsec-Sec)*1000000)) # microsecond 0 - 1000000 timestr = "%d %.3d %.2d:%.2d:%.2d %s" % (year,doy,Hour,Min,Sec,musec) dt = datetime.datetime.strptime( timestr , "%Y %j %H:%M:%S %f") # Create datetime object from timestr if string: if string == "ordinalf": # return a floating point ordinal day return dt.toordinal()+fofday else: return dt.strftime(string) else: # just return the datetime instanse return dt def currDatetime(days=0,refday=datetime.datetime.today(),string=None): """ Returns a datetime object for the date, "days" from refday. Input: days: integer, Defaults to 0 days to offset refday: datetime object or a string, defaults to datetime.datetime.today() reference day string: formating string. defaults to None (infering refday as datetime object) If refday is a date string, this has to contain it's formating (i.e %Y-%m-%d %H:%M) Output: returns a datetime object defaults to current day if ran without arguments """ day = refday + datetime.timedelta(days) if string: return day.strftime(string) else: return day def currDate(days=0,refday=datetime.date.today(),string=None,fromYearf=False): """ Returns a datetime object for the date, "days" from today. Defaults to current day """ if fromYearf and type(refday) == float or type(refday) == int: refday = TimefromYearf(refday) day = refday + datetime.timedelta(days) if string == "yearf": return TimetoYearf(*day.timetuple()[0:3]) elif string: return day.strftime(string) else: return day def gpsWeekDay( days=0, refday=currDate() , fromYearf=False): """ Returns tuple gps Week and day of Week """ if fromYearf: print refday refday = TimefromYearf(refday,) print refday refday = refday + datetime.timedelta(days) tmp = refday.timetuple()[0:3] return gpsFromUTC(*tmp,hour=12,min=0,sec=0)[0:3:2] ############################################ # derived functions def currTime(string): """ Returns the current UTC time in a format determent by string input: string: A string determinaning the outpur format of the current time formated according to format codes that the C standard (1989 version) requires, see documentation for datetime module. Example Example, string = "%Y %j %H:%M:%S %f" -> '2013 060 16:03:54 970424' See datetime documentation for details output: Returns the current time formated according to input string. """ return datetime.datetime.now(tzlocal()).strftime(string) def DayofYear(days=0, year=None, month=None, day=None): """ Returns the day of year, "days" (defaults to 0) relative to the date given i.e. (year,month,day) (defaults to today) No argument returns the day of today input: days: Day relative to (year,month,day) or today if (year,month,day) not given year: Four digit year "yyyy". Example 2013 month: Month in integer from 1-12 day: Day of month as integer 1-(28-31) depending on month output: doy: Integer containing day of year. Exampls (2013,1,3) -> 60 spans 1 -365(366 if leap year) """ if year and month and day: nday = datetime.date(year,month,day)+datetime.timedelta(days) doy = nday.timetuple()[7] else: nday = datetime.date.today() + datetime.timedelta(days) doy = nday.timetuple()[7] return doy def DaysinYear( year=None ): """ Returns the last day of year 365 or 366, (defaults to current year) input: year: Integer or floating point year (defaults to current year) out: daysinyear: Returns and integer value, the last day of the year 365 or 366 """ if year == None: # defaults to current year year=datetime.date.today().year year = np.int_(np.floor(year)) # allow for floating point year daysinyear = 366 if calendar.isleap(year) else 365 #checking if it is leap year and assigning the correct day number return daysinyear def yearDoy(yearf): """ simple wrapper that calls TimefromYearf, to return a date in the form "year-doyT" from fractional year. convinient for fancy time labels in GMT hence the T. """ return TimefromYearf(yearf,"%Y-%jT",) def currYearfDate( days=0, refday=datetime.date.today(), fromYearf=True ): """ Wrapper for currDate() to return the date, "days" from "refday" in decimal year, defaults to current day """ return currDate(days=days,refday=refday,string="yearf",fromYearf=fromYearf) def currYear(): """ Current year in YYYY """ return datetime.date.today().year def shlyear(yyyy=currYear(),change=True): """ Changes a year from two digit format to four and wize versa. input: YYYY: Year in YYYY or YY (defaults to current year) change: True of False convinies in case we want to pass YYYY unchanged through the function output: Year converterded from two->four or four->two digit form. returns current year in two digit form in the apsence of input """ if len(str(abs(yyyy))) == 4 and change == True: yyyy = datetime.datetime.strptime(str(yyyy),"%Y") return yyyy.strftime("%y") elif len(str(abs(yyyy))) <= 2 and change == True: yyyy = datetime.datetime.strptime("%02d" % yyyy,"%y") return yyyy.strftime("%Y") elif change == False: return yyyy def dateTuple(days=0,refday=datetime.datetime.today(),string=None,fromYearf=False): """ Return tuple with different elements of a given date (year, month, day of month, day of year, fractional year, gps week, gps day of week) """ #(Week,dow) = gpsWeekDay(days,refday,fromYearf) day=currDatetime(days,refday,None) month=day.strftime("%b") day=day.timetuple() return day[0:3] + day[7:8] + (currYearfDate(days,refday),) + gpsWeekDay(days,refday,fromYearf) + (int(str(day[0])[-1]),) + (int(shlyear(day[0])),) + (month,) # Temporary functions to deal with numpy arrays Will become apsolete when implementd directly in the main moduvls def convfromYearf(yearf, string=None): # from floating point year to floating point ordinal import numpy as np tmp = range(len(yearf)) for i in range(len(yearf)): if string: tmp[i] = TimefromYearf(yearf[i],string) else: tmp[i] = (TimefromYearf(yearf[i])) return np.asarray(tmp) # functions using gps week and day of week ---------------- def datefgpsWeekDOW(gpsWeek,DOW,string=None,leapSecs=16): """ Return date converted from GPS Week and Day of week """ SOW = (DOW+1) * secsInDay day=datetime.datetime(*UTCFromGps(gpsWeek, SOW,leapSecs=leapSecs)[0:3]) if string == "yearf": return TimetoYearf(*day.timetuple()[0:3]) elif string == "tuple": return day.timetuple()[0:3] elif string: return day.strftime(string) else: return day def datefgpsWeekDoy(gpsWeek,Doy,string=None,leapSecs=16): """ Return date converted from GPS Week and Day of year """ SOW = 1 * secsInDay day=datetime.datetimes(*UTCFromGps(gpsWeek, SOW,leapSecs=leapSecs)[0:3]) doy0 = day.timetuple()[7] if doy0 <= Doy < doy0 + 7: DOW = Doy - doy0 day = day + datetime.timedelta(DOW) else: print "ERROR: Doy %s not in week %s returning date of day 0 in week %s" % (Doy, gpsWeek, gpsWeek) if string == "yearf": return TimetoYearf(*day.timetuple()[0:3]) elif string == "tuple": return day.timetuple()[0:3] elif string: return day.strftime(string) else: return day def toDatetime(dStr,fStr): """ Convert date/time strings to datetime objects accorting to formating rule defined in fStr input: dStr: (list of) string(s) holding a date and/or time fStr: formating rule constituding the following input formats default: fStr formated according to standard rules see for example datetime documentation for formating (i.e dStr=20150120 entailes fStr=%Y%m%d ) yearf: decimal year w-dow: GPS week and day of week on the form WWWW-DOW (example 1820-3, where DOW is sunday = 0 ... 6 = saturday) w-doy: GPS week and day of year on the form WWWW-DOY output: returns datetime object. """ if type(dStr) == datetime.datetime: day=dStr elif fStr == "yearf": day=TimefromYearf(float(dStr)) elif fStr == "w-dow": wdow=tuple([int(i) for i in dStr.split("-")]) day=timefunc.datefgpsWeekDOW(*wdow) elif fStr == "w-doy": wdoy=tuple([int(i) for i in dStr.split("-")]) day=timefunc.datefgpsWeekDoy(*wdoy) else: day=datetime.datetime.strptime(dStr,fStr) #returning datetime object return day def toDatetimel(dStrlist,fStr): """ A simple wrapper around toDatetime to allow for list input works like toDatetime if dStrlist is a single object. input: dStr: (list of) string(s) holding a date and/or time fStr: See docstring of toDatetime output: returns a list of datetime objects. """ # To allow for single object input as well, otherwise python will treat a string as a list in the for loop if type(dStrlist) is not list: dStrlist = [ dStrlist ] dStrlist = [ toDatetime(dStr,fStr) for dStr in dStrlist ] # converting to a list of datetime strings if len(dStrlist) == 1: # toDatetime can be replaced by toDatetime return dStrlist[0] else: return dStrlist HOURS_PER_DAY = 24. MINUTES_PER_DAY = 60.*HOURS_PER_DAY SECONDS_PER_DAY = 60.*MINUTES_PER_DAY MUSECONDS_PER_DAY = 1e6*SECONDS_PER_DAY SEC_PER_MIN = 60 SEC_PER_HOUR = 3600 SEC_PER_DAY = SEC_PER_HOUR * 24 SEC_PER_WEEK = SEC_PER_DAY * 7 def _to_ordinalf(dt): """ Convert :mod:`datetime` to the Gregorian date as UTC float days, preserving hours, minutes, seconds and microseconds. Return value is a :func:`float`. """ if hasattr(dt, 'tzinfo') and dt.tzinfo is not None: delta = dt.tzinfo.utcoffset(dt) if delta is not None: dt -= delta base = float(dt.toordinal()) if hasattr(dt, 'hour'): base += (dt.hour/HOURS_PER_DAY + dt.minute/MINUTES_PER_DAY + dt.second/SECONDS_PER_DAY + dt.microsecond/MUSECONDS_PER_DAY ) return base PK´bH^-Ò $gtimes-0.1.dist-info/DESCRIPTION.rstUNKNOWN PK´bHÔ‘zK¸¸"gtimes-0.1.dist-info/metadata.json{"extensions": {"python.details": {"contacts": [{"email": "bgo@vedur.is", "name": "Benedikt G. Ofeigsson", "role": "author"}], "document_names": {"description": "DESCRIPTION.rst"}, "project_urls": {"Home": "http://github.com/imo/gtimes"}}}, "generator": "bdist_wheel (0.26.0)", "license": "Icelandic Met Office", "metadata_version": "2.0", "name": "gtimes", "summary": "Time and date modules capable of handling GPS time", "version": "0.1"}PK´bHÀ{´"gtimes-0.1.dist-info/top_level.txtgtimes PK´bHŒ''\\gtimes-0.1.dist-info/WHEELWheel-Version: 1.0 Generator: bdist_wheel (0.26.0) Root-Is-Purelib: true Tag: py2-none-any PK´bHªûpÈgtimes-0.1.dist-info/METADATAMetadata-Version: 2.0 Name: gtimes Version: 0.1 Summary: Time and date modules capable of handling GPS time Home-page: http://github.com/imo/gtimes Author: Benedikt G. Ofeigsson Author-email: bgo@vedur.is License: Icelandic Met Office Platform: UNKNOWN UNKNOWN PK´bHò†¨gtimes-0.1.dist-info/RECORDgtimes/__init__.py,sha256=G-d438vPx7m_ks5e9XTtM3u7LDRO5dSSukibukWmyPM,56 gtimes/gpstime.py,sha256=o6RH8lLF7l5kTJ4WPH7Q_vNa-Cz9uwOsXYPjwYs_QrM,8426 gtimes/timefunc.py,sha256=4dY6Gbuv_xS_KpSSRg3iOnD5fBj6oD2r_zHST7YeU0o,13668 gtimes-0.1.data/scripts/timecalc,sha256=oor6kg2EOHPyqro7Ndw8BmVm_6qMVwYZFCQ-LS2-JVQ,5935 gtimes-0.1.dist-info/DESCRIPTION.rst,sha256=OCTuuN6LcWulhHS3d5rfjdsQtW22n7HENFRh6jC6ego,10 gtimes-0.1.dist-info/METADATA,sha256=K7cz-m7UcogDxqZZy7zcGv730t1LHOwjdAgpnSE0CGY,264 gtimes-0.1.dist-info/RECORD,, gtimes-0.1.dist-info/WHEEL,sha256=JTb7YztR8fkPg6aSjc571Q4eiVHCwmUDlX8PhuuqIIE,92 gtimes-0.1.dist-info/metadata.json,sha256=Scxeq_jlGByxiMWfbMcBlhtBNO8Q9lJonTbkFgyFdR8,440 gtimes-0.1.dist-info/top_level.txt,sha256=oLF8cE55mMdh2HQXUtcSuWlFrQDXrdfW8b-N7UTWmt8,7 PK ~FF9 !// gtimes-0.1.data/scripts/timecalcPKp~ŠE(åØ88mgtimes/__init__.pyPKp~ŠEÏLkëê ê Õgtimes/gpstime.pyPK"K4H)êjd5d5î8gtimes/timefunc.pyPK´bH^-Ò $‚ngtimes-0.1.dist-info/DESCRIPTION.rstPK´bHÔ‘zK¸¸"Îngtimes-0.1.dist-info/metadata.jsonPK´bHÀ{´"Æpgtimes-0.1.dist-info/top_level.txtPK´bHŒ''\\ qgtimes-0.1.dist-info/WHEELPK´bHªûpÈ¡qgtimes-0.1.dist-info/METADATAPK´bHò†¨ärgtimes-0.1.dist-info/RECORDPK Û0v