Skip to content

Commit

Permalink
Fix timezone offset
Browse files Browse the repository at this point in the history
  • Loading branch information
cristiancolosimo committed Nov 6, 2023
1 parent f087552 commit 5e40b4c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
10 changes: 8 additions & 2 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}
Expand Down
5 changes: 4 additions & 1 deletion src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -25,5 +27,6 @@ export function get_env() {
GET_LAB_STATE_ENDPOINT,
GET_LAB_HISTORY_ENDPOINT,
HISTORY_INTERVAL:parseInt(HISTORY_INTERVAL),
TIMEZONE_OFFSET
};
}

0 comments on commit 5e40b4c

Please sign in to comment.