gcpy.date_time

Internal utilities for managing datetime objects and strings

Functions

add_months(start_date, n_months)

Adds a given number of months to a numpy.datetime64 date.

datetime64_to_str(timestamp[, format_str])

Convenience routine to convert a numpy.datetime64 object to a date/time string.

get_timestamp_string(date_array)

Convenience function returning the datetime timestamp based on the given input.

is_full_year(start_date, end_date)

Verifies if two dates span a full year starting on January 1st.

gcpy.date_time.get_timestamp_string(date_array)[source]

Convenience function returning the datetime timestamp based on the given input.

Parameters:

date_array (array of int) – Array of integers corresponding to [year, month, day, hour, minute, second]. Any integers not provided will be padded accordingly.

Returns:

date_str – String in datetime format (e.g. ‘2019-01-01T00:00:00Z’).

Return type:

str

gcpy.date_time.add_months(start_date, n_months)[source]

Adds a given number of months to a numpy.datetime64 date.

Parameters:
  • start_date (numpy.datetime64) – The starting date.

  • n_months (int) – Number of months to add to start_date.

Returns:

new_date – Date with exactly n_months added to start_date.

Return type:

numpy.datetime64

gcpy.date_time.is_full_year(start_date, end_date)[source]

Verifies if two dates span a full year starting on January 1st.

Parameters:
Returns:

result – True if end_date is exactly 12 months after start_date and start_date falls on January 1st; False otherwise.

Return type:

bool

gcpy.date_time.datetime64_to_str(timestamp, format_str='%Y-%m-%d')[source]

Convenience routine to convert a numpy.datetime64 object to a date/time string.

Parameters:
  • timestamp (numpy.datetime64) – Date and time to be converted.

  • format_str (str, optional) – Format string for the output date/time string. Default value: ‘%Y-%m-%d’

Returns:

date_str – String representation of timestamp formatted according to format_str.

Return type:

str