Exemplo n.º 1
0
def _serialize(value):
    """Serializes a complex ndb type.

  Args:
    value: A ndb type to be serialized.

  Returns:
    Value serialized to simple data type such as integer or string.
  """
    if isinstance(value, datetime.datetime):
        return utils.datetime_to_unix(value)
    elif isinstance(value, (ndb.Key, ndb.GeoPt, messages.Enum)):
        return str(value)
    else:
        return value
Exemplo n.º 2
0
 def testConvertDatetimeToUnix_milliseconds(self):
     timestamp = datetime.datetime(2016, 8, 1, 1, 1)
     unix_timestamp = utils.datetime_to_unix(timestamp, True)
     self.assertEqual(unix_timestamp, 1470013260000)
Exemplo n.º 3
0
 def testConvertDatetimeToUnix(self):
     timestamp = datetime.datetime(2016, 8, 1, 1, 1)
     unix_timestamp = utils.datetime_to_unix(timestamp)
     self.assertEqual(unix_timestamp, 1470013260)