File size: 375 Bytes
d9494a5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import { isNonEmptyString } from '@sniptt/guards';

export const getValidTimeZoneOrUndefined = (
  timeZone: string | null | undefined,
): string | undefined => {
  if (!isNonEmptyString(timeZone) || timeZone === 'system') {
    return undefined;
  }

  try {
    new Intl.DateTimeFormat('en-US', { timeZone });

    return timeZone;
  } catch {
    return undefined;
  }
};