def format(self, value): if value is None: return {'__tp': 'time', 'value': None} try: return {'__tp': 'time', 'value': value.isoformat()} except Exception as ae: raise _fields.MarshallingException(ae)
def format(self, value): if value is None: return None try: return float(value) except ValueError as ve: raise _fields.MarshallingException(ve)
def format(self, value): try: # print(value) return datetime.strftime( value, '%Y-%m-%dT%H:%M:%S') if value else str(value) except Exception: raise fields.MarshallingException( 'Can NOT format this datetime field')
def format(self, dt): """Format a datetime object in ISO format.""" 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): if value is None: return {'__tp': 'decimal', 'value': None} try: ret = str(value) if '.' in ret: ret = ret.rstrip('0').rstrip('.') return {'__tp': 'decimal', 'value': ret} except Exception as ae: raise _fields.MarshallingException(ae)
def format(self, dt): """Format a datetime object in ISO format. Convert to UTC if necessary. """ 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)
def format(self, value): """Format a string which represents a datetime in ISO format. Convert to UTC if necessary. """ try: dt = parser.parse(value) 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)
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 rfc822(value) except AttributeError as ae: raise fields.MarshallingException(ae)
def format(self, value): try: return value.isoformat() except AttributeError as e: raise rest_fields.MarshallingException(e)
def format(self, value): try: return value.strftime(DATE_FORMAT) except AttributeError as ae: raise fields.MarshallingException(ae)
def format(self, value): try: return timedelta_to_xsd_duration(value) except Exception as e: raise fields.MarshallingException(e)
def format(self, value): try: return float(value) except ValueError as ve: raise fields.MarshallingException(ve)