2011/9/29 Grové
<grove.steyn@gmail.com>
Hi Mark
Did you ever get to write:
date_as_datetime(datearray, hour, minute, second, microsecond,
timezone='local', unit=None, out=None)
and
datetime_as_date(datetimearray, timezone='local', out=None)
?
I never got to these functions, no.
I am looking for an easy way of using datetime[m] data to test for business days
and do half hourly comparisons.
I am using:
In [181]: np.__version__
Out[181]: '2.0.0.dev-aded70c'
Here's a stopgap solution for converting to dates, that works for a single np.datetime64:
def my_datetime_as_date(dt, timezone = 'local'):
s = np.datetime_as_string(np.datetime64(dt), timezone=timezone)
e = s.find('T')
if e != -1:
s = s[:e]
return np.datetime64(s, 'D')
>>> my_datetime_as_date('now')
numpy.datetime64('2011-09-30')
>>> my_datetime_as_date('2011-03-13T00:30Z')
numpy.datetime64('2011-03-12')
>>> my_datetime_as_date('2011-03-13T00:30')
numpy.datetime64('2011-03-13')
>>> my_datetime_as_date('2011-03-13T00:30Z', timezone='UTC')
numpy.datetime64('2011-03-13')
Cheers,
Mark
Regards
Grové Steyn