Beispiel #1
0
    def test_tzto_bad_precision(self):
        """Test bad TZTimeOnly precision value"""
        if VERSION == 26:
            return

        msg = FixMessage()
        t = 1484581872.933458
        with self.assertRaises(ValueError):
            msg.append_tz_time_only(1079, t, 9)
Beispiel #2
0
    def test_tzto_minutes(self):
        """Test TZTimeOnly formatting without seconds"""
        msg = FixMessage()
        t = 1484581872.933458
        msg.append_tz_time_only(1079, t, precision=None)

        test = time.localtime(t)
        s = "%02u:%02u" % (test.tm_hour, test.tm_min)
        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(1079))
Beispiel #3
0
    def test_tzto_seconds_only(self):
        """Test formatting of TZTimeOnly values with seconds only"""
        msg = FixMessage()
        t = 1484581872.933458
        msg.append_tz_time_only(1079, t, 0)

        test = time.localtime(t)
        s = "%02u:%02u:%02u" % \
            (test.tm_hour, test.tm_min, test.tm_sec)
        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(1079))
Beispiel #4
0
    def test_tzto_datetime(self):
        msg = FixMessage()
        t = 1484581872.933458
        local = datetime.datetime.fromtimestamp(t)
        msg.append_tz_time_only(1079, local)

        test = time.localtime(t)
        s = "%02u:%02u:%02u.%03u" % \
            (test.tm_hour, test.tm_min, test.tm_sec, int((t % 1) * 1e3))
        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(1079))
Beispiel #5
0
    def test_tzto_microseconds(self):
        """Test formatting of TZTimeOnly values with microseconds"""
        msg = FixMessage()
        t = 1484581872.933458
        msg.append_tz_time_only(1079, t, 6)

        test = time.localtime(t)
        s = "%02u:%02u:%02u.%06u" % \
            (test.tm_hour, test.tm_min, test.tm_sec, int((t % 1) * 1e6))
        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(1079))
        return
Beispiel #6
0
 def test_append_tzts_default(self):
     """Test TZTimeOnly with no supplied timestamp value"""
     msg = FixMessage()
     msg.append_tz_time_only(1253)
     return
Beispiel #7
0
 def test_append_tzts_default(self):
     """Test TZTimeOnly with no supplied timestamp value"""
     msg = FixMessage()
     msg.append_tz_time_only(1253)
     self.assertIsNotNone(msg.get(1253))