- updated version to 1.0.23, enhance audio file handling, and improve UTC synchronization checks
This commit is contained in:
@@ -197,3 +197,21 @@ export const ValidateIPaddress = (value: string | undefined) => {
|
||||
return "Invalid IP address format";
|
||||
}
|
||||
};
|
||||
|
||||
export function isUtcOutOfSync(
|
||||
data: {
|
||||
utctime: number;
|
||||
localdate: string;
|
||||
localtime: string;
|
||||
},
|
||||
maxDriftMs = 60_000
|
||||
) {
|
||||
const utc = new Date(data.utctime);
|
||||
|
||||
const [d, m, y] = data.localdate.split("/").map(Number);
|
||||
const [hh, mm, ss] = data.localtime.split(":").map(Number);
|
||||
// Construct local Date in device’s local timezone
|
||||
const local = new Date(y, m - 1, d, hh, mm, ss);
|
||||
const driftMs = Math.abs(utc.getTime() - local.getTime() + utc.getTimezoneOffset() * 60_000);
|
||||
return { driftMs, outOfSync: driftMs > maxDriftMs };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user