Skip to main content
Version: devel

dlt.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 on GitHub

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 on GitHub

check if timestamp is before max timestamp, inclusive

parse_iso_like_datetime

def parse_iso_like_datetime(
value: str) -> Union[pendulum.DateTime, pendulum.Date, pendulum.Time]

View source on GitHub

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 on GitHub

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_utc

def ensure_pendulum_datetime_utc(value: TAnyDateTime) -> pendulum.DateTime

View source on GitHub

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_datetime_non_utc

def ensure_pendulum_datetime_non_utc(value: TAnyDateTime) -> pendulum.DateTime

View source on GitHub

Coerce a date/time value to a pendulum.DateTime object.

Tz-awareness is preserved. Naive datetimes remain naive. Tz-aware datetimes keep their original timezone. Dates are converted to naive datetimes as dates are naive

Arguments:

  • value - The value to coerce. Can be a pendulum.DateTime, pendulum.Date, datetime, date or iso date/time str.

Returns:

pendulum.DateTime object that preserver original timezone

normalize_timezone

def normalize_timezone(dt: pendulum.DateTime,
timezone: bool) -> pendulum.DateTime

View source on GitHub

Normalizes timezone in a pendulum instance according to dlt convention:

  • naive datetimes represent UTC (system timezone is ignored) time zone
  • tz-aware datetimes are always UTC

Following conversions will be made:

  • when timezone is false: tz-aware tz is converted into UTC tz and then naive
  • when timezone is true: naive and aware datetimes are converted to UTC

ensure_pendulum_time

def ensure_pendulum_time(
value: Union[str, int, float, datetime.time,
timedelta]) -> pendulum.Time

View source on GitHub

Coerce a time-like value to a pendulum.Time object using timezone=False semantics.

this follows normalize_timezone(..., timezone=False): tz-aware inputs are converted to UTC and then made naive; naive values are treated as UTC and kept naive.

Arguments:

  • value - Time value to coerce. Supported types:
    • pendulum.Time or datetime.time
    • ISO time string (e.g. "12:34:56", "12:34:56+02:00")
    • timedelta representing seconds since midnight

Returns:

A naive pendulum.Time object that represents UTC time-of-day.

to_py_datetime

def to_py_datetime(value: datetime.datetime) -> datetime.datetime

View source on GitHub

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 on GitHub

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

get_precision_from_datetime_unit

def get_precision_from_datetime_unit(unit: str) -> int

View source on GitHub

Convert PyArrow datetime unit to numeric precision.

Arguments:

  • unit - PyArrow datetime unit ("s", "ms", "us", "ns")

Returns:

Numeric precision (0, 3, 6, or 9)

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.