akkudoktoreos.utils.datetimeutil.Time

class akkudoktoreos.utils.datetimeutil.Time(*args: Any, tzinfo: tzinfo | Timezone | str | None = None, **kwargs: Any)

Bases: Time

A timezone-aware Time class derived from pendulum.Time.

Provides methods to get hour information for specific timezones with local timezone as default. Makes Time handled by pydantic.

__init__()

Methods

__init__()

add([hours, minutes, seconds, microseconds])

Add duration to the instance.

add_timedelta(delta)

Add timedelta duration to the instance.

closest(dt1, dt2)

Get the closest time from the instance.

diff([dt, abs])

Returns the difference between two Time objects as an Duration.

diff_for_humans([other, absolute, locale])

Get the difference in a human readable format in the current locale.

dst

Return self.tzinfo.dst(self).

farthest(dt1, dt2)

Get the farthest time from the instance.

for_json()

Methods for automatic json serialization by simplejson.

format(fmt[, locale])

Formats the instance using the given format.

format_user_friendly([include_seconds, ...])

Format time in a user-friendly way.

fromisoformat

string -> time from a string in ISO 8601 format

in_timezone(timezone)

Convert to specified timezone.

instance(t[, tz])

is_aware()

Check if time is timezone-aware.

is_naive()

Check if time is timezone-naive.

isoformat

Return string in ISO 8601 format, [HH[:MM[:SS[.mmm[uuu]]]]][+HH:MM].

now([tz])

Get current time with optional timezone.

parse(time_string)

Parse time string using your enhanced parser.

replace([hour, minute, second, microsecond, ...])

Return time with new specified fields.

replace_timezone(tz)

Replace timezone without converting the time value.

strftime

format -> strftime() style string.

subtract([hours, minutes, seconds, microseconds])

Add duration to the instance.

subtract_timedelta(delta)

Remove timedelta duration from the instance.

to_local()

Convert to local timezone.

to_utc()

Convert to UTC timezone.

tzname

Return self.tzinfo.tzname(self).

utcoffset

Return self.tzinfo.utcoffset(self).

Attributes

fold

hour

max

microsecond

min

minute

resolution

second

tzinfo

static __new__(cls, *args: Any, tzinfo: tzinfo | Timezone | str | None = None, **kwargs: Any) Time

Create a new Time instance with optional tzinfo parameter.

Parameters:
  • *args – Positional arguments passed to pendulum.Time

  • tzinfo – Optional timezone information - can be: - datetime.tzinfo object - pendulum.Timezone object - string (timezone name like ‘UTC’, ‘Europe/Berlin’)

  • **kwargs – Keyword arguments passed to pendulum.Time

__repr__() str

Enhanced repr with more detailed information.

__str__() str

String representation for user-friendly display.

__eq__(other: Any) bool

Enhanced equality comparison that handles timezone conversion.

__hash__() int

Hash function that considers timezone.

to_local() Time

Convert to local timezone.

to_utc() Time

Convert to UTC timezone.

in_timezone(timezone: str | Timezone) Time

Convert to specified timezone.

is_naive() bool

Check if time is timezone-naive.

is_aware() bool

Check if time is timezone-aware.

replace_timezone(tz: str | Timezone | None) Time

Replace timezone without converting the time value.

format_user_friendly(include_seconds: bool = False, include_timezone: bool | None = None) str

Format time in a user-friendly way.

Parameters:
  • include_seconds – Whether to include seconds in the output

  • include_timezone – Whether to include timezone info (auto-detected if None)

classmethod now(tz: str | Timezone = None) Time

Get current time with optional timezone.

classmethod parse(time_string: str) Time

Parse time string using your enhanced parser.

add(hours: int = 0, minutes: int = 0, seconds: int = 0, microseconds: int = 0) Time

Add duration to the instance.

Parameters:
  • hours – The number of hours

  • minutes – The number of minutes

  • seconds – The number of seconds

  • microseconds – The number of microseconds

add_timedelta(delta: timedelta) Time

Add timedelta duration to the instance.

Parameters:

delta – The timedelta instance

closest(dt1: Time | time, dt2: Time | time) Self

Get the closest time from the instance.

diff(dt: time | None = None, abs: bool = True) Duration

Returns the difference between two Time objects as an Duration.

Parameters:
  • dt – The time to subtract from

  • abs – Whether to return an absolute duration or not

diff_for_humans(other: time | None = None, absolute: bool = False, locale: str | None = None) str

Get the difference in a human readable format in the current locale.

Parameters:
  • dt – The time to subtract from

  • absolute – removes time difference modifiers ago, after, etc

  • locale – The locale to use for localization

dst()

Return self.tzinfo.dst(self).

farthest(dt1: Time | time, dt2: Time | time) Self

Get the farthest time from the instance.

fold
for_json() str

Methods for automatic json serialization by simplejson.

format(fmt: str, locale: str | None = None) str

Formats the instance using the given format.

Parameters:
  • fmt – The format to use

  • locale – The locale to use

classmethod fromisoformat()

string -> time from a string in ISO 8601 format

hour
classmethod instance(t: time, tz: str | Timezone | FixedTimezone | datetime.tzinfo | None = Timezone('UTC')) Self
isoformat()

Return string in ISO 8601 format, [HH[:MM[:SS[.mmm[uuu]]]]][+HH:MM].

The optional argument timespec specifies the number of additional terms of the time to include. Valid options are ‘auto’, ‘hours’, ‘minutes’, ‘seconds’, ‘milliseconds’ and ‘microseconds’.

max = Time(23, 59, 59, 999999)
microsecond
min = Time(0, 0, 0)
minute
replace(hour: SupportsIndex | None = None, minute: SupportsIndex | None = None, second: SupportsIndex | None = None, microsecond: SupportsIndex | None = None, tzinfo: bool | datetime.tzinfo | Literal[True] | None = True, fold: int = 0) Self

Return time with new specified fields.

resolution = Duration(microseconds=1)
second
strftime()

format -> strftime() style string.

subtract(hours: int = 0, minutes: int = 0, seconds: int = 0, microseconds: int = 0) Time

Add duration to the instance.

Parameters:
  • hours (int) – The number of hours

  • minutes (int) – The number of minutes

  • seconds (int) – The number of seconds

  • microseconds (int) – The number of microseconds

Return type:

Time

subtract_timedelta(delta: timedelta) Time

Remove timedelta duration from the instance.

Parameters:

delta – The timedelta instance

tzinfo
tzname()

Return self.tzinfo.tzname(self).

utcoffset()

Return self.tzinfo.utcoffset(self).