feelin 4.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +6 -0
  3. data/.rspec +2 -0
  4. data/CHANGELOG.md +10 -0
  5. data/Gemfile +3 -0
  6. data/LICENSE.txt +21 -0
  7. data/README.md +43 -0
  8. data/feelin.gemspec +22 -0
  9. data/lib/feelin/js/node_modules/.package-lock.json +67 -0
  10. data/lib/feelin/js/node_modules/@lezer/common/LICENSE +21 -0
  11. data/lib/feelin/js/node_modules/@lezer/common/README.md +14 -0
  12. data/lib/feelin/js/node_modules/@lezer/common/dist/index.cjs +2181 -0
  13. data/lib/feelin/js/node_modules/@lezer/common/dist/index.d.cts +1137 -0
  14. data/lib/feelin/js/node_modules/@lezer/common/dist/index.d.ts +1137 -0
  15. data/lib/feelin/js/node_modules/@lezer/common/dist/index.js +2168 -0
  16. data/lib/feelin/js/node_modules/@lezer/common/package.json +32 -0
  17. data/lib/feelin/js/node_modules/@lezer/highlight/LICENSE +21 -0
  18. data/lib/feelin/js/node_modules/@lezer/highlight/README.md +14 -0
  19. data/lib/feelin/js/node_modules/@lezer/highlight/dist/index.cjs +915 -0
  20. data/lib/feelin/js/node_modules/@lezer/highlight/dist/index.d.cts +621 -0
  21. data/lib/feelin/js/node_modules/@lezer/highlight/dist/index.d.ts +623 -0
  22. data/lib/feelin/js/node_modules/@lezer/highlight/dist/index.js +904 -0
  23. data/lib/feelin/js/node_modules/@lezer/highlight/package.json +31 -0
  24. data/lib/feelin/js/node_modules/@lezer/lr/LICENSE +21 -0
  25. data/lib/feelin/js/node_modules/@lezer/lr/README.md +25 -0
  26. data/lib/feelin/js/node_modules/@lezer/lr/dist/constants.d.ts +45 -0
  27. data/lib/feelin/js/node_modules/@lezer/lr/dist/constants.js +5 -0
  28. data/lib/feelin/js/node_modules/@lezer/lr/dist/index.cjs +1890 -0
  29. data/lib/feelin/js/node_modules/@lezer/lr/dist/index.d.cts +303 -0
  30. data/lib/feelin/js/node_modules/@lezer/lr/dist/index.d.ts +303 -0
  31. data/lib/feelin/js/node_modules/@lezer/lr/dist/index.js +1883 -0
  32. data/lib/feelin/js/node_modules/@lezer/lr/package.json +32 -0
  33. data/lib/feelin/js/node_modules/feelin/LICENSE +21 -0
  34. data/lib/feelin/js/node_modules/feelin/README.md +65 -0
  35. data/lib/feelin/js/node_modules/feelin/dist/builtins.d.ts +355 -0
  36. data/lib/feelin/js/node_modules/feelin/dist/index.cjs +2072 -0
  37. data/lib/feelin/js/node_modules/feelin/dist/index.cjs.map +1 -0
  38. data/lib/feelin/js/node_modules/feelin/dist/index.d.ts +3 -0
  39. data/lib/feelin/js/node_modules/feelin/dist/index.esm.js +2063 -0
  40. data/lib/feelin/js/node_modules/feelin/dist/index.esm.js.map +1 -0
  41. data/lib/feelin/js/node_modules/feelin/dist/interpreter.d.ts +26 -0
  42. data/lib/feelin/js/node_modules/feelin/dist/parser.d.ts +4 -0
  43. data/lib/feelin/js/node_modules/feelin/dist/temporal.d.ts +6 -0
  44. data/lib/feelin/js/node_modules/feelin/dist/types.d.ts +35 -0
  45. data/lib/feelin/js/node_modules/feelin/dist/utils.d.ts +12 -0
  46. data/lib/feelin/js/node_modules/feelin/package.json +63 -0
  47. data/lib/feelin/js/node_modules/lezer-feel/LICENSE +21 -0
  48. data/lib/feelin/js/node_modules/lezer-feel/README.md +94 -0
  49. data/lib/feelin/js/node_modules/lezer-feel/dist/index.cjs +1328 -0
  50. data/lib/feelin/js/node_modules/lezer-feel/dist/index.cjs.map +1 -0
  51. data/lib/feelin/js/node_modules/lezer-feel/dist/index.d.ts +32 -0
  52. data/lib/feelin/js/node_modules/lezer-feel/dist/index.js +1323 -0
  53. data/lib/feelin/js/node_modules/lezer-feel/dist/index.js.map +1 -0
  54. data/lib/feelin/js/node_modules/lezer-feel/package.json +61 -0
  55. data/lib/feelin/js/node_modules/luxon/LICENSE.md +7 -0
  56. data/lib/feelin/js/node_modules/luxon/README.md +55 -0
  57. data/lib/feelin/js/node_modules/luxon/build/amd/luxon.js +8623 -0
  58. data/lib/feelin/js/node_modules/luxon/build/amd/luxon.js.map +1 -0
  59. data/lib/feelin/js/node_modules/luxon/build/cjs-browser/luxon.js +8621 -0
  60. data/lib/feelin/js/node_modules/luxon/build/cjs-browser/luxon.js.map +1 -0
  61. data/lib/feelin/js/node_modules/luxon/build/es6/luxon.js +8011 -0
  62. data/lib/feelin/js/node_modules/luxon/build/es6/luxon.js.map +1 -0
  63. data/lib/feelin/js/node_modules/luxon/build/global/luxon.js +8626 -0
  64. data/lib/feelin/js/node_modules/luxon/build/global/luxon.js.map +1 -0
  65. data/lib/feelin/js/node_modules/luxon/build/global/luxon.min.js +1 -0
  66. data/lib/feelin/js/node_modules/luxon/build/global/luxon.min.js.map +1 -0
  67. data/lib/feelin/js/node_modules/luxon/build/node/luxon.js +7679 -0
  68. data/lib/feelin/js/node_modules/luxon/build/node/luxon.js.map +1 -0
  69. data/lib/feelin/js/node_modules/luxon/package.json +87 -0
  70. data/lib/feelin/js/node_modules/luxon/src/datetime.js +2566 -0
  71. data/lib/feelin/js/node_modules/luxon/src/duration.js +990 -0
  72. data/lib/feelin/js/node_modules/luxon/src/errors.js +61 -0
  73. data/lib/feelin/js/node_modules/luxon/src/impl/conversions.js +206 -0
  74. data/lib/feelin/js/node_modules/luxon/src/impl/diff.js +95 -0
  75. data/lib/feelin/js/node_modules/luxon/src/impl/digits.js +90 -0
  76. data/lib/feelin/js/node_modules/luxon/src/impl/english.js +233 -0
  77. data/lib/feelin/js/node_modules/luxon/src/impl/formats.js +176 -0
  78. data/lib/feelin/js/node_modules/luxon/src/impl/formatter.js +409 -0
  79. data/lib/feelin/js/node_modules/luxon/src/impl/invalid.js +14 -0
  80. data/lib/feelin/js/node_modules/luxon/src/impl/locale.js +554 -0
  81. data/lib/feelin/js/node_modules/luxon/src/impl/regexParser.js +335 -0
  82. data/lib/feelin/js/node_modules/luxon/src/impl/tokenParser.js +505 -0
  83. data/lib/feelin/js/node_modules/luxon/src/impl/util.js +316 -0
  84. data/lib/feelin/js/node_modules/luxon/src/impl/zoneUtil.js +34 -0
  85. data/lib/feelin/js/node_modules/luxon/src/info.js +205 -0
  86. data/lib/feelin/js/node_modules/luxon/src/interval.js +665 -0
  87. data/lib/feelin/js/node_modules/luxon/src/luxon.js +26 -0
  88. data/lib/feelin/js/node_modules/luxon/src/package.json +4 -0
  89. data/lib/feelin/js/node_modules/luxon/src/settings.js +180 -0
  90. data/lib/feelin/js/node_modules/luxon/src/zone.js +97 -0
  91. data/lib/feelin/js/node_modules/luxon/src/zones/IANAZone.js +231 -0
  92. data/lib/feelin/js/node_modules/luxon/src/zones/fixedOffsetZone.js +150 -0
  93. data/lib/feelin/js/node_modules/luxon/src/zones/invalidZone.js +53 -0
  94. data/lib/feelin/js/node_modules/luxon/src/zones/systemZone.js +61 -0
  95. data/lib/feelin/js/node_modules/min-dash/LICENSE +21 -0
  96. data/lib/feelin/js/node_modules/min-dash/README.md +38 -0
  97. data/lib/feelin/js/node_modules/min-dash/dist/array.d.ts +12 -0
  98. data/lib/feelin/js/node_modules/min-dash/dist/collection.d.ts +174 -0
  99. data/lib/feelin/js/node_modules/min-dash/dist/fn.d.ts +37 -0
  100. data/lib/feelin/js/node_modules/min-dash/dist/index.cjs +910 -0
  101. data/lib/feelin/js/node_modules/min-dash/dist/index.d.ts +5 -0
  102. data/lib/feelin/js/node_modules/min-dash/dist/index.esm.js +872 -0
  103. data/lib/feelin/js/node_modules/min-dash/dist/lang.d.ts +29 -0
  104. data/lib/feelin/js/node_modules/min-dash/dist/min-dash.js +916 -0
  105. data/lib/feelin/js/node_modules/min-dash/dist/min-dash.min.js +1 -0
  106. data/lib/feelin/js/node_modules/min-dash/dist/object.d.ts +112 -0
  107. data/lib/feelin/js/node_modules/min-dash/package.json +72 -0
  108. data/lib/feelin/js/package-lock.json +72 -0
  109. data/lib/feelin/js/package.json +5 -0
  110. data/lib/feelin/version.rb +3 -0
  111. data/lib/feelin.rb +63 -0
  112. data/spec/feelin/feelin_spec.rb +38 -0
  113. data/spec/spec_helper.rb +2 -0
  114. metadata +198 -0
@@ -0,0 +1,180 @@
1
+ import SystemZone from "./zones/systemZone.js";
2
+ import IANAZone from "./zones/IANAZone.js";
3
+ import Locale from "./impl/locale.js";
4
+ import DateTime from "./datetime.js";
5
+
6
+ import { normalizeZone } from "./impl/zoneUtil.js";
7
+ import { validateWeekSettings } from "./impl/util.js";
8
+ import { resetDigitRegexCache } from "./impl/digits.js";
9
+
10
+ let now = () => Date.now(),
11
+ defaultZone = "system",
12
+ defaultLocale = null,
13
+ defaultNumberingSystem = null,
14
+ defaultOutputCalendar = null,
15
+ twoDigitCutoffYear = 60,
16
+ throwOnInvalid,
17
+ defaultWeekSettings = null;
18
+
19
+ /**
20
+ * Settings contains static getters and setters that control Luxon's overall behavior. Luxon is a simple library with few options, but the ones it does have live here.
21
+ */
22
+ export default class Settings {
23
+ /**
24
+ * Get the callback for returning the current timestamp.
25
+ * @type {function}
26
+ */
27
+ static get now() {
28
+ return now;
29
+ }
30
+
31
+ /**
32
+ * Set the callback for returning the current timestamp.
33
+ * The function should return a number, which will be interpreted as an Epoch millisecond count
34
+ * @type {function}
35
+ * @example Settings.now = () => Date.now() + 3000 // pretend it is 3 seconds in the future
36
+ * @example Settings.now = () => 0 // always pretend it's Jan 1, 1970 at midnight in UTC time
37
+ */
38
+ static set now(n) {
39
+ now = n;
40
+ }
41
+
42
+ /**
43
+ * Set the default time zone to create DateTimes in. Does not affect existing instances.
44
+ * Use the value "system" to reset this value to the system's time zone.
45
+ * @type {string}
46
+ */
47
+ static set defaultZone(zone) {
48
+ defaultZone = zone;
49
+ }
50
+
51
+ /**
52
+ * Get the default time zone object currently used to create DateTimes. Does not affect existing instances.
53
+ * The default value is the system's time zone (the one set on the machine that runs this code).
54
+ * @type {Zone}
55
+ */
56
+ static get defaultZone() {
57
+ return normalizeZone(defaultZone, SystemZone.instance);
58
+ }
59
+
60
+ /**
61
+ * Get the default locale to create DateTimes with. Does not affect existing instances.
62
+ * @type {string}
63
+ */
64
+ static get defaultLocale() {
65
+ return defaultLocale;
66
+ }
67
+
68
+ /**
69
+ * Set the default locale to create DateTimes with. Does not affect existing instances.
70
+ * @type {string}
71
+ */
72
+ static set defaultLocale(locale) {
73
+ defaultLocale = locale;
74
+ }
75
+
76
+ /**
77
+ * Get the default numbering system to create DateTimes with. Does not affect existing instances.
78
+ * @type {string}
79
+ */
80
+ static get defaultNumberingSystem() {
81
+ return defaultNumberingSystem;
82
+ }
83
+
84
+ /**
85
+ * Set the default numbering system to create DateTimes with. Does not affect existing instances.
86
+ * @type {string}
87
+ */
88
+ static set defaultNumberingSystem(numberingSystem) {
89
+ defaultNumberingSystem = numberingSystem;
90
+ }
91
+
92
+ /**
93
+ * Get the default output calendar to create DateTimes with. Does not affect existing instances.
94
+ * @type {string}
95
+ */
96
+ static get defaultOutputCalendar() {
97
+ return defaultOutputCalendar;
98
+ }
99
+
100
+ /**
101
+ * Set the default output calendar to create DateTimes with. Does not affect existing instances.
102
+ * @type {string}
103
+ */
104
+ static set defaultOutputCalendar(outputCalendar) {
105
+ defaultOutputCalendar = outputCalendar;
106
+ }
107
+
108
+ /**
109
+ * @typedef {Object} WeekSettings
110
+ * @property {number} firstDay
111
+ * @property {number} minimalDays
112
+ * @property {number[]} weekend
113
+ */
114
+
115
+ /**
116
+ * @return {WeekSettings|null}
117
+ */
118
+ static get defaultWeekSettings() {
119
+ return defaultWeekSettings;
120
+ }
121
+
122
+ /**
123
+ * Allows overriding the default locale week settings, i.e. the start of the week, the weekend and
124
+ * how many days are required in the first week of a year.
125
+ * Does not affect existing instances.
126
+ *
127
+ * @param {WeekSettings|null} weekSettings
128
+ */
129
+ static set defaultWeekSettings(weekSettings) {
130
+ defaultWeekSettings = validateWeekSettings(weekSettings);
131
+ }
132
+
133
+ /**
134
+ * Get the cutoff year for whether a 2-digit year string is interpreted in the current or previous century. Numbers higher than the cutoff will be considered to mean 19xx and numbers lower or equal to the cutoff will be considered 20xx.
135
+ * @type {number}
136
+ */
137
+ static get twoDigitCutoffYear() {
138
+ return twoDigitCutoffYear;
139
+ }
140
+
141
+ /**
142
+ * Set the cutoff year for whether a 2-digit year string is interpreted in the current or previous century. Numbers higher than the cutoff will be considered to mean 19xx and numbers lower or equal to the cutoff will be considered 20xx.
143
+ * @type {number}
144
+ * @example Settings.twoDigitCutoffYear = 0 // all 'yy' are interpreted as 20th century
145
+ * @example Settings.twoDigitCutoffYear = 99 // all 'yy' are interpreted as 21st century
146
+ * @example Settings.twoDigitCutoffYear = 50 // '49' -> 2049; '50' -> 1950
147
+ * @example Settings.twoDigitCutoffYear = 1950 // interpreted as 50
148
+ * @example Settings.twoDigitCutoffYear = 2050 // ALSO interpreted as 50
149
+ */
150
+ static set twoDigitCutoffYear(cutoffYear) {
151
+ twoDigitCutoffYear = cutoffYear % 100;
152
+ }
153
+
154
+ /**
155
+ * Get whether Luxon will throw when it encounters invalid DateTimes, Durations, or Intervals
156
+ * @type {boolean}
157
+ */
158
+ static get throwOnInvalid() {
159
+ return throwOnInvalid;
160
+ }
161
+
162
+ /**
163
+ * Set whether Luxon will throw when it encounters invalid DateTimes, Durations, or Intervals
164
+ * @type {boolean}
165
+ */
166
+ static set throwOnInvalid(t) {
167
+ throwOnInvalid = t;
168
+ }
169
+
170
+ /**
171
+ * Reset Luxon's global caches. Should only be necessary in testing scenarios.
172
+ * @return {void}
173
+ */
174
+ static resetCaches() {
175
+ Locale.resetCache();
176
+ IANAZone.resetCache();
177
+ DateTime.resetCache();
178
+ resetDigitRegexCache();
179
+ }
180
+ }
@@ -0,0 +1,97 @@
1
+ import { ZoneIsAbstractError } from "./errors.js";
2
+
3
+ /**
4
+ * @interface
5
+ */
6
+ export default class Zone {
7
+ /**
8
+ * The type of zone
9
+ * @abstract
10
+ * @type {string}
11
+ */
12
+ get type() {
13
+ throw new ZoneIsAbstractError();
14
+ }
15
+
16
+ /**
17
+ * The name of this zone.
18
+ * @abstract
19
+ * @type {string}
20
+ */
21
+ get name() {
22
+ throw new ZoneIsAbstractError();
23
+ }
24
+
25
+ /**
26
+ * The IANA name of this zone.
27
+ * Defaults to `name` if not overwritten by a subclass.
28
+ * @abstract
29
+ * @type {string}
30
+ */
31
+ get ianaName() {
32
+ return this.name;
33
+ }
34
+
35
+ /**
36
+ * Returns whether the offset is known to be fixed for the whole year.
37
+ * @abstract
38
+ * @type {boolean}
39
+ */
40
+ get isUniversal() {
41
+ throw new ZoneIsAbstractError();
42
+ }
43
+
44
+ /**
45
+ * Returns the offset's common name (such as EST) at the specified timestamp
46
+ * @abstract
47
+ * @param {number} ts - Epoch milliseconds for which to get the name
48
+ * @param {Object} opts - Options to affect the format
49
+ * @param {string} opts.format - What style of offset to return. Accepts 'long' or 'short'.
50
+ * @param {string} opts.locale - What locale to return the offset name in.
51
+ * @return {string}
52
+ */
53
+ offsetName(ts, opts) {
54
+ throw new ZoneIsAbstractError();
55
+ }
56
+
57
+ /**
58
+ * Returns the offset's value as a string
59
+ * @abstract
60
+ * @param {number} ts - Epoch milliseconds for which to get the offset
61
+ * @param {string} format - What style of offset to return.
62
+ * Accepts 'narrow', 'short', or 'techie'. Returning '+6', '+06:00', or '+0600' respectively
63
+ * @return {string}
64
+ */
65
+ formatOffset(ts, format) {
66
+ throw new ZoneIsAbstractError();
67
+ }
68
+
69
+ /**
70
+ * Return the offset in minutes for this zone at the specified timestamp.
71
+ * @abstract
72
+ * @param {number} ts - Epoch milliseconds for which to compute the offset
73
+ * @return {number}
74
+ */
75
+ offset(ts) {
76
+ throw new ZoneIsAbstractError();
77
+ }
78
+
79
+ /**
80
+ * Return whether this Zone is equal to another zone
81
+ * @abstract
82
+ * @param {Zone} otherZone - the zone to compare
83
+ * @return {boolean}
84
+ */
85
+ equals(otherZone) {
86
+ throw new ZoneIsAbstractError();
87
+ }
88
+
89
+ /**
90
+ * Return whether this Zone is valid.
91
+ * @abstract
92
+ * @type {boolean}
93
+ */
94
+ get isValid() {
95
+ throw new ZoneIsAbstractError();
96
+ }
97
+ }
@@ -0,0 +1,231 @@
1
+ import { formatOffset, parseZoneInfo, isUndefined, objToLocalTS } from "../impl/util.js";
2
+ import Zone from "../zone.js";
3
+
4
+ let dtfCache = {};
5
+ function makeDTF(zone) {
6
+ if (!dtfCache[zone]) {
7
+ dtfCache[zone] = new Intl.DateTimeFormat("en-US", {
8
+ hour12: false,
9
+ timeZone: zone,
10
+ year: "numeric",
11
+ month: "2-digit",
12
+ day: "2-digit",
13
+ hour: "2-digit",
14
+ minute: "2-digit",
15
+ second: "2-digit",
16
+ era: "short",
17
+ });
18
+ }
19
+ return dtfCache[zone];
20
+ }
21
+
22
+ const typeToPos = {
23
+ year: 0,
24
+ month: 1,
25
+ day: 2,
26
+ era: 3,
27
+ hour: 4,
28
+ minute: 5,
29
+ second: 6,
30
+ };
31
+
32
+ function hackyOffset(dtf, date) {
33
+ const formatted = dtf.format(date).replace(/\u200E/g, ""),
34
+ parsed = /(\d+)\/(\d+)\/(\d+) (AD|BC),? (\d+):(\d+):(\d+)/.exec(formatted),
35
+ [, fMonth, fDay, fYear, fadOrBc, fHour, fMinute, fSecond] = parsed;
36
+ return [fYear, fMonth, fDay, fadOrBc, fHour, fMinute, fSecond];
37
+ }
38
+
39
+ function partsOffset(dtf, date) {
40
+ const formatted = dtf.formatToParts(date);
41
+ const filled = [];
42
+ for (let i = 0; i < formatted.length; i++) {
43
+ const { type, value } = formatted[i];
44
+ const pos = typeToPos[type];
45
+
46
+ if (type === "era") {
47
+ filled[pos] = value;
48
+ } else if (!isUndefined(pos)) {
49
+ filled[pos] = parseInt(value, 10);
50
+ }
51
+ }
52
+ return filled;
53
+ }
54
+
55
+ let ianaZoneCache = {};
56
+ /**
57
+ * A zone identified by an IANA identifier, like America/New_York
58
+ * @implements {Zone}
59
+ */
60
+ export default class IANAZone extends Zone {
61
+ /**
62
+ * @param {string} name - Zone name
63
+ * @return {IANAZone}
64
+ */
65
+ static create(name) {
66
+ if (!ianaZoneCache[name]) {
67
+ ianaZoneCache[name] = new IANAZone(name);
68
+ }
69
+ return ianaZoneCache[name];
70
+ }
71
+
72
+ /**
73
+ * Reset local caches. Should only be necessary in testing scenarios.
74
+ * @return {void}
75
+ */
76
+ static resetCache() {
77
+ ianaZoneCache = {};
78
+ dtfCache = {};
79
+ }
80
+
81
+ /**
82
+ * Returns whether the provided string is a valid specifier. This only checks the string's format, not that the specifier identifies a known zone; see isValidZone for that.
83
+ * @param {string} s - The string to check validity on
84
+ * @example IANAZone.isValidSpecifier("America/New_York") //=> true
85
+ * @example IANAZone.isValidSpecifier("Sport~~blorp") //=> false
86
+ * @deprecated For backward compatibility, this forwards to isValidZone, better use `isValidZone()` directly instead.
87
+ * @return {boolean}
88
+ */
89
+ static isValidSpecifier(s) {
90
+ return this.isValidZone(s);
91
+ }
92
+
93
+ /**
94
+ * Returns whether the provided string identifies a real zone
95
+ * @param {string} zone - The string to check
96
+ * @example IANAZone.isValidZone("America/New_York") //=> true
97
+ * @example IANAZone.isValidZone("Fantasia/Castle") //=> false
98
+ * @example IANAZone.isValidZone("Sport~~blorp") //=> false
99
+ * @return {boolean}
100
+ */
101
+ static isValidZone(zone) {
102
+ if (!zone) {
103
+ return false;
104
+ }
105
+ try {
106
+ new Intl.DateTimeFormat("en-US", { timeZone: zone }).format();
107
+ return true;
108
+ } catch (e) {
109
+ return false;
110
+ }
111
+ }
112
+
113
+ constructor(name) {
114
+ super();
115
+ /** @private **/
116
+ this.zoneName = name;
117
+ /** @private **/
118
+ this.valid = IANAZone.isValidZone(name);
119
+ }
120
+
121
+ /**
122
+ * The type of zone. `iana` for all instances of `IANAZone`.
123
+ * @override
124
+ * @type {string}
125
+ */
126
+ get type() {
127
+ return "iana";
128
+ }
129
+
130
+ /**
131
+ * The name of this zone (i.e. the IANA zone name).
132
+ * @override
133
+ * @type {string}
134
+ */
135
+ get name() {
136
+ return this.zoneName;
137
+ }
138
+
139
+ /**
140
+ * Returns whether the offset is known to be fixed for the whole year:
141
+ * Always returns false for all IANA zones.
142
+ * @override
143
+ * @type {boolean}
144
+ */
145
+ get isUniversal() {
146
+ return false;
147
+ }
148
+
149
+ /**
150
+ * Returns the offset's common name (such as EST) at the specified timestamp
151
+ * @override
152
+ * @param {number} ts - Epoch milliseconds for which to get the name
153
+ * @param {Object} opts - Options to affect the format
154
+ * @param {string} opts.format - What style of offset to return. Accepts 'long' or 'short'.
155
+ * @param {string} opts.locale - What locale to return the offset name in.
156
+ * @return {string}
157
+ */
158
+ offsetName(ts, { format, locale }) {
159
+ return parseZoneInfo(ts, format, locale, this.name);
160
+ }
161
+
162
+ /**
163
+ * Returns the offset's value as a string
164
+ * @override
165
+ * @param {number} ts - Epoch milliseconds for which to get the offset
166
+ * @param {string} format - What style of offset to return.
167
+ * Accepts 'narrow', 'short', or 'techie'. Returning '+6', '+06:00', or '+0600' respectively
168
+ * @return {string}
169
+ */
170
+ formatOffset(ts, format) {
171
+ return formatOffset(this.offset(ts), format);
172
+ }
173
+
174
+ /**
175
+ * Return the offset in minutes for this zone at the specified timestamp.
176
+ * @override
177
+ * @param {number} ts - Epoch milliseconds for which to compute the offset
178
+ * @return {number}
179
+ */
180
+ offset(ts) {
181
+ const date = new Date(ts);
182
+
183
+ if (isNaN(date)) return NaN;
184
+
185
+ const dtf = makeDTF(this.name);
186
+ let [year, month, day, adOrBc, hour, minute, second] = dtf.formatToParts
187
+ ? partsOffset(dtf, date)
188
+ : hackyOffset(dtf, date);
189
+
190
+ if (adOrBc === "BC") {
191
+ year = -Math.abs(year) + 1;
192
+ }
193
+
194
+ // because we're using hour12 and https://bugs.chromium.org/p/chromium/issues/detail?id=1025564&can=2&q=%2224%3A00%22%20datetimeformat
195
+ const adjustedHour = hour === 24 ? 0 : hour;
196
+
197
+ const asUTC = objToLocalTS({
198
+ year,
199
+ month,
200
+ day,
201
+ hour: adjustedHour,
202
+ minute,
203
+ second,
204
+ millisecond: 0,
205
+ });
206
+
207
+ let asTS = +date;
208
+ const over = asTS % 1000;
209
+ asTS -= over >= 0 ? over : 1000 + over;
210
+ return (asUTC - asTS) / (60 * 1000);
211
+ }
212
+
213
+ /**
214
+ * Return whether this Zone is equal to another zone
215
+ * @override
216
+ * @param {Zone} otherZone - the zone to compare
217
+ * @return {boolean}
218
+ */
219
+ equals(otherZone) {
220
+ return otherZone.type === "iana" && otherZone.name === this.name;
221
+ }
222
+
223
+ /**
224
+ * Return whether this Zone is valid.
225
+ * @override
226
+ * @type {boolean}
227
+ */
228
+ get isValid() {
229
+ return this.valid;
230
+ }
231
+ }
@@ -0,0 +1,150 @@
1
+ import { formatOffset, signedOffset } from "../impl/util.js";
2
+ import Zone from "../zone.js";
3
+
4
+ let singleton = null;
5
+
6
+ /**
7
+ * A zone with a fixed offset (meaning no DST)
8
+ * @implements {Zone}
9
+ */
10
+ export default class FixedOffsetZone extends Zone {
11
+ /**
12
+ * Get a singleton instance of UTC
13
+ * @return {FixedOffsetZone}
14
+ */
15
+ static get utcInstance() {
16
+ if (singleton === null) {
17
+ singleton = new FixedOffsetZone(0);
18
+ }
19
+ return singleton;
20
+ }
21
+
22
+ /**
23
+ * Get an instance with a specified offset
24
+ * @param {number} offset - The offset in minutes
25
+ * @return {FixedOffsetZone}
26
+ */
27
+ static instance(offset) {
28
+ return offset === 0 ? FixedOffsetZone.utcInstance : new FixedOffsetZone(offset);
29
+ }
30
+
31
+ /**
32
+ * Get an instance of FixedOffsetZone from a UTC offset string, like "UTC+6"
33
+ * @param {string} s - The offset string to parse
34
+ * @example FixedOffsetZone.parseSpecifier("UTC+6")
35
+ * @example FixedOffsetZone.parseSpecifier("UTC+06")
36
+ * @example FixedOffsetZone.parseSpecifier("UTC-6:00")
37
+ * @return {FixedOffsetZone}
38
+ */
39
+ static parseSpecifier(s) {
40
+ if (s) {
41
+ const r = s.match(/^utc(?:([+-]\d{1,2})(?::(\d{2}))?)?$/i);
42
+ if (r) {
43
+ return new FixedOffsetZone(signedOffset(r[1], r[2]));
44
+ }
45
+ }
46
+ return null;
47
+ }
48
+
49
+ constructor(offset) {
50
+ super();
51
+ /** @private **/
52
+ this.fixed = offset;
53
+ }
54
+
55
+ /**
56
+ * The type of zone. `fixed` for all instances of `FixedOffsetZone`.
57
+ * @override
58
+ * @type {string}
59
+ */
60
+ get type() {
61
+ return "fixed";
62
+ }
63
+
64
+ /**
65
+ * The name of this zone.
66
+ * All fixed zones' names always start with "UTC" (plus optional offset)
67
+ * @override
68
+ * @type {string}
69
+ */
70
+ get name() {
71
+ return this.fixed === 0 ? "UTC" : `UTC${formatOffset(this.fixed, "narrow")}`;
72
+ }
73
+
74
+ /**
75
+ * The IANA name of this zone, i.e. `Etc/UTC` or `Etc/GMT+/-nn`
76
+ *
77
+ * @override
78
+ * @type {string}
79
+ */
80
+ get ianaName() {
81
+ if (this.fixed === 0) {
82
+ return "Etc/UTC";
83
+ } else {
84
+ return `Etc/GMT${formatOffset(-this.fixed, "narrow")}`;
85
+ }
86
+ }
87
+
88
+ /**
89
+ * Returns the offset's common name at the specified timestamp.
90
+ *
91
+ * For fixed offset zones this equals to the zone name.
92
+ * @override
93
+ */
94
+ offsetName() {
95
+ return this.name;
96
+ }
97
+
98
+ /**
99
+ * Returns the offset's value as a string
100
+ * @override
101
+ * @param {number} ts - Epoch milliseconds for which to get the offset
102
+ * @param {string} format - What style of offset to return.
103
+ * Accepts 'narrow', 'short', or 'techie'. Returning '+6', '+06:00', or '+0600' respectively
104
+ * @return {string}
105
+ */
106
+ formatOffset(ts, format) {
107
+ return formatOffset(this.fixed, format);
108
+ }
109
+
110
+ /**
111
+ * Returns whether the offset is known to be fixed for the whole year:
112
+ * Always returns true for all fixed offset zones.
113
+ * @override
114
+ * @type {boolean}
115
+ */
116
+ get isUniversal() {
117
+ return true;
118
+ }
119
+
120
+ /**
121
+ * Return the offset in minutes for this zone at the specified timestamp.
122
+ *
123
+ * For fixed offset zones, this is constant and does not depend on a timestamp.
124
+ * @override
125
+ * @return {number}
126
+ */
127
+ offset() {
128
+ return this.fixed;
129
+ }
130
+
131
+ /**
132
+ * Return whether this Zone is equal to another zone (i.e. also fixed and same offset)
133
+ * @override
134
+ * @param {Zone} otherZone - the zone to compare
135
+ * @return {boolean}
136
+ */
137
+ equals(otherZone) {
138
+ return otherZone.type === "fixed" && otherZone.fixed === this.fixed;
139
+ }
140
+
141
+ /**
142
+ * Return whether this Zone is valid:
143
+ * All fixed offset zones are valid.
144
+ * @override
145
+ * @type {boolean}
146
+ */
147
+ get isValid() {
148
+ return true;
149
+ }
150
+ }
@@ -0,0 +1,53 @@
1
+ import Zone from "../zone.js";
2
+
3
+ /**
4
+ * A zone that failed to parse. You should never need to instantiate this.
5
+ * @implements {Zone}
6
+ */
7
+ export default class InvalidZone extends Zone {
8
+ constructor(zoneName) {
9
+ super();
10
+ /** @private */
11
+ this.zoneName = zoneName;
12
+ }
13
+
14
+ /** @override **/
15
+ get type() {
16
+ return "invalid";
17
+ }
18
+
19
+ /** @override **/
20
+ get name() {
21
+ return this.zoneName;
22
+ }
23
+
24
+ /** @override **/
25
+ get isUniversal() {
26
+ return false;
27
+ }
28
+
29
+ /** @override **/
30
+ offsetName() {
31
+ return null;
32
+ }
33
+
34
+ /** @override **/
35
+ formatOffset() {
36
+ return "";
37
+ }
38
+
39
+ /** @override **/
40
+ offset() {
41
+ return NaN;
42
+ }
43
+
44
+ /** @override **/
45
+ equals() {
46
+ return false;
47
+ }
48
+
49
+ /** @override **/
50
+ get isValid() {
51
+ return false;
52
+ }
53
+ }