Skip to content

Commit

Permalink
#382 return date in isoformat
Browse files Browse the repository at this point in the history
  • Loading branch information
korvinos committed Oct 23, 2018
1 parent be72a45 commit 106e39e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
9 changes: 4 additions & 5 deletions nansat/mappers/mapper_opendap_mywave.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,26 +50,25 @@ def __init__(self, filename, gdal_dataset, gdal_metadata, date=None,
@staticmethod
def get_date(filename):
"""Extract date and time parameters from filename and return
it as a formatted string
it as a formatted (isoformat) string
Parameters
----------
filename: str
nn
Returns
-------
str, YYYY-mm-ddThh:MMZ
str, YYYY-mm-ddThh:MM:00Z
Examples
--------
>>> Mapper.get_date('/path/to/MyWave_wam4_WAVE_20171029T18Z.nc')
'2017-10-29T18:00Z'
'2017-10-29T18:00:00Z'
"""
_, filename = os.path.split(filename)
t = datetime.strptime(filename.split('_')[-1], '%Y%m%dT%HZ.nc')
return datetime.strftime(t, '%Y-%m-%dT%H:%MZ')
return datetime.strftime(t, '%Y-%m-%dT%H:%M:00Z')

def convert_dstime_datetimes(self, ds_time):
"""Convert time variable to np.datetime64"""
Expand Down
2 changes: 1 addition & 1 deletion nansat/tests/mappers/test_mapper_opendap_mywave.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ def setUp(self):
def test_get_date(self):
res = Mapper.get_date(self.src)
self.assertIsInstance(res, str)
self.assertEqual(res, '2017-10-29T18:00Z')
self.assertEqual(res, '2017-10-29T18:00:00Z')

0 comments on commit 106e39e

Please sign in to comment.