#1030 Fix parser using tzlocal() instead of tzutc() if both accurate

Open

@@ -1186,6 +1186,9 @@
Loading
1186 1186
            aware = naive.replace(tzinfo=tzinfo)
1187 1187
            aware = self._assign_tzname(aware, res.tzname)
1188 1188
1189 +
        elif res.tzoffset == 0:
1190 +
            aware = naive.replace(tzinfo=tz.UTC)
1191 +
1189 1192
        elif res.tzname and res.tzname in time.tzname:
1190 1193
            aware = naive.replace(tzinfo=tz.tzlocal())
1191 1194
@@ -1197,9 +1200,6 @@
Loading
1197 1200
                    res.tzname in self.info.UTCZONE):
1198 1201
                aware = aware.replace(tzinfo=tz.UTC)
1199 1202
1200 -
        elif res.tzoffset == 0:
1201 -
            aware = naive.replace(tzinfo=tz.UTC)
1202 -
1203 1203
        elif res.tzoffset:
1204 1204
            aware = naive.replace(tzinfo=tz.tzoffset(res.tzname, res.tzoffset))
1205 1205

@@ -914,6 +914,25 @@
Loading
914 914
            assert dt.astimezone(tz.UTC) == dt_exp.astimezone(tz.UTC)
915 915
916 916
917 +
@pytest.mark.skipif(IS_WIN, reason="Windows does not use TZ var")
918 +
@pytest.mark.parametrize("dtstr", [
919 +
    "2015-08-20T00:20:45.000000+00:00",
920 +
    "2015-08-20T00:20:45Z",
921 +
])
922 +
def test_use_utc_over_tzlocal(dtstr):
923 +
    """
924 +
    Parser should use tzutc() instead of tzlocal() in cases where both are accurate.
925 +
926 +
    see: https://github.com/dateutil/dateutil/issues/349
927 +
         https://github.com/dateutil/dateutil/issues/842
928 +
    """
929 +
    with TZEnvContext("UTC"):
930 +
        dt_exp = datetime(2015, 8, 20, 0, 20, 45, tzinfo=tz.tzutc())
931 +
        dt_act = parse(dtstr)
932 +
        assert dt_act == dt_exp
933 +
        assert dt_act.tzinfo is dt_exp.tzinfo
934 +
935 +
917 936
def test_parse_tzinfos_fold():
918 937
    NYC = tz.gettz('America/New_York')
919 938
    tzinfos = {'EST': NYC, 'EDT': NYC}

Everything is accounted for!

No changes detected that need to be reviewed.
What changes does Codecov check for?
Lines, not adjusted in diff, that have changed coverage data.
Files that introduced coverage data that had none before.
Files that have missing coverage data that once were tracked.
Files Coverage
dateutil -0.01% 95.96%
Project Totals (31 files) 95.96%
Loading