Skip to content

TimeZoneOffsetProvider

QuantConnect.TimeZoneOffsetProvider

TimeZoneOffsetProvider(
    time_zone: Any,
    utc_start_time: Union[datetime, date],
    utc_end_time: Union[datetime, date],
)

Bases: Object

Represents the discontinuties in a single time zone and provides offsets to UTC. This type assumes that times will be asked in a forward marching manner. This type is not thread safe.

Initializes a new instance of the TimeZoneOffsetProvider class

Parameters:

Name Type Description Default
time_zone Any

The time zone to provide offsets for

required
utc_start_time Union[datetime, date]

The start of the range of offsets. Careful here, it will determine the current discontinuity offset value. When requested to convert a date we only look forward for new discontinuities but we suppose the current offset is correct for the requested date if in the past.

required
utc_end_time Union[datetime, date]

The end of the range of offsets

required

time_zone

time_zone: Any

Gets the time zone this instances provides offsets for

convert_from_utc

convert_from_utc(
    utc_time: Union[datetime, date],
) -> datetime

Converts the specified utc_time using the offset resolved from a call to get_offset_ticks

Parameters:

Name Type Description Default
utc_time Union[datetime, date]

The time to convert from utc

required

Returns:

Type Description
datetime

The same instant in time represented in the time_zone.

convert_to_utc

convert_to_utc(
    local_time: Union[datetime, date],
) -> datetime

Converts the specified local time to UTC. This function will advance this offset provider

Parameters:

Name Type Description Default
local_time Union[datetime, date]

The local time to be converted to UTC

required

Returns:

Type Description
datetime

The specified time in UTC.

get_next_discontinuity

get_next_discontinuity() -> int

Gets this offset provider's next discontinuity

Returns:

Type Description
int

The next discontinuity in UTC ticks.

get_offset_ticks

get_offset_ticks(utc_time: Union[datetime, date]) -> int

Gets the offset in ticks from this time zone to UTC, such that UTC time + offset = local time

Parameters:

Name Type Description Default
utc_time Union[datetime, date]

The time in UTC to get an offset to local

required

Returns:

Type Description
int

The offset in ticks between UTC and the local time zone.