@chainflip/utils 0.4.1 → 0.4.2
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/chainflip.cjs +25 -3
- package/dist/chainflip.d.cts +23 -2
- package/dist/chainflip.d.ts +23 -2
- package/dist/chainflip.js +5 -1
- package/dist/{chunk-XFHVSV76.js → chunk-FKSZD3R5.js} +24 -4
- package/dist/consts.cjs +3 -0
- package/dist/consts.d.cts +2 -1
- package/dist/consts.d.ts +2 -1
- package/dist/consts.js +2 -0
- package/dist/date.cjs +13 -388
- package/dist/date.d.cts +3 -2
- package/dist/date.d.ts +3 -2
- package/dist/date.js +17 -383
- package/dist/number.cjs +2 -1347
- package/dist/number.js +2 -5
- package/dist/tickMath.cjs +9 -1346
- package/dist/tickMath.js +4 -6
- package/package.json +6 -3
- package/dist/chunk-WGS2RGVR.js +0 -1348
package/dist/date.js
CHANGED
|
@@ -2,361 +2,18 @@ import {
|
|
|
2
2
|
isNullish
|
|
3
3
|
} from "./chunk-HBIFE4XN.js";
|
|
4
4
|
|
|
5
|
-
// ../../node_modules/.pnpm/@babel+runtime@7.26.0/node_modules/@babel/runtime/helpers/esm/typeof.js
|
|
6
|
-
function _typeof(o) {
|
|
7
|
-
"@babel/helpers - typeof";
|
|
8
|
-
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o2) {
|
|
9
|
-
return typeof o2;
|
|
10
|
-
} : function(o2) {
|
|
11
|
-
return o2 && "function" == typeof Symbol && o2.constructor === Symbol && o2 !== Symbol.prototype ? "symbol" : typeof o2;
|
|
12
|
-
}, _typeof(o);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// ../../node_modules/.pnpm/date-fns@2.30.0/node_modules/date-fns/esm/_lib/toInteger/index.js
|
|
16
|
-
function toInteger(dirtyNumber) {
|
|
17
|
-
if (dirtyNumber === null || dirtyNumber === true || dirtyNumber === false) {
|
|
18
|
-
return NaN;
|
|
19
|
-
}
|
|
20
|
-
var number = Number(dirtyNumber);
|
|
21
|
-
if (isNaN(number)) {
|
|
22
|
-
return number;
|
|
23
|
-
}
|
|
24
|
-
return number < 0 ? Math.ceil(number) : Math.floor(number);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// ../../node_modules/.pnpm/date-fns@2.30.0/node_modules/date-fns/esm/_lib/requiredArgs/index.js
|
|
28
|
-
function requiredArgs(required, args) {
|
|
29
|
-
if (args.length < required) {
|
|
30
|
-
throw new TypeError(required + " argument" + (required > 1 ? "s" : "") + " required, but only " + args.length + " present");
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// ../../node_modules/.pnpm/date-fns@2.30.0/node_modules/date-fns/esm/toDate/index.js
|
|
35
|
-
function toDate(argument) {
|
|
36
|
-
requiredArgs(1, arguments);
|
|
37
|
-
var argStr = Object.prototype.toString.call(argument);
|
|
38
|
-
if (argument instanceof Date || _typeof(argument) === "object" && argStr === "[object Date]") {
|
|
39
|
-
return new Date(argument.getTime());
|
|
40
|
-
} else if (typeof argument === "number" || argStr === "[object Number]") {
|
|
41
|
-
return new Date(argument);
|
|
42
|
-
} else {
|
|
43
|
-
if ((typeof argument === "string" || argStr === "[object String]") && typeof console !== "undefined") {
|
|
44
|
-
console.warn("Starting with v2.0.0-beta.1 date-fns doesn't accept strings as date arguments. Please use `parseISO` to parse strings. See: https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#string-arguments");
|
|
45
|
-
console.warn(new Error().stack);
|
|
46
|
-
}
|
|
47
|
-
return /* @__PURE__ */ new Date(NaN);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// ../../node_modules/.pnpm/date-fns@2.30.0/node_modules/date-fns/esm/addDays/index.js
|
|
52
|
-
function addDays(dirtyDate, dirtyAmount) {
|
|
53
|
-
requiredArgs(2, arguments);
|
|
54
|
-
var date = toDate(dirtyDate);
|
|
55
|
-
var amount = toInteger(dirtyAmount);
|
|
56
|
-
if (isNaN(amount)) {
|
|
57
|
-
return /* @__PURE__ */ new Date(NaN);
|
|
58
|
-
}
|
|
59
|
-
if (!amount) {
|
|
60
|
-
return date;
|
|
61
|
-
}
|
|
62
|
-
date.setDate(date.getDate() + amount);
|
|
63
|
-
return date;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// ../../node_modules/.pnpm/date-fns@2.30.0/node_modules/date-fns/esm/addMonths/index.js
|
|
67
|
-
function addMonths(dirtyDate, dirtyAmount) {
|
|
68
|
-
requiredArgs(2, arguments);
|
|
69
|
-
var date = toDate(dirtyDate);
|
|
70
|
-
var amount = toInteger(dirtyAmount);
|
|
71
|
-
if (isNaN(amount)) {
|
|
72
|
-
return /* @__PURE__ */ new Date(NaN);
|
|
73
|
-
}
|
|
74
|
-
if (!amount) {
|
|
75
|
-
return date;
|
|
76
|
-
}
|
|
77
|
-
var dayOfMonth = date.getDate();
|
|
78
|
-
var endOfDesiredMonth = new Date(date.getTime());
|
|
79
|
-
endOfDesiredMonth.setMonth(date.getMonth() + amount + 1, 0);
|
|
80
|
-
var daysInMonth = endOfDesiredMonth.getDate();
|
|
81
|
-
if (dayOfMonth >= daysInMonth) {
|
|
82
|
-
return endOfDesiredMonth;
|
|
83
|
-
} else {
|
|
84
|
-
date.setFullYear(endOfDesiredMonth.getFullYear(), endOfDesiredMonth.getMonth(), dayOfMonth);
|
|
85
|
-
return date;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// ../../node_modules/.pnpm/date-fns@2.30.0/node_modules/date-fns/esm/add/index.js
|
|
90
|
-
function add(dirtyDate, duration) {
|
|
91
|
-
requiredArgs(2, arguments);
|
|
92
|
-
if (!duration || _typeof(duration) !== "object") return /* @__PURE__ */ new Date(NaN);
|
|
93
|
-
var years = duration.years ? toInteger(duration.years) : 0;
|
|
94
|
-
var months = duration.months ? toInteger(duration.months) : 0;
|
|
95
|
-
var weeks = duration.weeks ? toInteger(duration.weeks) : 0;
|
|
96
|
-
var days = duration.days ? toInteger(duration.days) : 0;
|
|
97
|
-
var hours = duration.hours ? toInteger(duration.hours) : 0;
|
|
98
|
-
var minutes = duration.minutes ? toInteger(duration.minutes) : 0;
|
|
99
|
-
var seconds = duration.seconds ? toInteger(duration.seconds) : 0;
|
|
100
|
-
var date = toDate(dirtyDate);
|
|
101
|
-
var dateWithMonths = months || years ? addMonths(date, months + years * 12) : date;
|
|
102
|
-
var dateWithDays = days || weeks ? addDays(dateWithMonths, days + weeks * 7) : dateWithMonths;
|
|
103
|
-
var minutesToAdd = minutes + hours * 60;
|
|
104
|
-
var secondsToAdd = seconds + minutesToAdd * 60;
|
|
105
|
-
var msToAdd = secondsToAdd * 1e3;
|
|
106
|
-
var finalDate = new Date(dateWithDays.getTime() + msToAdd);
|
|
107
|
-
return finalDate;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// ../../node_modules/.pnpm/date-fns@2.30.0/node_modules/date-fns/esm/addMilliseconds/index.js
|
|
111
|
-
function addMilliseconds(dirtyDate, dirtyAmount) {
|
|
112
|
-
requiredArgs(2, arguments);
|
|
113
|
-
var timestamp = toDate(dirtyDate).getTime();
|
|
114
|
-
var amount = toInteger(dirtyAmount);
|
|
115
|
-
return new Date(timestamp + amount);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// ../../node_modules/.pnpm/date-fns@2.30.0/node_modules/date-fns/esm/addHours/index.js
|
|
119
|
-
var MILLISECONDS_IN_HOUR = 36e5;
|
|
120
|
-
function addHours(dirtyDate, dirtyAmount) {
|
|
121
|
-
requiredArgs(2, arguments);
|
|
122
|
-
var amount = toInteger(dirtyAmount);
|
|
123
|
-
return addMilliseconds(dirtyDate, amount * MILLISECONDS_IN_HOUR);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
// ../../node_modules/.pnpm/date-fns@2.30.0/node_modules/date-fns/esm/_lib/getTimezoneOffsetInMilliseconds/index.js
|
|
127
|
-
function getTimezoneOffsetInMilliseconds(date) {
|
|
128
|
-
var utcDate = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds()));
|
|
129
|
-
utcDate.setUTCFullYear(date.getFullYear());
|
|
130
|
-
return date.getTime() - utcDate.getTime();
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
// ../../node_modules/.pnpm/date-fns@2.30.0/node_modules/date-fns/esm/startOfDay/index.js
|
|
134
|
-
function startOfDay(dirtyDate) {
|
|
135
|
-
requiredArgs(1, arguments);
|
|
136
|
-
var date = toDate(dirtyDate);
|
|
137
|
-
date.setHours(0, 0, 0, 0);
|
|
138
|
-
return date;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
// ../../node_modules/.pnpm/date-fns@2.30.0/node_modules/date-fns/esm/differenceInCalendarDays/index.js
|
|
142
|
-
var MILLISECONDS_IN_DAY = 864e5;
|
|
143
|
-
function differenceInCalendarDays(dirtyDateLeft, dirtyDateRight) {
|
|
144
|
-
requiredArgs(2, arguments);
|
|
145
|
-
var startOfDayLeft = startOfDay(dirtyDateLeft);
|
|
146
|
-
var startOfDayRight = startOfDay(dirtyDateRight);
|
|
147
|
-
var timestampLeft = startOfDayLeft.getTime() - getTimezoneOffsetInMilliseconds(startOfDayLeft);
|
|
148
|
-
var timestampRight = startOfDayRight.getTime() - getTimezoneOffsetInMilliseconds(startOfDayRight);
|
|
149
|
-
return Math.round((timestampLeft - timestampRight) / MILLISECONDS_IN_DAY);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
// ../../node_modules/.pnpm/date-fns@2.30.0/node_modules/date-fns/esm/compareAsc/index.js
|
|
153
|
-
function compareAsc(dirtyDateLeft, dirtyDateRight) {
|
|
154
|
-
requiredArgs(2, arguments);
|
|
155
|
-
var dateLeft = toDate(dirtyDateLeft);
|
|
156
|
-
var dateRight = toDate(dirtyDateRight);
|
|
157
|
-
var diff = dateLeft.getTime() - dateRight.getTime();
|
|
158
|
-
if (diff < 0) {
|
|
159
|
-
return -1;
|
|
160
|
-
} else if (diff > 0) {
|
|
161
|
-
return 1;
|
|
162
|
-
} else {
|
|
163
|
-
return diff;
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
// ../../node_modules/.pnpm/date-fns@2.30.0/node_modules/date-fns/esm/constants/index.js
|
|
168
|
-
var daysInYear = 365.2425;
|
|
169
|
-
var maxTime = Math.pow(10, 8) * 24 * 60 * 60 * 1e3;
|
|
170
|
-
var millisecondsInMinute = 6e4;
|
|
171
|
-
var millisecondsInHour = 36e5;
|
|
172
|
-
var minTime = -maxTime;
|
|
173
|
-
var secondsInHour = 3600;
|
|
174
|
-
var secondsInDay = secondsInHour * 24;
|
|
175
|
-
var secondsInWeek = secondsInDay * 7;
|
|
176
|
-
var secondsInYear = secondsInDay * daysInYear;
|
|
177
|
-
var secondsInMonth = secondsInYear / 12;
|
|
178
|
-
var secondsInQuarter = secondsInMonth * 3;
|
|
179
|
-
|
|
180
|
-
// ../../node_modules/.pnpm/date-fns@2.30.0/node_modules/date-fns/esm/differenceInCalendarMonths/index.js
|
|
181
|
-
function differenceInCalendarMonths(dirtyDateLeft, dirtyDateRight) {
|
|
182
|
-
requiredArgs(2, arguments);
|
|
183
|
-
var dateLeft = toDate(dirtyDateLeft);
|
|
184
|
-
var dateRight = toDate(dirtyDateRight);
|
|
185
|
-
var yearDiff = dateLeft.getFullYear() - dateRight.getFullYear();
|
|
186
|
-
var monthDiff = dateLeft.getMonth() - dateRight.getMonth();
|
|
187
|
-
return yearDiff * 12 + monthDiff;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
// ../../node_modules/.pnpm/date-fns@2.30.0/node_modules/date-fns/esm/differenceInCalendarYears/index.js
|
|
191
|
-
function differenceInCalendarYears(dirtyDateLeft, dirtyDateRight) {
|
|
192
|
-
requiredArgs(2, arguments);
|
|
193
|
-
var dateLeft = toDate(dirtyDateLeft);
|
|
194
|
-
var dateRight = toDate(dirtyDateRight);
|
|
195
|
-
return dateLeft.getFullYear() - dateRight.getFullYear();
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
// ../../node_modules/.pnpm/date-fns@2.30.0/node_modules/date-fns/esm/differenceInDays/index.js
|
|
199
|
-
function compareLocalAsc(dateLeft, dateRight) {
|
|
200
|
-
var diff = dateLeft.getFullYear() - dateRight.getFullYear() || dateLeft.getMonth() - dateRight.getMonth() || dateLeft.getDate() - dateRight.getDate() || dateLeft.getHours() - dateRight.getHours() || dateLeft.getMinutes() - dateRight.getMinutes() || dateLeft.getSeconds() - dateRight.getSeconds() || dateLeft.getMilliseconds() - dateRight.getMilliseconds();
|
|
201
|
-
if (diff < 0) {
|
|
202
|
-
return -1;
|
|
203
|
-
} else if (diff > 0) {
|
|
204
|
-
return 1;
|
|
205
|
-
} else {
|
|
206
|
-
return diff;
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
function differenceInDays(dirtyDateLeft, dirtyDateRight) {
|
|
210
|
-
requiredArgs(2, arguments);
|
|
211
|
-
var dateLeft = toDate(dirtyDateLeft);
|
|
212
|
-
var dateRight = toDate(dirtyDateRight);
|
|
213
|
-
var sign = compareLocalAsc(dateLeft, dateRight);
|
|
214
|
-
var difference = Math.abs(differenceInCalendarDays(dateLeft, dateRight));
|
|
215
|
-
dateLeft.setDate(dateLeft.getDate() - sign * difference);
|
|
216
|
-
var isLastDayNotFull = Number(compareLocalAsc(dateLeft, dateRight) === -sign);
|
|
217
|
-
var result = sign * (difference - isLastDayNotFull);
|
|
218
|
-
return result === 0 ? 0 : result;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
// ../../node_modules/.pnpm/date-fns@2.30.0/node_modules/date-fns/esm/differenceInMilliseconds/index.js
|
|
222
|
-
function differenceInMilliseconds(dateLeft, dateRight) {
|
|
223
|
-
requiredArgs(2, arguments);
|
|
224
|
-
return toDate(dateLeft).getTime() - toDate(dateRight).getTime();
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
// ../../node_modules/.pnpm/date-fns@2.30.0/node_modules/date-fns/esm/_lib/roundingMethods/index.js
|
|
228
|
-
var roundingMap = {
|
|
229
|
-
ceil: Math.ceil,
|
|
230
|
-
round: Math.round,
|
|
231
|
-
floor: Math.floor,
|
|
232
|
-
trunc: function trunc(value) {
|
|
233
|
-
return value < 0 ? Math.ceil(value) : Math.floor(value);
|
|
234
|
-
}
|
|
235
|
-
// Math.trunc is not supported by IE
|
|
236
|
-
};
|
|
237
|
-
var defaultRoundingMethod = "trunc";
|
|
238
|
-
function getRoundingMethod(method) {
|
|
239
|
-
return method ? roundingMap[method] : roundingMap[defaultRoundingMethod];
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
// ../../node_modules/.pnpm/date-fns@2.30.0/node_modules/date-fns/esm/differenceInHours/index.js
|
|
243
|
-
function differenceInHours(dateLeft, dateRight, options) {
|
|
244
|
-
requiredArgs(2, arguments);
|
|
245
|
-
var diff = differenceInMilliseconds(dateLeft, dateRight) / millisecondsInHour;
|
|
246
|
-
return getRoundingMethod(options === null || options === void 0 ? void 0 : options.roundingMethod)(diff);
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
// ../../node_modules/.pnpm/date-fns@2.30.0/node_modules/date-fns/esm/differenceInMinutes/index.js
|
|
250
|
-
function differenceInMinutes(dateLeft, dateRight, options) {
|
|
251
|
-
requiredArgs(2, arguments);
|
|
252
|
-
var diff = differenceInMilliseconds(dateLeft, dateRight) / millisecondsInMinute;
|
|
253
|
-
return getRoundingMethod(options === null || options === void 0 ? void 0 : options.roundingMethod)(diff);
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
// ../../node_modules/.pnpm/date-fns@2.30.0/node_modules/date-fns/esm/endOfDay/index.js
|
|
257
|
-
function endOfDay(dirtyDate) {
|
|
258
|
-
requiredArgs(1, arguments);
|
|
259
|
-
var date = toDate(dirtyDate);
|
|
260
|
-
date.setHours(23, 59, 59, 999);
|
|
261
|
-
return date;
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
// ../../node_modules/.pnpm/date-fns@2.30.0/node_modules/date-fns/esm/endOfMonth/index.js
|
|
265
|
-
function endOfMonth(dirtyDate) {
|
|
266
|
-
requiredArgs(1, arguments);
|
|
267
|
-
var date = toDate(dirtyDate);
|
|
268
|
-
var month = date.getMonth();
|
|
269
|
-
date.setFullYear(date.getFullYear(), month + 1, 0);
|
|
270
|
-
date.setHours(23, 59, 59, 999);
|
|
271
|
-
return date;
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
// ../../node_modules/.pnpm/date-fns@2.30.0/node_modules/date-fns/esm/isLastDayOfMonth/index.js
|
|
275
|
-
function isLastDayOfMonth(dirtyDate) {
|
|
276
|
-
requiredArgs(1, arguments);
|
|
277
|
-
var date = toDate(dirtyDate);
|
|
278
|
-
return endOfDay(date).getTime() === endOfMonth(date).getTime();
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
// ../../node_modules/.pnpm/date-fns@2.30.0/node_modules/date-fns/esm/differenceInMonths/index.js
|
|
282
|
-
function differenceInMonths(dirtyDateLeft, dirtyDateRight) {
|
|
283
|
-
requiredArgs(2, arguments);
|
|
284
|
-
var dateLeft = toDate(dirtyDateLeft);
|
|
285
|
-
var dateRight = toDate(dirtyDateRight);
|
|
286
|
-
var sign = compareAsc(dateLeft, dateRight);
|
|
287
|
-
var difference = Math.abs(differenceInCalendarMonths(dateLeft, dateRight));
|
|
288
|
-
var result;
|
|
289
|
-
if (difference < 1) {
|
|
290
|
-
result = 0;
|
|
291
|
-
} else {
|
|
292
|
-
if (dateLeft.getMonth() === 1 && dateLeft.getDate() > 27) {
|
|
293
|
-
dateLeft.setDate(30);
|
|
294
|
-
}
|
|
295
|
-
dateLeft.setMonth(dateLeft.getMonth() - sign * difference);
|
|
296
|
-
var isLastMonthNotFull = compareAsc(dateLeft, dateRight) === -sign;
|
|
297
|
-
if (isLastDayOfMonth(toDate(dirtyDateLeft)) && difference === 1 && compareAsc(dirtyDateLeft, dateRight) === 1) {
|
|
298
|
-
isLastMonthNotFull = false;
|
|
299
|
-
}
|
|
300
|
-
result = sign * (difference - Number(isLastMonthNotFull));
|
|
301
|
-
}
|
|
302
|
-
return result === 0 ? 0 : result;
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
// ../../node_modules/.pnpm/date-fns@2.30.0/node_modules/date-fns/esm/differenceInSeconds/index.js
|
|
306
|
-
function differenceInSeconds(dateLeft, dateRight, options) {
|
|
307
|
-
requiredArgs(2, arguments);
|
|
308
|
-
var diff = differenceInMilliseconds(dateLeft, dateRight) / 1e3;
|
|
309
|
-
return getRoundingMethod(options === null || options === void 0 ? void 0 : options.roundingMethod)(diff);
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
// ../../node_modules/.pnpm/date-fns@2.30.0/node_modules/date-fns/esm/differenceInYears/index.js
|
|
313
|
-
function differenceInYears(dirtyDateLeft, dirtyDateRight) {
|
|
314
|
-
requiredArgs(2, arguments);
|
|
315
|
-
var dateLeft = toDate(dirtyDateLeft);
|
|
316
|
-
var dateRight = toDate(dirtyDateRight);
|
|
317
|
-
var sign = compareAsc(dateLeft, dateRight);
|
|
318
|
-
var difference = Math.abs(differenceInCalendarYears(dateLeft, dateRight));
|
|
319
|
-
dateLeft.setFullYear(1584);
|
|
320
|
-
dateRight.setFullYear(1584);
|
|
321
|
-
var isLastYearNotFull = compareAsc(dateLeft, dateRight) === -sign;
|
|
322
|
-
var result = sign * (difference - Number(isLastYearNotFull));
|
|
323
|
-
return result === 0 ? 0 : result;
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
// ../../node_modules/.pnpm/date-fns@2.30.0/node_modules/date-fns/esm/intervalToDuration/index.js
|
|
327
|
-
function intervalToDuration(interval) {
|
|
328
|
-
requiredArgs(1, arguments);
|
|
329
|
-
var start = toDate(interval.start);
|
|
330
|
-
var end = toDate(interval.end);
|
|
331
|
-
if (isNaN(start.getTime())) throw new RangeError("Start Date is invalid");
|
|
332
|
-
if (isNaN(end.getTime())) throw new RangeError("End Date is invalid");
|
|
333
|
-
var duration = {};
|
|
334
|
-
duration.years = Math.abs(differenceInYears(end, start));
|
|
335
|
-
var sign = compareAsc(end, start);
|
|
336
|
-
var remainingMonths = add(start, {
|
|
337
|
-
years: sign * duration.years
|
|
338
|
-
});
|
|
339
|
-
duration.months = Math.abs(differenceInMonths(end, remainingMonths));
|
|
340
|
-
var remainingDays = add(remainingMonths, {
|
|
341
|
-
months: sign * duration.months
|
|
342
|
-
});
|
|
343
|
-
duration.days = Math.abs(differenceInDays(end, remainingDays));
|
|
344
|
-
var remainingHours = add(remainingDays, {
|
|
345
|
-
days: sign * duration.days
|
|
346
|
-
});
|
|
347
|
-
duration.hours = Math.abs(differenceInHours(end, remainingHours));
|
|
348
|
-
var remainingMinutes = add(remainingHours, {
|
|
349
|
-
hours: sign * duration.hours
|
|
350
|
-
});
|
|
351
|
-
duration.minutes = Math.abs(differenceInMinutes(end, remainingMinutes));
|
|
352
|
-
var remainingSeconds = add(remainingMinutes, {
|
|
353
|
-
minutes: sign * duration.minutes
|
|
354
|
-
});
|
|
355
|
-
duration.seconds = Math.abs(differenceInSeconds(end, remainingSeconds));
|
|
356
|
-
return duration;
|
|
357
|
-
}
|
|
358
|
-
|
|
359
5
|
// src/date.ts
|
|
6
|
+
import { utc } from "@date-fns/utc";
|
|
7
|
+
import {
|
|
8
|
+
differenceInDays,
|
|
9
|
+
differenceInHours,
|
|
10
|
+
differenceInMinutes,
|
|
11
|
+
differenceInSeconds,
|
|
12
|
+
intervalToDuration,
|
|
13
|
+
eachDayOfInterval,
|
|
14
|
+
endOfDay,
|
|
15
|
+
startOfDay
|
|
16
|
+
} from "date-fns";
|
|
360
17
|
var pluralize = (word, numb) => numb !== 1 ? `${word}s` : word;
|
|
361
18
|
var pad = (number) => String(number).padStart(2, "0");
|
|
362
19
|
var toISODateString = (date) => date.toISOString().slice(0, 10);
|
|
@@ -406,42 +63,19 @@ var intervalToDurationWords = (interval) => {
|
|
|
406
63
|
if (duration.months) return ">1 month";
|
|
407
64
|
if (duration.days) {
|
|
408
65
|
return `${pad(duration.days)}${duration.days === 1 ? "day" : "days"} ${pad(
|
|
409
|
-
duration.hours
|
|
410
|
-
)}h ${pad(duration.minutes)}min ${pad(duration.seconds)}s`;
|
|
66
|
+
duration.hours ?? 0
|
|
67
|
+
)}h ${pad(duration.minutes ?? 0)}min ${pad(duration.seconds ?? 0)}s`;
|
|
411
68
|
}
|
|
412
69
|
if (duration.hours) {
|
|
413
70
|
return `${pad(duration.hours)}h ${pad(duration.minutes)}min ${pad(duration.seconds)}s`;
|
|
414
71
|
}
|
|
415
72
|
if (duration.minutes) return `${pad(duration.minutes)}min ${pad(duration.seconds)}s`;
|
|
416
73
|
if (duration.seconds) return `${pad(duration.seconds)}s`;
|
|
417
|
-
return "
|
|
418
|
-
};
|
|
419
|
-
var getUTCDateParts = (date) => {
|
|
420
|
-
const day = date.getUTCDate().toString().padStart(2, "0");
|
|
421
|
-
const month = (date.getUTCMonth() + 1).toString().padStart(2, "0");
|
|
422
|
-
const year = date.getUTCFullYear().toString().padStart(4, "0");
|
|
423
|
-
return { day, month, year };
|
|
424
|
-
};
|
|
425
|
-
var toStartOfUtcDayString = (date) => {
|
|
426
|
-
const { day, month, year } = getUTCDateParts(date);
|
|
427
|
-
return `${year}-${month}-${day}T00:00:00.000Z`;
|
|
428
|
-
};
|
|
429
|
-
var toEndOfUtcDayString = (date) => {
|
|
430
|
-
const { day, month, year } = getUTCDateParts(date);
|
|
431
|
-
return `${year}-${month}-${day}T23:59:59.999Z`;
|
|
432
|
-
};
|
|
433
|
-
var eachUtcDayOfInterval = ({ start, end }) => {
|
|
434
|
-
let accumulator = start;
|
|
435
|
-
const days = [];
|
|
436
|
-
while (end >= accumulator) {
|
|
437
|
-
if (new Date(toStartOfUtcDayString(accumulator)).getTime() > (/* @__PURE__ */ new Date()).getTime()) {
|
|
438
|
-
break;
|
|
439
|
-
}
|
|
440
|
-
days.push(new Date(toStartOfUtcDayString(accumulator)));
|
|
441
|
-
accumulator = addHours(accumulator, 24);
|
|
442
|
-
}
|
|
443
|
-
return days;
|
|
74
|
+
return "A few seconds";
|
|
444
75
|
};
|
|
76
|
+
var toStartOfUtcDayString = (date) => startOfDay(date, { in: utc }).toISOString();
|
|
77
|
+
var toEndOfUtcDayString = (date) => endOfDay(date, { in: utc }).toISOString();
|
|
78
|
+
var eachUtcDayOfInterval = (interval) => eachDayOfInterval(interval, { in: utc });
|
|
445
79
|
export {
|
|
446
80
|
differenceInTimeAgo,
|
|
447
81
|
eachUtcDayOfInterval,
|