Ejemplo n.º 1
0
 def testValueFromMessageWithTimeZone(self):
   message = message_types.DateTimeMessage(milliseconds=1991128000000,
                                           time_zone_offset=300)
   field = message_types.DateTimeField(1)
   timestamp = field.value_from_message(message)
   time_zone = util.TimeZoneOffset(60 * 5)
   self.assertEqual(datetime.datetime(2033, 2, 4, 11, 6, 40, tzinfo=time_zone),
                    timestamp)
Ejemplo n.º 2
0
 def testValueToMessageWithTimeZone(self):
   time_zone = util.TimeZoneOffset(60 * 10)
   field = message_types.DateTimeField(1)
   message = field.value_to_message(
       datetime.datetime(2033, 2, 4, 11, 22, 10, tzinfo=time_zone))
   self.assertEqual(message_types.DateTimeMessage(milliseconds=1991128930000,
                                                  time_zone_offset=600),
                    message)
Ejemplo n.º 3
0
    def testProtobufDecodeDateTimeMessage(self):
        """Test what happens when decoding a DateTimeMessage."""

        nested = NestedDateTimeMessage()
        nested.value = message_types.DateTimeMessage(milliseconds=2500)
        value = protobuf.decode_message(HasDateTimeMessage,
                                        protobuf.encode_message(nested)).value
        self.assertEqual(datetime.datetime(1970, 1, 1, 0, 0, 2, 500000), value)
Ejemplo n.º 4
0
    def testProtobufEncodeDateTimeMessage(self):
        """Test what happens when encoding a DateTimeField."""
        mine = HasDateTimeMessage(value=datetime.datetime(1970, 1, 1))
        nested = NestedDateTimeMessage()
        nested.value = message_types.DateTimeMessage(milliseconds=0)

        my_encoded = protobuf.encode_message(mine)
        encoded = protobuf.encode_message(nested)
        self.assertEquals(my_encoded, encoded)
Ejemplo n.º 5
0
    def testProtobufEncodeDateTimeMessageWithTimeZone(self):
        """Test what happens when encoding a DateTimeField with a time zone."""
        for tz_offset in (30, -30, 8 * 60, 0):
            mine = HasDateTimeMessage(value=datetime.datetime(
                1970, 1, 1, tzinfo=util.TimeZoneOffset(tz_offset)))
            nested = NestedDateTimeMessage()
            nested.value = message_types.DateTimeMessage(
                milliseconds=0, time_zone_offset=tz_offset)

            my_encoded = protobuf.encode_message(mine)
            encoded = protobuf.encode_message(nested)
            self.assertEquals(my_encoded, encoded)
Ejemplo n.º 6
0
 def testProtobufDecodeDateTimeMessageWithTimeZone(self):
     """Test what happens when decoding a DateTimeMessage with a time zone."""
     nested = NestedDateTimeMessage()
     nested.value = message_types.DateTimeMessage(milliseconds=12345678,
                                                  time_zone_offset=60)
     value = protobuf.decode_message(HasDateTimeMessage,
                                     protobuf.encode_message(nested)).value
     self.assertEqual(
         datetime.datetime(1970,
                           1,
                           1,
                           3,
                           25,
                           45,
                           678000,
                           tzinfo=util.TimeZoneOffset(60)), value)
Ejemplo n.º 7
0
 def testValueFromMessage(self):
   message = message_types.DateTimeMessage(milliseconds=1991128000000)
   field = message_types.DateTimeField(1)
   timestamp = field.value_from_message(message)
   self.assertEqual(datetime.datetime(2033, 2, 4, 11, 6, 40),
                    timestamp)
Ejemplo n.º 8
0
 def testValueToMessage(self):
   field = message_types.DateTimeField(1)
   message = field.value_to_message(datetime.datetime(2033, 2, 4, 11, 22, 10))
   self.assertEqual(message_types.DateTimeMessage(milliseconds=1991128930000),
                    message)