Example #1
0
    def test_naive_unix_timestamp(self):
        # The application is configured to use system's local date and time.
        settings.timezone = None

        assert datetime(1970,1,1,0,0,1,334300) == \
            parse_datetime('1.3343')
        assert datetime(1970,1,1,0,0,1,334300) == \
            parse_datetime('1.3343')
Example #2
0
    def test_timezone_aware_datetime_parsing(self):
        # The application is configured to use a specific timezone
        settings.timezone = tzoffset('Tehran', 12600)
        with pytest.raises(ValueError):
            parse_datetime('1970-01-01T00:00:00')

        assert datetime(1970, 1, 1, 3, 30, tzinfo=tzoffset(
            'Tehran', 12600)) == parse_datetime('1970-01-01T00:00:00Z')
        assert datetime(1970, 1, 1, 4, 30, tzinfo=tzoffset(
            'Tehran', 12600)) == parse_datetime('1970-01-01T00:00:00-1:00')
Example #3
0
    def test_timezone_aware_unix_timestamp(self):
        # The application is configured to use a specific timezone as the
        # default
        settings.timezone = tzoffset('Tehran', 12600)

        assert datetime(
            1970, 1, 1, 3, 30, 1, 334300, tzinfo=tzoffset('Tehran', 12600)
        ) == parse_datetime('1.3343')
Example #4
0
    def test_naive_datetime_parsing(self):
        # The application is configured to use system's local date and time.
        settings.timezone = None

        # Submit without timezone: accept and assume the local date and time.
        assert datetime(1970, 1, 1) == parse_datetime('1970-01-01T00:00:00')
        assert datetime(1970, 1, 1, microsecond=1000) == \
            parse_datetime('1970-01-01T00:00:00.001')
        assert datetime(1970, 1, 1, microsecond=1000) == \
            parse_datetime('1970-01-01T00:00:00.001000')

        # Timezone aware
        # Submit with 'Z' and or '+3:30':
        # accept and assume as the UTC, so we have to convert
        # it to local date and time before continuing the rest of process
        with mockup_localtimezone(tzoffset(None, 3600)):
            assert datetime(1970, 1, 1, 1) == \
                parse_datetime('1970-01-01T00:00:00Z')
            assert datetime(1970, 1, 1, 1, 30) == \
                parse_datetime('1970-01-01T00:00:00-0:30')
Example #5
0
 def test_timezone_string(self):
     # The application is configured to use a named timzone
     settings.timezone = 'GMT+3'
     dt = parse_datetime('1.3343')
     assert dt == datetime(1970,
                           1,
                           1,
                           3,
                           30,
                           1,
                           334300,
                           tzinfo=tzoffset('Tehran', 12600))
     assert dt.utcoffset() == timedelta(0, 10800)