@@ -4,36 +4,40 @@ import rawTimeZones from "../raw-time-zones.json";
4
4
5
5
import formatTimeZone from "./formatTimeZone.js" ;
6
6
7
- export default function getTimeZones ( ) {
7
+ export default function getTimeZones ( opts ) {
8
+ const includeUtc = ! ! opts && opts . includeUtc ;
8
9
return rawTimeZones
9
- . reduce ( function ( acc , timeZone ) {
10
- const currentDate = DateTime . fromObject ( {
11
- locale : "en-US" ,
12
- zone : timeZone . name ,
13
- } ) ;
14
-
15
- // We build on the latest Node.js version, Node.js embed IANA databases
16
- // it might happen that the environment that will execute getTimeZones() will not know about some
17
- // timezones. So we ignore the timezone at runtim
18
- // See https://github.com/vvo/tzdb/issues/43
19
- if ( currentDate . isValid === false ) {
10
+ . reduce (
11
+ function ( acc , timeZone ) {
12
+ const currentDate = DateTime . fromObject ( {
13
+ locale : "en-US" ,
14
+ zone : timeZone . name ,
15
+ } ) ;
16
+
17
+ // We build on the latest Node.js version, Node.js embed IANA databases
18
+ // it might happen that the environment that will execute getTimeZones() will not know about some
19
+ // timezones. So we ignore the timezone at runtim
20
+ // See https://github.com/vvo/tzdb/issues/43
21
+ if ( currentDate . isValid === false ) {
22
+ return acc ;
23
+ }
24
+
25
+ const timeZoneWithCurrentTimeData = {
26
+ ...timeZone ,
27
+ currentTimeOffsetInMinutes : currentDate . offset ,
28
+ } ;
29
+
30
+ acc . push ( {
31
+ ...timeZoneWithCurrentTimeData ,
32
+ currentTimeFormat : formatTimeZone ( timeZoneWithCurrentTimeData , {
33
+ useCurrentOffset : true ,
34
+ } ) ,
35
+ } ) ;
36
+
20
37
return acc ;
21
- }
22
-
23
- const timeZoneWithCurrentTimeData = {
24
- ...timeZone ,
25
- currentTimeOffsetInMinutes : currentDate . offset ,
26
- } ;
27
-
28
- acc . push ( {
29
- ...timeZoneWithCurrentTimeData ,
30
- currentTimeFormat : formatTimeZone ( timeZoneWithCurrentTimeData , {
31
- useCurrentOffset : true ,
32
- } ) ,
33
- } ) ;
34
-
35
- return acc ;
36
- } , [ ] )
38
+ } ,
39
+ includeUtc ? [ utcTimezone ] : [ ] ,
40
+ )
37
41
. sort ( ( a , b ) => {
38
42
return (
39
43
compareNumbers ( a , b ) ||
@@ -53,3 +57,18 @@ function compareStrings(x, y) {
53
57
}
54
58
return 0 ;
55
59
}
60
+
61
+ const utcTimezone = {
62
+ name : "UTC" ,
63
+ alternativeName : "Coordinated Universal Time (UTC)" ,
64
+ abbreviation : "UTC" ,
65
+ group : [ "UTC" ] ,
66
+ countryName : "" ,
67
+ continentCode : "" ,
68
+ continentName : "" ,
69
+ mainCities : [ "" ] ,
70
+ rawOffsetInMinutes : 0 ,
71
+ rawFormat : "+00:00 Coordinated Universal Time (UTC)" ,
72
+ currentTimeOffsetInMinutes : 0 ,
73
+ currentTimeFormat : "+00:00 Coordinated Universal Time (UTC)" ,
74
+ } ;
0 commit comments