compostjs 0.0.11 → 0.0.12
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.
- package/dist/fable_modules/fable-library-js.4.28.0/Array.d.ts +123 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Array.js +1242 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Async.d.ts +26 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Async.js +145 -0
- package/dist/fable_modules/fable-library-js.4.28.0/AsyncBuilder.d.ts +59 -0
- package/dist/fable_modules/fable-library-js.4.28.0/AsyncBuilder.js +183 -0
- package/dist/fable_modules/fable-library-js.4.28.0/BigInt.d.ts +115 -0
- package/dist/fable_modules/fable-library-js.4.28.0/BigInt.js +283 -0
- package/dist/fable_modules/fable-library-js.4.28.0/BitConverter.d.ts +27 -0
- package/dist/fable_modules/fable-library-js.4.28.0/BitConverter.js +138 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Boolean.d.ts +3 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Boolean.js +21 -0
- package/dist/fable_modules/fable-library-js.4.28.0/CHANGELOG.md +100 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Char.d.ts +65 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Char.js +169 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Choice.d.ts +121 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Choice.js +184 -0
- package/dist/fable_modules/fable-library-js.4.28.0/CollectionUtil.d.ts +7 -0
- package/dist/fable_modules/fable-library-js.4.28.0/CollectionUtil.js +182 -0
- package/dist/fable_modules/fable-library-js.4.28.0/ConditionalWeakTable.d.ts +9 -0
- package/dist/fable_modules/fable-library-js.4.28.0/ConditionalWeakTable.js +21 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Date.d.ts +70 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Date.js +748 -0
- package/dist/fable_modules/fable-library-js.4.28.0/DateOffset.d.ts +63 -0
- package/dist/fable_modules/fable-library-js.4.28.0/DateOffset.js +268 -0
- package/dist/fable_modules/fable-library-js.4.28.0/DateOnly.d.ts +18 -0
- package/dist/fable_modules/fable-library-js.4.28.0/DateOnly.js +124 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Decimal.d.ts +45 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Decimal.js +212 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Double.d.ts +11 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Double.js +46 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Encoding.d.ts +12 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Encoding.js +173 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Event.d.ts +31 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Event.js +93 -0
- package/dist/fable_modules/fable-library-js.4.28.0/FSharp.Collections.d.ts +7 -0
- package/dist/fable_modules/fable-library-js.4.28.0/FSharp.Collections.js +27 -0
- package/dist/fable_modules/fable-library-js.4.28.0/FSharp.Core.CompilerServices.d.ts +12 -0
- package/dist/fable_modules/fable-library-js.4.28.0/FSharp.Core.CompilerServices.js +27 -0
- package/dist/fable_modules/fable-library-js.4.28.0/FSharp.Core.d.ts +17 -0
- package/dist/fable_modules/fable-library-js.4.28.0/FSharp.Core.js +69 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Global.d.ts +24 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Global.js +8 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Guid.d.ts +10 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Guid.js +142 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Int32.d.ts +28 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Int32.js +135 -0
- package/dist/fable_modules/fable-library-js.4.28.0/List.d.ts +143 -0
- package/dist/fable_modules/fable-library-js.4.28.0/List.js +1273 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Long.d.ts +3 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Long.js +46 -0
- package/dist/fable_modules/fable-library-js.4.28.0/MailboxProcessor.d.ts +25 -0
- package/dist/fable_modules/fable-library-js.4.28.0/MailboxProcessor.js +93 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Map.d.ts +178 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Map.js +1396 -0
- package/dist/fable_modules/fable-library-js.4.28.0/MapUtil.d.ts +12 -0
- package/dist/fable_modules/fable-library-js.4.28.0/MapUtil.js +127 -0
- package/dist/fable_modules/fable-library-js.4.28.0/MutableMap.d.ts +52 -0
- package/dist/fable_modules/fable-library-js.4.28.0/MutableMap.js +327 -0
- package/dist/fable_modules/fable-library-js.4.28.0/MutableSet.d.ts +39 -0
- package/dist/fable_modules/fable-library-js.4.28.0/MutableSet.js +233 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Native.d.ts +2 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Native.js +8 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Numeric.d.ts +19 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Numeric.js +71 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Observable.d.ts +32 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Observable.js +113 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Option.d.ts +28 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Option.js +96 -0
- package/dist/fable_modules/fable-library-js.4.28.0/README.md +3 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Random.d.ts +37 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Random.js +170 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Range.d.ts +12 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Range.js +45 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Reflection.d.ts +119 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Reflection.js +461 -0
- package/dist/fable_modules/fable-library-js.4.28.0/RegExp.d.ts +10 -0
- package/dist/fable_modules/fable-library-js.4.28.0/RegExp.js +131 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Result.d.ts +37 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Result.js +165 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Seq.d.ts +165 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Seq.js +1378 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Seq2.d.ts +18 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Seq2.js +111 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Set.d.ts +190 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Set.js +1789 -0
- package/dist/fable_modules/fable-library-js.4.28.0/String.d.ts +58 -0
- package/dist/fable_modules/fable-library-js.4.28.0/String.js +554 -0
- package/dist/fable_modules/fable-library-js.4.28.0/System.Collections.Generic.d.ts +79 -0
- package/dist/fable_modules/fable-library-js.4.28.0/System.Collections.Generic.js +317 -0
- package/dist/fable_modules/fable-library-js.4.28.0/System.Text.d.ts +38 -0
- package/dist/fable_modules/fable-library-js.4.28.0/System.Text.js +162 -0
- package/dist/fable_modules/fable-library-js.4.28.0/SystemException.d.ts +5 -0
- package/dist/fable_modules/fable-library-js.4.28.0/SystemException.js +5 -0
- package/dist/fable_modules/fable-library-js.4.28.0/TimeOnly.d.ts +15 -0
- package/dist/fable_modules/fable-library-js.4.28.0/TimeOnly.js +122 -0
- package/dist/fable_modules/fable-library-js.4.28.0/TimeSpan.d.ts +34 -0
- package/dist/fable_modules/fable-library-js.4.28.0/TimeSpan.js +177 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Timer.d.ts +19 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Timer.js +67 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Types.d.ts +58 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Types.js +208 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Unicode.13.0.0.d.ts +2 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Unicode.13.0.0.js +4 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Uri.d.ts +31 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Uri.js +159 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Util.d.ts +210 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Util.js +769 -0
- package/dist/fable_modules/fable-library-js.4.28.0/big.d.ts +338 -0
- package/dist/fable_modules/fable-library-js.4.28.0/lib/big.d.ts +5 -0
- package/dist/fable_modules/fable-library-js.4.28.0/lib/big.js +825 -0
- package/dist/fable_modules/fable-library-js.4.28.0/package.json +24 -0
- package/dist/fable_modules/project_cracked.json +1 -0
- package/package.json +4 -3
- package/.claude/settings.local.json +0 -11
- package/copy-latest.sh +0 -1
- package/dist/fable-library.2.10.1/Array.js +0 -1336
- package/dist/fable-library.2.10.1/Async.js +0 -121
- package/dist/fable-library.2.10.1/AsyncBuilder.js +0 -200
- package/dist/fable-library.2.10.1/Date.js +0 -501
- package/dist/fable-library.2.10.1/Decimal.js +0 -208
- package/dist/fable-library.2.10.1/Event.js +0 -193
- package/dist/fable-library.2.10.1/Int32.js +0 -157
- package/dist/fable-library.2.10.1/List.js +0 -1234
- package/dist/fable-library.2.10.1/Long.js +0 -155
- package/dist/fable-library.2.10.1/Map.js +0 -1292
- package/dist/fable-library.2.10.1/MutableMap.js +0 -360
- package/dist/fable-library.2.10.1/MutableSet.js +0 -279
- package/dist/fable-library.2.10.1/Observable.js +0 -131
- package/dist/fable-library.2.10.1/Option.js +0 -118
- package/dist/fable-library.2.10.1/Reflection.js +0 -345
- package/dist/fable-library.2.10.1/RegExp.js +0 -118
- package/dist/fable-library.2.10.1/Seq.js +0 -917
- package/dist/fable-library.2.10.1/Set.js +0 -1692
- package/dist/fable-library.2.10.1/String.js +0 -679
- package/dist/fable-library.2.10.1/Types.js +0 -308
- package/dist/fable-library.2.10.1/Util.js +0 -761
- package/dist/helpers.js +0 -31
- package/dist/lib/big.js +0 -905
- package/dist/lib/long.js +0 -1375
- package/index.html +0 -49
|
@@ -0,0 +1,748 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DateTimeOffset functions.
|
|
3
|
+
*
|
|
4
|
+
* Note: Date instances are always DateObjects in local
|
|
5
|
+
* timezone (because JS dates are all kinds of messed up).
|
|
6
|
+
* A local date returns UTC epoch when `.getTime()` is called.
|
|
7
|
+
*
|
|
8
|
+
* Basically; invariant: date.getTime() always return UTC time.
|
|
9
|
+
*/
|
|
10
|
+
import { toInt64, toFloat64 } from "./BigInt.js";
|
|
11
|
+
import { compareDates, dateOffset, padWithZeros } from "./Util.js";
|
|
12
|
+
const shortDays = [
|
|
13
|
+
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
|
|
14
|
+
];
|
|
15
|
+
const longDays = [
|
|
16
|
+
"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
|
|
17
|
+
];
|
|
18
|
+
const shortMonths = [
|
|
19
|
+
"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
|
|
20
|
+
];
|
|
21
|
+
const longMonths = [
|
|
22
|
+
"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
|
|
23
|
+
];
|
|
24
|
+
function parseRepeatToken(format, pos, patternChar) {
|
|
25
|
+
let tokenLength = 0;
|
|
26
|
+
let internalPos = pos;
|
|
27
|
+
while (internalPos < format.length && format[internalPos] === patternChar) {
|
|
28
|
+
internalPos++;
|
|
29
|
+
tokenLength++;
|
|
30
|
+
}
|
|
31
|
+
return tokenLength;
|
|
32
|
+
}
|
|
33
|
+
function parseNextChar(format, pos) {
|
|
34
|
+
if (pos >= format.length - 1) {
|
|
35
|
+
return -1;
|
|
36
|
+
}
|
|
37
|
+
return format.charCodeAt(pos + 1);
|
|
38
|
+
}
|
|
39
|
+
function parseQuotedString(format, pos) {
|
|
40
|
+
let beginPos = pos;
|
|
41
|
+
// Get the character used to quote the string
|
|
42
|
+
const quoteChar = format[pos];
|
|
43
|
+
let result = "";
|
|
44
|
+
let foundQuote = false;
|
|
45
|
+
while (pos < format.length) {
|
|
46
|
+
pos++;
|
|
47
|
+
const currentChar = format[pos];
|
|
48
|
+
if (currentChar === quoteChar) {
|
|
49
|
+
foundQuote = true;
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
else if (currentChar === "\\") {
|
|
53
|
+
if (pos < format.length) {
|
|
54
|
+
pos++;
|
|
55
|
+
result += format[pos];
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
// This means that '\' is the last character in the string.
|
|
59
|
+
throw new Error("Invalid string format");
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
result += currentChar;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (!foundQuote) {
|
|
67
|
+
// We could not find the matching quote
|
|
68
|
+
throw new Error(`Invalid string format could not find matching quote for ${quoteChar}`);
|
|
69
|
+
}
|
|
70
|
+
return [result, pos - beginPos + 1];
|
|
71
|
+
}
|
|
72
|
+
function dateToStringWithCustomFormat(date, format, utc) {
|
|
73
|
+
let cursorPos = 0;
|
|
74
|
+
let tokenLength = 0;
|
|
75
|
+
let result = "";
|
|
76
|
+
const localizedDate = utc ? DateTime(date.getTime(), 1 /* DateKind.UTC */) : date;
|
|
77
|
+
while (cursorPos < format.length) {
|
|
78
|
+
const token = format[cursorPos];
|
|
79
|
+
switch (token) {
|
|
80
|
+
case "d":
|
|
81
|
+
tokenLength = parseRepeatToken(format, cursorPos, "d");
|
|
82
|
+
cursorPos += tokenLength;
|
|
83
|
+
switch (tokenLength) {
|
|
84
|
+
case 1:
|
|
85
|
+
result += day(localizedDate);
|
|
86
|
+
break;
|
|
87
|
+
case 2:
|
|
88
|
+
result += padWithZeros(day(localizedDate), 2);
|
|
89
|
+
break;
|
|
90
|
+
case 3:
|
|
91
|
+
result += shortDays[dayOfWeek(localizedDate)];
|
|
92
|
+
break;
|
|
93
|
+
case 4:
|
|
94
|
+
result += longDays[dayOfWeek(localizedDate)];
|
|
95
|
+
break;
|
|
96
|
+
default:
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
break;
|
|
100
|
+
case "f":
|
|
101
|
+
tokenLength = parseRepeatToken(format, cursorPos, "f");
|
|
102
|
+
cursorPos += tokenLength;
|
|
103
|
+
if (tokenLength <= 3) {
|
|
104
|
+
const precision = 10 ** (3 - tokenLength);
|
|
105
|
+
result += padWithZeros(Math.floor(millisecond(localizedDate) / precision), tokenLength);
|
|
106
|
+
}
|
|
107
|
+
else if (tokenLength <= 7) {
|
|
108
|
+
// JavaScript Date only support precision to the millisecond
|
|
109
|
+
// so we fill the rest of the precision with 0 as if the date didn't have
|
|
110
|
+
// milliseconds provided to it.
|
|
111
|
+
// This is to have the same behavior as .NET when doing:
|
|
112
|
+
// DateTime(1, 2, 3, 4, 5, 6, DateTimeKind.Utc).ToString("fffff") => 00000
|
|
113
|
+
result += ("" + millisecond(localizedDate)).padEnd(tokenLength, "0");
|
|
114
|
+
}
|
|
115
|
+
break;
|
|
116
|
+
case "F":
|
|
117
|
+
tokenLength = parseRepeatToken(format, cursorPos, "F");
|
|
118
|
+
cursorPos += tokenLength;
|
|
119
|
+
if (tokenLength <= 3) {
|
|
120
|
+
const precision = 10 ** (3 - tokenLength);
|
|
121
|
+
const value = Math.floor(millisecond(localizedDate) / precision);
|
|
122
|
+
if (value != 0) {
|
|
123
|
+
result += padWithZeros(value, tokenLength);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
else if (tokenLength <= 7) {
|
|
127
|
+
// JavaScript Date only support precision to the millisecond
|
|
128
|
+
// so we can't go beyond that.
|
|
129
|
+
// We also need to pad start with 0 if the value is not 0
|
|
130
|
+
const value = millisecond(localizedDate);
|
|
131
|
+
if (value != 0) {
|
|
132
|
+
result += padWithZeros(value, 3);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
break;
|
|
136
|
+
case "g":
|
|
137
|
+
tokenLength = parseRepeatToken(format, cursorPos, "g");
|
|
138
|
+
cursorPos += tokenLength;
|
|
139
|
+
if (tokenLength <= 2) {
|
|
140
|
+
result += "A.D.";
|
|
141
|
+
}
|
|
142
|
+
break;
|
|
143
|
+
case "h":
|
|
144
|
+
tokenLength = parseRepeatToken(format, cursorPos, "h");
|
|
145
|
+
cursorPos += tokenLength;
|
|
146
|
+
switch (tokenLength) {
|
|
147
|
+
case 1:
|
|
148
|
+
result += hour(localizedDate) % 12;
|
|
149
|
+
break;
|
|
150
|
+
case 2:
|
|
151
|
+
result += padWithZeros(hour(localizedDate) % 12, 2);
|
|
152
|
+
break;
|
|
153
|
+
default:
|
|
154
|
+
break;
|
|
155
|
+
}
|
|
156
|
+
break;
|
|
157
|
+
case "H":
|
|
158
|
+
tokenLength = parseRepeatToken(format, cursorPos, "H");
|
|
159
|
+
cursorPos += tokenLength;
|
|
160
|
+
switch (tokenLength) {
|
|
161
|
+
case 1:
|
|
162
|
+
result += hour(localizedDate);
|
|
163
|
+
break;
|
|
164
|
+
case 2:
|
|
165
|
+
result += padWithZeros(hour(localizedDate), 2);
|
|
166
|
+
break;
|
|
167
|
+
default:
|
|
168
|
+
break;
|
|
169
|
+
}
|
|
170
|
+
break;
|
|
171
|
+
case "K":
|
|
172
|
+
tokenLength = parseRepeatToken(format, cursorPos, "K");
|
|
173
|
+
cursorPos += tokenLength;
|
|
174
|
+
switch (tokenLength) {
|
|
175
|
+
case 1:
|
|
176
|
+
switch (kind(localizedDate)) {
|
|
177
|
+
case 1 /* DateKind.UTC */:
|
|
178
|
+
result += "Z";
|
|
179
|
+
break;
|
|
180
|
+
case 2 /* DateKind.Local */:
|
|
181
|
+
result += dateOffsetToString(localizedDate.getTimezoneOffset() * -60000);
|
|
182
|
+
break;
|
|
183
|
+
case 0 /* DateKind.Unspecified */:
|
|
184
|
+
break;
|
|
185
|
+
}
|
|
186
|
+
break;
|
|
187
|
+
default:
|
|
188
|
+
break;
|
|
189
|
+
}
|
|
190
|
+
break;
|
|
191
|
+
case "m":
|
|
192
|
+
tokenLength = parseRepeatToken(format, cursorPos, "m");
|
|
193
|
+
cursorPos += tokenLength;
|
|
194
|
+
switch (tokenLength) {
|
|
195
|
+
case 1:
|
|
196
|
+
result += minute(localizedDate);
|
|
197
|
+
break;
|
|
198
|
+
case 2:
|
|
199
|
+
result += padWithZeros(minute(localizedDate), 2);
|
|
200
|
+
break;
|
|
201
|
+
default:
|
|
202
|
+
break;
|
|
203
|
+
}
|
|
204
|
+
break;
|
|
205
|
+
case "M":
|
|
206
|
+
tokenLength = parseRepeatToken(format, cursorPos, "M");
|
|
207
|
+
cursorPos += tokenLength;
|
|
208
|
+
switch (tokenLength) {
|
|
209
|
+
case 1:
|
|
210
|
+
result += month(localizedDate);
|
|
211
|
+
break;
|
|
212
|
+
case 2:
|
|
213
|
+
result += padWithZeros(month(localizedDate), 2);
|
|
214
|
+
break;
|
|
215
|
+
case 3:
|
|
216
|
+
result += shortMonths[month(localizedDate) - 1];
|
|
217
|
+
break;
|
|
218
|
+
case 4:
|
|
219
|
+
result += longMonths[month(localizedDate) - 1];
|
|
220
|
+
break;
|
|
221
|
+
default:
|
|
222
|
+
break;
|
|
223
|
+
}
|
|
224
|
+
break;
|
|
225
|
+
case "s":
|
|
226
|
+
tokenLength = parseRepeatToken(format, cursorPos, "s");
|
|
227
|
+
cursorPos += tokenLength;
|
|
228
|
+
switch (tokenLength) {
|
|
229
|
+
case 1:
|
|
230
|
+
result += second(localizedDate);
|
|
231
|
+
break;
|
|
232
|
+
case 2:
|
|
233
|
+
result += padWithZeros(second(localizedDate), 2);
|
|
234
|
+
break;
|
|
235
|
+
default:
|
|
236
|
+
break;
|
|
237
|
+
}
|
|
238
|
+
break;
|
|
239
|
+
case "t":
|
|
240
|
+
tokenLength = parseRepeatToken(format, cursorPos, "t");
|
|
241
|
+
cursorPos += tokenLength;
|
|
242
|
+
switch (tokenLength) {
|
|
243
|
+
case 1:
|
|
244
|
+
result += localizedDate.getHours() < 12 ? "A" : "P";
|
|
245
|
+
break;
|
|
246
|
+
case 2:
|
|
247
|
+
result += localizedDate.getHours() < 12 ? "AM" : "PM";
|
|
248
|
+
break;
|
|
249
|
+
default:
|
|
250
|
+
break;
|
|
251
|
+
}
|
|
252
|
+
break;
|
|
253
|
+
case "y":
|
|
254
|
+
tokenLength = parseRepeatToken(format, cursorPos, "y");
|
|
255
|
+
cursorPos += tokenLength;
|
|
256
|
+
switch (tokenLength) {
|
|
257
|
+
case 1:
|
|
258
|
+
result += localizedDate.getFullYear() % 100;
|
|
259
|
+
break;
|
|
260
|
+
case 2:
|
|
261
|
+
result += padWithZeros(localizedDate.getFullYear() % 100, 2);
|
|
262
|
+
break;
|
|
263
|
+
case 3:
|
|
264
|
+
result += padWithZeros(localizedDate.getFullYear(), 3);
|
|
265
|
+
break;
|
|
266
|
+
case 4:
|
|
267
|
+
result += padWithZeros(localizedDate.getFullYear(), 4);
|
|
268
|
+
break;
|
|
269
|
+
case 5:
|
|
270
|
+
result += padWithZeros(localizedDate.getFullYear(), 5);
|
|
271
|
+
break;
|
|
272
|
+
default:
|
|
273
|
+
break;
|
|
274
|
+
}
|
|
275
|
+
break;
|
|
276
|
+
case "z":
|
|
277
|
+
tokenLength = parseRepeatToken(format, cursorPos, "z");
|
|
278
|
+
cursorPos += tokenLength;
|
|
279
|
+
let utcOffsetText = "";
|
|
280
|
+
switch (kind(localizedDate)) {
|
|
281
|
+
case 1 /* DateKind.UTC */:
|
|
282
|
+
utcOffsetText = "+00:00";
|
|
283
|
+
break;
|
|
284
|
+
case 2 /* DateKind.Local */:
|
|
285
|
+
utcOffsetText = dateOffsetToString(localizedDate.getTimezoneOffset() * -60000);
|
|
286
|
+
break;
|
|
287
|
+
case 0 /* DateKind.Unspecified */:
|
|
288
|
+
utcOffsetText = dateOffsetToString(toLocalTime(localizedDate).getTimezoneOffset() * -60000);
|
|
289
|
+
break;
|
|
290
|
+
}
|
|
291
|
+
const sign = utcOffsetText[0] === "-" ? "-" : "+";
|
|
292
|
+
const hours = parseInt(utcOffsetText.substring(1, 3), 10);
|
|
293
|
+
const minutes = parseInt(utcOffsetText.substring(4, 6), 10);
|
|
294
|
+
switch (tokenLength) {
|
|
295
|
+
case 1:
|
|
296
|
+
result += `${sign}${hours}`;
|
|
297
|
+
break;
|
|
298
|
+
case 2:
|
|
299
|
+
result += `${sign}${padWithZeros(hours, 2)}`;
|
|
300
|
+
break;
|
|
301
|
+
default:
|
|
302
|
+
result += `${sign}${padWithZeros(hours, 2)}:${padWithZeros(minutes, 2)}`;
|
|
303
|
+
break;
|
|
304
|
+
}
|
|
305
|
+
break;
|
|
306
|
+
case ":":
|
|
307
|
+
result += ":";
|
|
308
|
+
cursorPos++;
|
|
309
|
+
break;
|
|
310
|
+
case "/":
|
|
311
|
+
result += "/";
|
|
312
|
+
cursorPos++;
|
|
313
|
+
break;
|
|
314
|
+
case "'":
|
|
315
|
+
case '"':
|
|
316
|
+
const [quotedString, quotedStringLenght] = parseQuotedString(format, cursorPos);
|
|
317
|
+
result += quotedString;
|
|
318
|
+
cursorPos += quotedStringLenght;
|
|
319
|
+
break;
|
|
320
|
+
case "%":
|
|
321
|
+
const nextChar = parseNextChar(format, cursorPos);
|
|
322
|
+
if (nextChar >= 0 && nextChar !== "%".charCodeAt(0)) {
|
|
323
|
+
cursorPos += 2;
|
|
324
|
+
result += dateToStringWithCustomFormat(localizedDate, String.fromCharCode(nextChar), utc);
|
|
325
|
+
}
|
|
326
|
+
else {
|
|
327
|
+
throw new Error("Invalid format string");
|
|
328
|
+
}
|
|
329
|
+
break;
|
|
330
|
+
case "\\":
|
|
331
|
+
const nextChar2 = parseNextChar(format, cursorPos);
|
|
332
|
+
if (nextChar2 >= 0) {
|
|
333
|
+
cursorPos += 2;
|
|
334
|
+
result += String.fromCharCode(nextChar2);
|
|
335
|
+
}
|
|
336
|
+
else {
|
|
337
|
+
throw new Error("Invalid format string");
|
|
338
|
+
}
|
|
339
|
+
break;
|
|
340
|
+
default:
|
|
341
|
+
cursorPos++;
|
|
342
|
+
result += token;
|
|
343
|
+
break;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
return result;
|
|
347
|
+
}
|
|
348
|
+
export function kind(value) {
|
|
349
|
+
return value.kind || 0;
|
|
350
|
+
}
|
|
351
|
+
export function unixEpochMillisecondsToTicks(ms, offset) {
|
|
352
|
+
return toInt64(((BigInt(ms) + 62135596800000n) + BigInt(offset)) * 10000n);
|
|
353
|
+
}
|
|
354
|
+
export function ticksToUnixEpochMilliseconds(ticks) {
|
|
355
|
+
return Number(((BigInt(ticks) / 10000n) - 62135596800000n));
|
|
356
|
+
}
|
|
357
|
+
export function dateOffsetToString(offset) {
|
|
358
|
+
const isMinus = offset < 0;
|
|
359
|
+
offset = Math.abs(offset);
|
|
360
|
+
const hours = ~~(offset / 3600000);
|
|
361
|
+
const minutes = (offset % 3600000) / 60000;
|
|
362
|
+
return (isMinus ? "-" : "+") +
|
|
363
|
+
padWithZeros(hours, 2) + ":" +
|
|
364
|
+
padWithZeros(minutes, 2);
|
|
365
|
+
}
|
|
366
|
+
export function dateToHalfUTCString(date, half) {
|
|
367
|
+
const str = date.toISOString();
|
|
368
|
+
return half === "first"
|
|
369
|
+
? str.substring(0, str.indexOf("T"))
|
|
370
|
+
: str.substring(str.indexOf("T") + 1, str.length - 1);
|
|
371
|
+
}
|
|
372
|
+
function dateToISOString(d, utc) {
|
|
373
|
+
if (utc) {
|
|
374
|
+
return d.toISOString();
|
|
375
|
+
}
|
|
376
|
+
else {
|
|
377
|
+
// JS Date is always local
|
|
378
|
+
const printOffset = d.kind == null ? true : d.kind === 2 /* DateKind.Local */;
|
|
379
|
+
return padWithZeros(d.getFullYear(), 4) + "-" +
|
|
380
|
+
padWithZeros(d.getMonth() + 1, 2) + "-" +
|
|
381
|
+
padWithZeros(d.getDate(), 2) + "T" +
|
|
382
|
+
padWithZeros(d.getHours(), 2) + ":" +
|
|
383
|
+
padWithZeros(d.getMinutes(), 2) + ":" +
|
|
384
|
+
padWithZeros(d.getSeconds(), 2) + "." +
|
|
385
|
+
padWithZeros(d.getMilliseconds(), 3) +
|
|
386
|
+
(printOffset ? dateOffsetToString(d.getTimezoneOffset() * -60000) : "");
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
function dateToISOStringWithOffset(dateWithOffset, offset) {
|
|
390
|
+
const str = dateWithOffset.toISOString();
|
|
391
|
+
return str.substring(0, str.length - 1) + dateOffsetToString(offset);
|
|
392
|
+
}
|
|
393
|
+
function dateToStringWithOffset(date, format) {
|
|
394
|
+
const d = new Date(date.getTime() + (date.offset ?? 0));
|
|
395
|
+
if (typeof format !== "string") {
|
|
396
|
+
return d.toISOString().replace(/\.\d+/, "").replace(/[A-Z]|\.\d+/g, " ") + dateOffsetToString((date.offset ?? 0));
|
|
397
|
+
}
|
|
398
|
+
else if (format.length === 1) {
|
|
399
|
+
switch (format) {
|
|
400
|
+
case "D":
|
|
401
|
+
case "d": return dateToHalfUTCString(d, "first");
|
|
402
|
+
case "T":
|
|
403
|
+
case "t": return dateToHalfUTCString(d, "second");
|
|
404
|
+
case "O":
|
|
405
|
+
case "o": return dateToISOStringWithOffset(d, (date.offset ?? 0));
|
|
406
|
+
default: throw new Error("Unrecognized Date print format");
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
else {
|
|
410
|
+
return dateToStringWithCustomFormat(d, format, true);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
function dateToStringWithKind(date, format) {
|
|
414
|
+
const utc = date.kind === 1 /* DateKind.UTC */;
|
|
415
|
+
if (typeof format !== "string") {
|
|
416
|
+
return utc ? date.toUTCString() : date.toLocaleString();
|
|
417
|
+
}
|
|
418
|
+
else if (format.length === 1) {
|
|
419
|
+
switch (format) {
|
|
420
|
+
case "D":
|
|
421
|
+
case "d":
|
|
422
|
+
return utc ? dateToHalfUTCString(date, "first") : date.toLocaleDateString();
|
|
423
|
+
case "T":
|
|
424
|
+
case "t":
|
|
425
|
+
return utc ? dateToHalfUTCString(date, "second") : date.toLocaleTimeString();
|
|
426
|
+
case "O":
|
|
427
|
+
case "o":
|
|
428
|
+
return dateToISOString(date, utc);
|
|
429
|
+
default:
|
|
430
|
+
throw new Error("Unrecognized Date print format");
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
else {
|
|
434
|
+
return dateToStringWithCustomFormat(date, format, utc);
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
export function toString(date, format, _provider) {
|
|
438
|
+
return date.offset != null
|
|
439
|
+
? dateToStringWithOffset(date, format)
|
|
440
|
+
: dateToStringWithKind(date, format);
|
|
441
|
+
}
|
|
442
|
+
export function DateTime(value, kind) {
|
|
443
|
+
const d = new Date(value);
|
|
444
|
+
d.kind = (kind == null ? 0 /* DateKind.Unspecified */ : kind) | 0;
|
|
445
|
+
return d;
|
|
446
|
+
}
|
|
447
|
+
export function fromTicks(ticks, kind) {
|
|
448
|
+
kind = kind != null ? kind : 2 /* DateKind.Local */; // better default than Unspecified
|
|
449
|
+
let date = DateTime(ticksToUnixEpochMilliseconds(ticks), kind);
|
|
450
|
+
// Ticks are local to offset (in this case, either UTC or Local/Unknown).
|
|
451
|
+
// If kind is anything but UTC, that means that the tick number was not
|
|
452
|
+
// in utc, thus getTime() cannot return UTC, and needs to be shifted.
|
|
453
|
+
if (kind !== 1 /* DateKind.UTC */) {
|
|
454
|
+
date = DateTime(date.getTime() - dateOffset(date), kind);
|
|
455
|
+
}
|
|
456
|
+
return date;
|
|
457
|
+
}
|
|
458
|
+
export function fromDateTimeOffset(date, kind) {
|
|
459
|
+
switch (kind) {
|
|
460
|
+
case 1 /* DateKind.UTC */: return DateTime(date.getTime(), 1 /* DateKind.UTC */);
|
|
461
|
+
case 2 /* DateKind.Local */: return DateTime(date.getTime(), 2 /* DateKind.Local */);
|
|
462
|
+
default:
|
|
463
|
+
const d = DateTime(date.getTime() + (date.offset ?? 0), kind);
|
|
464
|
+
return DateTime(d.getTime() - dateOffset(d), kind);
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
export function getTicks(date) {
|
|
468
|
+
return unixEpochMillisecondsToTicks(date.getTime(), dateOffset(date));
|
|
469
|
+
}
|
|
470
|
+
export function minValue() {
|
|
471
|
+
// This is "0001-01-01T00:00:00.000Z", actual JS min value is -8640000000000000
|
|
472
|
+
return DateTime(-62135596800000, 1 /* DateKind.UTC */);
|
|
473
|
+
}
|
|
474
|
+
export function maxValue() {
|
|
475
|
+
// This is "9999-12-31T23:59:59.999Z", actual JS max value is 8640000000000000
|
|
476
|
+
return DateTime(253402300799999, 1 /* DateKind.UTC */);
|
|
477
|
+
}
|
|
478
|
+
export function parseRaw(input) {
|
|
479
|
+
function fail() {
|
|
480
|
+
throw new Error(`The string is not a valid Date: ${input}`);
|
|
481
|
+
}
|
|
482
|
+
if (input == null || input.trim() === "") {
|
|
483
|
+
fail();
|
|
484
|
+
}
|
|
485
|
+
// ISO dates without TZ are parsed as UTC. Adding time without TZ keeps them local.
|
|
486
|
+
if (input.length === 10 && input[4] === "-" && input[7] === "-") {
|
|
487
|
+
input += "T00:00:00";
|
|
488
|
+
}
|
|
489
|
+
let date = new Date(input);
|
|
490
|
+
let offset = null;
|
|
491
|
+
if (isNaN(date.getTime())) {
|
|
492
|
+
// Try to check strings JS Date cannot parse (see #1045, #1422)
|
|
493
|
+
const m = /^\s*(\d+[^\w\s:]\d+[^\w\s:]\d+)?\s*(\d+:\d+(?::\d+(?:\.\d+)?)?)?\s*([AaPp][Mm])?\s*(Z|[+-]([01]?\d):?([0-5]?\d)?)?\s*$/.exec(input);
|
|
494
|
+
if (m != null) {
|
|
495
|
+
let baseDate;
|
|
496
|
+
let timeInSeconds = 0;
|
|
497
|
+
if (m[2] != null) {
|
|
498
|
+
const timeParts = m[2].split(":");
|
|
499
|
+
const hourPart = parseInt(timeParts[0], 10);
|
|
500
|
+
timeInSeconds =
|
|
501
|
+
hourPart * 3600 +
|
|
502
|
+
parseInt(timeParts[1] || "0", 10) * 60 +
|
|
503
|
+
parseFloat(timeParts[2] || "0");
|
|
504
|
+
if (m[3] != null && m[3].toUpperCase() === "PM" && hourPart < 12) {
|
|
505
|
+
timeInSeconds += 720;
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
if (m[4] != null) { // There's an offset, parse as UTC
|
|
509
|
+
if (m[1] != null) {
|
|
510
|
+
baseDate = new Date(m[1] + " UTC");
|
|
511
|
+
}
|
|
512
|
+
else {
|
|
513
|
+
const d = new Date();
|
|
514
|
+
baseDate = new Date(d.getUTCFullYear() + "/" + (d.getUTCMonth() + 1) + "/" + d.getUTCDate());
|
|
515
|
+
}
|
|
516
|
+
if (m[4] === "Z") {
|
|
517
|
+
offset = "Z";
|
|
518
|
+
}
|
|
519
|
+
else {
|
|
520
|
+
let offsetInMinutes = parseInt(m[5], 10) * 60 + parseInt(m[6] || "0", 10);
|
|
521
|
+
if (m[4][0] === "-") {
|
|
522
|
+
offsetInMinutes *= -1;
|
|
523
|
+
}
|
|
524
|
+
offset = offsetInMinutes;
|
|
525
|
+
timeInSeconds -= offsetInMinutes * 60;
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
else {
|
|
529
|
+
if (m[1] != null) {
|
|
530
|
+
baseDate = new Date(m[1]);
|
|
531
|
+
}
|
|
532
|
+
else {
|
|
533
|
+
const d = new Date();
|
|
534
|
+
baseDate = new Date(d.getFullYear() + "/" + (d.getMonth() + 1) + "/" + d.getDate());
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
date = new Date(baseDate.getTime() + timeInSeconds * 1000);
|
|
538
|
+
// correct for daylight savings time
|
|
539
|
+
date = new Date(date.getTime() + (date.getTimezoneOffset() - baseDate.getTimezoneOffset()) * 60000);
|
|
540
|
+
}
|
|
541
|
+
else {
|
|
542
|
+
fail();
|
|
543
|
+
}
|
|
544
|
+
// Check again the date is valid after transformations, see #2229
|
|
545
|
+
if (isNaN(date.getTime())) {
|
|
546
|
+
fail();
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
return [date, offset];
|
|
550
|
+
}
|
|
551
|
+
export function parse(str, detectUTC = false) {
|
|
552
|
+
const [date, offset] = parseRaw(str);
|
|
553
|
+
// .NET always parses DateTime as Local if there's offset info (even "Z")
|
|
554
|
+
// Newtonsoft.Json uses UTC if the offset is "Z"
|
|
555
|
+
const kind = offset != null
|
|
556
|
+
? (detectUTC && offset === "Z" ? 1 /* DateKind.UTC */ : 2 /* DateKind.Local */)
|
|
557
|
+
: 0 /* DateKind.Unspecified */;
|
|
558
|
+
return DateTime(date.getTime(), kind);
|
|
559
|
+
}
|
|
560
|
+
export function tryParse(v, defValue) {
|
|
561
|
+
try {
|
|
562
|
+
defValue.contents = parse(v);
|
|
563
|
+
return true;
|
|
564
|
+
}
|
|
565
|
+
catch (_err) {
|
|
566
|
+
return false;
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
export function create(year, month, day, h = 0, m = 0, s = 0, ms = 0, kind) {
|
|
570
|
+
const date = kind === 1 /* DateKind.UTC */
|
|
571
|
+
? new Date(Date.UTC(year, month - 1, day, h, m, s, ms))
|
|
572
|
+
: new Date(year, month - 1, day, h, m, s, ms);
|
|
573
|
+
if (year <= 99) {
|
|
574
|
+
if (kind === 1 /* DateKind.UTC */) {
|
|
575
|
+
date.setUTCFullYear(year, month - 1, day);
|
|
576
|
+
}
|
|
577
|
+
else {
|
|
578
|
+
date.setFullYear(year, month - 1, day);
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
const dateValue = date.getTime();
|
|
582
|
+
if (isNaN(dateValue)) {
|
|
583
|
+
throw new Error("The parameters describe an unrepresentable Date.");
|
|
584
|
+
}
|
|
585
|
+
return DateTime(dateValue, kind);
|
|
586
|
+
}
|
|
587
|
+
export function now() {
|
|
588
|
+
return DateTime(Date.now(), 2 /* DateKind.Local */);
|
|
589
|
+
}
|
|
590
|
+
export function utcNow() {
|
|
591
|
+
return DateTime(Date.now(), 1 /* DateKind.UTC */);
|
|
592
|
+
}
|
|
593
|
+
export function today() {
|
|
594
|
+
return date(now());
|
|
595
|
+
}
|
|
596
|
+
export function isLeapYear(year) {
|
|
597
|
+
return year % 4 === 0 && year % 100 !== 0 || year % 400 === 0;
|
|
598
|
+
}
|
|
599
|
+
export function daysInMonth(year, month) {
|
|
600
|
+
return month === 2
|
|
601
|
+
? (isLeapYear(year) ? 29 : 28)
|
|
602
|
+
: (month >= 8 ? (month % 2 === 0 ? 31 : 30) : (month % 2 === 0 ? 30 : 31));
|
|
603
|
+
}
|
|
604
|
+
export function toUniversalTime(date) {
|
|
605
|
+
return date.kind === 1 /* DateKind.UTC */ ? date : DateTime(date.getTime(), 1 /* DateKind.UTC */);
|
|
606
|
+
}
|
|
607
|
+
export function toLocalTime(date) {
|
|
608
|
+
return date.kind === 2 /* DateKind.Local */ ? date : DateTime(date.getTime(), 2 /* DateKind.Local */);
|
|
609
|
+
}
|
|
610
|
+
export function specifyKind(d, kind) {
|
|
611
|
+
return create(year(d), month(d), day(d), hour(d), minute(d), second(d), millisecond(d), kind);
|
|
612
|
+
}
|
|
613
|
+
export function timeOfDay(d) {
|
|
614
|
+
return hour(d) * 3600000
|
|
615
|
+
+ minute(d) * 60000
|
|
616
|
+
+ second(d) * 1000
|
|
617
|
+
+ millisecond(d);
|
|
618
|
+
}
|
|
619
|
+
export function date(d) {
|
|
620
|
+
return create(year(d), month(d), day(d), 0, 0, 0, 0, d.kind);
|
|
621
|
+
}
|
|
622
|
+
export function day(d) {
|
|
623
|
+
return d.kind === 1 /* DateKind.UTC */ ? d.getUTCDate() : d.getDate();
|
|
624
|
+
}
|
|
625
|
+
export function hour(d) {
|
|
626
|
+
return d.kind === 1 /* DateKind.UTC */ ? d.getUTCHours() : d.getHours();
|
|
627
|
+
}
|
|
628
|
+
export function millisecond(d) {
|
|
629
|
+
return d.kind === 1 /* DateKind.UTC */ ? d.getUTCMilliseconds() : d.getMilliseconds();
|
|
630
|
+
}
|
|
631
|
+
export function minute(d) {
|
|
632
|
+
return d.kind === 1 /* DateKind.UTC */ ? d.getUTCMinutes() : d.getMinutes();
|
|
633
|
+
}
|
|
634
|
+
export function month(d) {
|
|
635
|
+
return (d.kind === 1 /* DateKind.UTC */ ? d.getUTCMonth() : d.getMonth()) + 1;
|
|
636
|
+
}
|
|
637
|
+
export function second(d) {
|
|
638
|
+
return d.kind === 1 /* DateKind.UTC */ ? d.getUTCSeconds() : d.getSeconds();
|
|
639
|
+
}
|
|
640
|
+
export function year(d) {
|
|
641
|
+
return d.kind === 1 /* DateKind.UTC */ ? d.getUTCFullYear() : d.getFullYear();
|
|
642
|
+
}
|
|
643
|
+
export function dayOfWeek(d) {
|
|
644
|
+
return d.kind === 1 /* DateKind.UTC */ ? d.getUTCDay() : d.getDay();
|
|
645
|
+
}
|
|
646
|
+
export function dayOfYear(d) {
|
|
647
|
+
const _year = year(d);
|
|
648
|
+
const _month = month(d);
|
|
649
|
+
let _day = day(d);
|
|
650
|
+
for (let i = 1; i < _month; i++) {
|
|
651
|
+
_day += daysInMonth(_year, i);
|
|
652
|
+
}
|
|
653
|
+
return _day;
|
|
654
|
+
}
|
|
655
|
+
export function add(d, ts) {
|
|
656
|
+
const newDate = DateTime(d.getTime() + ts, d.kind);
|
|
657
|
+
if (d.kind !== 1 /* DateKind.UTC */) {
|
|
658
|
+
const oldTzOffset = d.getTimezoneOffset();
|
|
659
|
+
const newTzOffset = newDate.getTimezoneOffset();
|
|
660
|
+
return oldTzOffset !== newTzOffset
|
|
661
|
+
? DateTime(newDate.getTime() + (newTzOffset - oldTzOffset) * 60000, d.kind)
|
|
662
|
+
: newDate;
|
|
663
|
+
}
|
|
664
|
+
else {
|
|
665
|
+
return newDate;
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
export function addDays(d, v) {
|
|
669
|
+
return add(d, v * 86400000);
|
|
670
|
+
}
|
|
671
|
+
export function addHours(d, v) {
|
|
672
|
+
return add(d, v * 3600000);
|
|
673
|
+
}
|
|
674
|
+
export function addMinutes(d, v) {
|
|
675
|
+
return add(d, v * 60000);
|
|
676
|
+
}
|
|
677
|
+
export function addSeconds(d, v) {
|
|
678
|
+
return add(d, v * 1000);
|
|
679
|
+
}
|
|
680
|
+
export function addMilliseconds(d, v) {
|
|
681
|
+
return add(d, v);
|
|
682
|
+
}
|
|
683
|
+
export function addTicks(d, v) {
|
|
684
|
+
return add(d, toFloat64(v / 10000n));
|
|
685
|
+
}
|
|
686
|
+
export function addYears(d, v) {
|
|
687
|
+
const newMonth = month(d);
|
|
688
|
+
const newYear = year(d) + v;
|
|
689
|
+
const _daysInMonth = daysInMonth(newYear, newMonth);
|
|
690
|
+
const newDay = Math.min(_daysInMonth, day(d));
|
|
691
|
+
return create(newYear, newMonth, newDay, hour(d), minute(d), second(d), millisecond(d), d.kind);
|
|
692
|
+
}
|
|
693
|
+
export function addMonths(d, v) {
|
|
694
|
+
let newMonth = month(d) + v;
|
|
695
|
+
let newMonth_ = 0;
|
|
696
|
+
let yearOffset = 0;
|
|
697
|
+
if (newMonth > 12) {
|
|
698
|
+
newMonth_ = newMonth % 12;
|
|
699
|
+
yearOffset = Math.floor(newMonth / 12);
|
|
700
|
+
newMonth = newMonth_;
|
|
701
|
+
}
|
|
702
|
+
else if (newMonth < 1) {
|
|
703
|
+
newMonth_ = 12 + newMonth % 12;
|
|
704
|
+
yearOffset = Math.floor(newMonth / 12) + (newMonth_ === 12 ? -1 : 0);
|
|
705
|
+
newMonth = newMonth_;
|
|
706
|
+
}
|
|
707
|
+
const newYear = year(d) + yearOffset;
|
|
708
|
+
const _daysInMonth = daysInMonth(newYear, newMonth);
|
|
709
|
+
const newDay = Math.min(_daysInMonth, day(d));
|
|
710
|
+
return create(newYear, newMonth, newDay, hour(d), minute(d), second(d), millisecond(d), d.kind);
|
|
711
|
+
}
|
|
712
|
+
export function subtract(d, that) {
|
|
713
|
+
return typeof that === "number"
|
|
714
|
+
? add(d, -that)
|
|
715
|
+
: d.getTime() - that.getTime();
|
|
716
|
+
}
|
|
717
|
+
export function toLongDateString(d) {
|
|
718
|
+
return d.toDateString();
|
|
719
|
+
}
|
|
720
|
+
export function toShortDateString(d) {
|
|
721
|
+
return d.toLocaleDateString();
|
|
722
|
+
}
|
|
723
|
+
export function toLongTimeString(d) {
|
|
724
|
+
return d.toLocaleTimeString();
|
|
725
|
+
}
|
|
726
|
+
export function toShortTimeString(d) {
|
|
727
|
+
return d.toLocaleTimeString().replace(/:\d\d(?!:)/, "");
|
|
728
|
+
}
|
|
729
|
+
export function equals(d1, d2) {
|
|
730
|
+
return d1.getTime() === d2.getTime();
|
|
731
|
+
}
|
|
732
|
+
export const compare = compareDates;
|
|
733
|
+
export const compareTo = compareDates;
|
|
734
|
+
export function op_Addition(x, y) {
|
|
735
|
+
return add(x, y);
|
|
736
|
+
}
|
|
737
|
+
export function op_Subtraction(x, y) {
|
|
738
|
+
return subtract(x, y);
|
|
739
|
+
}
|
|
740
|
+
export function isDaylightSavingTime(x) {
|
|
741
|
+
const jan = new Date(x.getFullYear(), 0, 1);
|
|
742
|
+
const jul = new Date(x.getFullYear(), 6, 1);
|
|
743
|
+
return isDST(jan.getTimezoneOffset(), jul.getTimezoneOffset(), x.getTimezoneOffset());
|
|
744
|
+
}
|
|
745
|
+
function isDST(janOffset, julOffset, tOffset) {
|
|
746
|
+
return Math.min(janOffset, julOffset) === tOffset;
|
|
747
|
+
}
|
|
748
|
+
export default DateTime;
|