Skip to main content
Version: 1.5.0 (latest)

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

[view_source]

check if timestamp within range uniformly treating none and range inclusiveness

timestamp_before

def timestamp_before(timestamp: float, max_inclusive: Optional[float]) -> bool

[view_source]

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]

[view_source]

Parses ISO8601 string into pendulum datetime, date or time. Preserves timezone info. Note: naive datetimes will be 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

[view_source]

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

[view_source]

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

[view_source]

Coerce a time value to a pendulum.Time object.

Arguments:

  • value - The value to coerce. Can be a pendulum.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

[view_source]

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

[view_source]

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

This demo works on codespaces. Codespaces is a development environment available for free to anyone with a Github account. You'll be asked to fork the demo repository and from there the README guides you with further steps.
The demo uses the Continue VSCode extension.

Off to codespaces!

DHelp

Ask a question

Welcome to "Codex Central", your next-gen help center, driven by OpenAI's GPT-4 model. It's more than just a forum or a FAQ hub – it's a dynamic knowledge base where coders can find AI-assisted solutions to their pressing problems. With GPT-4's powerful comprehension and predictive abilities, Codex Central provides instantaneous issue resolution, insightful debugging, and personalized guidance. Get your code running smoothly with the unparalleled support at Codex Central - coding help reimagined with AI prowess.