fingerprintjs

Форк
0
/
timezone.ts 
29 строк · 1.1 Кб
1
import { toFloat } from '../utils/data'
2

3
export default function getTimezone(): string {
4
  const DateTimeFormat = window.Intl?.DateTimeFormat
5
  if (DateTimeFormat) {
6
    const timezone = new DateTimeFormat().resolvedOptions().timeZone
7
    if (timezone) {
8
      return timezone
9
    }
10
  }
11

12
  // For browsers that don't support timezone names
13
  // The minus is intentional because the JS offset is opposite to the real offset
14
  const offset = -getTimezoneOffset()
15
  return `UTC${offset >= 0 ? '+' : ''}${offset}`
16
}
17

18
function getTimezoneOffset(): number {
19
  const currentYear = new Date().getFullYear()
20
  // The timezone offset may change over time due to daylight saving time (DST) shifts.
21
  // The non-DST timezone offset is used as the result timezone offset.
22
  // Since the DST season differs in the northern and the southern hemispheres,
23
  // both January and July timezones offsets are considered.
24
  return Math.max(
25
    // `getTimezoneOffset` returns a number as a string in some unidentified cases
26
    toFloat(new Date(currentYear, 0, 1).getTimezoneOffset()),
27
    toFloat(new Date(currentYear, 6, 1).getTimezoneOffset()),
28
  )
29
}
30

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.