compostjs 0.0.11 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/compost.js +34 -28
- package/dist/core.js +94 -73
- 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 +5 -4
- 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,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DateTimeOffset functions.
|
|
3
|
+
*
|
|
4
|
+
* Note: DateOffset 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
|
+
* However, this means that in order to construct an UTC date
|
|
9
|
+
* from a DateOffset with offset of +5 hours, you first need
|
|
10
|
+
* to subtract those 5 hours, than add the "local" offset.
|
|
11
|
+
* As said, all kinds of messed up.
|
|
12
|
+
*
|
|
13
|
+
* Basically; invariant: date.getTime() always return UTC time.
|
|
14
|
+
*/
|
|
15
|
+
import { int64 } from "./BigInt.js";
|
|
16
|
+
import { FSharpRef } from "./Types.js";
|
|
17
|
+
import { IDateTime, IDateTimeOffset } from "./Util.js";
|
|
18
|
+
export default function DateTimeOffset(value: number, offset?: number): IDateTimeOffset;
|
|
19
|
+
export declare function offset(value: IDateTimeOffset): number;
|
|
20
|
+
export declare function fromDate(date: IDateTime, offset?: number): IDateTimeOffset;
|
|
21
|
+
export declare function fromTicks(ticks: int64, offset: number): IDateTimeOffset;
|
|
22
|
+
export declare function fromUnixTimeMilliseconds(ms: int64): IDateTimeOffset;
|
|
23
|
+
export declare function fromUnixTimeSeconds(seconds: int64): IDateTimeOffset;
|
|
24
|
+
export declare function getUtcTicks(date: IDateTimeOffset): bigint;
|
|
25
|
+
export declare function minValue(): IDateTimeOffset;
|
|
26
|
+
export declare function maxValue(): IDateTimeOffset;
|
|
27
|
+
export declare function parse(str: string): IDateTimeOffset;
|
|
28
|
+
export declare function tryParse(v: string, defValue: FSharpRef<IDateTimeOffset>): boolean;
|
|
29
|
+
export declare function create(year: number, month: number, day: number, h: number, m: number, s: number, ms: number, offset?: number): IDateTimeOffset;
|
|
30
|
+
export declare function now(): IDateTimeOffset;
|
|
31
|
+
export declare function utcNow(): IDateTimeOffset;
|
|
32
|
+
export declare function toUniversalTime(date: IDateTimeOffset): Date;
|
|
33
|
+
export declare function toLocalTime(date: IDateTimeOffset): Date;
|
|
34
|
+
export declare function timeOfDay(d: IDateTimeOffset): number;
|
|
35
|
+
export declare function date(d: IDateTimeOffset): IDateTime;
|
|
36
|
+
export declare function day(d: IDateTimeOffset): number;
|
|
37
|
+
export declare function hour(d: IDateTimeOffset): number;
|
|
38
|
+
export declare function millisecond(d: IDateTimeOffset): number;
|
|
39
|
+
export declare function minute(d: IDateTimeOffset): number;
|
|
40
|
+
export declare function month(d: IDateTimeOffset): number;
|
|
41
|
+
export declare function second(d: IDateTimeOffset): number;
|
|
42
|
+
export declare function year(d: IDateTimeOffset): number;
|
|
43
|
+
export declare function dayOfWeek(d: IDateTimeOffset): number;
|
|
44
|
+
export declare function dayOfYear(d: IDateTimeOffset): number;
|
|
45
|
+
export declare function add(d: IDateTimeOffset, ts: number): IDateTimeOffset;
|
|
46
|
+
export declare function addDays(d: IDateTimeOffset, v: number): IDateTimeOffset;
|
|
47
|
+
export declare function addHours(d: IDateTimeOffset, v: number): IDateTimeOffset;
|
|
48
|
+
export declare function addMinutes(d: IDateTimeOffset, v: number): IDateTimeOffset;
|
|
49
|
+
export declare function addSeconds(d: IDateTimeOffset, v: number): IDateTimeOffset;
|
|
50
|
+
export declare function addMilliseconds(d: IDateTimeOffset, v: number): IDateTimeOffset;
|
|
51
|
+
export declare function addTicks(d: IDateTimeOffset, v: int64): IDateTimeOffset;
|
|
52
|
+
export declare function addYears(d: IDateTimeOffset, v: number): IDateTimeOffset;
|
|
53
|
+
export declare function addMonths(d: IDateTimeOffset, v: number): IDateTimeOffset;
|
|
54
|
+
export declare function subtract<Input extends number | IDateTimeOffset, Output = Input extends number ? IDateTimeOffset : number>(d: IDateTimeOffset, that: Input): Output;
|
|
55
|
+
export declare function equals(d1: IDateTimeOffset, d2: IDateTimeOffset): boolean;
|
|
56
|
+
export declare function equalsExact(d1: IDateTimeOffset, d2: IDateTimeOffset): boolean;
|
|
57
|
+
export declare function compare(d1: IDateTimeOffset, d2: IDateTimeOffset): 0 | 1 | -1;
|
|
58
|
+
export declare const compareTo: typeof compare;
|
|
59
|
+
export declare function op_Addition(x: IDateTimeOffset, y: number): IDateTimeOffset;
|
|
60
|
+
export declare function op_Subtraction<Input extends number | IDateTimeOffset, Output = Input extends number ? IDateTimeOffset : number>(x: IDateTimeOffset, y: Input): Output;
|
|
61
|
+
export declare function toOffset(d: IDateTimeOffset, offset: number): IDateTimeOffset;
|
|
62
|
+
export declare function toUnixTimeMilliseconds(d: IDateTimeOffset): int64;
|
|
63
|
+
export declare function toUnixTimeSeconds(d: IDateTimeOffset): int64;
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DateTimeOffset functions.
|
|
3
|
+
*
|
|
4
|
+
* Note: DateOffset 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
|
+
* However, this means that in order to construct an UTC date
|
|
9
|
+
* from a DateOffset with offset of +5 hours, you first need
|
|
10
|
+
* to subtract those 5 hours, than add the "local" offset.
|
|
11
|
+
* As said, all kinds of messed up.
|
|
12
|
+
*
|
|
13
|
+
* Basically; invariant: date.getTime() always return UTC time.
|
|
14
|
+
*/
|
|
15
|
+
import { fromFloat64, toFloat64 } from "./BigInt.js";
|
|
16
|
+
import DateTime, { create as createDate, dateOffsetToString, daysInMonth, parseRaw, ticksToUnixEpochMilliseconds, unixEpochMillisecondsToTicks } from "./Date.js";
|
|
17
|
+
import { compareDates, padWithZeros } from "./Util.js";
|
|
18
|
+
export default function DateTimeOffset(value, offset) {
|
|
19
|
+
checkOffsetInRange(offset);
|
|
20
|
+
const d = new Date(value);
|
|
21
|
+
d.offset = offset != null ? offset : new Date().getTimezoneOffset() * -60000;
|
|
22
|
+
return d;
|
|
23
|
+
}
|
|
24
|
+
export function offset(value) {
|
|
25
|
+
return value.offset || 0;
|
|
26
|
+
}
|
|
27
|
+
function checkOffsetInRange(offset) {
|
|
28
|
+
if (offset != null && offset !== 0) {
|
|
29
|
+
if (offset % 60000 !== 0) {
|
|
30
|
+
throw new Error("Offset must be specified in whole minutes.");
|
|
31
|
+
}
|
|
32
|
+
if (Math.abs(offset / 3600000) > 14) {
|
|
33
|
+
throw new Error("Offset must be within plus or minus 14 hours.");
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
export function fromDate(date, offset) {
|
|
38
|
+
let offset2 = 0;
|
|
39
|
+
switch (date.kind) {
|
|
40
|
+
case 1 /* DateKind.UTC */:
|
|
41
|
+
if (offset != null && offset !== 0) {
|
|
42
|
+
throw new Error("The UTC Offset for Utc DateTime instances must be 0.");
|
|
43
|
+
}
|
|
44
|
+
offset2 = 0;
|
|
45
|
+
break;
|
|
46
|
+
case 2 /* DateKind.Local */:
|
|
47
|
+
offset2 = date.getTimezoneOffset() * -60000;
|
|
48
|
+
if (offset != null && offset !== offset2) {
|
|
49
|
+
throw new Error("The UTC Offset of the local dateTime parameter does not match the offset argument.");
|
|
50
|
+
}
|
|
51
|
+
break;
|
|
52
|
+
case 0 /* DateKind.Unspecified */:
|
|
53
|
+
default:
|
|
54
|
+
if (offset == null) {
|
|
55
|
+
offset2 = date.getTimezoneOffset() * -60000;
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
offset2 = offset;
|
|
59
|
+
}
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
return DateTimeOffset(date.getTime(), offset2);
|
|
63
|
+
}
|
|
64
|
+
export function fromTicks(ticks, offset) {
|
|
65
|
+
const ms = ticksToUnixEpochMilliseconds(ticks) - offset;
|
|
66
|
+
return DateTimeOffset(ms, offset);
|
|
67
|
+
}
|
|
68
|
+
export function fromUnixTimeMilliseconds(ms) {
|
|
69
|
+
return DateTimeOffset(toFloat64(ms), 0);
|
|
70
|
+
}
|
|
71
|
+
export function fromUnixTimeSeconds(seconds) {
|
|
72
|
+
return DateTimeOffset(toFloat64(seconds * 1000n), 0);
|
|
73
|
+
}
|
|
74
|
+
export function getUtcTicks(date) {
|
|
75
|
+
return unixEpochMillisecondsToTicks(date.getTime(), 0);
|
|
76
|
+
}
|
|
77
|
+
export function minValue() {
|
|
78
|
+
// This is "0001-01-01T00:00:00.000Z", actual JS min value is -8640000000000000
|
|
79
|
+
return DateTimeOffset(-62135596800000, 0);
|
|
80
|
+
}
|
|
81
|
+
export function maxValue() {
|
|
82
|
+
// This is "9999-12-31T23:59:59.999Z", actual JS max value is 8640000000000000
|
|
83
|
+
return DateTimeOffset(253402300799999, 0);
|
|
84
|
+
}
|
|
85
|
+
export function parse(str) {
|
|
86
|
+
const [date, offsetMatch] = parseRaw(str);
|
|
87
|
+
const offset = offsetMatch == null
|
|
88
|
+
? date.getTimezoneOffset() * -60000
|
|
89
|
+
: (offsetMatch === "Z" ? 0 : offsetMatch * 60000);
|
|
90
|
+
return DateTimeOffset(date.getTime(), offset);
|
|
91
|
+
}
|
|
92
|
+
export function tryParse(v, defValue) {
|
|
93
|
+
try {
|
|
94
|
+
defValue.contents = parse(v);
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
catch (_err) {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
export function create(year, month, day, h, m, s, ms, offset) {
|
|
102
|
+
if (offset == null) {
|
|
103
|
+
offset = ms;
|
|
104
|
+
ms = 0;
|
|
105
|
+
}
|
|
106
|
+
checkOffsetInRange(offset);
|
|
107
|
+
let date;
|
|
108
|
+
if (offset === 0) {
|
|
109
|
+
date = new Date(Date.UTC(year, month - 1, day, h, m, s, ms));
|
|
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);
|
|
124
|
+
}
|
|
125
|
+
const dateValue = date.getTime();
|
|
126
|
+
if (isNaN(dateValue)) {
|
|
127
|
+
throw new Error("The parameters describe an unrepresentable Date");
|
|
128
|
+
}
|
|
129
|
+
return DateTimeOffset(dateValue, offset);
|
|
130
|
+
}
|
|
131
|
+
export function now() {
|
|
132
|
+
const date = new Date();
|
|
133
|
+
const offset = date.getTimezoneOffset() * -60000;
|
|
134
|
+
return DateTimeOffset(date.getTime(), offset);
|
|
135
|
+
}
|
|
136
|
+
export function utcNow() {
|
|
137
|
+
const date = now();
|
|
138
|
+
return DateTimeOffset(date.getTime(), 0);
|
|
139
|
+
}
|
|
140
|
+
export function toUniversalTime(date) {
|
|
141
|
+
return DateTime(date.getTime(), 1 /* DateKind.UTC */);
|
|
142
|
+
}
|
|
143
|
+
export function toLocalTime(date) {
|
|
144
|
+
return DateTime(date.getTime(), 2 /* DateKind.Local */);
|
|
145
|
+
}
|
|
146
|
+
export function timeOfDay(d) {
|
|
147
|
+
const d2 = new Date(d.getTime() + (d.offset ?? 0));
|
|
148
|
+
return d2.getUTCHours() * 3600000
|
|
149
|
+
+ d2.getUTCMinutes() * 60000
|
|
150
|
+
+ d2.getUTCSeconds() * 1000
|
|
151
|
+
+ d2.getUTCMilliseconds();
|
|
152
|
+
}
|
|
153
|
+
export function date(d) {
|
|
154
|
+
const d2 = new Date(d.getTime() + (d.offset ?? 0));
|
|
155
|
+
return createDate(d2.getUTCFullYear(), d2.getUTCMonth() + 1, d2.getUTCDate(), 0, 0, 0, 0);
|
|
156
|
+
}
|
|
157
|
+
export function day(d) {
|
|
158
|
+
return new Date(d.getTime() + (d.offset ?? 0)).getUTCDate();
|
|
159
|
+
}
|
|
160
|
+
export function hour(d) {
|
|
161
|
+
return new Date(d.getTime() + (d.offset ?? 0)).getUTCHours();
|
|
162
|
+
}
|
|
163
|
+
export function millisecond(d) {
|
|
164
|
+
return new Date(d.getTime() + (d.offset ?? 0)).getUTCMilliseconds();
|
|
165
|
+
}
|
|
166
|
+
export function minute(d) {
|
|
167
|
+
return new Date(d.getTime() + (d.offset ?? 0)).getUTCMinutes();
|
|
168
|
+
}
|
|
169
|
+
export function month(d) {
|
|
170
|
+
return new Date(d.getTime() + (d.offset ?? 0)).getUTCMonth() + 1;
|
|
171
|
+
}
|
|
172
|
+
export function second(d) {
|
|
173
|
+
return new Date(d.getTime() + (d.offset ?? 0)).getUTCSeconds();
|
|
174
|
+
}
|
|
175
|
+
export function year(d) {
|
|
176
|
+
return new Date(d.getTime() + (d.offset ?? 0)).getUTCFullYear();
|
|
177
|
+
}
|
|
178
|
+
export function dayOfWeek(d) {
|
|
179
|
+
return new Date(d.getTime() + (d.offset ?? 0)).getUTCDay();
|
|
180
|
+
}
|
|
181
|
+
export function dayOfYear(d) {
|
|
182
|
+
const d2 = new Date(d.getTime() + (d.offset ?? 0));
|
|
183
|
+
const _year = d2.getUTCFullYear();
|
|
184
|
+
const _month = d2.getUTCMonth() + 1;
|
|
185
|
+
let _day = d2.getUTCDate();
|
|
186
|
+
for (let i = 1; i < _month; i++) {
|
|
187
|
+
_day += daysInMonth(_year, i);
|
|
188
|
+
}
|
|
189
|
+
return _day;
|
|
190
|
+
}
|
|
191
|
+
export function add(d, ts) {
|
|
192
|
+
return DateTimeOffset(d.getTime() + ts, (d.offset ?? 0));
|
|
193
|
+
}
|
|
194
|
+
export function addDays(d, v) {
|
|
195
|
+
return add(d, v * 86400000);
|
|
196
|
+
}
|
|
197
|
+
export function addHours(d, v) {
|
|
198
|
+
return add(d, v * 3600000);
|
|
199
|
+
}
|
|
200
|
+
export function addMinutes(d, v) {
|
|
201
|
+
return add(d, v * 60000);
|
|
202
|
+
}
|
|
203
|
+
export function addSeconds(d, v) {
|
|
204
|
+
return add(d, v * 1000);
|
|
205
|
+
}
|
|
206
|
+
export function addMilliseconds(d, v) {
|
|
207
|
+
return add(d, v);
|
|
208
|
+
}
|
|
209
|
+
export function addTicks(d, v) {
|
|
210
|
+
return add(d, toFloat64(v / 10000n));
|
|
211
|
+
}
|
|
212
|
+
export function addYears(d, v) {
|
|
213
|
+
const newMonth = d.getUTCMonth() + 1;
|
|
214
|
+
const newYear = d.getUTCFullYear() + v;
|
|
215
|
+
const _daysInMonth = daysInMonth(newYear, newMonth);
|
|
216
|
+
const newDay = Math.min(_daysInMonth, d.getUTCDate());
|
|
217
|
+
return create(newYear, newMonth, newDay, d.getUTCHours(), d.getUTCMinutes(), d.getUTCSeconds(), d.getUTCMilliseconds(), (d.offset ?? 0));
|
|
218
|
+
}
|
|
219
|
+
export function addMonths(d, v) {
|
|
220
|
+
const d2 = new Date(d.getTime() + (d.offset ?? 0));
|
|
221
|
+
let newMonth = d2.getUTCMonth() + 1 + v;
|
|
222
|
+
let newMonth_ = 0;
|
|
223
|
+
let yearOffset = 0;
|
|
224
|
+
if (newMonth > 12) {
|
|
225
|
+
newMonth_ = newMonth % 12;
|
|
226
|
+
yearOffset = Math.floor(newMonth / 12);
|
|
227
|
+
newMonth = newMonth_;
|
|
228
|
+
}
|
|
229
|
+
else if (newMonth < 1) {
|
|
230
|
+
newMonth_ = 12 + newMonth % 12;
|
|
231
|
+
yearOffset = Math.floor(newMonth / 12) + (newMonth_ === 12 ? -1 : 0);
|
|
232
|
+
newMonth = newMonth_;
|
|
233
|
+
}
|
|
234
|
+
const newYear = d2.getUTCFullYear() + yearOffset;
|
|
235
|
+
const _daysInMonth = daysInMonth(newYear, newMonth);
|
|
236
|
+
const newDay = Math.min(_daysInMonth, d2.getUTCDate());
|
|
237
|
+
return create(newYear, newMonth, newDay, d2.getUTCHours(), d2.getUTCMinutes(), d2.getUTCSeconds(), d2.getUTCMilliseconds(), (d.offset ?? 0));
|
|
238
|
+
}
|
|
239
|
+
export function subtract(d, that) {
|
|
240
|
+
return typeof that === "number"
|
|
241
|
+
? DateTimeOffset(d.getTime() - that, (d.offset ?? 0))
|
|
242
|
+
: d.getTime() - that.getTime();
|
|
243
|
+
}
|
|
244
|
+
export function equals(d1, d2) {
|
|
245
|
+
return d1.getTime() === d2.getTime();
|
|
246
|
+
}
|
|
247
|
+
export function equalsExact(d1, d2) {
|
|
248
|
+
return d1.getTime() === d2.getTime() && d1.offset === d2.offset;
|
|
249
|
+
}
|
|
250
|
+
export function compare(d1, d2) {
|
|
251
|
+
return compareDates(d1, d2);
|
|
252
|
+
}
|
|
253
|
+
export const compareTo = compare;
|
|
254
|
+
export function op_Addition(x, y) {
|
|
255
|
+
return add(x, y);
|
|
256
|
+
}
|
|
257
|
+
export function op_Subtraction(x, y) {
|
|
258
|
+
return subtract(x, y);
|
|
259
|
+
}
|
|
260
|
+
export function toOffset(d, offset) {
|
|
261
|
+
return DateTimeOffset(d.getTime(), offset);
|
|
262
|
+
}
|
|
263
|
+
export function toUnixTimeMilliseconds(d) {
|
|
264
|
+
return fromFloat64(d.getTime());
|
|
265
|
+
}
|
|
266
|
+
export function toUnixTimeSeconds(d) {
|
|
267
|
+
return fromFloat64(d.getTime() / 1000.0);
|
|
268
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { FSharpRef } from "./Types.js";
|
|
2
|
+
import { IDateTime, DateKind } from "./Util.js";
|
|
3
|
+
export declare function fromUnixMilliseconds(value: number): IDateTime;
|
|
4
|
+
export declare function create(year: number, month: number, day: number): IDateTime;
|
|
5
|
+
export declare function maxValue(): IDateTime;
|
|
6
|
+
export declare function minValue(): IDateTime;
|
|
7
|
+
export declare function dayNumber(d: IDateTime): number;
|
|
8
|
+
export declare function fromDayNumber(dayNumber: number): IDateTime;
|
|
9
|
+
export declare function fromDateTime(d: IDateTime): IDateTime;
|
|
10
|
+
export declare function day(d: IDateTime): number;
|
|
11
|
+
export declare function month(d: IDateTime): number;
|
|
12
|
+
export declare function year(d: IDateTime): number;
|
|
13
|
+
export declare function dayOfWeek(d: IDateTime): number;
|
|
14
|
+
export declare function dayOfYear(d: IDateTime): number;
|
|
15
|
+
export declare function toDateTime(d: IDateTime, time: number, kind?: DateKind): IDateTime;
|
|
16
|
+
export declare function toString(d: IDateTime, format?: string, _provider?: any): string;
|
|
17
|
+
export declare function parse(str: string): IDateTime;
|
|
18
|
+
export declare function tryParse(v: string, defValue: FSharpRef<IDateTime>): boolean;
|
|
@@ -0,0 +1,124 @@
|
|
|
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";
|
|
3
|
+
export function fromUnixMilliseconds(value) {
|
|
4
|
+
return DateTime(value, 1 /* DateKind.UTC */);
|
|
5
|
+
}
|
|
6
|
+
export function create(year, month, day) {
|
|
7
|
+
const d = fromUnixMilliseconds(Date.UTC(year, month - 1, day));
|
|
8
|
+
if (year <= 99) {
|
|
9
|
+
d.setUTCFullYear(year);
|
|
10
|
+
}
|
|
11
|
+
return d;
|
|
12
|
+
}
|
|
13
|
+
export function maxValue() {
|
|
14
|
+
// This is "9999-12-31T00:00:00.000Z"
|
|
15
|
+
return fromUnixMilliseconds(253402214400000);
|
|
16
|
+
}
|
|
17
|
+
export function minValue() {
|
|
18
|
+
// This is "0001-01-01T00:00:00.000Z"
|
|
19
|
+
return fromUnixMilliseconds(-62135596800000);
|
|
20
|
+
}
|
|
21
|
+
export function dayNumber(d) {
|
|
22
|
+
return Number((getTicks(d) / 864000000000n));
|
|
23
|
+
}
|
|
24
|
+
export function fromDayNumber(dayNumber) {
|
|
25
|
+
const ticks = 864000000000n * BigInt(dayNumber);
|
|
26
|
+
return fromUnixMilliseconds(ticksToUnixEpochMilliseconds(ticks));
|
|
27
|
+
}
|
|
28
|
+
export function fromDateTime(d) {
|
|
29
|
+
return create(Date_year(d), Date_month(d), Date_day(d));
|
|
30
|
+
}
|
|
31
|
+
export function day(d) {
|
|
32
|
+
return d.getUTCDate();
|
|
33
|
+
}
|
|
34
|
+
export function month(d) {
|
|
35
|
+
return d.getUTCMonth() + 1;
|
|
36
|
+
}
|
|
37
|
+
export function year(d) {
|
|
38
|
+
return d.getUTCFullYear();
|
|
39
|
+
}
|
|
40
|
+
export function dayOfWeek(d) {
|
|
41
|
+
return d.getUTCDay();
|
|
42
|
+
}
|
|
43
|
+
export function dayOfYear(d) {
|
|
44
|
+
return Date_dayOfYear(d);
|
|
45
|
+
}
|
|
46
|
+
export function toDateTime(d, time, kind = 0 /* DateKind.Unspecified */) {
|
|
47
|
+
return DateTime(d.getTime() + time + (kind !== 1 /* DateKind.UTC */ ? d.getTimezoneOffset() : 0) * 60000, kind);
|
|
48
|
+
}
|
|
49
|
+
export function toString(d, format = "d", _provider) {
|
|
50
|
+
if (["d", "o", "O"].indexOf(format) === -1) {
|
|
51
|
+
throw new Error("Custom formats are not supported");
|
|
52
|
+
}
|
|
53
|
+
const y = padWithZeros(year(d), 4);
|
|
54
|
+
const m = padWithZeros(month(d), 2);
|
|
55
|
+
const dd = padWithZeros(day(d), 2);
|
|
56
|
+
return format === "d" ? `${m}/${dd}/${y}` : `${y}-${m}-${dd}`;
|
|
57
|
+
}
|
|
58
|
+
export function parse(str) {
|
|
59
|
+
function fail() {
|
|
60
|
+
throw new Error(`String '${str}' was not recognized as a valid DateOnly.`);
|
|
61
|
+
}
|
|
62
|
+
// Allowed separators: . , / -
|
|
63
|
+
// TODO whitespace alone as the separator
|
|
64
|
+
//
|
|
65
|
+
// Whitespace around separators
|
|
66
|
+
//
|
|
67
|
+
// Allowed format types:
|
|
68
|
+
// yyyy/mm/dd
|
|
69
|
+
// mm/dd/yyyy
|
|
70
|
+
// mm/dd
|
|
71
|
+
// mm/yyyy
|
|
72
|
+
// yyyy/mm
|
|
73
|
+
const r = /^\s*(\d{1,4})(?:\s*[.,-\/]\s*(\d{1,2}))?\s*[.,-\/]\s*(\d{1,4})\s*$/.exec(str);
|
|
74
|
+
if (r != null) {
|
|
75
|
+
let y = 0;
|
|
76
|
+
let m = 0;
|
|
77
|
+
let d = 1;
|
|
78
|
+
if (r[2] == null) {
|
|
79
|
+
if (r[1].length < 3) {
|
|
80
|
+
if (r[3].length < 3) {
|
|
81
|
+
// 12/30 = December 30, {CurrentYear}
|
|
82
|
+
y = new Date().getFullYear();
|
|
83
|
+
m = +r[1];
|
|
84
|
+
d = +r[3];
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
// 12/2000 = December 1, 2000
|
|
88
|
+
m = +r[1];
|
|
89
|
+
y = +r[3];
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
if (r[3].length > 2)
|
|
94
|
+
fail();
|
|
95
|
+
// 2000/12 = December 1, 2000
|
|
96
|
+
y = +r[1];
|
|
97
|
+
m = +r[3];
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
// 2000/1/30 or 1/30/2000
|
|
102
|
+
const yearFirst = r[1].length > 2;
|
|
103
|
+
const yTmp = r[yearFirst ? 1 : 3];
|
|
104
|
+
y = +yTmp;
|
|
105
|
+
// year 0-29 is 2000-2029, 30-99 is 1930-1999
|
|
106
|
+
if (yTmp.length < 3)
|
|
107
|
+
y += y >= 30 ? 1900 : 2000;
|
|
108
|
+
m = +r[yearFirst ? 2 : 1];
|
|
109
|
+
d = +r[yearFirst ? 3 : 2];
|
|
110
|
+
}
|
|
111
|
+
if (y > 0 && m > 0 && m < 13 && d > 0 && d <= Date_daysInMonth(y, m))
|
|
112
|
+
return create(y, m, d);
|
|
113
|
+
}
|
|
114
|
+
return fail();
|
|
115
|
+
}
|
|
116
|
+
export function tryParse(v, defValue) {
|
|
117
|
+
try {
|
|
118
|
+
defValue.contents = parse(v);
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import Decimal from "./lib/big.js";
|
|
2
|
+
import { FSharpRef } from "./Types.js";
|
|
3
|
+
export default Decimal;
|
|
4
|
+
export type decimal = Decimal;
|
|
5
|
+
export declare const get_Zero: Decimal;
|
|
6
|
+
export declare const get_One: Decimal;
|
|
7
|
+
export declare const get_MinusOne: Decimal;
|
|
8
|
+
export declare const get_MaxValue: Decimal;
|
|
9
|
+
export declare const get_MinValue: Decimal;
|
|
10
|
+
export declare function compare(x: Decimal, y: Decimal): import("./lib/big.js").Comparison;
|
|
11
|
+
export declare function equals(x: Decimal, y: Decimal): boolean;
|
|
12
|
+
export declare function abs(x: Decimal): Decimal;
|
|
13
|
+
export declare function sign(x: Decimal): number;
|
|
14
|
+
export declare function max(x: Decimal, y: Decimal): Decimal;
|
|
15
|
+
export declare function min(x: Decimal, y: Decimal): Decimal;
|
|
16
|
+
export declare function maxMagnitude(x: Decimal, y: Decimal): Decimal;
|
|
17
|
+
export declare function minMagnitude(x: Decimal, y: Decimal): Decimal;
|
|
18
|
+
export declare function clamp(x: Decimal, min: Decimal, max: Decimal): Decimal;
|
|
19
|
+
export declare function round(x: Decimal, digits?: number): Decimal;
|
|
20
|
+
export declare function truncate(x: Decimal): Decimal;
|
|
21
|
+
export declare function ceiling(x: Decimal): Decimal;
|
|
22
|
+
export declare function floor(x: Decimal): Decimal;
|
|
23
|
+
export declare function pow(x: Decimal, n: number): Decimal;
|
|
24
|
+
export declare function sqrt(x: Decimal): Decimal;
|
|
25
|
+
export declare function op_Addition(x: Decimal, y: Decimal): Decimal;
|
|
26
|
+
export declare function op_Subtraction(x: Decimal, y: Decimal): Decimal;
|
|
27
|
+
export declare function op_Multiply(x: Decimal, y: Decimal): Decimal;
|
|
28
|
+
export declare function op_Division(x: Decimal, y: Decimal): Decimal;
|
|
29
|
+
export declare function op_Modulus(x: Decimal, y: Decimal): Decimal;
|
|
30
|
+
export declare function op_UnaryNegation(x: Decimal): Decimal;
|
|
31
|
+
export declare function op_UnaryPlus(x: Decimal): Decimal;
|
|
32
|
+
export declare const add: typeof op_Addition;
|
|
33
|
+
export declare const subtract: typeof op_Subtraction;
|
|
34
|
+
export declare const multiply: typeof op_Multiply;
|
|
35
|
+
export declare const divide: typeof op_Division;
|
|
36
|
+
export declare const remainder: typeof op_Modulus;
|
|
37
|
+
export declare const negate: typeof op_UnaryNegation;
|
|
38
|
+
export declare function toString(x: Decimal): string;
|
|
39
|
+
export declare function tryParse(str: string, defValue: FSharpRef<Decimal>): boolean;
|
|
40
|
+
export declare function parse(str: string): Decimal;
|
|
41
|
+
export declare function toNumber(x: Decimal): number;
|
|
42
|
+
export declare function fromIntArray(bits: ArrayLike<number>): Decimal;
|
|
43
|
+
export declare function fromInts(low: number, mid: number, high: number, signExp: number): Decimal;
|
|
44
|
+
export declare function fromParts(low: number, mid: number, high: number, isNegative: boolean, scale: number): Decimal;
|
|
45
|
+
export declare function getBits(d: Decimal): number[];
|