Fix: added a check for invalid timezone
This commit is contained in:
@@ -39,18 +39,28 @@ function getTimes(configApi: ConfigApi) {
|
||||
|
||||
for (const clock of clockConfigs) {
|
||||
if (clock.has('label') && clock.has('timezone')) {
|
||||
let label = clock.getString('label');
|
||||
|
||||
const options = {
|
||||
timeZone: clock.getString('timezone'),
|
||||
...timeFormat,
|
||||
};
|
||||
|
||||
const time = d.toLocaleTimeString(lang, options);
|
||||
const label = clock.getString('label');
|
||||
try {
|
||||
new Date().toLocaleString(lang, options);
|
||||
} catch (e) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.warn(
|
||||
`The timezone ${options.timeZone} is invalid. Defaulting to America/Los Angeles`,
|
||||
);
|
||||
options.timeZone = 'America/Los_Angeles';
|
||||
label = 'Los Angeles';
|
||||
}
|
||||
|
||||
const time = d.toLocaleTimeString(lang, options);
|
||||
clocks.push({ time, label });
|
||||
}
|
||||
}
|
||||
|
||||
return clocks;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user