Exemple #1
0
 def format(self, value):
     '''数据库默认认为以 'Asia/Shanghai' 时区存储,在输出时做转换。'''
     try:
         dt = value if value.tzinfo != None else tz_server.localize(value)
         return rfc3339(dt)
     except AttributeError as ae:
         raise fields.MarshallingException(ae)
Exemple #2
0
 def format(self, dt):
     try:
         if not dt.tzinfo:
             dt = dt.replace(tzinfo=tzlocal())
         return six.text_type(dt.astimezone(tzutc()).isoformat())
     except AttributeError as ae:
         raise fields.MarshallingException(ae)
Exemple #3
0
 def format(self, dt):
     try:
         if isinstance(dt, date):
             return six.text_type(dt.isoformat())
         else:
             return six.text_type(dt)
     except AttributeError as ae:
         raise fields.MarshallingException(ae)
    def format(self, value):
        try:
            return time.mktime(value.timetuple())
        except OverflowError:
            # The `value` was generate by time zone UTC+0,
            #  but `time.mktime()` will generate timestamp by local time zone (eg. in China, was UTC+8).
            # So, in some situation, we may got a timestamp that was negative.
            # In Linux, there's no problem. But in windows, this will cause an `OverflowError`.
            # Thinking of generally we don't need to handle a time so long before, at here we simply return 0.
            return 0

        except AttributeError as ae:
            raise _fields.MarshallingException(ae)
 def format(self, value):
     try:
         return float(value)
     except ValueError as ve:
         raise _fields.MarshallingException(ve)
Exemple #6
0
 def format(self, value):
     try:
         return value.isoformat()
     except AttributeError as e:
         raise fields.MarshallingException(e)