Skip to content

Commit 68e70c4

Browse files
committed
init
1 parent e8628f1 commit 68e70c4

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

pymap3d/timeconv.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import numpy as np
2+
from six import string_types
3+
from dateutil.parser import parse
4+
from datetime import datetime
5+
6+
def str2dt(t):
7+
"""
8+
output: datetime
9+
"""
10+
11+
t = np.atleast_1d(t)
12+
if isinstance(t[0], string_types):
13+
t = np.array([parse(T) for T in t])
14+
15+
assert isinstance(t[0], datetime), 'did not convert {} to datetime'.format(type(t[0]))
16+
17+
return t[()] # [()] to pop scalar from 0d array while being OK with ndim>0

0 commit comments

Comments
 (0)