time_utils

Module with useful time/date functions

sentinelhub.time_utils.get_dates_in_range(start_date, end_date)[source]

Get all dates within input start and end date in ISO 8601 format

Parameters:
  • start_date (str) – start date in ISO 8601 format
  • end_date (str) – end date in ISO 8601 format
Returns:

list of dates between start_date and end_date in ISO 8601 format

Return type:

list of str

sentinelhub.time_utils.next_date(date)[source]

Get date of day after input date in ISO 8601 format

For instance, if input date is '2017-03-12', the function returns '2017-03-13'

Parameters:date (str) – input date in ISO 8601 format
Returns:date after input date in ISO 8601 format
Return type:str
sentinelhub.time_utils.prev_date(date)[source]

Get date of day previous to input date in ISO 8601 format

For instance, if input date is '2017-03-12', the function returns '2017-03-11'

Parameters:date (str) – input date in ISO 8601 format
Returns:date previous to input date in ISO 8601 format
Return type:str
sentinelhub.time_utils.iso_to_datetime(date)[source]

Convert ISO 8601 time format to datetime format

This function converts a date in ISO format, e.g. 2017-09-14 to a datetime instance, e.g. datetime.datetime(2017,9,14,0,0)

Parameters:date (str) – date in ISO 8601 format
Returns:datetime instance
Return type:datetime
sentinelhub.time_utils.datetime_to_iso(date, only_date=True)[source]

Convert datetime format to ISO 8601 time format

This function converts a date in datetime instance, e.g. datetime.datetime(2017,9,14,0,0) to ISO format, e.g. 2017-09-14

Parameters:
  • date (datetime) – datetime instance to convert
  • only_date (bool) – whether to return date only or also time information. Default is True
Returns:

date in ISO 8601 format

Return type:

str

sentinelhub.time_utils.get_current_date()[source]

Get current date in ISO 8601 format

Returns:current date in ISO 8601 format
Return type:str
sentinelhub.time_utils.is_valid_time(time)[source]

Check if input string represents a valid time/date stamp

Parameters:time (str) – a string containing a time/date stamp
Returns:True is string is a valid time/date stamp, False otherwise
Return type:bool
sentinelhub.time_utils.parse_time(time_input)[source]

Parse input time/date string into ISO 8601 string

Parameters:time_input (str or datetime.date or datetime.datetime) – time/date to parse
Returns:parsed string in ISO 8601 format
Return type:str
sentinelhub.time_utils.parse_time_interval(time)[source]

Parse input into an interval of two times, specifying start and end time, in ISO 8601 format, for example:

(2017-01-15:T00:00:00, 2017-01-16:T23:59:59)

The input time can have the following formats, which will be parsed as:

  • YYYY-MM-DD -> [YYYY-MM-DD:T00:00:00, YYYY-MM-DD:T23:59:59]
  • YYYY-MM-DDThh:mm:ss -> [YYYY-MM-DDThh:mm:ss, YYYY-MM-DDThh:mm:ss]
  • list or tuple of two dates in form YYYY-MM-DD -> [YYYY-MM-DDT00:00:00, YYYY-MM-DDT23:59:59]
  • list or tuple of two dates in form YYYY-MM-DDThh:mm:ss -> [YYYY-MM-DDThh:mm:ss, YYYY-MM-DDThh:mm:ss],
  • None -> [default_start_date from config.json, current date]

All input times can also be specified as datetime objects. Instances of datetime.date will be treated as YYYY-MM-DD and instance of datetime.datetime will be treated as YYYY-MM-DDThh:mm:ss.

Parameters:time (str or datetime.datetime) – An input time
Returns:interval of start and end date of the form YYYY-MM-DDThh:mm:ss
Return type:(str, str)
Raises:ValueError