timecapsule/libs/timeGet.ts
2024-03-29 22:41:06 +01:00

17 lines
564 B
TypeScript

import type timeKey from "./types/timeKey";
import { Client as NTP } from "ntp-time"
const ntp_client = new NTP('0.europe.pool.ntp.org', 123, { timeout: 1000 });
// Get time from NTP and create a timeKey without a password linked
export default async function timeGet(): Promise<timeKey>{
const ntp = await ntp_client.syncTime();
const date = new Date(ntp.time);
return {
time: {
day: date.getDate(),
month: date.getMonth() + 1,
year: date.getFullYear(),
},
password: "",
} as timeKey;
}