1
1
mirror of https://github.com/leon-ai/leon.git synced 2024-11-28 12:43:35 +03:00

fix: precise units used in time zone data

This commit is contained in:
Théo LUDWIG 2023-06-29 23:14:14 +02:00
parent cc01bd18b2
commit 02e1de8ffa
No known key found for this signature in database
GPG Key ID: ADFE5A563D718F3B
4 changed files with 8 additions and 41 deletions

View File

@ -424,8 +424,8 @@ export interface SpacyLocationCityEntity
time_zone: {
country_code: string
id: string
coordinated_universal_time_offset: number
daylight_saving_time_offset: number
coordinated_universal_time_offset_hours: number
daylight_saving_time_offset_hours: number
}
}
}

View File

@ -44,11 +44,11 @@ export const run: ActionFunction = async function (params) {
const currentDate = getCurrentCoordinatedUniversalTime()
if (isDaylightSavingTime(currentDate)) {
currentDate.setHours(
currentDate.getHours() + time_zone.daylight_saving_time_offset
currentDate.getHours() + time_zone.daylight_saving_time_offset_hours
)
} else {
currentDate.setHours(
currentDate.getHours() + time_zone.coordinated_universal_time_offset
currentDate.getHours() + time_zone.coordinated_universal_time_offset_hours
)
}

View File

@ -36,8 +36,8 @@ cities = gc.get_cities()
class TimeZone(TypedDict):
country_code: str
id: str
coordinated_universal_time_offset: float
daylight_saving_time_offset: float
coordinated_universal_time_offset_hours: float
daylight_saving_time_offset_hours: float
# Extracted from: <https://download.geonames.org/export/dump/timeZones.txt>
@ -57,8 +57,8 @@ def get_time_zone_data(time_zone_id: str) -> Union[TimeZone, None]:
time_zone_data = {
'country_code': time_zone[0],
'id': time_zone[1],
'coordinated_universal_time_offset': float(time_zone[2]),
'daylight_saving_time_offset': float(time_zone[3])
'coordinated_universal_time_offset_hours': float(time_zone[2]),
'daylight_saving_time_offset_hours': float(time_zone[3])
}
break
return time_zone_data

View File

@ -1,33 +0,0 @@
import os
from typing import Union, TypedDict
class TimeZone(TypedDict):
country_code: str
id: str
coordinated_universal_time_offset: float
daylight_saving_time_offset: float
# Extracted from: <https://download.geonames.org/export/dump/timeZones.txt>
time_zones_path = os.path.join(os.path.dirname(__file__), 'time_zones.txt')
time_zones: list[list[str]] = []
with open(time_zones_path, 'r') as file:
lines = file.read().splitlines()
for line in lines:
time_zones.append(line.rstrip().split('\t'))
def get_time_zone_data(time_zone_id: str) -> Union[TimeZone, None]:
time_zone_data: Union[TimeZone, None] = None
for time_zone in time_zones:
if time_zone[1] == time_zone_id:
time_zone_data = {
'country_code': time_zone[0],
'id': time_zone[1],
'coordinated_universal_time_offset': float(time_zone[2]),
'daylight_saving_time_offset': float(time_zone[3])
}
break
return time_zone_data