diff --git a/index.ts b/index.ts index 6aa912c..b43762d 100644 --- a/index.ts +++ b/index.ts @@ -8,6 +8,13 @@ import { import { get_db } from "./src/db.ts"; import { get_env } from "./src/env.ts"; import { ResponseLab } from "./src/interface.ts"; + + + + + + + const env = get_env(); const db = get_db(); function generataRisposta(id: number, nome?: string): string { @@ -43,8 +50,7 @@ const getCurrentLabState = async () => { const jsonFetchApetureOnline = await rawFetchApetureOnline.json(); let nome = undefined; const dataAttuale = new Date() as any; - dataAttuale.setHours(dataAttuale.getHours() + 2); - const dataApetura = new Date(jsonFetchApetureOnline[0].time) as any; + const dataApetura = new Date(jsonFetchApetureOnline[0].time+env.TIMEZONE_OFFSET) as any; if (dataAttuale - dataApetura < env.HISTORY_INTERVAL) { nome = jsonFetchApetureOnline[0].user; } diff --git a/src/env.ts b/src/env.ts index c50c799..cebd23b 100644 --- a/src/env.ts +++ b/src/env.ts @@ -4,12 +4,14 @@ export function get_env() { const GET_LAB_STATE_ENDPOINT = Deno.env.get("GET_LAB_STATE_ENDPOINT"); const GET_LAB_HISTORY_ENDPOINT = Deno.env.get("GET_LAB_HISTORY_ENDPOINT"); const HISTORY_INTERVAL = Deno.env.get("HISTORY_INTERVAL"); + const TIMEZONE_OFFSET = Deno.env.get("TIMEZONE_OFFSET"); console.log( "keys", TOKEN_TELEGRAM, POLLING_INTERVAL, GET_LAB_STATE_ENDPOINT, - GET_LAB_HISTORY_ENDPOINT + GET_LAB_HISTORY_ENDPOINT, + TIMEZONE_OFFSET ); if (!TOKEN_TELEGRAM) throw new Error("Bot token is not provided"); if (!POLLING_INTERVAL) throw new Error("Polling interval is not provided"); @@ -25,5 +27,6 @@ export function get_env() { GET_LAB_STATE_ENDPOINT, GET_LAB_HISTORY_ENDPOINT, HISTORY_INTERVAL:parseInt(HISTORY_INTERVAL), + TIMEZONE_OFFSET }; }