common.time
precise_time
A precise timer using win_precise_time library on windows and time.time on other systems
timestamp_within
def timestamp_within(timestamp: float, min_exclusive: Optional[float],
max_inclusive: Optional[float]) -> bool
check if timestamp within range uniformly treating none and range inclusiveness
timestamp_before
def timestamp_before(timestamp: float, max_inclusive: Optional[float]) -> bool
check if timestamp is before max timestamp, inclusive
parse_iso_like_datetime
def parse_iso_like_datetime(
value: Any) -> Union[pendulum.DateTime, pendulum.Date, pendulum.Time]
Parses ISO8601 string into pendulum datetime, date or time. Preserves timezone info. Note: naive datetimes will generated from string without timezone
we use internal pendulum parse function. the generic function, for example, parses string "now" as now() it also tries to parse ISO intervals but the code is very low quality
ensure_pendulum_date
def ensure_pendulum_date(value: TAnyDateTime) -> pendulum.Date
Coerce a date/time value to a pendulum.Date
object.
UTC is assumed if the value is not timezone aware. Other timezones are shifted to UTC
Arguments:
value
- The value to coerce. Can be a pendulum.DateTime, pendulum.Date, datetime, date or iso date/time str.
Returns:
A timezone aware pendulum.Date object.
ensure_pendulum_datetime
def ensure_pendulum_datetime(value: TAnyDateTime) -> pendulum.DateTime
Coerce a date/time value to a pendulum.DateTime
object.
UTC is assumed if the value is not timezone aware. Other timezones are shifted to UTC
Arguments:
value
- The value to coerce. Can be a pendulum.DateTime, pendulum.Date, datetime, date or iso date/time str.
Returns:
A timezone aware pendulum.DateTime object in UTC timezone.
ensure_pendulum_time
def ensure_pendulum_time(value: Union[str, datetime.time]) -> pendulum.Time
Coerce a time value to a pendulum.Time
object.
Arguments:
value
- The value to coerce. Can be apendulum.Time
/datetime.time
or an iso time string.
Returns:
A pendulum.Time object
to_py_datetime
def to_py_datetime(value: datetime.datetime) -> datetime.datetime
Convert a pendulum.DateTime to a py datetime object.
Arguments:
value
- The value to convert. Can be a pendulum.DateTime or datetime.
Returns:
A py datetime object
to_py_date
def to_py_date(value: datetime.date) -> datetime.date
Convert a pendulum.Date to a py date object.
Arguments:
value
- The value to convert. Can be a pendulum.Date or date.
Returns:
A py date object