Exemple #1
0
def format_time(time: datetime.datetime) -> str:
    offset = time.utcoffset()
    if not offset or offset == 0:
        tz = 'Z'
    else:
        tz = time.strftime('%z')
    if time.microsecond:
        ms = time.strftime('.%f')[:4]  # Miliseconds only!
    else:
        ms = ''
    return ''.join((time.strftime('%Y-%m-%dT%H:%M:%S'), ms, tz))
Exemple #2
0
 def __init__(self, time, adjusted=True):
     """
     @param time: The value of the object.
     @type time: (time|str)
     @param adjusted: Adjust for I{local} Timezone.
     @type adjusted: boolean
     @raise ValueError: When I{time} is invalid.
     """
     self.tz = Timezone()
     if isinstance(time, dt.time):
         self.time = time
         self.offset = time.utcoffset()
         if adjusted:
             self.__adjust()
         return
     if isinstance(time, str):
         self.time = self.__parse(time)
         if adjusted:
             self.__adjust()
         return
     raise ValueError(type(time))
 def as_utc(cls, time):
     if time.utcoffset():
         return (time - time.utcoffset()).replace(tzinfo=None)
     return time
 def as_utc(cls, time):
     if time.utcoffset():
         return (time - time.utcoffset()).replace(tzinfo=None)
     return time