camstreamerlib
Version:
Helper library for CamStreamer ACAP applications.
26 lines (25 loc) • 874 B
JavaScript
import { exec } from 'child_process';
import { promisify } from 'util';
const execPromise = promisify(exec);
export class TimeZoneDaemon {
checkTimer;
constructor(checkInterval = 60000) {
this.checkTimer = setInterval(() => this.checkAndUpdateTimeZone(), checkInterval);
}
stop() {
clearInterval(this.checkTimer);
}
async checkAndUpdateTimeZone() {
try {
const { stdout } = await execPromise('timedatectl show -p Timezone --value');
const systemTimezone = stdout.toString().trim();
const nodeTimezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
if (systemTimezone !== nodeTimezone) {
process.env.TZ = systemTimezone;
}
}
catch (error) {
console.error('Error checking/updating timezone:', error);
}
}
}