Make timezone more global

This commit is contained in:
Stefan Ålund
2020-03-03 21:06:58 +01:00
parent f08fcbec30
commit e572b65e4e
@@ -3,14 +3,14 @@ import { HeaderLabel } from '@spotify-backstage/core';
const timeFormat = { hour: '2-digit', minute: '2-digit' };
const nycOptions = { timeZone: 'America/New_York', ...timeFormat };
const utcOptions = { timeZone: 'UTC', ...timeFormat };
const lonOptions = { timeZone: 'Europe/London', ...timeFormat };
const sydOptions = { timeZone: 'Australia/Sydney', ...timeFormat };
const tyoOptions = { timeZone: 'Asia/Tokyo', ...timeFormat };
const stoOptions = { timeZone: 'Europe/Stockholm', ...timeFormat };
const defaultTimes = {
timeNY: '',
timeUTC: '',
timeLON: '',
timeSYD: '',
timeTYO: '',
timeSTO: '',
};
@@ -21,15 +21,15 @@ function getTimes() {
// Using the browser native toLocaleTimeString instead of huge moment-tz
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleTimeString
const timeNY = d.toLocaleTimeString(lang, nycOptions);
const timeUTC = d.toLocaleTimeString(lang, utcOptions);
const timeLON = d.toLocaleTimeString(lang, lonOptions);
const timeSYD = d.toLocaleTimeString(lang, sydOptions);
const timeTYO = d.toLocaleTimeString(lang, tyoOptions);
const timeSTO = d.toLocaleTimeString(lang, stoOptions);
return { timeNY, timeUTC, timeLON, timeSTO };
return { timeNY, timeSYD, timeTYO, timeSTO };
}
const HomePageTimer: FC<{}> = () => {
const [{ timeNY, timeUTC, timeLON, timeSTO }, setTimes] = React.useState(
const [{ timeNY, timeSYD, timeTYO, timeSTO }, setTimes] = React.useState(
defaultTimes,
);
@@ -48,9 +48,9 @@ const HomePageTimer: FC<{}> = () => {
return (
<>
<HeaderLabel label="NYC" value={timeNY} />
<HeaderLabel label="UTC" value={timeUTC} />
<HeaderLabel label="LON" value={timeLON} />
<HeaderLabel label="STO" value={timeSTO} />
<HeaderLabel label="TYO" value={timeTYO} />
<HeaderLabel label="SYD" value={timeSYD} />
</>
);
};