wiki:DatesBestPractice

Version 5 (modified by spascoe, 13 years ago) (diff)

--

Dates Best Practice

The consensus at the PythonCoding meeting was that there was no alternative to cdtime for climate data because of it's support for non-gregorian calendars. Since all bundles are going to require cdat-lite this shouldn't be a problem. The standard python module datetime is also invaluable because of it's support for standard internet timestamps and timezones.

Cdtime is fairly small module providing a simple interface to it's two time types reltime and comptime. It would probably be possible to wrap cdtime's features as a datetime subclass which includes calendaring features. However, this would require further wrapping/unwrapping when using CDAT's utilities. An alternative is to clearly differentiate when the two packages should be used and to share code that manages conversion between the two libraries where appropriate.

One area where conversion between the two may be needed is in metadata relating to climate data (e.g. timestamps in CSML) where the date encoding must follow internet standards. It would seem sensible to convert to a datetime type before encoding. Conversely dates in CF-NetCDF metadata should be in the format "<units> since <basetime>" which is conveniently handled by cdtime.

General Guidelines

  1. Use cdtime for climate data.
  2. Use datetime in all "real world" cases, i.e. where the calendar is definitely Gregorian.
  3. Use or convert to datetime when ever standard encoding is required.
  4. Share utilities for converting between cdtime and datetime in the ndg.utils package.