@fable-org/fable-library-js 2.0.0-beta.4 → 2.0.0-beta.6
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/Array.js +56 -52
- package/Async.js +8 -7
- package/AsyncBuilder.js +6 -6
- package/BigInt.js +3 -3
- package/Boolean.js +2 -1
- package/CHANGELOG.md +14 -0
- package/Char.js +64 -31
- package/CollectionUtil.js +3 -3
- package/Date.js +50 -46
- package/DateOffset.js +37 -47
- package/DateOnly.js +6 -6
- package/Decimal.js +4 -4
- package/Double.js +2 -1
- package/FSharp.Collections.js +28 -10
- package/FSharp.Core.js +23 -23
- package/Global.js +21 -0
- package/Guid.js +5 -4
- package/Int32.js +17 -17
- package/List.js +36 -35
- package/Long.js +3 -2
- package/MailboxProcessor.js +2 -1
- package/Map.js +29 -27
- package/MapUtil.js +4 -4
- package/MutableMap.js +22 -10
- package/MutableSet.js +3 -3
- package/Option.js +3 -3
- package/Random.js +12 -11
- package/Range.js +2 -2
- package/Reflection.js +16 -16
- package/RegExp.js +4 -3
- package/Seq.js +31 -29
- package/Set.js +34 -33
- package/String.js +44 -35
- package/System.Collections.Generic.js +20 -4
- package/System.Text.js +3 -3
- package/System.js +283 -0
- package/TimeOnly.js +6 -6
- package/TimeSpan.js +5 -5
- package/Types.js +1 -17
- package/Uri.js +25 -19
- package/Util.js +31 -17
- package/package.json +1 -1
- package/Array.d.ts +0 -123
- package/Async.d.ts +0 -26
- package/AsyncBuilder.d.ts +0 -59
- package/BigInt.d.ts +0 -129
- package/BitConverter.d.ts +0 -27
- package/Boolean.d.ts +0 -3
- package/Char.d.ts +0 -65
- package/Choice.d.ts +0 -121
- package/CollectionUtil.d.ts +0 -7
- package/ConditionalWeakTable.d.ts +0 -9
- package/Date.d.ts +0 -69
- package/DateOffset.d.ts +0 -64
- package/DateOnly.d.ts +0 -18
- package/Decimal.d.ts +0 -63
- package/Double.d.ts +0 -11
- package/Encoding.d.ts +0 -12
- package/Event.d.ts +0 -31
- package/FSharp.Collections.d.ts +0 -7
- package/FSharp.Core.CompilerServices.d.ts +0 -12
- package/FSharp.Core.d.ts +0 -30
- package/Global.d.ts +0 -24
- package/Guid.d.ts +0 -10
- package/Int32.d.ts +0 -28
- package/List.d.ts +0 -143
- package/Long.d.ts +0 -3
- package/MailboxProcessor.d.ts +0 -25
- package/Map.d.ts +0 -178
- package/MapUtil.d.ts +0 -12
- package/MutableMap.d.ts +0 -52
- package/MutableSet.d.ts +0 -39
- package/Native.d.ts +0 -3
- package/Numeric.d.ts +0 -20
- package/Observable.d.ts +0 -32
- package/Option.d.ts +0 -29
- package/Random.d.ts +0 -37
- package/Range.d.ts +0 -12
- package/Reflection.d.ts +0 -119
- package/RegExp.d.ts +0 -10
- package/Result.d.ts +0 -37
- package/Seq.d.ts +0 -164
- package/Seq2.d.ts +0 -18
- package/Set.d.ts +0 -190
- package/String.d.ts +0 -58
- package/System.Collections.Generic.d.ts +0 -79
- package/System.Text.d.ts +0 -40
- package/SystemException.d.ts +0 -5
- package/SystemException.js +0 -5
- package/TimeOnly.d.ts +0 -15
- package/TimeSpan.d.ts +0 -35
- package/Timer.d.ts +0 -19
- package/Types.d.ts +0 -58
- package/Unicode.13.0.0.d.ts +0 -2
- package/Uri.d.ts +0 -31
- package/Util.d.ts +0 -212
- package/lib/big.d.ts +0 -5
package/Date.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* Basically; invariant: date.getTime() always return UTC time.
|
|
9
9
|
*/
|
|
10
10
|
import { toInt64, toFloat64 } from "./BigInt.js";
|
|
11
|
-
import { compareDates, dateOffset, padWithZeros } from "./Util.js";
|
|
11
|
+
import { Exception, compareDates, DateTimeKind, dateOffset, padWithZeros } from "./Util.js";
|
|
12
12
|
const shortDays = [
|
|
13
13
|
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
|
|
14
14
|
];
|
|
@@ -56,7 +56,7 @@ function parseQuotedString(format, pos) {
|
|
|
56
56
|
}
|
|
57
57
|
else {
|
|
58
58
|
// This means that '\' is the last character in the string.
|
|
59
|
-
throw new
|
|
59
|
+
throw new Exception("Invalid string format");
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
else {
|
|
@@ -65,7 +65,7 @@ function parseQuotedString(format, pos) {
|
|
|
65
65
|
}
|
|
66
66
|
if (!foundQuote) {
|
|
67
67
|
// We could not find the matching quote
|
|
68
|
-
throw new
|
|
68
|
+
throw new Exception(`Invalid string format could not find matching quote for ${quoteChar}`);
|
|
69
69
|
}
|
|
70
70
|
return [result, pos - beginPos + 1];
|
|
71
71
|
}
|
|
@@ -73,7 +73,7 @@ function dateToStringWithCustomFormat(date, format, utc) {
|
|
|
73
73
|
let cursorPos = 0;
|
|
74
74
|
let tokenLength = 0;
|
|
75
75
|
let result = "";
|
|
76
|
-
const localizedDate = utc ? DateTime(date.getTime(),
|
|
76
|
+
const localizedDate = utc ? DateTime(date.getTime(), DateTimeKind.Utc) : date;
|
|
77
77
|
while (cursorPos < format.length) {
|
|
78
78
|
const token = format[cursorPos];
|
|
79
79
|
switch (token) {
|
|
@@ -176,14 +176,14 @@ function dateToStringWithCustomFormat(date, format, utc) {
|
|
|
176
176
|
cursorPos += tokenLength;
|
|
177
177
|
switch (tokenLength) {
|
|
178
178
|
case 1:
|
|
179
|
-
switch (
|
|
180
|
-
case
|
|
179
|
+
switch (getKind(localizedDate)) {
|
|
180
|
+
case DateTimeKind.Utc:
|
|
181
181
|
result += "Z";
|
|
182
182
|
break;
|
|
183
|
-
case
|
|
183
|
+
case DateTimeKind.Local:
|
|
184
184
|
result += dateOffsetToString(localizedDate.getTimezoneOffset() * -60000);
|
|
185
185
|
break;
|
|
186
|
-
case
|
|
186
|
+
case DateTimeKind.Unspecified:
|
|
187
187
|
break;
|
|
188
188
|
}
|
|
189
189
|
break;
|
|
@@ -268,14 +268,14 @@ function dateToStringWithCustomFormat(date, format, utc) {
|
|
|
268
268
|
tokenLength = parseRepeatToken(format, cursorPos, "z");
|
|
269
269
|
cursorPos += tokenLength;
|
|
270
270
|
let utcOffsetText = "";
|
|
271
|
-
switch (
|
|
272
|
-
case
|
|
271
|
+
switch (getKind(localizedDate)) {
|
|
272
|
+
case DateTimeKind.Utc:
|
|
273
273
|
utcOffsetText = "+00:00";
|
|
274
274
|
break;
|
|
275
|
-
case
|
|
275
|
+
case DateTimeKind.Local:
|
|
276
276
|
utcOffsetText = dateOffsetToString(localizedDate.getTimezoneOffset() * -60000);
|
|
277
277
|
break;
|
|
278
|
-
case
|
|
278
|
+
case DateTimeKind.Unspecified:
|
|
279
279
|
utcOffsetText = dateOffsetToString(toLocalTime(localizedDate).getTimezoneOffset() * -60000);
|
|
280
280
|
break;
|
|
281
281
|
}
|
|
@@ -315,7 +315,7 @@ function dateToStringWithCustomFormat(date, format, utc) {
|
|
|
315
315
|
result += dateToStringWithCustomFormat(localizedDate, String.fromCharCode(nextChar), utc);
|
|
316
316
|
}
|
|
317
317
|
else {
|
|
318
|
-
throw new
|
|
318
|
+
throw new Exception("Invalid format string");
|
|
319
319
|
}
|
|
320
320
|
break;
|
|
321
321
|
case "\\":
|
|
@@ -325,7 +325,7 @@ function dateToStringWithCustomFormat(date, format, utc) {
|
|
|
325
325
|
result += String.fromCharCode(nextChar2);
|
|
326
326
|
}
|
|
327
327
|
else {
|
|
328
|
-
throw new
|
|
328
|
+
throw new Exception("Invalid format string");
|
|
329
329
|
}
|
|
330
330
|
break;
|
|
331
331
|
default:
|
|
@@ -336,8 +336,8 @@ function dateToStringWithCustomFormat(date, format, utc) {
|
|
|
336
336
|
}
|
|
337
337
|
return result;
|
|
338
338
|
}
|
|
339
|
-
export function
|
|
340
|
-
return value.kind
|
|
339
|
+
export function getKind(value) {
|
|
340
|
+
return value.kind ?? DateTimeKind.Unspecified;
|
|
341
341
|
}
|
|
342
342
|
export function unixEpochMillisecondsToTicks(ms, offset) {
|
|
343
343
|
return toInt64(((BigInt(ms) + 62135596800000n) + BigInt(offset)) * 10000n);
|
|
@@ -360,7 +360,7 @@ function dateToISOString(d, utc) {
|
|
|
360
360
|
}
|
|
361
361
|
else {
|
|
362
362
|
// JS Date is always local
|
|
363
|
-
const printOffset = d.kind == null ? true : d.kind ===
|
|
363
|
+
const printOffset = d.kind == null ? true : d.kind === DateTimeKind.Local;
|
|
364
364
|
return padWithZeros(d.getFullYear(), 4) + "-" +
|
|
365
365
|
padWithZeros(d.getMonth() + 1, 2) + "-" +
|
|
366
366
|
padWithZeros(d.getDate(), 2) + "T" +
|
|
@@ -388,7 +388,7 @@ function dateToStringWithOffset(date, format) {
|
|
|
388
388
|
case "t": return dateToString_t(toUniversalTime(d));
|
|
389
389
|
case "O":
|
|
390
390
|
case "o": return dateToISOStringWithOffset(d, (date.offset ?? 0));
|
|
391
|
-
default: throw new
|
|
391
|
+
default: throw new Exception("Unrecognized Date print format");
|
|
392
392
|
}
|
|
393
393
|
}
|
|
394
394
|
else {
|
|
@@ -416,7 +416,7 @@ function dateToString_t(date) {
|
|
|
416
416
|
+ ":" + padWithZeros(minute(date), 2);
|
|
417
417
|
}
|
|
418
418
|
function dateToStringWithKind(date, format) {
|
|
419
|
-
const utc = date.kind ===
|
|
419
|
+
const utc = date.kind === DateTimeKind.Utc;
|
|
420
420
|
if (typeof format !== "string") {
|
|
421
421
|
return utc ? date.toUTCString() : date.toLocaleString();
|
|
422
422
|
}
|
|
@@ -430,7 +430,7 @@ function dateToStringWithKind(date, format) {
|
|
|
430
430
|
case "o":
|
|
431
431
|
return dateToISOString(date, utc);
|
|
432
432
|
default:
|
|
433
|
-
throw new
|
|
433
|
+
throw new Exception("Unrecognized Date print format");
|
|
434
434
|
}
|
|
435
435
|
}
|
|
436
436
|
else {
|
|
@@ -444,24 +444,28 @@ export function toString(date, format, _provider) {
|
|
|
444
444
|
}
|
|
445
445
|
export function DateTime(value, kind) {
|
|
446
446
|
const d = new Date(value);
|
|
447
|
-
d.kind = (kind == null ?
|
|
447
|
+
d.kind = (kind == null ? DateTimeKind.Unspecified : kind);
|
|
448
448
|
return d;
|
|
449
449
|
}
|
|
450
450
|
export function fromTicks(ticks, kind) {
|
|
451
|
-
kind = kind != null ? kind :
|
|
451
|
+
kind = kind != null ? kind : DateTimeKind.Local; // better default than Unspecified
|
|
452
452
|
let date = DateTime(ticksToUnixEpochMilliseconds(ticks), kind);
|
|
453
453
|
// Ticks are local to offset (in this case, either UTC or Local/Unknown).
|
|
454
454
|
// If kind is anything but UTC, that means that the tick number was not
|
|
455
455
|
// in utc, thus getTime() cannot return UTC, and needs to be shifted.
|
|
456
|
-
if (kind !==
|
|
456
|
+
if (kind !== DateTimeKind.Utc) {
|
|
457
457
|
date = DateTime(date.getTime() - dateOffset(date), kind);
|
|
458
458
|
}
|
|
459
459
|
return date;
|
|
460
460
|
}
|
|
461
|
+
export function fromDateTime(dateOnly, timeOnly, kind) {
|
|
462
|
+
const d = DateTime(dateOnly.getTime() + timeOnly, kind);
|
|
463
|
+
return DateTime(d.getTime() - dateOffset(d), kind);
|
|
464
|
+
}
|
|
461
465
|
export function fromDateTimeOffset(date, kind) {
|
|
462
466
|
switch (kind) {
|
|
463
|
-
case
|
|
464
|
-
case
|
|
467
|
+
case DateTimeKind.Utc: return DateTime(date.getTime(), DateTimeKind.Utc);
|
|
468
|
+
case DateTimeKind.Local: return DateTime(date.getTime(), DateTimeKind.Local);
|
|
465
469
|
default:
|
|
466
470
|
const d = DateTime(date.getTime() + (date.offset ?? 0), kind);
|
|
467
471
|
return DateTime(d.getTime() - dateOffset(d), kind);
|
|
@@ -472,15 +476,15 @@ export function getTicks(date) {
|
|
|
472
476
|
}
|
|
473
477
|
export function minValue() {
|
|
474
478
|
// This is "0001-01-01T00:00:00.000Z", actual JS min value is -8640000000000000
|
|
475
|
-
return DateTime(-62135596800000,
|
|
479
|
+
return DateTime(-62135596800000, DateTimeKind.Utc);
|
|
476
480
|
}
|
|
477
481
|
export function maxValue() {
|
|
478
482
|
// This is "9999-12-31T23:59:59.999Z", actual JS max value is 8640000000000000
|
|
479
|
-
return DateTime(253402300799999,
|
|
483
|
+
return DateTime(253402300799999, DateTimeKind.Utc);
|
|
480
484
|
}
|
|
481
485
|
export function parseRaw(input) {
|
|
482
486
|
function fail() {
|
|
483
|
-
throw new
|
|
487
|
+
throw new Exception(`The string is not a valid Date: ${input}`);
|
|
484
488
|
}
|
|
485
489
|
if (input == null || input.trim() === "") {
|
|
486
490
|
fail();
|
|
@@ -556,8 +560,8 @@ export function parse(str, detectUTC = false) {
|
|
|
556
560
|
// .NET always parses DateTime as Local if there's offset info (even "Z")
|
|
557
561
|
// Newtonsoft.Json uses UTC if the offset is "Z"
|
|
558
562
|
const kind = offset != null
|
|
559
|
-
? (detectUTC && offset === "Z" ?
|
|
560
|
-
:
|
|
563
|
+
? (detectUTC && offset === "Z" ? DateTimeKind.Utc : DateTimeKind.Local)
|
|
564
|
+
: DateTimeKind.Unspecified;
|
|
561
565
|
return DateTime(date.getTime(), kind);
|
|
562
566
|
}
|
|
563
567
|
export function tryParse(v, defValue) {
|
|
@@ -570,11 +574,11 @@ export function tryParse(v, defValue) {
|
|
|
570
574
|
}
|
|
571
575
|
}
|
|
572
576
|
export function create(year, month, day, h = 0, m = 0, s = 0, ms = 0, kind) {
|
|
573
|
-
const date = kind ===
|
|
577
|
+
const date = kind === DateTimeKind.Utc
|
|
574
578
|
? new Date(Date.UTC(year, month - 1, day, h, m, s, ms))
|
|
575
579
|
: new Date(year, month - 1, day, h, m, s, ms);
|
|
576
580
|
if (year <= 99) {
|
|
577
|
-
if (kind ===
|
|
581
|
+
if (kind === DateTimeKind.Utc) {
|
|
578
582
|
date.setUTCFullYear(year, month - 1, day);
|
|
579
583
|
}
|
|
580
584
|
else {
|
|
@@ -583,15 +587,15 @@ export function create(year, month, day, h = 0, m = 0, s = 0, ms = 0, kind) {
|
|
|
583
587
|
}
|
|
584
588
|
const dateValue = date.getTime();
|
|
585
589
|
if (isNaN(dateValue)) {
|
|
586
|
-
throw new
|
|
590
|
+
throw new Exception("The parameters describe an unrepresentable Date.");
|
|
587
591
|
}
|
|
588
592
|
return DateTime(dateValue, kind);
|
|
589
593
|
}
|
|
590
594
|
export function now() {
|
|
591
|
-
return DateTime(Date.now(),
|
|
595
|
+
return DateTime(Date.now(), DateTimeKind.Local);
|
|
592
596
|
}
|
|
593
597
|
export function utcNow() {
|
|
594
|
-
return DateTime(Date.now(),
|
|
598
|
+
return DateTime(Date.now(), DateTimeKind.Utc);
|
|
595
599
|
}
|
|
596
600
|
export function today() {
|
|
597
601
|
return date(now());
|
|
@@ -605,10 +609,10 @@ export function daysInMonth(year, month) {
|
|
|
605
609
|
: (month >= 8 ? (month % 2 === 0 ? 31 : 30) : (month % 2 === 0 ? 30 : 31));
|
|
606
610
|
}
|
|
607
611
|
export function toUniversalTime(date) {
|
|
608
|
-
return date.kind ===
|
|
612
|
+
return date.kind === DateTimeKind.Utc ? date : DateTime(date.getTime(), DateTimeKind.Utc);
|
|
609
613
|
}
|
|
610
614
|
export function toLocalTime(date) {
|
|
611
|
-
return date.kind ===
|
|
615
|
+
return date.kind === DateTimeKind.Local ? date : DateTime(date.getTime(), DateTimeKind.Local);
|
|
612
616
|
}
|
|
613
617
|
export function specifyKind(d, kind) {
|
|
614
618
|
return create(year(d), month(d), day(d), hour(d), minute(d), second(d), millisecond(d), kind);
|
|
@@ -623,28 +627,28 @@ export function date(d) {
|
|
|
623
627
|
return create(year(d), month(d), day(d), 0, 0, 0, 0, d.kind);
|
|
624
628
|
}
|
|
625
629
|
export function day(d) {
|
|
626
|
-
return d.kind ===
|
|
630
|
+
return d.kind === DateTimeKind.Utc ? d.getUTCDate() : d.getDate();
|
|
627
631
|
}
|
|
628
632
|
export function hour(d) {
|
|
629
|
-
return d.kind ===
|
|
633
|
+
return d.kind === DateTimeKind.Utc ? d.getUTCHours() : d.getHours();
|
|
630
634
|
}
|
|
631
635
|
export function millisecond(d) {
|
|
632
|
-
return d.kind ===
|
|
636
|
+
return d.kind === DateTimeKind.Utc ? d.getUTCMilliseconds() : d.getMilliseconds();
|
|
633
637
|
}
|
|
634
638
|
export function minute(d) {
|
|
635
|
-
return d.kind ===
|
|
639
|
+
return d.kind === DateTimeKind.Utc ? d.getUTCMinutes() : d.getMinutes();
|
|
636
640
|
}
|
|
637
641
|
export function month(d) {
|
|
638
|
-
return (d.kind ===
|
|
642
|
+
return (d.kind === DateTimeKind.Utc ? d.getUTCMonth() : d.getMonth()) + 1;
|
|
639
643
|
}
|
|
640
644
|
export function second(d) {
|
|
641
|
-
return d.kind ===
|
|
645
|
+
return d.kind === DateTimeKind.Utc ? d.getUTCSeconds() : d.getSeconds();
|
|
642
646
|
}
|
|
643
647
|
export function year(d) {
|
|
644
|
-
return d.kind ===
|
|
648
|
+
return d.kind === DateTimeKind.Utc ? d.getUTCFullYear() : d.getFullYear();
|
|
645
649
|
}
|
|
646
650
|
export function dayOfWeek(d) {
|
|
647
|
-
return d.kind ===
|
|
651
|
+
return d.kind === DateTimeKind.Utc ? d.getUTCDay() : d.getDay();
|
|
648
652
|
}
|
|
649
653
|
export function dayOfYear(d) {
|
|
650
654
|
const _year = year(d);
|
|
@@ -657,7 +661,7 @@ export function dayOfYear(d) {
|
|
|
657
661
|
}
|
|
658
662
|
export function add(d, ts) {
|
|
659
663
|
const newDate = DateTime(d.getTime() + ts, d.kind);
|
|
660
|
-
if (d.kind !==
|
|
664
|
+
if (d.kind !== DateTimeKind.Utc) {
|
|
661
665
|
const oldTzOffset = d.getTimezoneOffset();
|
|
662
666
|
const newTzOffset = newDate.getTimezoneOffset();
|
|
663
667
|
return oldTzOffset !== newTzOffset
|
package/DateOffset.js
CHANGED
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
* Basically; invariant: date.getTime() always return UTC time.
|
|
14
14
|
*/
|
|
15
15
|
import { fromFloat64, toFloat64 } from "./BigInt.js";
|
|
16
|
-
import DateTime, { create as createDate,
|
|
17
|
-
import { compareDates,
|
|
16
|
+
import DateTime, { create as createDate, daysInMonth, parseRaw, ticksToUnixEpochMilliseconds, unixEpochMillisecondsToTicks } from "./Date.js";
|
|
17
|
+
import { Exception, compareDates, DateTimeKind } from "./Util.js";
|
|
18
18
|
export default function DateTimeOffset(value, offset) {
|
|
19
19
|
checkOffsetInRange(offset);
|
|
20
20
|
const d = new Date(value);
|
|
@@ -27,29 +27,29 @@ export function offset(value) {
|
|
|
27
27
|
function checkOffsetInRange(offset) {
|
|
28
28
|
if (offset != null && offset !== 0) {
|
|
29
29
|
if (offset % 60000 !== 0) {
|
|
30
|
-
throw new
|
|
30
|
+
throw new Exception("Offset must be specified in whole minutes.");
|
|
31
31
|
}
|
|
32
32
|
if (Math.abs(offset / 3600000) > 14) {
|
|
33
|
-
throw new
|
|
33
|
+
throw new Exception("Offset must be within plus or minus 14 hours.");
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
export function fromDate(date, offset) {
|
|
38
38
|
let offset2 = 0;
|
|
39
39
|
switch (date.kind) {
|
|
40
|
-
case
|
|
40
|
+
case DateTimeKind.Utc:
|
|
41
41
|
if (offset != null && offset !== 0) {
|
|
42
|
-
throw new
|
|
42
|
+
throw new Exception("The UTC Offset for Utc DateTime instances must be 0.");
|
|
43
43
|
}
|
|
44
44
|
offset2 = 0;
|
|
45
45
|
break;
|
|
46
|
-
case
|
|
46
|
+
case DateTimeKind.Local:
|
|
47
47
|
offset2 = date.getTimezoneOffset() * -60000;
|
|
48
48
|
if (offset != null && offset !== offset2) {
|
|
49
|
-
throw new
|
|
49
|
+
throw new Exception("The UTC Offset of the local dateTime parameter does not match the offset argument.");
|
|
50
50
|
}
|
|
51
51
|
break;
|
|
52
|
-
case
|
|
52
|
+
case DateTimeKind.Unspecified:
|
|
53
53
|
default:
|
|
54
54
|
if (offset == null) {
|
|
55
55
|
offset2 = date.getTimezoneOffset() * -60000;
|
|
@@ -61,6 +61,9 @@ export function fromDate(date, offset) {
|
|
|
61
61
|
}
|
|
62
62
|
return DateTimeOffset(date.getTime(), offset2);
|
|
63
63
|
}
|
|
64
|
+
export function fromDateTime(dateOnly, timeOnly, offset) {
|
|
65
|
+
return DateTimeOffset(dateOnly.getTime() - offset + timeOnly, offset);
|
|
66
|
+
}
|
|
64
67
|
export function fromTicks(ticks, offset) {
|
|
65
68
|
const ms = ticksToUnixEpochMilliseconds(ticks) - offset;
|
|
66
69
|
return DateTimeOffset(ms, offset);
|
|
@@ -104,27 +107,13 @@ export function create(year, month, day, h, m, s, ms, offset) {
|
|
|
104
107
|
ms = 0;
|
|
105
108
|
}
|
|
106
109
|
checkOffsetInRange(offset);
|
|
107
|
-
let date;
|
|
108
|
-
if (
|
|
109
|
-
date
|
|
110
|
-
if (year <= 99) {
|
|
111
|
-
date.setUTCFullYear(year, month - 1, day);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
const str = padWithZeros(year, 4) + "-" +
|
|
116
|
-
padWithZeros(month, 2) + "-" +
|
|
117
|
-
padWithZeros(day, 2) + "T" +
|
|
118
|
-
padWithZeros(h, 2) + ":" +
|
|
119
|
-
padWithZeros(m, 2) + ":" +
|
|
120
|
-
padWithZeros(s, 2) + "." +
|
|
121
|
-
padWithZeros(ms, 3) +
|
|
122
|
-
dateOffsetToString(offset);
|
|
123
|
-
date = new Date(str);
|
|
110
|
+
let date = new Date(Date.UTC(year, month - 1, day, h, m, s, ms) - offset);
|
|
111
|
+
if (year <= 99) {
|
|
112
|
+
date.setUTCFullYear(year, month - 1, day);
|
|
124
113
|
}
|
|
125
114
|
const dateValue = date.getTime();
|
|
126
115
|
if (isNaN(dateValue)) {
|
|
127
|
-
throw new
|
|
116
|
+
throw new Exception("The parameters describe an unrepresentable Date");
|
|
128
117
|
}
|
|
129
118
|
return DateTimeOffset(dateValue, offset);
|
|
130
119
|
}
|
|
@@ -134,55 +123,56 @@ export function now() {
|
|
|
134
123
|
return DateTimeOffset(date.getTime(), offset);
|
|
135
124
|
}
|
|
136
125
|
export function utcNow() {
|
|
137
|
-
const date =
|
|
126
|
+
const date = new Date();
|
|
127
|
+
// const offset = date.getTimezoneOffset() * -60_000;
|
|
138
128
|
return DateTimeOffset(date.getTime(), 0);
|
|
139
129
|
}
|
|
140
130
|
export function toUniversalTime(date) {
|
|
141
|
-
return DateTime(date.getTime(),
|
|
131
|
+
return DateTime(date.getTime(), DateTimeKind.Utc);
|
|
142
132
|
}
|
|
143
133
|
export function toLocalTime(date) {
|
|
144
|
-
return DateTime(date.getTime()
|
|
134
|
+
return DateTime(date.getTime(), DateTimeKind.Local);
|
|
145
135
|
}
|
|
146
136
|
export function localDateTime(date) {
|
|
147
|
-
return DateTime(date.getTime(),
|
|
137
|
+
return DateTime(date.getTime(), DateTimeKind.Local);
|
|
148
138
|
}
|
|
149
139
|
export function timeOfDay(d) {
|
|
150
|
-
const d2 = new Date(d.getTime() + (d
|
|
140
|
+
const d2 = new Date(d.getTime() + offset(d));
|
|
151
141
|
return d2.getUTCHours() * 3600000
|
|
152
142
|
+ d2.getUTCMinutes() * 60000
|
|
153
143
|
+ d2.getUTCSeconds() * 1000
|
|
154
144
|
+ d2.getUTCMilliseconds();
|
|
155
145
|
}
|
|
156
146
|
export function date(d) {
|
|
157
|
-
const d2 = new Date(d.getTime() + (d
|
|
147
|
+
const d2 = new Date(d.getTime() + offset(d));
|
|
158
148
|
return createDate(d2.getUTCFullYear(), d2.getUTCMonth() + 1, d2.getUTCDate(), 0, 0, 0, 0);
|
|
159
149
|
}
|
|
160
150
|
export function day(d) {
|
|
161
|
-
return new Date(d.getTime() + (d
|
|
151
|
+
return new Date(d.getTime() + offset(d)).getUTCDate();
|
|
162
152
|
}
|
|
163
153
|
export function hour(d) {
|
|
164
|
-
return new Date(d.getTime() + (d
|
|
154
|
+
return new Date(d.getTime() + offset(d)).getUTCHours();
|
|
165
155
|
}
|
|
166
156
|
export function millisecond(d) {
|
|
167
|
-
return new Date(d.getTime() + (d
|
|
157
|
+
return new Date(d.getTime() + offset(d)).getUTCMilliseconds();
|
|
168
158
|
}
|
|
169
159
|
export function minute(d) {
|
|
170
|
-
return new Date(d.getTime() + (d
|
|
160
|
+
return new Date(d.getTime() + offset(d)).getUTCMinutes();
|
|
171
161
|
}
|
|
172
162
|
export function month(d) {
|
|
173
|
-
return new Date(d.getTime() + (d
|
|
163
|
+
return new Date(d.getTime() + offset(d)).getUTCMonth() + 1;
|
|
174
164
|
}
|
|
175
165
|
export function second(d) {
|
|
176
|
-
return new Date(d.getTime() + (d
|
|
166
|
+
return new Date(d.getTime() + offset(d)).getUTCSeconds();
|
|
177
167
|
}
|
|
178
168
|
export function year(d) {
|
|
179
|
-
return new Date(d.getTime() + (d
|
|
169
|
+
return new Date(d.getTime() + offset(d)).getUTCFullYear();
|
|
180
170
|
}
|
|
181
171
|
export function dayOfWeek(d) {
|
|
182
|
-
return new Date(d.getTime() + (d
|
|
172
|
+
return new Date(d.getTime() + offset(d)).getUTCDay();
|
|
183
173
|
}
|
|
184
174
|
export function dayOfYear(d) {
|
|
185
|
-
const d2 = new Date(d.getTime() + (d
|
|
175
|
+
const d2 = new Date(d.getTime() + offset(d));
|
|
186
176
|
const _year = d2.getUTCFullYear();
|
|
187
177
|
const _month = d2.getUTCMonth() + 1;
|
|
188
178
|
let _day = d2.getUTCDate();
|
|
@@ -192,7 +182,7 @@ export function dayOfYear(d) {
|
|
|
192
182
|
return _day;
|
|
193
183
|
}
|
|
194
184
|
export function add(d, ts) {
|
|
195
|
-
return DateTimeOffset(d.getTime() + ts, (d
|
|
185
|
+
return DateTimeOffset(d.getTime() + ts, offset(d));
|
|
196
186
|
}
|
|
197
187
|
export function addDays(d, v) {
|
|
198
188
|
return add(d, v * 86400000);
|
|
@@ -217,10 +207,10 @@ export function addYears(d, v) {
|
|
|
217
207
|
const newYear = d.getUTCFullYear() + v;
|
|
218
208
|
const _daysInMonth = daysInMonth(newYear, newMonth);
|
|
219
209
|
const newDay = Math.min(_daysInMonth, d.getUTCDate());
|
|
220
|
-
return create(newYear, newMonth, newDay, d.getUTCHours(), d.getUTCMinutes(), d.getUTCSeconds(), d.getUTCMilliseconds(), (d
|
|
210
|
+
return create(newYear, newMonth, newDay, d.getUTCHours(), d.getUTCMinutes(), d.getUTCSeconds(), d.getUTCMilliseconds(), offset(d));
|
|
221
211
|
}
|
|
222
212
|
export function addMonths(d, v) {
|
|
223
|
-
const d2 = new Date(d.getTime() + (d
|
|
213
|
+
const d2 = new Date(d.getTime() + offset(d));
|
|
224
214
|
let newMonth = d2.getUTCMonth() + 1 + v;
|
|
225
215
|
let newMonth_ = 0;
|
|
226
216
|
let yearOffset = 0;
|
|
@@ -237,11 +227,11 @@ export function addMonths(d, v) {
|
|
|
237
227
|
const newYear = d2.getUTCFullYear() + yearOffset;
|
|
238
228
|
const _daysInMonth = daysInMonth(newYear, newMonth);
|
|
239
229
|
const newDay = Math.min(_daysInMonth, d2.getUTCDate());
|
|
240
|
-
return create(newYear, newMonth, newDay, d2.getUTCHours(), d2.getUTCMinutes(), d2.getUTCSeconds(), d2.getUTCMilliseconds(), (d
|
|
230
|
+
return create(newYear, newMonth, newDay, d2.getUTCHours(), d2.getUTCMinutes(), d2.getUTCSeconds(), d2.getUTCMilliseconds(), offset(d));
|
|
241
231
|
}
|
|
242
232
|
export function subtract(d, that) {
|
|
243
233
|
return typeof that === "number"
|
|
244
|
-
? DateTimeOffset(d.getTime() - that, (d
|
|
234
|
+
? DateTimeOffset(d.getTime() - that, offset(d))
|
|
245
235
|
: d.getTime() - that.getTime();
|
|
246
236
|
}
|
|
247
237
|
export function equals(d1, d2) {
|
package/DateOnly.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DateTime, getTicks, dayOfYear as Date_dayOfYear, year as Date_year, month as Date_month, day as Date_day, daysInMonth as Date_daysInMonth, ticksToUnixEpochMilliseconds } from "./Date.js";
|
|
2
|
-
import { padWithZeros } from "./Util.js";
|
|
2
|
+
import { Exception, DateTimeKind, padWithZeros } from "./Util.js";
|
|
3
3
|
export function fromUnixMilliseconds(value) {
|
|
4
|
-
return DateTime(value,
|
|
4
|
+
return DateTime(value, DateTimeKind.Utc);
|
|
5
5
|
}
|
|
6
6
|
export function create(year, month, day) {
|
|
7
7
|
const d = fromUnixMilliseconds(Date.UTC(year, month - 1, day));
|
|
@@ -43,12 +43,12 @@ export function dayOfWeek(d) {
|
|
|
43
43
|
export function dayOfYear(d) {
|
|
44
44
|
return Date_dayOfYear(d);
|
|
45
45
|
}
|
|
46
|
-
export function toDateTime(d, time, kind =
|
|
47
|
-
return DateTime(d.getTime() + time + (kind !==
|
|
46
|
+
export function toDateTime(d, time, kind = DateTimeKind.Unspecified) {
|
|
47
|
+
return DateTime(d.getTime() + time + (kind !== DateTimeKind.Utc ? d.getTimezoneOffset() : 0) * 60000, kind);
|
|
48
48
|
}
|
|
49
49
|
export function toString(d, format = "d", _provider) {
|
|
50
50
|
if (["d", "o", "O"].indexOf(format) === -1) {
|
|
51
|
-
throw new
|
|
51
|
+
throw new Exception("Custom formats are not supported");
|
|
52
52
|
}
|
|
53
53
|
const y = padWithZeros(year(d), 4);
|
|
54
54
|
const m = padWithZeros(month(d), 2);
|
|
@@ -57,7 +57,7 @@ export function toString(d, format = "d", _provider) {
|
|
|
57
57
|
}
|
|
58
58
|
export function parse(str) {
|
|
59
59
|
function fail() {
|
|
60
|
-
throw new
|
|
60
|
+
throw new Exception(`String '${str}' was not recognized as a valid DateOnly.`);
|
|
61
61
|
}
|
|
62
62
|
// Allowed separators: . , / -
|
|
63
63
|
// TODO whitespace alone as the separator
|
package/Decimal.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Decimal from "./lib/big.js";
|
|
2
2
|
import { symbol } from "./Numeric.js";
|
|
3
3
|
import { FSharpRef } from "./Types.js";
|
|
4
|
-
import { combineHashCodes } from "./Util.js";
|
|
4
|
+
import { Exception, combineHashCodes } from "./Util.js";
|
|
5
5
|
import { fromDecimal } from "./BigInt.js";
|
|
6
6
|
import * as bigInt from "./BigInt.js";
|
|
7
7
|
Decimal.prototype.GetHashCode = function () {
|
|
@@ -109,7 +109,7 @@ export function parse(str) {
|
|
|
109
109
|
return defValue.contents;
|
|
110
110
|
}
|
|
111
111
|
else {
|
|
112
|
-
throw new
|
|
112
|
+
throw new Exception(`The input string ${str} was not in a correct format.`);
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
115
|
export function toNumber(x) {
|
|
@@ -118,7 +118,7 @@ export function toNumber(x) {
|
|
|
118
118
|
export function toChar(x) {
|
|
119
119
|
const n = toNumber(x);
|
|
120
120
|
if (n < 0 || n > 65535 || isNaN(n)) {
|
|
121
|
-
throw new
|
|
121
|
+
throw new Exception("Value was either too large or too small for a character.");
|
|
122
122
|
}
|
|
123
123
|
return String.fromCharCode(n);
|
|
124
124
|
}
|
|
@@ -221,7 +221,7 @@ export function getBits(d) {
|
|
|
221
221
|
// export function makeRangeStepFunction(step: Decimal, last: Decimal) {
|
|
222
222
|
// const stepComparedWithZero = step.cmp(get_Zero);
|
|
223
223
|
// if (stepComparedWithZero === 0) {
|
|
224
|
-
// throw new
|
|
224
|
+
// throw new Exception("The step of a range cannot be zero");
|
|
225
225
|
// }
|
|
226
226
|
// const stepGreaterThanZero = stepComparedWithZero > 0;
|
|
227
227
|
// return (x: Decimal) => {
|
package/Double.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { FSharpRef } from "./Types.js";
|
|
2
|
+
import { Exception } from "./Util.js";
|
|
2
3
|
export function tryParse(str, defValue) {
|
|
3
4
|
// TODO: test if value is valid and in range
|
|
4
5
|
if (str != null && /\S/.test(str)) {
|
|
@@ -16,7 +17,7 @@ export function parse(str) {
|
|
|
16
17
|
return defValue.contents;
|
|
17
18
|
}
|
|
18
19
|
else {
|
|
19
|
-
throw new
|
|
20
|
+
throw new Exception(`The input string ${str} was not in a correct format.`);
|
|
20
21
|
}
|
|
21
22
|
}
|
|
22
23
|
// JS Number.isFinite function evals false for NaN
|
package/FSharp.Collections.js
CHANGED
|
@@ -1,27 +1,45 @@
|
|
|
1
|
-
import { compare, physicalHash,
|
|
2
|
-
export function HashIdentity_FromFunctions(
|
|
1
|
+
import { compare, physicalHash, equals as equals_1, structuralHash } from "./Util.js";
|
|
2
|
+
export function HashIdentity_FromFunctions(hasher, equals) {
|
|
3
3
|
return {
|
|
4
|
-
|
|
5
|
-
return
|
|
4
|
+
GetHashCode(x) {
|
|
5
|
+
return hasher(x) | 0;
|
|
6
6
|
},
|
|
7
|
-
|
|
8
|
-
return
|
|
7
|
+
Equals(x_1, y) {
|
|
8
|
+
return (x_1 == null) ? (y == null) : ((y == null) ? false : equals(x_1, y));
|
|
9
9
|
},
|
|
10
10
|
};
|
|
11
11
|
}
|
|
12
12
|
export function HashIdentity_Structural() {
|
|
13
|
-
return
|
|
13
|
+
return {
|
|
14
|
+
GetHashCode(x) {
|
|
15
|
+
return structuralHash(x) | 0;
|
|
16
|
+
},
|
|
17
|
+
Equals(x_1, y) {
|
|
18
|
+
return equals_1(x_1, y);
|
|
19
|
+
},
|
|
20
|
+
};
|
|
14
21
|
}
|
|
15
22
|
export function HashIdentity_Reference() {
|
|
16
|
-
return
|
|
23
|
+
return {
|
|
24
|
+
GetHashCode(x) {
|
|
25
|
+
return physicalHash(x) | 0;
|
|
26
|
+
},
|
|
27
|
+
Equals(x_1, y) {
|
|
28
|
+
return equals_1(x_1, y);
|
|
29
|
+
},
|
|
30
|
+
};
|
|
17
31
|
}
|
|
18
32
|
export function ComparisonIdentity_FromFunction(comparer) {
|
|
19
33
|
return {
|
|
20
34
|
Compare(x, y) {
|
|
21
|
-
return comparer(x, y) | 0;
|
|
35
|
+
return ((x == null) ? ((y == null) ? 0 : -1) : ((y == null) ? 1 : comparer(x, y))) | 0;
|
|
22
36
|
},
|
|
23
37
|
};
|
|
24
38
|
}
|
|
25
39
|
export function ComparisonIdentity_Structural() {
|
|
26
|
-
return
|
|
40
|
+
return {
|
|
41
|
+
Compare(x, y) {
|
|
42
|
+
return compare(x, y) | 0;
|
|
43
|
+
},
|
|
44
|
+
};
|
|
27
45
|
}
|