@glutinum/cli 0.14.0 → 0.14.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (144) hide show
  1. package/dist/fable_modules/Fable.Promise.3.2.1/AsyncIterable.fs +89 -0
  2. package/dist/fable_modules/Fable.Promise.3.2.1/AsyncIterable.fs.js +105 -0
  3. package/dist/fable_modules/Fable.Promise.3.2.1/Fable.Promise.fableproj +25 -0
  4. package/dist/fable_modules/Fable.Promise.3.2.1/Promise.fs +842 -0
  5. package/dist/fable_modules/Fable.Promise.3.2.1/Promise.fs.js +232 -0
  6. package/dist/fable_modules/Fable.Promise.3.2.1/PromiseImpl.fs +31 -0
  7. package/dist/fable_modules/Fable.Promise.3.2.1/PromiseImpl.fs.js +20 -0
  8. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Array.fs +235 -0
  9. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Array.fs.js +384 -0
  10. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AssemblyInfo.fs +19 -0
  11. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Async.fs +287 -0
  12. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Async.fs.js +128 -0
  13. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncOption.fs +127 -0
  14. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncOptionCE.fs +174 -0
  15. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncOptionCE.fs.js +37 -0
  16. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncOptionOp.fs +24 -0
  17. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncResult.fs +483 -0
  18. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncResultCE.fs +201 -0
  19. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncResultCE.fs.js +18 -0
  20. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncResultOp.fs +24 -0
  21. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncResultOption.fs +87 -0
  22. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncResultOption.fs.js +26 -0
  23. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncResultOptionCE.fs +236 -0
  24. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncResultOptionCE.fs.js +18 -0
  25. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncResultOptionOp.fs +24 -0
  26. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncValidation.fs +185 -0
  27. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncValidationCE.fs +186 -0
  28. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncValidationCE.fs.js +18 -0
  29. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncValidationOp.fs +35 -0
  30. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/FsToolkit.ErrorHandling.fableproj +69 -0
  31. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/List.fs +276 -0
  32. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/List.fs.js +364 -0
  33. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Nullness.fs +81 -0
  34. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Option.fs +462 -0
  35. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/OptionCE.fs +139 -0
  36. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/OptionCE.fs.js +48 -0
  37. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/OptionOp.fs +21 -0
  38. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ParallelAsyncResult.fs +88 -0
  39. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ParallelAsyncResult.fs.js +30 -0
  40. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ParallelAsyncResultCE.fs +200 -0
  41. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ParallelAsyncResultCE.fs.js +18 -0
  42. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ParallelAsyncValidation.fs +34 -0
  43. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ParallelAsyncValidationCE.fs +244 -0
  44. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ParallelAsyncValidationCE.fs.js +18 -0
  45. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Result.fs +731 -0
  46. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Result.fs.js +45 -0
  47. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ResultCE.fs +140 -0
  48. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ResultCE.fs.js +23 -0
  49. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ResultOp.fs +45 -0
  50. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ResultOption.fs +201 -0
  51. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ResultOption.fs.js +65 -0
  52. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ResultOptionCE.fs +135 -0
  53. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ResultOptionCE.fs.js +18 -0
  54. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ResultOptionOp.fs +57 -0
  55. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Seq.fs +503 -0
  56. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Seq.fs.js +295 -0
  57. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Validation.fs +167 -0
  58. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ValidationCE.fs +142 -0
  59. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ValidationCE.fs.js +18 -0
  60. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ValidationOp.fs +35 -0
  61. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ValueOption.fs +148 -0
  62. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ValueTaskValueOption.fs +102 -0
  63. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ValueTaskValueOptionCE.fs +587 -0
  64. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ValueTaskValueOptionOp.fs +10 -0
  65. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/obj/Debug/netstandard2.1/.NETStandard,Version=v2.1.AssemblyAttributes.fs +3 -0
  66. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/obj/Debug/netstandard2.1/FsToolkit.ErrorHandling.AssemblyInfo.fs +20 -0
  67. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/obj/Release/net9.0/.NETCoreApp,Version=v9.0.AssemblyAttributes.fs +3 -0
  68. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/obj/Release/net9.0/FsToolkit.ErrorHandling.AssemblyInfo.fs +20 -0
  69. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/obj/Release/netstandard2.0/.NETStandard,Version=v2.0.AssemblyAttributes.fs +3 -0
  70. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/obj/Release/netstandard2.0/FsToolkit.ErrorHandling.AssemblyInfo.fs +20 -0
  71. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/obj/Release/netstandard2.1/.NETStandard,Version=v2.1.AssemblyAttributes.fs +3 -0
  72. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/obj/Release/netstandard2.1/FsToolkit.ErrorHandling.AssemblyInfo.fs +20 -0
  73. package/dist/fable_modules/fable-library-js.5.17.2/Array.js +1348 -0
  74. package/dist/fable_modules/fable-library-js.5.17.2/Async.js +163 -0
  75. package/dist/fable_modules/fable-library-js.5.17.2/AsyncBuilder.js +204 -0
  76. package/dist/fable_modules/fable-library-js.5.17.2/BigInt.js +307 -0
  77. package/dist/fable_modules/fable-library-js.5.17.2/BitConverter.js +138 -0
  78. package/dist/fable_modules/fable-library-js.5.17.2/Boolean.js +22 -0
  79. package/dist/fable_modules/fable-library-js.5.17.2/CHANGELOG.md +348 -0
  80. package/dist/fable_modules/fable-library-js.5.17.2/Char.js +202 -0
  81. package/dist/fable_modules/fable-library-js.5.17.2/Choice.js +184 -0
  82. package/dist/fable_modules/fable-library-js.5.17.2/CollectionUtil.js +182 -0
  83. package/dist/fable_modules/fable-library-js.5.17.2/ConditionalWeakTable.js +21 -0
  84. package/dist/fable_modules/fable-library-js.5.17.2/Date.js +834 -0
  85. package/dist/fable_modules/fable-library-js.5.17.2/DateOffset.js +252 -0
  86. package/dist/fable_modules/fable-library-js.5.17.2/DateOnly.js +124 -0
  87. package/dist/fable_modules/fable-library-js.5.17.2/DateOnlyTemporal.js +146 -0
  88. package/dist/fable_modules/fable-library-js.5.17.2/DateTimeFormat.js +523 -0
  89. package/dist/fable_modules/fable-library-js.5.17.2/DateTimeOffsetTemporal.js +283 -0
  90. package/dist/fable_modules/fable-library-js.5.17.2/DateTimeTemporal.js +243 -0
  91. package/dist/fable_modules/fable-library-js.5.17.2/Decimal.js +238 -0
  92. package/dist/fable_modules/fable-library-js.5.17.2/Directory.js +11 -0
  93. package/dist/fable_modules/fable-library-js.5.17.2/Double.js +53 -0
  94. package/dist/fable_modules/fable-library-js.5.17.2/Encoding.js +185 -0
  95. package/dist/fable_modules/fable-library-js.5.17.2/Environment.js +3 -0
  96. package/dist/fable_modules/fable-library-js.5.17.2/Event.js +102 -0
  97. package/dist/fable_modules/fable-library-js.5.17.2/FSharp.Collections.js +45 -0
  98. package/dist/fable_modules/fable-library-js.5.17.2/FSharp.Core.CompilerServices.js +27 -0
  99. package/dist/fable_modules/fable-library-js.5.17.2/FSharp.Core.js +156 -0
  100. package/dist/fable_modules/fable-library-js.5.17.2/File.js +27 -0
  101. package/dist/fable_modules/fable-library-js.5.17.2/Global.js +29 -0
  102. package/dist/fable_modules/fable-library-js.5.17.2/Guid.js +163 -0
  103. package/dist/fable_modules/fable-library-js.5.17.2/Int32.js +135 -0
  104. package/dist/fable_modules/fable-library-js.5.17.2/List.js +1337 -0
  105. package/dist/fable_modules/fable-library-js.5.17.2/Long.js +38 -0
  106. package/dist/fable_modules/fable-library-js.5.17.2/MailboxProcessor.js +100 -0
  107. package/dist/fable_modules/fable-library-js.5.17.2/Map.js +1400 -0
  108. package/dist/fable_modules/fable-library-js.5.17.2/MapUtil.js +130 -0
  109. package/dist/fable_modules/fable-library-js.5.17.2/MutableMap.js +339 -0
  110. package/dist/fable_modules/fable-library-js.5.17.2/MutableSet.js +233 -0
  111. package/dist/fable_modules/fable-library-js.5.17.2/Native.js +14 -0
  112. package/dist/fable_modules/fable-library-js.5.17.2/Numeric.js +112 -0
  113. package/dist/fable_modules/fable-library-js.5.17.2/Observable.js +115 -0
  114. package/dist/fable_modules/fable-library-js.5.17.2/Option.js +87 -0
  115. package/dist/fable_modules/fable-library-js.5.17.2/Path.js +31 -0
  116. package/dist/fable_modules/fable-library-js.5.17.2/README.md +3 -0
  117. package/dist/fable_modules/fable-library-js.5.17.2/Random.js +172 -0
  118. package/dist/fable_modules/fable-library-js.5.17.2/Range.js +45 -0
  119. package/dist/fable_modules/fable-library-js.5.17.2/Reflection.js +489 -0
  120. package/dist/fable_modules/fable-library-js.5.17.2/RegExp.js +170 -0
  121. package/dist/fable_modules/fable-library-js.5.17.2/Result.js +165 -0
  122. package/dist/fable_modules/fable-library-js.5.17.2/Seq.js +1504 -0
  123. package/dist/fable_modules/fable-library-js.5.17.2/Seq2.js +111 -0
  124. package/dist/fable_modules/fable-library-js.5.17.2/Set.js +1829 -0
  125. package/dist/fable_modules/fable-library-js.5.17.2/String.js +731 -0
  126. package/dist/fable_modules/fable-library-js.5.17.2/System.Collections.Generic.js +333 -0
  127. package/dist/fable_modules/fable-library-js.5.17.2/System.Text.js +200 -0
  128. package/dist/fable_modules/fable-library-js.5.17.2/System.js +289 -0
  129. package/dist/fable_modules/fable-library-js.5.17.2/Task.js +27 -0
  130. package/dist/fable_modules/fable-library-js.5.17.2/TaskBuilder.js +72 -0
  131. package/dist/fable_modules/fable-library-js.5.17.2/TimeOnly.js +122 -0
  132. package/dist/fable_modules/fable-library-js.5.17.2/TimeOnlyTemporal.js +142 -0
  133. package/dist/fable_modules/fable-library-js.5.17.2/TimeSpan.js +180 -0
  134. package/dist/fable_modules/fable-library-js.5.17.2/TimeSpanTemporal.js +259 -0
  135. package/dist/fable_modules/fable-library-js.5.17.2/Timer.js +67 -0
  136. package/dist/fable_modules/fable-library-js.5.17.2/Types.js +198 -0
  137. package/dist/fable_modules/fable-library-js.5.17.2/Unicode.13.0.0.js +4 -0
  138. package/dist/fable_modules/fable-library-js.5.17.2/Uri.js +165 -0
  139. package/dist/fable_modules/fable-library-js.5.17.2/Util.js +807 -0
  140. package/dist/fable_modules/fable-library-js.5.17.2/big.d.ts +338 -0
  141. package/dist/fable_modules/fable-library-js.5.17.2/lib/big.js +829 -0
  142. package/dist/fable_modules/fable-library-js.5.17.2/package.json +24 -0
  143. package/dist/fable_modules/fable-library-js.5.17.2/quotation.js +682 -0
  144. package/package.json +1 -1
@@ -0,0 +1,252 @@
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, daysInMonth, parseRaw, ticksToUnixEpochMilliseconds, unixEpochMillisecondsToTicks } from "./Date.js";
17
+ import { Exception, compareDates, DateTimeKind } 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 Exception("Offset must be specified in whole minutes.");
31
+ }
32
+ if (Math.abs(offset / 3600000) > 14) {
33
+ throw new Exception("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 DateTimeKind.Utc:
41
+ if (offset != null && offset !== 0) {
42
+ throw new Exception("The UTC Offset for Utc DateTime instances must be 0.");
43
+ }
44
+ offset2 = 0;
45
+ break;
46
+ case DateTimeKind.Local:
47
+ offset2 = date.getTimezoneOffset() * -60000;
48
+ if (offset != null && offset !== offset2) {
49
+ throw new Exception("The UTC Offset of the local dateTime parameter does not match the offset argument.");
50
+ }
51
+ break;
52
+ case DateTimeKind.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 fromDateTime(dateOnly, timeOnly, offset) {
65
+ return DateTimeOffset(dateOnly.getTime() - offset + timeOnly, offset);
66
+ }
67
+ export function fromTicks(ticks, offset) {
68
+ const ms = ticksToUnixEpochMilliseconds(ticks) - offset;
69
+ return DateTimeOffset(ms, offset);
70
+ }
71
+ export function fromUnixTimeMilliseconds(ms) {
72
+ return DateTimeOffset(toFloat64(ms), 0);
73
+ }
74
+ export function fromUnixTimeSeconds(seconds) {
75
+ return DateTimeOffset(toFloat64(seconds * 1000n), 0);
76
+ }
77
+ export function getUtcTicks(date) {
78
+ return unixEpochMillisecondsToTicks(date.getTime(), 0);
79
+ }
80
+ export function minValue() {
81
+ // This is "0001-01-01T00:00:00.000Z", actual JS min value is -8640000000000000
82
+ return DateTimeOffset(-62135596800000, 0);
83
+ }
84
+ export function maxValue() {
85
+ // This is "9999-12-31T23:59:59.999Z", actual JS max value is 8640000000000000
86
+ return DateTimeOffset(253402300799999, 0);
87
+ }
88
+ export function parse(str) {
89
+ const [date, offsetMatch] = parseRaw(str);
90
+ const offset = offsetMatch == null
91
+ ? date.getTimezoneOffset() * -60000
92
+ : (offsetMatch === "Z" ? 0 : offsetMatch * 60000);
93
+ return DateTimeOffset(date.getTime(), offset);
94
+ }
95
+ export function tryParse(v, defValue) {
96
+ try {
97
+ defValue.contents = parse(v);
98
+ return true;
99
+ }
100
+ catch (_err) {
101
+ return false;
102
+ }
103
+ }
104
+ export function create(year, month, day, h, m, s, ms, offset) {
105
+ if (offset == null) {
106
+ offset = ms;
107
+ ms = 0;
108
+ }
109
+ checkOffsetInRange(offset);
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);
113
+ }
114
+ const dateValue = date.getTime();
115
+ if (isNaN(dateValue)) {
116
+ throw new Exception("The parameters describe an unrepresentable Date");
117
+ }
118
+ return DateTimeOffset(dateValue, offset);
119
+ }
120
+ export function now() {
121
+ const date = new Date();
122
+ const offset = date.getTimezoneOffset() * -60000;
123
+ return DateTimeOffset(date.getTime(), offset);
124
+ }
125
+ export function utcNow() {
126
+ const date = new Date();
127
+ // const offset = date.getTimezoneOffset() * -60_000;
128
+ return DateTimeOffset(date.getTime(), 0);
129
+ }
130
+ export function toUniversalTime(date) {
131
+ return DateTime(date.getTime(), DateTimeKind.Utc);
132
+ }
133
+ export function toLocalTime(date) {
134
+ return DateTime(date.getTime(), DateTimeKind.Local);
135
+ }
136
+ export function localDateTime(date) {
137
+ return DateTime(date.getTime(), DateTimeKind.Local);
138
+ }
139
+ export function timeOfDay(d) {
140
+ const d2 = new Date(d.getTime() + offset(d));
141
+ return d2.getUTCHours() * 3600000
142
+ + d2.getUTCMinutes() * 60000
143
+ + d2.getUTCSeconds() * 1000
144
+ + d2.getUTCMilliseconds();
145
+ }
146
+ export function date(d) {
147
+ const d2 = new Date(d.getTime() + offset(d));
148
+ return createDate(d2.getUTCFullYear(), d2.getUTCMonth() + 1, d2.getUTCDate(), 0, 0, 0, 0);
149
+ }
150
+ export function day(d) {
151
+ return new Date(d.getTime() + offset(d)).getUTCDate();
152
+ }
153
+ export function hour(d) {
154
+ return new Date(d.getTime() + offset(d)).getUTCHours();
155
+ }
156
+ export function millisecond(d) {
157
+ return new Date(d.getTime() + offset(d)).getUTCMilliseconds();
158
+ }
159
+ export function minute(d) {
160
+ return new Date(d.getTime() + offset(d)).getUTCMinutes();
161
+ }
162
+ export function month(d) {
163
+ return new Date(d.getTime() + offset(d)).getUTCMonth() + 1;
164
+ }
165
+ export function second(d) {
166
+ return new Date(d.getTime() + offset(d)).getUTCSeconds();
167
+ }
168
+ export function year(d) {
169
+ return new Date(d.getTime() + offset(d)).getUTCFullYear();
170
+ }
171
+ export function dayOfWeek(d) {
172
+ return new Date(d.getTime() + offset(d)).getUTCDay();
173
+ }
174
+ export function dayOfYear(d) {
175
+ const d2 = new Date(d.getTime() + offset(d));
176
+ const _year = d2.getUTCFullYear();
177
+ const _month = d2.getUTCMonth() + 1;
178
+ let _day = d2.getUTCDate();
179
+ for (let i = 1; i < _month; i++) {
180
+ _day += daysInMonth(_year, i);
181
+ }
182
+ return _day;
183
+ }
184
+ export function add(d, ts) {
185
+ return DateTimeOffset(d.getTime() + ts, offset(d));
186
+ }
187
+ export function addDays(d, v) {
188
+ return add(d, v * 86400000);
189
+ }
190
+ export function addHours(d, v) {
191
+ return add(d, v * 3600000);
192
+ }
193
+ export function addMinutes(d, v) {
194
+ return add(d, v * 60000);
195
+ }
196
+ export function addSeconds(d, v) {
197
+ return add(d, v * 1000);
198
+ }
199
+ export function addMilliseconds(d, v) {
200
+ return add(d, v);
201
+ }
202
+ export function addTicks(d, v) {
203
+ return add(d, toFloat64(v / 10000n));
204
+ }
205
+ export function addYears(d, v) {
206
+ const d2 = new Date(d.getTime() + offset(d));
207
+ const newMonth = d2.getUTCMonth() + 1;
208
+ const newYear = d2.getUTCFullYear() + v;
209
+ const _daysInMonth = daysInMonth(newYear, newMonth);
210
+ const newDay = Math.min(_daysInMonth, d2.getUTCDate());
211
+ return create(newYear, newMonth, newDay, d2.getUTCHours(), d2.getUTCMinutes(), d2.getUTCSeconds(), d2.getUTCMilliseconds(), offset(d));
212
+ }
213
+ export function addMonths(d, v) {
214
+ const d2 = new Date(d.getTime() + offset(d));
215
+ const totalMonths = d2.getUTCMonth() + 1 + v;
216
+ const newMonth = ((totalMonths - 1) % 12 + 12) % 12 + 1;
217
+ const yearOffset = Math.floor((totalMonths - 1) / 12);
218
+ const newYear = d2.getUTCFullYear() + yearOffset;
219
+ const _daysInMonth = daysInMonth(newYear, newMonth);
220
+ const newDay = Math.min(_daysInMonth, d2.getUTCDate());
221
+ return create(newYear, newMonth, newDay, d2.getUTCHours(), d2.getUTCMinutes(), d2.getUTCSeconds(), d2.getUTCMilliseconds(), offset(d));
222
+ }
223
+ export function subtract(d, that) {
224
+ return typeof that === "number"
225
+ ? DateTimeOffset(d.getTime() - that, offset(d))
226
+ : d.getTime() - that.getTime();
227
+ }
228
+ export function equals(d1, d2) {
229
+ return d1.getTime() === d2.getTime();
230
+ }
231
+ export function equalsExact(d1, d2) {
232
+ return d1.getTime() === d2.getTime() && d1.offset === d2.offset;
233
+ }
234
+ export function compare(d1, d2) {
235
+ return compareDates(d1, d2);
236
+ }
237
+ export const compareTo = compare;
238
+ export function op_Addition(x, y) {
239
+ return add(x, y);
240
+ }
241
+ export function op_Subtraction(x, y) {
242
+ return subtract(x, y);
243
+ }
244
+ export function toOffset(d, offset) {
245
+ return DateTimeOffset(d.getTime(), offset);
246
+ }
247
+ export function toUnixTimeMilliseconds(d) {
248
+ return fromFloat64(d.getTime());
249
+ }
250
+ export function toUnixTimeSeconds(d) {
251
+ return fromFloat64(d.getTime() / 1000.0);
252
+ }
@@ -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 { Exception, DateTimeKind, padWithZeros } from "./Util.js";
3
+ export function fromUnixMilliseconds(value) {
4
+ return DateTime(value, DateTimeKind.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 = DateTimeKind.Unspecified) {
47
+ return DateTime(d.getTime() + time + (kind !== DateTimeKind.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 Exception("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 Exception(`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,146 @@
1
+ import { dateTime as DateTime_stamp } from "./DateTimeTemporal.js";
2
+ import { fromDate as DateTimeOffset_fromDate } from "./DateTimeOffsetTemporal.js";
3
+ import { Exception, DateTimeKind, padWithZeros } from "./Util.js";
4
+ export const PlainDate = Temporal.PlainDate;
5
+ // The generic equality/comparison/hashing helpers in Util.ts dispatch at runtime
6
+ // on .NET-style Equals/CompareTo/GetHashCode methods (with a special case for JS
7
+ // Date, which Temporal.PlainDate cannot benefit from). Attach them so DateOnly
8
+ // also works in generic contexts: records, tuples, erased generics, etc.
9
+ const proto = Temporal.PlainDate.prototype;
10
+ proto.Equals = function (other) { return this.equals(other); };
11
+ proto.CompareTo = function (other) { return Temporal.PlainDate.compare(this, other); };
12
+ proto.GetHashCode = function () { return dayNumber(this); };
13
+ // Lets String.Format format this value without String.ts importing this module (see String.ts)
14
+ proto[Symbol.for("Fable.DateTimeFormattable")] = function (format) { return toString(this, format); };
15
+ export function create(year, month, day) {
16
+ return new Temporal.PlainDate(year, month, day);
17
+ }
18
+ export function maxValue() {
19
+ return new Temporal.PlainDate(9999, 12, 31);
20
+ }
21
+ export function minValue() {
22
+ return new Temporal.PlainDate(1, 1, 1);
23
+ }
24
+ export function dayNumber(d) {
25
+ return minValue().until(d).days;
26
+ }
27
+ export function fromDayNumber(dayNumber) {
28
+ return minValue().add({ days: dayNumber });
29
+ }
30
+ export function fromDateTime(d) {
31
+ // Under the Temporal representation a DateTime is a PlainDateTime (kind-agnostic wall-clock)
32
+ return new Temporal.PlainDate(d.year, d.month, d.day);
33
+ }
34
+ export function dayOfWeek(d) {
35
+ // Temporal: Monday = 1 ... Sunday = 7, .NET: Sunday = 0 ... Saturday = 6
36
+ return d.dayOfWeek % 7;
37
+ }
38
+ export function toDateTime(d, time, kind = DateTimeKind.Unspecified) {
39
+ return DateTime_stamp(d.toPlainDateTime(time), kind);
40
+ }
41
+ export function toDateTimeOffset(d, time, offset) {
42
+ return DateTimeOffset_fromDate(DateTime_stamp(d.toPlainDateTime(time), DateTimeKind.Unspecified), offset);
43
+ }
44
+ export function addDays(d, v) {
45
+ return d.add({ days: v });
46
+ }
47
+ export function addMonths(d, v) {
48
+ return d.add({ months: v });
49
+ }
50
+ export function addYears(d, v) {
51
+ return d.add({ years: v });
52
+ }
53
+ export function equals(x, y) {
54
+ return x.equals(y);
55
+ }
56
+ export function compare(x, y) {
57
+ return Temporal.PlainDate.compare(x, y);
58
+ }
59
+ export function hash(d) {
60
+ return dayNumber(d);
61
+ }
62
+ export function toString(d, format = "d", _provider) {
63
+ switch (format) {
64
+ case "d":
65
+ return `${padWithZeros(d.month, 2)}/${padWithZeros(d.day, 2)}/${padWithZeros(d.year, 4)}`;
66
+ case "o":
67
+ case "O":
68
+ // PlainDate.toString() is the ISO yyyy-MM-dd round-trip format
69
+ return d.toString();
70
+ default:
71
+ throw new Exception("Custom formats are not supported");
72
+ }
73
+ }
74
+ export function parse(str) {
75
+ function fail() {
76
+ throw new Exception(`String '${str}' was not recognized as a valid DateOnly.`);
77
+ }
78
+ // Allowed separators: . , / -
79
+ // TODO whitespace alone as the separator
80
+ //
81
+ // Whitespace around separators
82
+ //
83
+ // Allowed format types:
84
+ // yyyy/mm/dd
85
+ // mm/dd/yyyy
86
+ // mm/dd
87
+ // mm/yyyy
88
+ // yyyy/mm
89
+ const r = /^\s*(\d{1,4})(?:\s*[.,-\/]\s*(\d{1,2}))?\s*[.,-\/]\s*(\d{1,4})\s*$/.exec(str);
90
+ if (r != null) {
91
+ let y = 0;
92
+ let m = 0;
93
+ let d = 1;
94
+ if (r[2] == null) {
95
+ if (r[1].length < 3) {
96
+ if (r[3].length < 3) {
97
+ // 12/30 = December 30, {CurrentYear}
98
+ y = Temporal.Now.plainDateISO().year;
99
+ m = +r[1];
100
+ d = +r[3];
101
+ }
102
+ else {
103
+ // 12/2000 = December 1, 2000
104
+ m = +r[1];
105
+ y = +r[3];
106
+ }
107
+ }
108
+ else {
109
+ if (r[3].length > 2)
110
+ fail();
111
+ // 2000/12 = December 1, 2000
112
+ y = +r[1];
113
+ m = +r[3];
114
+ }
115
+ }
116
+ else {
117
+ // 2000/1/30 or 1/30/2000
118
+ const yearFirst = r[1].length > 2;
119
+ const yTmp = r[yearFirst ? 1 : 3];
120
+ y = +yTmp;
121
+ // year 0-29 is 2000-2029, 30-99 is 1930-1999
122
+ if (yTmp.length < 3)
123
+ y += y >= 30 ? 1900 : 2000;
124
+ m = +r[yearFirst ? 2 : 1];
125
+ d = +r[yearFirst ? 3 : 2];
126
+ }
127
+ if (y > 0) {
128
+ try {
129
+ return new Temporal.PlainDate(y, m, d);
130
+ }
131
+ catch {
132
+ return fail();
133
+ }
134
+ }
135
+ }
136
+ return fail();
137
+ }
138
+ export function tryParse(v, defValue) {
139
+ try {
140
+ defValue.contents = parse(v);
141
+ return true;
142
+ }
143
+ catch {
144
+ return false;
145
+ }
146
+ }