Example #1
0
 def test_parse_vumi_date_no_microseconds(self):
     """
     We can parse a timestamp even if it has no microseconds.
     """
     self.assertEqual(
         parse_vumi_date('2015-01-02 23:14:11'),
         datetime(2015, 1, 2, 23, 14, 11, microsecond=0))
 def get_timestamp(self, timestamp):
     """
     Return a timestamp value for a datetime value.
     """
     if isinstance(timestamp, basestring):
         timestamp = parse_vumi_date(timestamp)
     return time.mktime(timestamp.timetuple())
Example #3
0
 def get_timestamp(self, timestamp):
     """
     Return a timestamp value for a datetime value.
     """
     if isinstance(timestamp, basestring):
         timestamp = parse_vumi_date(timestamp)
     return time.mktime(timestamp.timetuple())
Example #4
0
def to_reverse_timestamp(vumi_timestamp):
    """
    Turn a vumi_date-formatted string into a string that sorts in reverse order
    and can be turned back into a timestamp later.

    This is done by converting to a unix timestamp and subtracting it from
    0xffffffffff (2**40 - 1) to get a number well outside the range
    representable by the datetime module. The result is returned as a
    hexadecimal string.
    """
    timestamp = timegm(parse_vumi_date(vumi_timestamp).timetuple())
    return "%X" % (0xffffffffff - timestamp)
def to_reverse_timestamp(vumi_timestamp):
    """
    Turn a vumi_date-formatted string into a string that sorts in reverse order
    and can be turned back into a timestamp later.

    This is done by converting to a unix timestamp and subtracting it from
    0xffffffffff (2**40 - 1) to get a number well outside the range
    representable by the datetime module. The result is returned as a
    hexadecimal string.
    """
    timestamp = timegm(parse_vumi_date(vumi_timestamp).timetuple())
    return "%X" % (0xffffffffff - timestamp)
    def test_outbound_delay_seconds(self):
        """
        When creating an outbound message sequence, the messages are returned
        in descending timestamp order and the delay between each timestamp is
        correct
        """
        batch_id, all_keys = (
            yield self.msg_seq_helper.create_outbound_message_sequence(
                msg_count=3, delay_seconds=2))

        timestamps = [parse_vumi_date(ts) for _, ts, _ in all_keys]
        self.assertEqual(timestamps[0] - timestamps[1], timedelta(seconds=2))
        self.assertEqual(timestamps[1] - timestamps[2], timedelta(seconds=2))
Example #7
0
 def _timestamp_from_json(self, value):
     return parse_vumi_date(value)
Example #8
0
 def custom_from_riak(self, value):
     return parse_vumi_date(value)
Example #9
0
 def _timestamp_from_json(self, value):
     return parse_vumi_date(value)
Example #10
0
 def custom_from_riak(self, value):
     return parse_vumi_date(value)
Example #11
0
 def test_parse_vumi_date(self):
     self.assertEqual(
         parse_vumi_date('2015-01-02 23:14:11.456000'),
         datetime(2015, 1, 2, 23, 14, 11, microsecond=456000))
Example #12
0
 def test_parse_vumi_date_no_microseconds(self):
     """
     We can parse a timestamp even if it has no microseconds.
     """
     self.assertEqual(parse_vumi_date('2015-01-02 23:14:11'),
                      datetime(2015, 1, 2, 23, 14, 11, microsecond=0))
Example #13
0
 def test_parse_vumi_date(self):
     self.assertEqual(parse_vumi_date('2015-01-02 23:14:11.456000'),
                      datetime(2015, 1, 2, 23, 14, 11, microsecond=456000))