Skip to content

Commit

Permalink
Use datetime to parse timestamps
Browse files Browse the repository at this point in the history
  • Loading branch information
sfinkens committed Dec 19, 2023
1 parent a9b876a commit edf933a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions satpy/readers/satpy_cf_nc.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@
import itertools
import json
import logging
from datetime import datetime

import xarray as xr
from pyresample import AreaDefinition
Expand Down Expand Up @@ -347,10 +348,9 @@ def _str2dict(self, val):


def _datetime_parser(json_dict):
import dateutil.parser
for key, value in json_dict.items():
try:
json_dict[key] = dateutil.parser.parse(value)
json_dict[key] = datetime.fromisoformat(value)
except (TypeError, ValueError):
pass
return json_dict
2 changes: 1 addition & 1 deletion satpy/tests/reader_tests/test_satpy_cf_nc.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def area():
def common_attrs(area):
"""Get common dataset attributes."""
return {
"start_time": datetime(2019, 4, 1, 12, 0),
"start_time": datetime(2019, 4, 1, 12, 0, 0, 123456),
"end_time": datetime(2019, 4, 1, 12, 15),
"platform_name": "tirosn",
"orbit_number": 99999,
Expand Down

0 comments on commit edf933a

Please sign in to comment.