[Numpy-discussion] datetimes with date vs time units, local time, and time zones

Mark Wiebe mwwiebe at gmail.com
Fri Sep 30 19:03:44 EDT 2011


2011/9/29 Grové <grove.steyn at 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
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20110930/1f7b1d7a/attachment.html>


More information about the NumPy-Discussion mailing list