Ejemplo n.º 1
0
def convert_time(newtime, lasttime):
    """
    timeout=convert_time(newtime, lasttime)
    converts the timestring given in newtime to a time in GPSseconds, return as timeout
    lasttime is the last time return, used for increments
    formats for newtime::

      ++dt                 - increments lasttime by dt seconds
      yyyy-mm-dd,hh:mm:ss  - UT date/time
      t                    - GPS seconds


    :param newtime: new time to parse
    :param lasttime: previous time passed, used for parsing increments
    :return: GPStime

    """
    
    timeout=0
    if not isinstance(newtime,str):
        return newtime
    if (newtime.startswith('++')):
        try:
            dt_string=newtime.replace('++','')
            if (dt_string.count('s')):
                # seconds
                dt=int(dt_string.replace('s',''))
            elif (dt_string.count('m')):
                # minutes
                dt=int(60*float(dt_string.replace('m','')))
            elif (dt_string.count('h')):
                # hours
                dt=int(3600*float(dt_string.replace('h','')))
            else:
                # assume seconds
                dt=int(dt_string)
        except ValueError:
            logging.warn('Unable to interpret time increment: %s' % newtime)
            return timeout
        timeout=ephem_utils.GPSseconds_next(lasttime+dt-8)
    elif (newtime.count(':')>0):
        try:
            [date,tm]=newtime.split(',')
            [yr,mn,dy]=date.split('-')
            UT=ephem_utils.sexstring2dec(tm)
            MJD=ephem_utils.cal_mjd(int(yr),int(mn),int(dy))
            timeout=ephem_utils.GPSseconds_next(ephem_utils.calcGPSseconds(MJD,UT)-8)
        except:
            logging.warn('Unable to interpret timestamp: %s' % newtime)
            return timeout
    else:
        try:
            timeout=ephem_utils.GPSseconds_next(int(newtime)-8)
        except ValueError:
            logging.warn('Unable to interpret GPStime: %s' % newtime)
            return timeout

    return timeout
Ejemplo n.º 2
0
def daystr2gps(daystr):
    """
    gpstime=daystr2gps(daystr)
    returns the gpstime associated with a daystring YYYYMMDDhhmmss
    """
    yr = int(daystr[0:4])
    mn = int(daystr[4:6])
    dy = int(daystr[6:8])

    hour = int(daystr[8:10])
    min = int(daystr[10:12])
    sec = int(daystr[12:14])

    UT = float(hour) + float(min) / 60.0 + float(sec) / 3600.0

    MJD = ephem_utils.cal_mjd(yr, mn, dy)

    gps = ephem_utils.calcGPSseconds(MJD, UT)
    return gps