Esempio n. 1
0
def _dict_to_tuple(d):
    '''Convert a dictionary to a time tuple.  Depends on key values in the
    regexp pattern!
    '''    
    # TODO: Adding a ms field to struct_time tuples is problematic 
    # since they don't have this field.  Should use datetime
    # which has a microseconds field, else no ms..  When mapping struct_time 
    # to gDateTime the last 3 fields are irrelevant, here using dummy values to make
    # everything happy.
    # 

    retval = _niltime[:]
    for k,i in ( ('Y', 0), ('M', 1), ('D', 2), ('h', 3), ('m', 4), ):
        v = d.get(k)
        if v: retval[i] = int(v)
        
    v = d.get('s')
    if v:
        msec,sec = _modf(float(v))
        retval[6],retval[5] = int(round(msec*1000)), int(sec)

    if d.get('neg', 0):
        retval[0:5] = map(lambda x: (x is not None or x) and operator.__neg__(x), retval[0:5])

    return tuple(retval)
Esempio n. 2
0
def _dict_to_tuple(d):
    '''Convert a dictionary to a time tuple.  Depends on key values in the
    regexp pattern!
    '''    
    # TODO: Adding a ms field to struct_time tuples is problematic 
    # since they don't have this field.  Should use datetime
    # which has a microseconds field, else no ms..  When mapping struct_time 
    # to gDateTime the last 3 fields are irrelevant, here using dummy values to make
    # everything happy.
    # 

    retval = _niltime[:]
    for k,i in ( ('Y', 0), ('M', 1), ('D', 2), ('h', 3), ('m', 4), ):
        v = d.get(k)
        if v: retval[i] = int(v)
        
    v = d.get('s')
    if v:
        msec,sec = _modf(float(v))
        retval[6],retval[5] = int(round(msec*1000)), int(sec)
            
    v = d.get('tz')
    if v and v != 'Z':
        h,m = map(int, v.split(':'))
        # check for time zone offset, if within the same timezone, 
        # ignore offset specific calculations
        offset=_localtimezone().utcoffset(_datetime.now())
        local_offset_hour = offset.seconds/3600
        local_offset_min = (offset.seconds%3600)%60
        if local_offset_hour > 12: 
            local_offset_hour -= 24
            
        if local_offset_hour != h or local_offset_min != m:                
            if h<0:
                #TODO: why is this set to server
                #foff = _fixedoffset(-((abs(h)*60+m)),"server")
                foff = _fixedoffset(-((abs(h)*60+m)))
            else:
                #TODO: why is this set to server
                #foff = _fixedoffset((abs(h)*60+m),"server")
                foff = _fixedoffset((abs(h)*60+m)) 
                
            dt = _datetime(retval[0],retval[1],retval[2],retval[3],retval[4],
                           retval[5],0,foff)
            
            # update dict with calculated timezone
            localdt=dt.astimezone(_localtimezone())
            retval[0] = localdt.year
            retval[1] = localdt.month
            retval[2] = localdt.day
            retval[3] = localdt.hour
            retval[4] = localdt.minute
            retval[5] = localdt.second
            
    if d.get('neg', 0):
        retval[0:5] = map(operator.__neg__, retval[0:5])
    return tuple(retval)
Esempio n. 3
0
def _dict_to_tuple(d):
    '''Convert a dictionary to a time tuple.  Depends on key values in the
    regexp pattern!
    '''    
    # TODO: Adding a ms field to struct_time tuples is problematic 
    # since they don't have this field.  Should use datetime
    # which has a microseconds field, else no ms..  When mapping struct_time 
    # to gDateTime the last 3 fields are irrelevant, here using dummy values to make
    # everything happy.
    # 

    retval = _niltime[:]
    for k,i in ( ('Y', 0), ('M', 1), ('D', 2), ('h', 3), ('m', 4), ):
        v = d.get(k)
        if v: retval[i] = int(v)
        
    v = d.get('s')
    if v:
        msec,sec = _modf(float(v))
        retval[6],retval[5] = int(round(msec*1000)), int(sec)
            
    v = d.get('tz')
    if v and v != 'Z':
        h,m = map(int, v.split(':'))
        # check for time zone offset, if within the same timezone, 
        # ignore offset specific calculations
        offset=_localtimezone().utcoffset(_datetime.now())
        local_offset_hour = offset.seconds/3600
        local_offset_min = (offset.seconds%3600)%60
        if local_offset_hour > 12: 
            local_offset_hour -= 24
            
        if local_offset_hour != h or local_offset_min != m:                
            if h<0:
                #TODO: why is this set to server
                #foff = _fixedoffset(-((abs(h)*60+m)),"server")
                foff = _fixedoffset(-((abs(h)*60+m)))
            else:
                #TODO: why is this set to server
                #foff = _fixedoffset((abs(h)*60+m),"server")
                foff = _fixedoffset((abs(h)*60+m)) 
                
            dt = _datetime(retval[0],retval[1],retval[2],retval[3],retval[4],
                           retval[5],0,foff)
            
            # update dict with calculated timezone
            localdt=dt.astimezone(_localtimezone())
            retval[0] = localdt.year
            retval[1] = localdt.month
            retval[2] = localdt.day
            retval[3] = localdt.hour
            retval[4] = localdt.minute
            retval[5] = localdt.second
            
    if d.get('neg', 0):
        retval[0:5] = map(operator.__neg__, retval[0:5])
    return tuple(retval)
Esempio n. 4
0
def _dict_to_tuple(d):
    '''Convert a dictionary to a time tuple.  Depends on key values in the
    regexp pattern!
    '''
    retval = _niltime[:]
    for k, i in (
        ('Y', 0),
        ('M', 1),
        ('D', 2),
        ('h', 3),
        ('m', 4),
    ):
        v = d.get(k)
        if v: retval[i] = int(v)

    v = d.get('s')
    if v:
        msec, sec = _modf(float(v))
        retval[6], retval[5] = int(round(msec * 1000)), int(sec)

    v = d.get('tz')
    if v and v != 'Z':
        h, m = map(int, v.split(':'))
        # check for time zone offset, if within the same timezone,
        # ignore offset specific calculations
        offset = _localtimezone().utcoffset(_datetime.now())
        local_offset_hour = offset.seconds / 3600
        local_offset_min = (offset.seconds % 3600) % 60
        if local_offset_hour > 12:
            local_offset_hour -= 24

        if local_offset_hour != h or local_offset_min != m:
            if h < 0:
                #TODO: why is this set to server
                #foff = _fixedoffset(-((abs(h)*60+m)),"server")
                foff = _fixedoffset(-((abs(h) * 60 + m)))
            else:
                #TODO: why is this set to server
                #foff = _fixedoffset((abs(h)*60+m),"server")
                foff = _fixedoffset((abs(h) * 60 + m))

            dt = _datetime(retval[0], retval[1], retval[2], retval[3],
                           retval[4], retval[5], 0, foff)

            # update dict with calculated timezone
            localdt = dt.astimezone(_localtimezone())
            retval[0] = localdt.year
            retval[1] = localdt.month
            retval[2] = localdt.day
            retval[3] = localdt.hour
            retval[4] = localdt.minute
            retval[5] = localdt.second

    if d.get('neg', 0):
        retval[0:5] = map(operator.__neg__, retval[0:5])
    return tuple(retval)
Esempio n. 5
0
def _dict_to_tuple(d):
    '''Convert a dictionary to a time tuple.  Depends on key values in the
    regexp pattern!
    '''
    retval = _niltime[:]
    for k,i in ( ('Y', 0), ('M', 1), ('D', 2), ('h', 3), ('m', 4), ):
        v = d.get(k)
        if v: retval[i] = int(v)

    v = d.get('s')
    if v:
        msec,sec = _modf(float(v))
        retval[6],retval[5] = int(round(msec*1000)), int(sec)

    v = d.get('tz')
    if v and v != 'Z':
        h,m = map(int, v.split(':'))
        # check for time zone offset, if within the same timezone,
        # ignore offset specific calculations
        offset=_localtimezone().utcoffset(_datetime.now())
        local_offset_hour = offset.seconds/3600
        local_offset_min = (offset.seconds%3600)%60
        if local_offset_hour > 12:
            local_offset_hour -= 24

        if local_offset_hour != h or local_offset_min != m:
            if h<0:
                #TODO: why is this set to server
                #foff = _fixedoffset(-((abs(h)*60+m)),"server")
                foff = _fixedoffset(-((abs(h)*60+m)))
            else:
                #TODO: why is this set to server
                #foff = _fixedoffset((abs(h)*60+m),"server")
                foff = _fixedoffset((abs(h)*60+m))

            dt = _datetime(retval[0],retval[1],retval[2],retval[3],retval[4],
                           retval[5],0,foff)

            # update dict with calculated timezone
            localdt=dt.astimezone(_localtimezone())
            retval[0] = localdt.year
            retval[1] = localdt.month
            retval[2] = localdt.day
            retval[3] = localdt.hour
            retval[4] = localdt.minute
            retval[5] = localdt.second

    if d.get('neg', 0):
        retval[0:5] = map(operator.__neg__, retval[0:5])
    return tuple(retval)