Module with useful time/date functions


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, *, force_datetime=False, allow_undefined=False, **kwargs)[source]

Parse input time/date string

  • time_input (str or datetime.date or datetime.datetime) – time/date to parse
  • force_datetime (bool) – If True it will always return datetime.datetime object, if False it can also return only datetime.date object if only date is provided as input.
  • allow_undefined – Flag to allow parsing None or ‘..’ into None
  • allow_undefined – bool (default is False)
  • kwargs – Any keyword arguments to be passed to dateutil.parser.parse. Example: ignoretz=True

A datetime object

Return type:

datetime.datetime or datetime.date

sentinelhub.time_utils.parse_time_interval(time, allow_undefined=False, **kwargs)[source]

Parse input into an interval of two times, specifying start and end time, into datetime objects.

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]

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.


interval of start and end date of the form YYYY-MM-DDThh:mm:ss

Return type:

(datetime.datetime, datetime.datetime)



sentinelhub.time_utils.serialize_time(timestamp_input, *, use_tz=False)[source]

Transforms datetime objects into ISO 8601 strings

  • timestamp_input (datetime.date or datetime.datetime or tuple(datetime.date or datetime.datetime)) – A datetime object or a tuple of datetime objects
  • use_tz (bool) – If True it will ensure that the serialized string contains a timezone information (typically with Z at the end instead of +00:00). If False it will make sure to remove any timezone information

Timestamp(s) serialized into string(s)

Return type:

str or tuple(str)

sentinelhub.time_utils.date_to_datetime(date, time=None)[source]

Converts a date object into datetime object

  • date (datetime.date) – a date object
  • time (datetime.time) – an option time object, if not provided it will replace it with 00:00:00

A datetime object derived from date and time

Return type:


sentinelhub.time_utils.filter_times(timestamps, time_difference)[source]

Filters out timestamps within time_difference, preserving only the oldest timestamp.


An ordered list of timestamps d_1<=d_2<=…<=d_n such that d_(i+1)-d_i > time_difference

Return type: