DateAndTime

This is a Python binding to the C++ class Mantid::Kernel::DateAndTime.

The equivalent object in python is numpy.datetime64. The two classes have a different EPOCH. Note that mantid.kernel.DateAndTime uses the GPS epoch of 1990, where numpy.datetime64 uses the unix epoch of 1970. For that reason, there is an additional method mantid.kernel.DateAndTime.to_datetime64().

To convert an array of mantid.kernel.DateAndTime, analgous to what mantid.kernel.FloatTimeSeriesProperty.times() does internally, use the code:

times = np.array(times, dtype=np.int64) * np.timedelta64(1,'ns') + np.datetime64('1990-01-01T00:00')

With numpy.datetime64, finding the number of seconds between two times is simply

diff = (timeArray[-1]-timeArray[0]) / np.timedelta64(1, 's')

For converting numpy.datetime64 data to a string for the default facilty, use numpy.datetime_as_string() explicitly (assuming the times are a variable named times)

import pytz
tz = pytz.timezone(ConfigService.getFacility().timezone())
times = numpy.datetime_as_string(times, timezone=tz)

This is how numpy internally converts numpy.datetime64 to strings for printing, but the selection of timezone is explicit (using pytz) to allow for matching where the data was recorded rather than the system’s timezone.

Converting strings to datetime64

How strings are interpreted by numpy.datetime64 changed in version 1.11. Before this point, a string without timezone designation was assumed to be in local timezone. After this point it is assumed to be in UTC. Additionally as of version 1.11, NumPy started warning if a string was supplied with timezone designation. This means that on rhel7 (in EDT)

repr(np.datetime64('1990-01-01T00:00Z'))
repr(np.datetime64('1990-01-01T00:00'))

result in "numpy.datetime64('1989-12-31T19:00-0500')" and "numpy.datetime64('1990-01-01T00:00-0500')" respectively. However, in “newer” python results "numpy.datetime64('1990-01-01T00:00')", but the first version results in a DeprecationWarning.

class mantid.kernel.DateAndTime((object)self, (str)ISO8601 string)
__init__((object)self, (str)ISO8601 string) → None :
Construct from an ISO8601 string
__init__( (object)self, (float)seconds, (float)nanoseconds) -> None :
Construct using a number of seconds and nanoseconds (floats)since 1990-01-01T00:00
__init__( (object)self, (int)seconds, (int)nanoseconds) -> None :
Construct using a number of seconds and nanoseconds (integers) since 1990-01-01T00:00
__init__( (object)self, (int)total_nanoseconds) -> None :
Construct a total number of nanoseconds since 1990-01-01T00:00
__init__( (object)arg1, (object)other) -> object :
Construct from numpy.datetime64
setToMinimum((DateAndTime)self) → None
toISO8601String((DateAndTime)self) → str :

Converts the time into ISO8601Standard and returns the string

to_datetime64((DateAndTime)self) → object :

Convert to numpy.datetime64

totalNanoseconds((DateAndTime)self) → int :

Since 1990-01-01T00:00

total_nanoseconds((DateAndTime)self) → int :

Since 1990-01-01T00:00