dates

Functions that concern dates and times.

Module summary

Functions

date_to_unix(year, month, day, hour, minute, …)

Convert date to unix time in seconds

jd_to_mjd(jd)

Convert Julian Date (relative 12h Jan 1, 4713 BC) to Modified Julian Date (relative 0h Nov 17, 1858)

mjd_to_jd(mjd)

Convert Modified Julian Date (relative 0h Nov 17, 1858) to Julian Date (relative 12h Jan 1, 4713 BC)

mjd_to_npdt(mjd)

Converts a modified Julian date to a numpy datetime64 value (UTC)

npdt_to_date(dt)

Converts a numpy datetime64 value to a date tuple

npdt_to_mjd(dt)

Converts a numpy datetime64 value (UTC) to a modified Julian date

npdt_to_unix(dt)

Converts a numpy datetime64 value (UTC) to unix seconds

unix_to_date(unix)

Convert unix time in seconds to UTC date datetime object

unix_to_datestr(unix)

Convert unix time in seconds to Gregorian calendar UTC date-time formatted string

unix_to_datestrf(x)

Convert unix time in seconds to Gregorian calendar UTC date-time formatted string

unix_to_npdt(unix)

Converts unix seconds to a numpy datetime64 value (UTC)

Contents

Functions

sorts.dates.date_to_unix(year, month, day, hour, minute, second)[source]

Convert date to unix time in seconds

Parameters
  • year (int) – Year as integer. Years preceding 1 A.D. should be 0 or negative. The year before 1 A.D. is 0, 10 B.C. is year -9.

  • month (int) – Month as integer, Jan = 1, Feb. = 2, etc.

  • day (int) – Day

  • hour (int) – Hour in 24h format

  • minute (int) – Minute

  • second (float) – Second, may contain fractional part.

Returns

Unix time in seconds

Return type

float

sorts.dates.jd_to_mjd(jd)[source]

Convert Julian Date (relative 12h Jan 1, 4713 BC) to Modified Julian Date (relative 0h Nov 17, 1858)

sorts.dates.mjd_to_jd(mjd)[source]

Convert Modified Julian Date (relative 0h Nov 17, 1858) to Julian Date (relative 12h Jan 1, 4713 BC)

sorts.dates.mjd_to_npdt(mjd)[source]

Converts a modified Julian date to a numpy datetime64 value (UTC)

sorts.dates.npdt_to_date(dt)[source]

Converts a numpy datetime64 value to a date tuple

Parameters

dt (numpy.datetime64) – Date and time (UTC) in numpy datetime64 format

Returns

tuple (year, month, day, hours, minutes, seconds, microsecond) all except usec are integer

sorts.dates.npdt_to_mjd(dt)[source]

Converts a numpy datetime64 value (UTC) to a modified Julian date

sorts.dates.npdt_to_unix(dt)[source]

Converts a numpy datetime64 value (UTC) to unix seconds

sorts.dates.unix_to_date(unix)[source]

Convert unix time in seconds to UTC date datetime object

Parameters

unix (float) – Unix time in seconds.

Returns

Datetime object in UTC

Return type

datetime.datetime

sorts.dates.unix_to_datestr(unix)[source]

Convert unix time in seconds to Gregorian calendar UTC date-time formatted string

Parameters

unix (float) – Unix time in seconds.

Returns

Gregorian calendar UTC date-time formatted string

Return type

str

sorts.dates.unix_to_datestrf(x)[source]

Convert unix time in seconds to Gregorian calendar UTC date-time formatted string

Different implementation?

Parameters

unix (float) – Unix time in seconds.

Returns

Gregorian calendar UTC date-time formatted string

Return type

str

sorts.dates.unix_to_npdt(unix)[source]

Converts unix seconds to a numpy datetime64 value (UTC)