summaryrefslogtreecommitdiff
path: root/src/components/_sila/Mixins/LocalTimezoneLabelMixin.js
blob: ffa54d59ae2367f75a3080e66033271aac6ee6f3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { format } from 'date-fns-tz';

const LocalTimezoneLabelMixin = {
  methods: {
    localOffset() {
      const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
      const pattern = ' O';
      return format(new Date(), pattern, { timezone }).replace('GMT', 'UTC');
    },
    timeZones() {
      const intlTimeZones = Intl.supportedValuesOf('timeZone');
      const pattern = 'O';
      return intlTimeZones.map((timeZone) => {
        let utc = format(new Date(), pattern, {
          timeZone,
        }).replace('GMT', 'UTC');
        return `(${utc}) ${timeZone}`;
      });
    },
  },
};

export default LocalTimezoneLabelMixin;