예제 #1
0
    def test_tzts_seconds_only(self):
        """Test formatting of TZTimestamp values with seconds only"""
        msg = FixMessage()
        t = 1484581872.933458
        msg.append_tz_timestamp(1253, t, 0)

        test = time.localtime(t)
        s = "%04u%02u%02u-%02u:%02u:%02u" % \
            (test.tm_year, test.tm_mon, test.tm_mday,
             test.tm_hour, test.tm_min, test.tm_sec)
        offset = int(
            (datetime.datetime.fromtimestamp(t) -
             datetime.datetime.utcfromtimestamp(t)).total_seconds() / 60)
        if offset == 0:
            s += "Z"
        else:
            offset_hours = abs(offset) / 60
            offset_mins = abs(offset) % 60

            s += "%c%02u" % ("+" if offset > 0 else "-", offset_hours)
            if offset_mins > 0:
                s += ":%02u" % offset_mins

        self.assertEqual(fix_str(s), msg.get(1253))
        return
예제 #2
0
    def test_append_tzts_datetime(self):
        msg = FixMessage()
        t = 1484581872.933458
        local = datetime.datetime.fromtimestamp(t)
        msg.append_tz_timestamp(1132, local)

        test = time.localtime(t)
        s = "%04u%02u%02u-%02u:%02u:%02u.%03u" % \
            (test.tm_year, test.tm_mon, test.tm_mday,
             test.tm_hour, test.tm_min, test.tm_sec,
             int((t - int(t)) * 1000))
        offset = int((datetime.datetime.fromtimestamp(t) -
                      datetime.datetime.utcfromtimestamp(t)).total_seconds()
                     / 60)
        if offset == 0:
            s += "Z"
        else:
            offset_hours = abs(offset) / 60
            offset_mins = abs(offset) % 60

            s += "%c%02u" % ("+" if offset > 0 else "-", offset_hours)
            if offset_mins > 0:
                s += ":%02u" % offset_mins

        self.assertEqual(fix_str(s), msg.get(1132))
        return
예제 #3
0
    def test_tzts_bad_precision(self):
        """Test bad TZTimestamp precision value"""
        if VERSION == 26:
            return

        msg = FixMessage()
        t = 1484581872.933458
        with self.assertRaises(ValueError):
            msg.append_tz_timestamp(1253, t, 9)
예제 #4
0
    def test_append_tzts_float(self):
        msg = FixMessage()
        t = 1484581872.933458
        msg.append_tz_timestamp(1132, t)

        test = time.localtime(t)
        s = "%04u%02u%02u-%02u:%02u:%02u.%03u" % \
            (test.tm_year, test.tm_mon, test.tm_mday,
             test.tm_hour, test.tm_min, test.tm_sec,
             int((t - int(t)) * 1000))
        offset = self.calculate_tz_offset(t)
        if offset == 0:
            s += "Z"
        else:
            offset_hours = abs(offset) / 60
            offset_mins = abs(offset) % 60

            s += "%c%02u" % ("+" if offset > 0 else "-", offset_hours)
            if offset_mins > 0:
                s += ":%02u" % offset_mins

        self.assertEqual(fix_str(s), msg.get(1132))
예제 #5
0
    def test_tzts_microseconds(self):
        """Test formatting of TZTimestamp values with microseconds"""
        msg = FixMessage()
        t = 1484581872.933458
        msg.append_tz_timestamp(1253, t, 6)

        test = time.localtime(t)
        s = "%04u%02u%02u-%02u:%02u:%02u.%06u" % \
            (test.tm_year, test.tm_mon, test.tm_mday,
             test.tm_hour, test.tm_min, test.tm_sec,
             int((t % 1) * 1e6))
        offset = self.calculate_tz_offset(t)
        if offset == 0:
            s += "Z"
        else:
            offset_hours = abs(offset) / 60
            offset_mins = abs(offset) % 60

            s += "%c%02u" % ("+" if offset > 0 else "-", offset_hours)
            if offset_mins > 0:
                s += ":%02u" % offset_mins

        self.assertEqual(fix_str(s), msg.get(1253))
예제 #6
0
 def test_append_tzts_none(self):
     """Test TimezoneTimeOnly with explicit None"""
     msg = FixMessage()
     msg.append_tz_timestamp(1253, None)
     return
예제 #7
0
 def test_append_tzts_none(self):
     """Test TimezoneTimeOnly with explicit None"""
     msg = FixMessage()
     msg.append_tz_timestamp(1253, None)
     self.assertIsNotNone(msg.get(1253))