akkudoktoreos.utils.datetimeutil.to_timezone
- akkudoktoreos.utils.datetimeutil.to_timezone(utc_offset: float | None = None, location: Tuple[float, float] | None = None, as_string: Literal[True] = True) str
- akkudoktoreos.utils.datetimeutil.to_timezone(utc_offset: float | None = None, location: Tuple[float, float] | None = None, as_string: Literal[False] | None = None) Timezone
Determines the timezone either by UTC offset, geographic location, or local system timezone.
By default, it returns a Timezone object representing the timezone. If as_string is set to True, the function returns the timezone name as a string instead.
- Parameters:
utc_offset (Optional[float]) – UTC offset in hours. Positive for UTC+, negative for UTC-.
location (Optional[Tuple[float,float]]) – A tuple containing latitude and longitude as floats.
as_string (Optional[bool]) –
If True, returns the timezone as a string (e.g., “America/New_York”).
If False or not provided, returns a Timezone object for the timezone.
- Returns:
A timezone name as a string (e.g., “America/New_York”) if as_string is True.
A Timezone object if as_string is False or not provided.
- Return type:
Union[Timezone, str]
- Raises:
ValueError – If invalid inputs are provided.
Example
>>> to_timezone(utc_offset=5.5, as_string=True) 'UTC+05:30'
>>> to_timezone(location=(40.7128, -74.0060)) <Timezone [America/New_York]>
>>> to_timezone() <Timezone [America/New_York]> # Returns local timezone