@parischap/conversions 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.
Files changed (142) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1304 -0
  3. package/cjs/BigDecimal.js +16 -0
  4. package/cjs/BigDecimal.js.map +1 -0
  5. package/cjs/BigInt.js +34 -0
  6. package/cjs/BigInt.js.map +1 -0
  7. package/cjs/DateTime.js +2202 -0
  8. package/cjs/DateTime.js.map +1 -0
  9. package/cjs/DateTimeFormat.js +269 -0
  10. package/cjs/DateTimeFormat.js.map +1 -0
  11. package/cjs/DateTimeFormatContext.js +327 -0
  12. package/cjs/DateTimeFormatContext.js.map +1 -0
  13. package/cjs/Email.js +73 -0
  14. package/cjs/Email.js.map +1 -0
  15. package/cjs/Integer.js +155 -0
  16. package/cjs/Integer.js.map +1 -0
  17. package/cjs/NumberBase10Format.js +759 -0
  18. package/cjs/NumberBase10Format.js.map +1 -0
  19. package/cjs/PositiveInteger.js +191 -0
  20. package/cjs/PositiveInteger.js.map +1 -0
  21. package/cjs/PositiveReal.js +162 -0
  22. package/cjs/PositiveReal.js.map +1 -0
  23. package/cjs/Real.js +113 -0
  24. package/cjs/Real.js.map +1 -0
  25. package/cjs/RoundingMode.js +86 -0
  26. package/cjs/RoundingMode.js.map +1 -0
  27. package/cjs/RoundingOption.js +152 -0
  28. package/cjs/RoundingOption.js.map +1 -0
  29. package/cjs/Schema.js +218 -0
  30. package/cjs/Schema.js.map +1 -0
  31. package/cjs/SemVer.js +73 -0
  32. package/cjs/SemVer.js.map +1 -0
  33. package/cjs/Template.js +189 -0
  34. package/cjs/Template.js.map +1 -0
  35. package/cjs/TemplatePart.js +51 -0
  36. package/cjs/TemplatePart.js.map +1 -0
  37. package/cjs/TemplateParts.js +46 -0
  38. package/cjs/TemplateParts.js.map +1 -0
  39. package/cjs/TemplatePlaceholder.js +381 -0
  40. package/cjs/TemplatePlaceholder.js.map +1 -0
  41. package/cjs/TemplateSeparator.js +116 -0
  42. package/cjs/TemplateSeparator.js.map +1 -0
  43. package/cjs/index.js +67 -0
  44. package/cjs/index.js.map +1 -0
  45. package/cjs/internal/Int.js +50 -0
  46. package/cjs/internal/Int.js.map +1 -0
  47. package/cjs/internal/Positive.js +50 -0
  48. package/cjs/internal/Positive.js.map +1 -0
  49. package/dts/BigDecimal.d.ts +11 -0
  50. package/dts/BigDecimal.d.ts.map +1 -0
  51. package/dts/BigInt.d.ts +30 -0
  52. package/dts/BigInt.d.ts.map +1 -0
  53. package/dts/DateTime.d.ts +1421 -0
  54. package/dts/DateTime.d.ts.map +1 -0
  55. package/dts/DateTimeFormat.d.ts +257 -0
  56. package/dts/DateTimeFormat.d.ts.map +1 -0
  57. package/dts/DateTimeFormatContext.d.ts +112 -0
  58. package/dts/DateTimeFormatContext.d.ts.map +1 -0
  59. package/dts/Email.d.ts +61 -0
  60. package/dts/Email.d.ts.map +1 -0
  61. package/dts/Integer.d.ts +123 -0
  62. package/dts/Integer.d.ts.map +1 -0
  63. package/dts/NumberBase10Format.d.ts +641 -0
  64. package/dts/NumberBase10Format.d.ts.map +1 -0
  65. package/dts/PositiveInteger.d.ts +161 -0
  66. package/dts/PositiveInteger.d.ts.map +1 -0
  67. package/dts/PositiveReal.d.ts +130 -0
  68. package/dts/PositiveReal.d.ts.map +1 -0
  69. package/dts/Real.d.ts +102 -0
  70. package/dts/Real.d.ts.map +1 -0
  71. package/dts/RoundingMode.d.ts +72 -0
  72. package/dts/RoundingMode.d.ts.map +1 -0
  73. package/dts/RoundingOption.d.ts +79 -0
  74. package/dts/RoundingOption.d.ts.map +1 -0
  75. package/dts/Schema.d.ts +159 -0
  76. package/dts/Schema.d.ts.map +1 -0
  77. package/dts/SemVer.d.ts +61 -0
  78. package/dts/SemVer.d.ts.map +1 -0
  79. package/dts/Template.d.ts +113 -0
  80. package/dts/Template.d.ts.map +1 -0
  81. package/dts/TemplatePart.d.ts +28 -0
  82. package/dts/TemplatePart.d.ts.map +1 -0
  83. package/dts/TemplateParts.d.ts +23 -0
  84. package/dts/TemplateParts.d.ts.map +1 -0
  85. package/dts/TemplatePlaceholder.d.ts +274 -0
  86. package/dts/TemplatePlaceholder.d.ts.map +1 -0
  87. package/dts/TemplateSeparator.d.ts +130 -0
  88. package/dts/TemplateSeparator.d.ts.map +1 -0
  89. package/dts/index.d.ts +21 -0
  90. package/dts/index.d.ts.map +1 -0
  91. package/dts/internal/Int.d.ts +6 -0
  92. package/dts/internal/Int.d.ts.map +1 -0
  93. package/dts/internal/Positive.d.ts +6 -0
  94. package/dts/internal/Positive.d.ts.map +1 -0
  95. package/esm/BigDecimal.js +9 -0
  96. package/esm/BigDecimal.js.map +1 -0
  97. package/esm/BigInt.js +27 -0
  98. package/esm/BigInt.js.map +1 -0
  99. package/esm/DateTime.js +2130 -0
  100. package/esm/DateTime.js.map +1 -0
  101. package/esm/DateTimeFormat.js +238 -0
  102. package/esm/DateTimeFormat.js.map +1 -0
  103. package/esm/DateTimeFormatContext.js +296 -0
  104. package/esm/DateTimeFormatContext.js.map +1 -0
  105. package/esm/Email.js +65 -0
  106. package/esm/Email.js.map +1 -0
  107. package/esm/Integer.js +128 -0
  108. package/esm/Integer.js.map +1 -0
  109. package/esm/NumberBase10Format.js +717 -0
  110. package/esm/NumberBase10Format.js.map +1 -0
  111. package/esm/PositiveInteger.js +164 -0
  112. package/esm/PositiveInteger.js.map +1 -0
  113. package/esm/PositiveReal.js +135 -0
  114. package/esm/PositiveReal.js.map +1 -0
  115. package/esm/Real.js +106 -0
  116. package/esm/Real.js.map +1 -0
  117. package/esm/RoundingMode.js +79 -0
  118. package/esm/RoundingMode.js.map +1 -0
  119. package/esm/RoundingOption.js +120 -0
  120. package/esm/RoundingOption.js.map +1 -0
  121. package/esm/Schema.js +203 -0
  122. package/esm/Schema.js.map +1 -0
  123. package/esm/SemVer.js +65 -0
  124. package/esm/SemVer.js.map +1 -0
  125. package/esm/Template.js +158 -0
  126. package/esm/Template.js.map +1 -0
  127. package/esm/TemplatePart.js +22 -0
  128. package/esm/TemplatePart.js.map +1 -0
  129. package/esm/TemplateParts.js +19 -0
  130. package/esm/TemplateParts.js.map +1 -0
  131. package/esm/TemplatePlaceholder.js +342 -0
  132. package/esm/TemplatePlaceholder.js.map +1 -0
  133. package/esm/TemplateSeparator.js +107 -0
  134. package/esm/TemplateSeparator.js.map +1 -0
  135. package/esm/index.js +21 -0
  136. package/esm/index.js.map +1 -0
  137. package/esm/internal/Int.js +43 -0
  138. package/esm/internal/Int.js.map +1 -0
  139. package/esm/internal/Positive.js +43 -0
  140. package/esm/internal/Positive.js.map +1 -0
  141. package/esm/package.json +3 -0
  142. package/package.json +49 -0
@@ -0,0 +1,2202 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.toLastIsoYearDay = exports.toFirstYearDay = exports.toFirstMonthDay = exports.toFirstIsoYearDay = exports.toEffectDateTime = exports.toDate = exports.timestamp = exports.setZoneOffsetKeepTimestampOrThrow = exports.setZoneOffsetKeepTimestamp = exports.setZoneOffsetKeepPartsOrThrow = exports.setZoneOffsetKeepParts = exports.setYearOrThrow = exports.setYear = exports.setWeekdayOrThrow = exports.setWeekday = exports.setSecondOrThrow = exports.setSecond = exports.setOrdinalDayOrThrow = exports.setOrdinalDay = exports.setMonthOrThrow = exports.setMonthDayOrThrow = exports.setMonthDay = exports.setMonth = exports.setMinuteOrThrow = exports.setMinute = exports.setMillisecondOrThrow = exports.setMillisecond = exports.setMeridiem = exports.setIsoYearOrThrow = exports.setIsoYear = exports.setIsoWeekOrThrow = exports.setIsoWeek = exports.setHour23OrThrow = exports.setHour23 = exports.setHour11OrThrow = exports.setHour11 = exports.offsetYearsOrThrow = exports.offsetYears = exports.offsetSecondsOrThrow = exports.offsetSeconds = exports.offsetMonthsOrThrow = exports.offsetMonths = exports.offsetMinutesOrThrow = exports.offsetMinutes = exports.offsetMillisecondsOrThrow = exports.offsetMilliseconds = exports.offsetIsoYearsOrThrow = exports.offsetIsoYears = exports.offsetHoursOrThrow = exports.offsetHours = exports.offsetDaysOrThrow = exports.offsetDays = exports.now = exports.moduleTag = exports.isoYearIsLong = exports.isLastYearDay = exports.isLastMonthDay = exports.isLastIsoYearDay = exports.isFirstYearDay = exports.isFirstMonthDay = exports.isFirstIsoYearDay = exports.has = exports.getZoneSecond = exports.getZoneMinute = exports.getZoneHour = exports.getYear = exports.getWeekday = exports.getSecond = exports.getOrdinalDay = exports.getMonthDay = exports.getMonth = exports.getMinute = exports.getMillisecond = exports.getMeridiem = exports.getIsoYear = exports.getIsoWeek = exports.getIsoString = exports.getHour23 = exports.getHour11 = exports.fromTimestampOrThrow = exports.fromTimestamp = exports.fromPartsOrThrow = exports.fromParts = exports.fromEffectDateTime = exports.fromDate = exports.equivalence = exports.WEEK_MS = exports.SHORT_YEAR_MS = exports.SECOND_MS = exports.MIN_TIMESTAMP = exports.MIN_FULL_YEAR = exports.MINUTE_MS = exports.MAX_TIMESTAMP = exports.MAX_FULL_YEAR = exports.LONG_YEAR_MS = exports.LOCAL_TIME_ZONE_OFFSET = exports.LEAP_YEAR_MS = exports.HOUR_MS = exports.DAY_MS = exports.COMMON_YEAR_MS = void 0;
7
+ exports.yearIsLeap = exports.toLastYearDay = exports.toLastMonthDay = exports.toLastIsoYearWeek = void 0;
8
+ var _effectLib = /*#__PURE__*/require("@parischap/effect-lib");
9
+ var _effect = /*#__PURE__*/require("effect");
10
+ var CVNumberBase10Format = /*#__PURE__*/_interopRequireWildcard(/*#__PURE__*/require("./NumberBase10Format.js"));
11
+ var CVTemplate = /*#__PURE__*/_interopRequireWildcard(/*#__PURE__*/require("./Template.js"));
12
+ var CVTemplatePlaceholder = /*#__PURE__*/_interopRequireWildcard(/*#__PURE__*/require("./TemplatePlaceholder.js"));
13
+ var CVTemplateSeparator = /*#__PURE__*/_interopRequireWildcard(/*#__PURE__*/require("./TemplateSeparator.js"));
14
+ function _interopRequireWildcard(e, t) {
15
+ if ("function" == typeof WeakMap) var r = new WeakMap(),
16
+ n = new WeakMap();
17
+ return (_interopRequireWildcard = function (e, t) {
18
+ if (!t && e && e.__esModule) return e;
19
+ var o,
20
+ i,
21
+ f = {
22
+ __proto__: null,
23
+ default: e
24
+ };
25
+ if (null === e || "object" != typeof e && "function" != typeof e) return f;
26
+ if (o = t ? n : r) {
27
+ if (o.has(e)) return o.get(e);
28
+ o.set(e, f);
29
+ }
30
+ for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]);
31
+ return f;
32
+ })(e, t);
33
+ }
34
+ /**
35
+ * This module implements an immutable DateTime object.
36
+ *
37
+ * DateTime objects keep an internal state. But all provided functions look pure insofar as they
38
+ * will always yield the same result whatever the state the object is in. The state is only used to
39
+ * improve performance but does not alter the results.
40
+ *
41
+ * Unlike the Javascript Date objects and the Effect DateTime objects, DateTime objects handle both
42
+ * the Gregorian and Iso calendars. So you can easily get/set the iso year and iso week of a
43
+ * DateTime object.
44
+ *
45
+ * A DateTime object has a `zoneOffset` which is the difference in hours between the time in the
46
+ * local zone and UTC time (e.g zoneOffset=1 for timezone +1:00). All the data in a DateTime object
47
+ * is `zoneOffset-dependent`, except `timestamp`. An important thing to note is that a DateTime
48
+ * object with a timestamp t and a zoneOffset zo has exactly the same date parts (year, ordinalDay,
49
+ * month, monthDay, isoYear...) as a DateTime object with a timestamp t+zox3600 and a 0 zoneOffset.
50
+ * That's the reason for the _zonedTimestamp field which is equal to t+zox3600. All calculations are
51
+ * performed UTC using _zonedTimestamp instead of timestamp.
52
+ */
53
+
54
+ /**
55
+ * Module tag
56
+ *
57
+ * @category Module markers
58
+ */
59
+ const moduleTag = exports.moduleTag = '@parischap/conversions/DateTime/';
60
+ const _TypeId = /*#__PURE__*/Symbol.for(moduleTag);
61
+ /**
62
+ * Duration of a second in milliseconds
63
+ *
64
+ * @category Constants
65
+ */
66
+ const SECOND_MS = exports.SECOND_MS = 1_000;
67
+ /**
68
+ * Duration of a minute in milliseconds
69
+ *
70
+ * @category Constants
71
+ */
72
+ const MINUTE_MS = exports.MINUTE_MS = 60 * SECOND_MS;
73
+ /**
74
+ * Duration of an hour in milliseconds
75
+ *
76
+ * @category Constants
77
+ */
78
+ const HOUR_MS = exports.HOUR_MS = 60 * MINUTE_MS;
79
+ /**
80
+ * Duration of a day in milliseconds
81
+ *
82
+ * @category Constants
83
+ */
84
+ const DAY_MS = exports.DAY_MS = 24 * HOUR_MS;
85
+ /**
86
+ * Duration of a week in milliseconds
87
+ *
88
+ * @category Constants
89
+ */
90
+ const WEEK_MS = exports.WEEK_MS = 7 * DAY_MS;
91
+ /**
92
+ * Duration of a normal year in milliseconds
93
+ *
94
+ * @category Constants
95
+ */
96
+ const COMMON_YEAR_MS = exports.COMMON_YEAR_MS = 365 * DAY_MS;
97
+ /**
98
+ * Duration of a leap year in milliseconds
99
+ *
100
+ * @category Constants
101
+ */
102
+ const LEAP_YEAR_MS = exports.LEAP_YEAR_MS = COMMON_YEAR_MS + DAY_MS;
103
+ /**
104
+ * Duration of a short iso year in milliseconds
105
+ *
106
+ * @category Constants
107
+ */
108
+ const SHORT_YEAR_MS = exports.SHORT_YEAR_MS = 52 * WEEK_MS;
109
+ /**
110
+ * Duration of a long iso year in milliseconds
111
+ *
112
+ * @category Constants
113
+ */
114
+ const LONG_YEAR_MS = exports.LONG_YEAR_MS = SHORT_YEAR_MS + WEEK_MS;
115
+ /**
116
+ * Local time zone offset in hours of the machine on which this code runs. The value is calculated
117
+ * once at startup.
118
+ *
119
+ * @category Constants
120
+ */
121
+ const LOCAL_TIME_ZONE_OFFSET = exports.LOCAL_TIME_ZONE_OFFSET = -(/*#__PURE__*/new Date().getTimezoneOffset() / 60);
122
+ /**
123
+ * Namespace for the data relative to a Month
124
+ *
125
+ * @category Models
126
+ */
127
+ const MAX_FULL_YEAR_OFFSET = 273_790;
128
+ /**
129
+ * Maximal usable year (ECMA-262)
130
+ *
131
+ * @category Constants
132
+ */
133
+ const MAX_FULL_YEAR = exports.MAX_FULL_YEAR = 1970 + MAX_FULL_YEAR_OFFSET;
134
+ /**
135
+ * Minimal usable year (ECMA-262)
136
+ *
137
+ * @category Constants
138
+ */
139
+ const MIN_FULL_YEAR = exports.MIN_FULL_YEAR = 1970 - MAX_FULL_YEAR_OFFSET - 1;
140
+ /**
141
+ * Maximal usable timestamp (ECMA-262)
142
+ *
143
+ * @category Constants
144
+ */
145
+ const MAX_TIMESTAMP = exports.MAX_TIMESTAMP = 8_640_000_000_000_000;
146
+ /**
147
+ * Minimal usable timestamp (ECMA-262)
148
+ *
149
+ * @category Constants
150
+ */
151
+ const MIN_TIMESTAMP = exports.MIN_TIMESTAMP = -MAX_TIMESTAMP;
152
+ const _integer = CVNumberBase10Format.integer;
153
+ const _params = {
154
+ fillChar: '0',
155
+ numberBase10Format: _integer
156
+ };
157
+ const _fixedLengthToReal = CVTemplatePlaceholder.fixedLengthToReal;
158
+ const _sep = CVTemplateSeparator;
159
+ /**
160
+ * Namespace for the a Gregorian date
161
+ *
162
+ * It is important to note that the Gregorian calendar is periodic with a 400-year period as far as
163
+ * leap years are concerned. Leap years are those that can be divided by 4, except those that can be
164
+ * divided by 100 except those that can be divided by 400. So 2100, 2200, 2300 are not leap years.
165
+ * But 2400 is a leap year.
166
+ *
167
+ * @category Models
168
+ */
169
+ var GregorianDate;
170
+ (function (GregorianDate) {
171
+ const _namespaceTag = moduleTag + 'GregorianDate/';
172
+ const _TypeId = /*#__PURE__*/Symbol.for(_namespaceTag);
173
+ /**
174
+ * Duration in milliseconds of a four-year period containing a leap year
175
+ *
176
+ * @category Constants
177
+ */
178
+ const FOUR_YEARS_MS = 3 * COMMON_YEAR_MS + LEAP_YEAR_MS;
179
+ /**
180
+ * Duration in milliseconds of a 100-year period that has a leap year every 4th year except the
181
+ * 100th year
182
+ *
183
+ * @category Constants
184
+ */
185
+ const HUNDRED_YEARS_MS = 25 * FOUR_YEARS_MS - DAY_MS;
186
+ /**
187
+ * Duration in milliseconds of a 400-year period that has a leap year every 4th year except the
188
+ * 100th year. But the 400th year is a leap year
189
+ *
190
+ * @category Constants
191
+ */
192
+ const FOUR_HUNDRED_YEARS_MS = 4 * HUNDRED_YEARS_MS + DAY_MS;
193
+ /** Timestamp of 1/1/2001 00:00:00:000+0:00 */
194
+ const YEAR_START_2001_MS = 978_307_200_000;
195
+ /** Number of days in each month of a leap year */
196
+ const LEAP_YEAR_DAYS_IN_MONTH = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
197
+ /** Number of days in each month of a leap year */
198
+ const COMMON_YEAR_DAYS_IN_MONTH = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
199
+ /**
200
+ * Type guard
201
+ *
202
+ * @category Guards
203
+ */
204
+ GregorianDate.has = u => _effect.Predicate.hasProperty(u, _TypeId);
205
+ /** Proto */
206
+ const proto = {
207
+ [_TypeId]: _TypeId,
208
+ ... /*#__PURE__*/_effectLib.MInspectable.BaseProto(_namespaceTag),
209
+ ..._effectLib.MPipeable.BaseProto
210
+ };
211
+ /** Constructor */
212
+ const _make = params => _effectLib.MTypes.objectFromDataAndProto(proto, params);
213
+ const _makeWithInternals = params => _make({
214
+ ...params,
215
+ _daysInMonth: params.yearIsLeap ? LEAP_YEAR_DAYS_IN_MONTH : COMMON_YEAR_DAYS_IN_MONTH
216
+ });
217
+ /**
218
+ * Constructs a GregorianDate from a timestamp
219
+ *
220
+ * @category Constructors
221
+ */
222
+ GregorianDate.fromTimestamp = timestamp => {
223
+ /**
224
+ * The 100-year periods [2001, 2100], [2101, 2200], and [2201, 2300] all last HUNDRED_YEARS_MS.
225
+ * Those three 100-year periods can be divided in 24 periods that last FOUR_YEARS_MS
226
+ * (4xCOMMON_YEAR_MS + DAY_MS) and a final 4-year period that lasts FOUR_YEARS_MS - DAY_MS
227
+ * (4xCOMMON_YEAR_MS).
228
+ *
229
+ * The 100-year period [2301, 2400] lasts HUNDRED_YEARS_MS + DAY_MS. This period can be divided
230
+ * in 25 periods that last FOUR_YEARS_MS (4xCOMMON_YEAR_MS + DAY_MS).
231
+ */
232
+ const offset2001 = timestamp - YEAR_START_2001_MS;
233
+ const q400Years = Math.floor(offset2001 / FOUR_HUNDRED_YEARS_MS);
234
+ const offset400Years = q400Years * FOUR_HUNDRED_YEARS_MS;
235
+ const r400Years = offset2001 - offset400Years;
236
+ // q100Years is equal to 4 on the last day of the 400-year period.
237
+ const q100Years = Math.min(3, Math.floor(r400Years / HUNDRED_YEARS_MS));
238
+ const offset100Years = q100Years * HUNDRED_YEARS_MS;
239
+ // r100Years is superior to HUNDRED_YEARS_MS on the last day of the 400-year period
240
+ const r100Years = r400Years - offset100Years;
241
+ const q4Years = Math.floor(r100Years / FOUR_YEARS_MS);
242
+ const offset4Years = q4Years * FOUR_YEARS_MS;
243
+ const r4Years = r100Years - offset4Years;
244
+ // q1Year is equal to 4 on the last day of each 4-year period except the last day of years 2100, 2200 and 2300.
245
+ const q1Year = Math.min(3, Math.floor(r4Years / COMMON_YEAR_MS));
246
+ const offset1Year = q1Year * COMMON_YEAR_MS;
247
+ const yearIsLeap = q1Year === 3 && (q4Years !== 24 || q100Years === 3);
248
+ const yearStartTimestamp = YEAR_START_2001_MS + offset400Years + offset100Years + offset4Years + offset1Year;
249
+ return _makeWithInternals({
250
+ timestamp,
251
+ year: 2001 + 400 * q400Years + 100 * q100Years + 4 * q4Years + q1Year,
252
+ yearIsLeap,
253
+ yearStartTimestamp,
254
+ ordinalDay: Math.floor((timestamp - yearStartTimestamp) / DAY_MS) + 1,
255
+ month: _effect.Option.none(),
256
+ monthDay: _effect.Option.none()
257
+ });
258
+ };
259
+ /**
260
+ * If possible, returns a new GregorianDate having `year` set to `year` and the same `month` and
261
+ * `monthDay` as `self`. Returns a left of an error otherwise. `year` must be an integer comprised
262
+ * in the range [MIN_FULL_YEAR, MAX_FULL_YEAR]. If `self` represents a 29th of february, `year`
263
+ * must be a leap year.
264
+ *
265
+ * @category Setters
266
+ */
267
+ GregorianDate.setYear = year => self => _effect.Either.gen(function* () {
268
+ const validatedYear = yield* (0, _effect.pipe)(year, _effectLib.MInputError.assertInRange({
269
+ min: MIN_FULL_YEAR,
270
+ max: MAX_FULL_YEAR,
271
+ minIncluded: true,
272
+ maxIncluded: true,
273
+ offset: 0,
274
+ name: "'year'"
275
+ }));
276
+ const offset2001 = validatedYear - 2001;
277
+ const q400Years = Math.floor(offset2001 / 400);
278
+ const r400Years = offset2001 - 400 * q400Years;
279
+ const q100Years = Math.floor(r400Years / 100);
280
+ const r100Years = r400Years - 100 * q100Years;
281
+ const q4Years = Math.floor(r100Years / 4);
282
+ const r4Years = r100Years - 4 * q4Years;
283
+ const yearIsLeap = r4Years === 3 && (r100Years !== 99 || r400Years === 399);
284
+ const yearStartTimestamp = YEAR_START_2001_MS + q400Years * FOUR_HUNDRED_YEARS_MS + q100Years * HUNDRED_YEARS_MS + q4Years * FOUR_YEARS_MS + r4Years * COMMON_YEAR_MS;
285
+ const selfYearIsLeap = self.yearIsLeap;
286
+ const selfOrdinalDay = self.ordinalDay;
287
+ const ordinalDayOffset = yield* selfYearIsLeap === yearIsLeap || selfOrdinalDay < 60 ? _effect.Either.right(0) : selfYearIsLeap ? selfOrdinalDay === 60 ? _effect.Either.left(new _effectLib.MInputError.Type({
288
+ message: `No February 29th on year ${year} which is not a leap year`
289
+ })) : _effect.Either.right(-1) : _effect.Either.right(1);
290
+ return _makeWithInternals({
291
+ timestamp: self.timestamp + yearStartTimestamp - self.yearStartTimestamp + ordinalDayOffset * DAY_MS,
292
+ year: validatedYear,
293
+ yearIsLeap,
294
+ yearStartTimestamp,
295
+ ordinalDay: selfOrdinalDay + ordinalDayOffset,
296
+ month: self.month,
297
+ monthDay: self.monthDay
298
+ });
299
+ });
300
+ /**
301
+ * If possible, returns a new GregorianDate having `month` set to `month` and the same `year` and
302
+ * `monthDay` as `self`. Returns a left of an error otherwise. `month` must be an integer greater
303
+ * than or equal to 1 (January) and less than or equal to 12 (December). `month` must also have at
304
+ * least `monthDay` days.
305
+ *
306
+ * @category Setters
307
+ */
308
+ GregorianDate.setMonth = month => self => _effect.Either.gen(function* () {
309
+ const validatedMonth = yield* (0, _effect.pipe)(month, _effectLib.MInputError.assertInRange({
310
+ min: 1,
311
+ max: 12,
312
+ minIncluded: true,
313
+ maxIncluded: true,
314
+ offset: 0,
315
+ name: "'month'"
316
+ }));
317
+ const monthDay = yield* (0, _effect.pipe)(self, GregorianDate.getMonthDay, _effect.Either.liftPredicate(_effect.Predicate.or(_effect.Number.lessThanOrEqualTo(28), _effect.Number.lessThanOrEqualTo(GregorianDate.getNumberOfDaysInMonth(validatedMonth)(self))), selfMonthDay => new _effectLib.MInputError.Type({
318
+ message: `Month ${month} of year ${self.year} does not have ${selfMonthDay} days`
319
+ })));
320
+ const ordinalDay = GregorianDate.getMonthOffset(validatedMonth)(self) + monthDay;
321
+ return (0, _effect.pipe)(self, _effectLib.MStruct.append({
322
+ timestamp: self.timestamp + (ordinalDay - self.ordinalDay) * DAY_MS,
323
+ ordinalDay,
324
+ month: _effect.Option.some(validatedMonth)
325
+ }), _make);
326
+ });
327
+ /**
328
+ * If possible, returns a new GregorianDate having `monthDay` set to `monthDay` and the same
329
+ * `year` and `month` as `self`. Returns a left of an error otherwise. `monthDay` must be an
330
+ * integer greater than or equal to 1 and less than or equal to the number of days in the current
331
+ * month.
332
+ *
333
+ * @category Setters
334
+ */
335
+ GregorianDate.setMonthDay = monthDay => self => _effect.Either.gen(function* () {
336
+ const validatedMonthDay = monthDay <= 28 ? monthDay : yield* (0, _effect.pipe)(monthDay, _effectLib.MInputError.assertInRange({
337
+ min: 1,
338
+ max: GregorianDate.getNumberOfDaysInMonth(GregorianDate.getMonth(self))(self),
339
+ minIncluded: true,
340
+ maxIncluded: true,
341
+ offset: 0,
342
+ name: "'monthDay'"
343
+ }));
344
+ const ordinalDayOffset = validatedMonthDay - GregorianDate.getMonthDay(self);
345
+ return (0, _effect.pipe)(self, _effectLib.MStruct.append({
346
+ timestamp: self.timestamp + ordinalDayOffset * DAY_MS,
347
+ ordinalDay: self.ordinalDay + ordinalDayOffset,
348
+ monthDay: _effect.Option.some(validatedMonthDay)
349
+ }), _make);
350
+ });
351
+ /**
352
+ * If possible, returns a new GregorianDate having `ordinalDay` set to `ordinalDay` and the same
353
+ * `year` as `self`. Returns a left of an error otherwise. `ordinalDay` must be an integer greater
354
+ * than or equal to 1 and less than or equal to the number of days in the current year
355
+ *
356
+ * @category Setters
357
+ */
358
+ GregorianDate.setOrdinalDay = ordinalDay => self => _effect.Either.gen(function* () {
359
+ const validatedOrdinalDay = yield* (0, _effect.pipe)(ordinalDay, _effectLib.MInputError.assertInRange({
360
+ min: 1,
361
+ max: GregorianDate.getYearDurationInDays(self),
362
+ minIncluded: true,
363
+ maxIncluded: true,
364
+ offset: 0,
365
+ name: "'ordinalDay'"
366
+ }));
367
+ return (0, _effect.pipe)(self, _effectLib.MStruct.append({
368
+ timestamp: self.timestamp + (validatedOrdinalDay - self.ordinalDay) * DAY_MS,
369
+ ordinalDay: validatedOrdinalDay,
370
+ month: _effect.Option.none(),
371
+ monthDay: _effect.Option.none()
372
+ }), _make);
373
+ });
374
+ /**
375
+ * Returns the `timestamp` property of `self`
376
+ *
377
+ * @category Destructors
378
+ */
379
+ GregorianDate.timestamp = /*#__PURE__*/_effect.Struct.get('timestamp');
380
+ /**
381
+ * Returns the `year` property of `self`
382
+ *
383
+ * @category Destructors
384
+ */
385
+ GregorianDate.year = /*#__PURE__*/_effect.Struct.get('year');
386
+ /**
387
+ * Returns the `yearIsLeap` property of `self`
388
+ *
389
+ * @category Destructors
390
+ */
391
+ GregorianDate.yearIsLeap = /*#__PURE__*/_effect.Struct.get('yearIsLeap');
392
+ /**
393
+ * Returns the `yearStartTimestamp` property of `self`
394
+ *
395
+ * @category Destructors
396
+ */
397
+ GregorianDate.yearStartTimestamp = /*#__PURE__*/_effect.Struct.get('yearStartTimestamp');
398
+ /**
399
+ * Returns the `ordinalDay` property of `self`
400
+ *
401
+ * @category Destructors
402
+ */
403
+ GregorianDate.ordinalDay = /*#__PURE__*/_effect.Struct.get('ordinalDay');
404
+ /**
405
+ * Returns the `month` of `self`
406
+ *
407
+ * @category Destructors
408
+ */
409
+ GregorianDate.getMonth = self => (0, _effect.pipe)(self.month, _effect.Option.getOrElse(() => {
410
+ const ordinalDay = self.ordinalDay;
411
+ const yearIsLeap = self.yearIsLeap;
412
+ const adjustedOrdinalDay = ordinalDay - (yearIsLeap ? 1 : 0);
413
+ const result = ordinalDay <= 31 ? 1 : adjustedOrdinalDay <= 59 ? 2 : Math.floor((adjustedOrdinalDay - 59) / 30.6 - 0.018) + 3;
414
+ /* eslint-disable-next-line functional/immutable-data, functional/no-expression-statements */
415
+ self.month = _effect.Option.some(result);
416
+ return result;
417
+ }));
418
+ /**
419
+ * Returns the `monthDay` of `self`
420
+ *
421
+ * @category Destructors
422
+ */
423
+ GregorianDate.getMonthDay = self => (0, _effect.pipe)(self.monthDay, _effect.Option.getOrElse(() => {
424
+ const result = self.ordinalDay - GregorianDate.getMonthOffset(GregorianDate.getMonth(self))(self);
425
+ /* eslint-disable-next-line functional/immutable-data, functional/no-expression-statements */
426
+ self.monthDay = _effect.Option.some(result);
427
+ return result;
428
+ }));
429
+ /**
430
+ * Returns the duration of the year described by `self` in milliseconds
431
+ *
432
+ * @category Destructors
433
+ */
434
+ GregorianDate.getYearDurationInMs = self => self.yearIsLeap ? LEAP_YEAR_MS : COMMON_YEAR_MS;
435
+ /**
436
+ * Returns the duration of the year described by `self` in days
437
+ *
438
+ * @category Destructors
439
+ */
440
+ GregorianDate.getYearDurationInDays = self => self.yearIsLeap ? 366 : 365;
441
+ /**
442
+ * Returns the number of days from the start of the `year` property of `self` to the day before
443
+ * the first day of month `month`
444
+ *
445
+ * @category Destructors
446
+ */
447
+ GregorianDate.getMonthOffset = month => self => month === 1 ? 0 : month === 2 ? 31 : 30 * (month - 1) + Math.floor(0.6 * (month + 1)) - (self.yearIsLeap ? 2 : 3);
448
+ /**
449
+ * Returns the number of days of month `month` of the `year` property of `self`
450
+ *
451
+ * @category Destructors
452
+ */
453
+ GregorianDate.getNumberOfDaysInMonth = month => (0, _effect.flow)(_effect.Struct.get('_daysInMonth'), _effectLib.MArray.unsafeGet(month - 1));
454
+ const _formatter = /*#__PURE__*/(0, _effect.flow)(/*#__PURE__*/CVTemplate.toFormatter(/*#__PURE__*/CVTemplate.make(/*#__PURE__*/_fixedLengthToReal({
455
+ ..._params,
456
+ name: 'year',
457
+ length: 4
458
+ }), _sep.hyphen, /*#__PURE__*/_fixedLengthToReal({
459
+ ..._params,
460
+ name: 'month',
461
+ length: 2
462
+ }), _sep.hyphen, /*#__PURE__*/_fixedLengthToReal({
463
+ ..._params,
464
+ name: 'monthDay',
465
+ length: 2
466
+ }))), /*#__PURE__*/_effect.Either.getOrThrowWith(_effect.Function.identity));
467
+ /**
468
+ * Returns the ISO representation of this Gregorian Date
469
+ *
470
+ * @category Destructors
471
+ */
472
+ GregorianDate.getIsoString = /*#__PURE__*/(0, _effect.flow)(/*#__PURE__*/_effectLib.MStruct.enrichWith({
473
+ month: GregorianDate.getMonth,
474
+ monthDay: GregorianDate.getMonthDay
475
+ }), _formatter);
476
+ })(GregorianDate || (GregorianDate = {}));
477
+ /**
478
+ * Namespace for an IsoDate.
479
+ *
480
+ * An iso year starts on the first day of the first iso week. An iso week starts on a monday and
481
+ * ends on a sunday. The first iso week of the year is the one that contains January 4th (see
482
+ * Wikipedia).
483
+ *
484
+ * @category Models
485
+ */
486
+ var IsoDate;
487
+ (function (IsoDate) {
488
+ const _namespaceTag = moduleTag + 'IsoDate/';
489
+ const _TypeId = /*#__PURE__*/Symbol.for(_namespaceTag);
490
+ /**
491
+ * Duration in milliseconds of a 6-iso-year period comprised of 1 long year and 5 short years (see
492
+ * Wikipedia)
493
+ *
494
+ * @category Constants
495
+ */
496
+ const SIX_YEARS_MS = LONG_YEAR_MS + 5 * SHORT_YEAR_MS;
497
+ /**
498
+ * Duration in milliseconds of an 11-iso-year period comprised of 2 long years and 9 short years
499
+ * (see Wikipedia)
500
+ *
501
+ * @category Constants
502
+ */
503
+ const ELEVEN_YEARS_MS = 2 * LONG_YEAR_MS + 9 * SHORT_YEAR_MS;
504
+ /**
505
+ * Duration in milliseconds of a 28-iso-year period comprised of 5 long years and 23 short years
506
+ * (see Wikipedia)
507
+ *
508
+ * @category Constants
509
+ */
510
+ const TWENTY_EIGHT_YEARS_MS = 5 * LONG_YEAR_MS + 23 * SHORT_YEAR_MS;
511
+ /**
512
+ * Duration in milliseconds of a 96-iso-year period comprised of 17 long years and 79 short years
513
+ * (see Wikipedia)
514
+ *
515
+ * @category Constants
516
+ */
517
+ const NINETY_SIX_YEARS_MS = 17 * LONG_YEAR_MS + 79 * SHORT_YEAR_MS;
518
+ /**
519
+ * Duration in milliseconds of a 100-iso-year period comprised of 18 long years and 82 short years
520
+ * (see Wikipedia)
521
+ *
522
+ * @category Constants
523
+ */
524
+ const ONE_HUNDRED_YEARS_MS = 18 * LONG_YEAR_MS + 82 * SHORT_YEAR_MS;
525
+ /**
526
+ * Duration in milliseconds of a 400-iso-year period comprised of 71 long years and 329 short
527
+ * years (see Wikipedia)
528
+ *
529
+ * @category Constants
530
+ */
531
+ const FOUR_HUNDRED_YEARS_MS = 71 * LONG_YEAR_MS + 329 * SHORT_YEAR_MS;
532
+ /**
533
+ * Timestamp of 03/01/2000 00:00:00:000+0:00
534
+ *
535
+ * @category Constants
536
+ */
537
+ const YEAR_START_2000_MS = 946_857_600_000;
538
+ /**
539
+ * Timestamp of 04/01/2010 00:00:00:000+0:00
540
+ *
541
+ * @category Constants
542
+ */
543
+ const YEAR_START_2010_MS = 1_262_563_200_000;
544
+ /**
545
+ * Type guard
546
+ *
547
+ * @category Guards
548
+ */
549
+ IsoDate.has = u => _effect.Predicate.hasProperty(u, _TypeId);
550
+ /** Proto */
551
+ const proto = {
552
+ [_TypeId]: _TypeId,
553
+ ... /*#__PURE__*/_effectLib.MInspectable.BaseProto(_namespaceTag),
554
+ ..._effectLib.MPipeable.BaseProto
555
+ };
556
+ /** Constructor */
557
+ const _make = params => _effectLib.MTypes.objectFromDataAndProto(proto, params);
558
+ /**
559
+ * Constructs an IsoDate from a timestamp
560
+ *
561
+ * @category Constructors
562
+ */
563
+ IsoDate.fromTimestamp = timestamp => {
564
+ const offset = timestamp - YEAR_START_2000_MS;
565
+ const q400Years = Math.floor(offset / FOUR_HUNDRED_YEARS_MS);
566
+ const r400Years = offset - q400Years * FOUR_HUNDRED_YEARS_MS;
567
+ // The second one-hundred year period is a week shorter because it has 17 long years instead of 18
568
+ // Also the hundred-th year must be put in the first one-hundred year period because it is not long
569
+ const q100Years = r400Years < ONE_HUNDRED_YEARS_MS + SHORT_YEAR_MS ? 0 : Math.floor((r400Years + WEEK_MS) / ONE_HUNDRED_YEARS_MS);
570
+ const adjustedR400Years = r400Years - q100Years * NINETY_SIX_YEARS_MS + SHORT_YEAR_MS;
571
+ const q28Years = Math.floor(adjustedR400Years / TWENTY_EIGHT_YEARS_MS);
572
+ const r28Years = adjustedR400Years - q28Years * TWENTY_EIGHT_YEARS_MS;
573
+ const adjustedR28Years = r28Years - ELEVEN_YEARS_MS;
574
+ const q11Years = Math.floor(adjustedR28Years / ELEVEN_YEARS_MS);
575
+ const r11Years = adjustedR28Years - q11Years * ELEVEN_YEARS_MS;
576
+ const q6Years = Math.floor(r11Years / SIX_YEARS_MS);
577
+ const r6Years = r11Years - q6Years * SIX_YEARS_MS;
578
+ const isFirstSixYearPeriod = q6Years === 0;
579
+ const q1Year = Math.min(Math.floor(r6Years / SHORT_YEAR_MS), isFirstSixYearPeriod ? 5 : 4);
580
+ //console.log(q400Years, q100Years, q28Years, q11Years, q6Years, q1Year);
581
+ return _make({
582
+ timestamp,
583
+ year: 2010 + q400Years * 400 + q100Years * 96 + q28Years * 28 + q11Years * 11 + q6Years * 6 + q1Year,
584
+ yearStartTimestamp: YEAR_START_2010_MS + q400Years * FOUR_HUNDRED_YEARS_MS + q100Years * NINETY_SIX_YEARS_MS + q28Years * TWENTY_EIGHT_YEARS_MS + q11Years * ELEVEN_YEARS_MS + q6Years * SIX_YEARS_MS + q1Year * SHORT_YEAR_MS,
585
+ yearIsLong: isFirstSixYearPeriod && q1Year == 5 || !isFirstSixYearPeriod && q1Year == 4,
586
+ isoWeek: _effect.Option.none(),
587
+ weekday: _effect.Option.none()
588
+ });
589
+ };
590
+ /**
591
+ * Constructs an IsoDate from a GregorianDate
592
+ *
593
+ * @category Constructors
594
+ */
595
+ IsoDate.fromGregorianDate = gregorianDate => {
596
+ // 0 is friday, 6 is thursday
597
+ const yearStartWeekday = _effectLib.MNumber.intModulo(7)(Math.floor((gregorianDate.yearStartTimestamp - DAY_MS) / DAY_MS));
598
+ const yearIsLeap = gregorianDate.yearIsLeap;
599
+ const minOrdinalDayIndex = 3 - yearStartWeekday;
600
+ const ordinalDay = gregorianDate.ordinalDay;
601
+ if (ordinalDay <= minOrdinalDayIndex) {
602
+ const year = gregorianDate.year - 1;
603
+ const yearIsLong = yearStartWeekday === 0 || yearStartWeekday === 1 && !yearIsLeap && (year % 4 == 0 && year % 100 != 0 || year % 400 == 0);
604
+ return _make({
605
+ timestamp: gregorianDate.timestamp,
606
+ year,
607
+ yearStartTimestamp: gregorianDate.yearStartTimestamp + (minOrdinalDayIndex - (yearIsLong ? 371 : 364)) * DAY_MS,
608
+ yearIsLong,
609
+ isoWeek: _effect.Option.none(),
610
+ weekday: _effect.Option.none()
611
+ });
612
+ }
613
+ const yearIsLong = yearStartWeekday === 6 || yearStartWeekday === 5 && yearIsLeap;
614
+ const maxOrdinalDay = minOrdinalDayIndex + (yearIsLong ? 371 : 364);
615
+ if (ordinalDay > maxOrdinalDay) {
616
+ const year = gregorianDate.year + 1;
617
+ const yearIsLong = yearIsLeap ? yearStartWeekday === 4 : yearStartWeekday === 5 || yearStartWeekday === 4 && (year % 4 == 0 && year % 100 != 0 || year % 400 == 0);
618
+ return _make({
619
+ timestamp: gregorianDate.timestamp,
620
+ year,
621
+ yearStartTimestamp: gregorianDate.yearStartTimestamp + maxOrdinalDay * DAY_MS,
622
+ yearIsLong,
623
+ isoWeek: _effect.Option.none(),
624
+ weekday: _effect.Option.none()
625
+ });
626
+ }
627
+ return _make({
628
+ timestamp: gregorianDate.timestamp,
629
+ year: gregorianDate.year,
630
+ yearStartTimestamp: gregorianDate.yearStartTimestamp + minOrdinalDayIndex * DAY_MS,
631
+ yearIsLong,
632
+ isoWeek: _effect.Option.none(),
633
+ weekday: _effect.Option.none()
634
+ });
635
+ };
636
+ /**
637
+ * If possible, returns a new IsoDate having `year` set to `year` and the same `isoWeek` and
638
+ * `weekday` as `self`. Returns a left of an error otherwise. `year` must be an integer comprised
639
+ * in the range [MIN_FULL_YEAR, MAX_FULL_YEAR]. If the isoWeek of `self` is equal to 53, `year`
640
+ * must be a long year.
641
+ *
642
+ * @category Setters
643
+ */
644
+ IsoDate.setYear = year => self => _effect.Either.gen(function* () {
645
+ const validatedYear = yield* (0, _effect.pipe)(year, _effectLib.MInputError.assertInRange({
646
+ min: MIN_FULL_YEAR,
647
+ max: MAX_FULL_YEAR,
648
+ minIncluded: true,
649
+ maxIncluded: true,
650
+ offset: 0,
651
+ name: "'year'"
652
+ }));
653
+ const offset = validatedYear - 2000;
654
+ const q400Years = Math.floor(offset / 400);
655
+ const r400Years = offset - q400Years * 400;
656
+ // year 100 needs to be treated in the first one-hundred year period because it is not a long year
657
+ const q100Years = r400Years === 100 ? 0 : Math.floor(r400Years / 100);
658
+ const adjustedR400Years = r400Years - q100Years * 96 + 1;
659
+ const q28Years = Math.floor(adjustedR400Years / 28);
660
+ const r28Years = adjustedR400Years - q28Years * 28;
661
+ const adjustedR28Years = r28Years - 11;
662
+ const q11Years = Math.floor(adjustedR28Years / 11);
663
+ const r11Years = adjustedR28Years - q11Years * 11;
664
+ const yearStartTimestamp = YEAR_START_2010_MS + q400Years * FOUR_HUNDRED_YEARS_MS + q100Years * NINETY_SIX_YEARS_MS + q28Years * TWENTY_EIGHT_YEARS_MS + q11Years * ELEVEN_YEARS_MS + r11Years * SHORT_YEAR_MS + (r11Years > 5 ? WEEK_MS : 0);
665
+ return yield* (0, _effect.pipe)(_make({
666
+ timestamp: self.timestamp + yearStartTimestamp - self.yearStartTimestamp,
667
+ year: validatedYear,
668
+ yearStartTimestamp,
669
+ yearIsLong: r11Years === 5 || r11Years === 10,
670
+ isoWeek: _effect.Option.some(IsoDate.getIsoWeek(self)),
671
+ weekday: _effect.Option.some(IsoDate.getWeekday(self))
672
+ }), _effect.Either.liftPredicate(_effect.Predicate.or(IsoDate.yearIsLong, (0, _effect.flow)(IsoDate.getIsoWeek, _effect.Number.lessThan(53))), () => new _effectLib.MInputError.Type({
673
+ message: `No 53rd week on iso year ${year} which is not a short year`
674
+ })));
675
+ });
676
+ /**
677
+ * If possible, returns a new IsoDate having `isoWeek` set to `isoWeek` and the same `year` and
678
+ * `weekday` as `self`. Returns a left of an error otherwise. `isoWeek` must be an integer greater
679
+ * than or equal to 1 and less than or equal to the number of iso weeks in the current year.
680
+ *
681
+ * @category Setters
682
+ */
683
+ IsoDate.setIsoWeek = isoWeek => self => _effect.Either.gen(function* () {
684
+ const validatedIsoWeek = yield* (0, _effect.pipe)(isoWeek, _effectLib.MInputError.assertInRange({
685
+ min: 1,
686
+ max: IsoDate.getLastIsoWeek(self),
687
+ minIncluded: true,
688
+ maxIncluded: true,
689
+ offset: 0,
690
+ name: "'isoWeek'"
691
+ }));
692
+ const offset = validatedIsoWeek - IsoDate.getIsoWeek(self);
693
+ return (0, _effect.pipe)(self, _effectLib.MStruct.evolve({
694
+ timestamp: _effect.Number.sum(offset * WEEK_MS),
695
+ isoWeek: (0, _effect.pipe)(validatedIsoWeek, _effect.Option.some, _effect.Function.constant)
696
+ }), _make);
697
+ });
698
+ /**
699
+ * If possible, returns a new IsoDate having `weekday` set to `weekday` and the same `year` and
700
+ * `isoWeek` as `self`. Returns a left of an error otherwise. `weekday` must be an integer greater
701
+ * than or equal to 1 (monday) and less than or equal to 7 (sunday).
702
+ *
703
+ * @category Setters
704
+ */
705
+ IsoDate.setWeekday = weekday => self => _effect.Either.gen(function* () {
706
+ const validatedWeekday = yield* (0, _effect.pipe)(weekday, _effectLib.MInputError.assertInRange({
707
+ min: 1,
708
+ max: 7,
709
+ minIncluded: true,
710
+ maxIncluded: true,
711
+ offset: 0,
712
+ name: "'weekday'"
713
+ }));
714
+ const offset = validatedWeekday - IsoDate.getWeekday(self);
715
+ return (0, _effect.pipe)(self, _effectLib.MStruct.evolve({
716
+ timestamp: _effect.Number.sum(offset * DAY_MS),
717
+ weekday: (0, _effect.pipe)(validatedWeekday, _effect.Option.some, _effect.Function.constant)
718
+ }), _make);
719
+ });
720
+ /**
721
+ * Returns the `timestamp` property of `self`
722
+ *
723
+ * @category Destructors
724
+ */
725
+ IsoDate.timestamp = /*#__PURE__*/_effect.Struct.get('timestamp');
726
+ /**
727
+ * Returns the `year` property of `self`
728
+ *
729
+ * @category Destructors
730
+ */
731
+ IsoDate.year = /*#__PURE__*/_effect.Struct.get('year');
732
+ /**
733
+ * Returns the `yearStartTimestamp` property of `self`
734
+ *
735
+ * @category Destructors
736
+ */
737
+ IsoDate.yearStartTimestamp = /*#__PURE__*/_effect.Struct.get('yearStartTimestamp');
738
+ /**
739
+ * Returns the `yearIsLong` property of `self`
740
+ *
741
+ * @category Destructors
742
+ */
743
+ IsoDate.yearIsLong = /*#__PURE__*/_effect.Struct.get('yearIsLong');
744
+ /**
745
+ * Returns the `isoWeek` of `self`
746
+ *
747
+ * @category Destructors
748
+ */
749
+ IsoDate.getIsoWeek = self => (0, _effect.pipe)(self.isoWeek, _effect.Option.getOrElse(() => {
750
+ const result = Math.floor((self.timestamp - self.yearStartTimestamp) / WEEK_MS) + 1;
751
+ /* eslint-disable-next-line functional/immutable-data, functional/no-expression-statements */
752
+ self.isoWeek = _effect.Option.some(result);
753
+ return result;
754
+ }));
755
+ /**
756
+ * Returns the `weekday` of `self`
757
+ *
758
+ * @category Destructors
759
+ */
760
+ IsoDate.getWeekday = self => (0, _effect.pipe)(self.weekday, _effect.Option.getOrElse(() => {
761
+ const result = Math.floor((self.timestamp - self.yearStartTimestamp - (IsoDate.getIsoWeek(self) - 1) * WEEK_MS) / DAY_MS) + 1;
762
+ /* eslint-disable-next-line functional/immutable-data, functional/no-expression-statements */
763
+ self.weekday = _effect.Option.some(result);
764
+ return result;
765
+ }));
766
+ /**
767
+ * Returns the duration of the year described by `self` in milliseconds
768
+ *
769
+ * @category Destructors
770
+ */
771
+ IsoDate.getMsDuration = self => self.yearIsLong ? LONG_YEAR_MS : SHORT_YEAR_MS;
772
+ /**
773
+ * Returns the duration of the year described by `self` in milliseconds
774
+ *
775
+ * @category Destructors
776
+ */
777
+ IsoDate.getLastIsoWeek = self => self.yearIsLong ? 53 : 52;
778
+ const _formatter = /*#__PURE__*/(0, _effect.flow)(/*#__PURE__*/CVTemplate.toFormatter(/*#__PURE__*/CVTemplate.make(/*#__PURE__*/_fixedLengthToReal({
779
+ ..._params,
780
+ name: 'year',
781
+ length: 4
782
+ }), /*#__PURE__*/_sep.make('-W'), /*#__PURE__*/_fixedLengthToReal({
783
+ ..._params,
784
+ name: 'isoWeek',
785
+ length: 2
786
+ }), _sep.hyphen, /*#__PURE__*/_fixedLengthToReal({
787
+ ..._params,
788
+ name: 'weekday',
789
+ length: 2
790
+ }))), /*#__PURE__*/_effect.Either.getOrThrowWith(_effect.Function.identity));
791
+ /**
792
+ * Returns the ISO representation of this Gregorian Date
793
+ *
794
+ * @category Destructors
795
+ */
796
+ IsoDate.getIsoString = /*#__PURE__*/(0, _effect.flow)(/*#__PURE__*/_effectLib.MStruct.enrichWith({
797
+ isoWeek: IsoDate.getIsoWeek,
798
+ weekday: IsoDate.getWeekday
799
+ }), _formatter);
800
+ })(IsoDate || (IsoDate = {}));
801
+ /**
802
+ * Namespace for the data relative to the time
803
+ *
804
+ * @category Models
805
+ */
806
+ var Time;
807
+ (function (Time) {
808
+ const _namespaceTag = moduleTag + 'Time/';
809
+ const _TypeId = /*#__PURE__*/Symbol.for(_namespaceTag);
810
+ /**
811
+ * Type guard
812
+ *
813
+ * @category Guards
814
+ */
815
+ Time.has = u => _effect.Predicate.hasProperty(u, _TypeId);
816
+ /** Proto */
817
+ const proto = {
818
+ [_TypeId]: _TypeId,
819
+ ... /*#__PURE__*/_effectLib.MInspectable.BaseProto(_namespaceTag),
820
+ ..._effectLib.MPipeable.BaseProto
821
+ };
822
+ /** Constructor */
823
+ const _make = params => _effectLib.MTypes.objectFromDataAndProto(proto, params);
824
+ /**
825
+ * Constructs the Time that corresponds to the passed `timestampOffset` which is the number of
826
+ * milliseconds from the start of the current day
827
+ *
828
+ * @category Constructors
829
+ */
830
+ Time.fromTimestamp = timestampOffset => {
831
+ const hour23 = Math.floor(timestampOffset / HOUR_MS);
832
+ const rHour23 = timestampOffset - hour23 * HOUR_MS;
833
+ const [hour11, meridiem] = hour23 >= 12 ? [hour23 - 12, 12] : [hour23, 0];
834
+ const minute = Math.floor(rHour23 / MINUTE_MS);
835
+ const rMinute = rHour23 - minute * MINUTE_MS;
836
+ const second = Math.floor(rMinute / SECOND_MS);
837
+ return _make({
838
+ timestampOffset,
839
+ hour23,
840
+ hour11,
841
+ meridiem,
842
+ minute,
843
+ second,
844
+ millisecond: rMinute - second * SECOND_MS
845
+ });
846
+ };
847
+ /**
848
+ * If possible, returns a right of a copy of `self` with `hour23` set to `hour23`. Returns a left
849
+ * of an error otherwise. `hour23` must be an integer greater than or equal to 0 and less than or
850
+ * equal to 23
851
+ *
852
+ * @category Setters
853
+ */
854
+ Time.setHour23 = hour23 => self => _effect.Either.gen(function* () {
855
+ const validatedHour23 = yield* (0, _effect.pipe)(hour23, _effectLib.MInputError.assertInRange({
856
+ min: 0,
857
+ max: 23,
858
+ minIncluded: true,
859
+ maxIncluded: true,
860
+ offset: 0,
861
+ name: "'hour23'"
862
+ }));
863
+ const isPast12 = validatedHour23 >= 12;
864
+ return _make({
865
+ ...self,
866
+ timestampOffset: self.timestampOffset + (validatedHour23 - self.hour23) * HOUR_MS,
867
+ hour23: validatedHour23,
868
+ hour11: isPast12 ? hour23 - 12 : hour23,
869
+ meridiem: isPast12 ? 12 : 0
870
+ });
871
+ });
872
+ /**
873
+ * If possible, returns a right of a copy of `self` with `hour11` set to `hour11`. Returns a left
874
+ * of an error otherwise. `hour11` must be an integer greater than or equal to 0 and less than or
875
+ * equal to 11
876
+ *
877
+ * @category Setters
878
+ */
879
+ Time.setHour11 = hour11 => self => _effect.Either.gen(function* () {
880
+ const validatedHour11 = yield* (0, _effect.pipe)(hour11, _effectLib.MInputError.assertInRange({
881
+ min: 0,
882
+ max: 11,
883
+ minIncluded: true,
884
+ maxIncluded: true,
885
+ offset: 0,
886
+ name: "'hour11'"
887
+ }));
888
+ const validatedHour23 = self.meridiem + validatedHour11;
889
+ return _make({
890
+ ...self,
891
+ timestampOffset: self.timestampOffset + (validatedHour23 - self.hour23) * HOUR_MS,
892
+ hour23: validatedHour23,
893
+ hour11: validatedHour11
894
+ });
895
+ });
896
+ /**
897
+ * Returns a copy of `self` with `meridiem` set to `merdiem`.
898
+ *
899
+ * @category Setters
900
+ */
901
+ Time.setMeridiem = meridiem => self => {
902
+ const validatedHour23 = self.hour11 + meridiem;
903
+ return _make({
904
+ ...self,
905
+ timestampOffset: self.timestampOffset + (validatedHour23 - self.hour23) * HOUR_MS,
906
+ hour23: validatedHour23,
907
+ meridiem
908
+ });
909
+ };
910
+ /**
911
+ * If possible, returns a right of a copy of `self` with `minute` set to `minute`. Returns a left
912
+ * of an error otherwise. `minute` must be an integer greater than or equal to 0 and less than or
913
+ * equal to 59
914
+ *
915
+ * @category Setters
916
+ */
917
+ Time.setMinute = minute => self => _effect.Either.gen(function* () {
918
+ const validatedMinute = yield* (0, _effect.pipe)(minute, _effectLib.MInputError.assertInRange({
919
+ min: 0,
920
+ max: 59,
921
+ minIncluded: true,
922
+ maxIncluded: true,
923
+ offset: 0,
924
+ name: "'minute'"
925
+ }));
926
+ return _make({
927
+ ...self,
928
+ timestampOffset: self.timestampOffset + (validatedMinute - self.minute) * MINUTE_MS,
929
+ minute: validatedMinute
930
+ });
931
+ });
932
+ /**
933
+ * If possible, returns a right of a copy of `self` with `second` set to `second`. Returns a left
934
+ * of an error otherwise. `second` must be an integer greater than or equal to 0 and less than or
935
+ * equal to 59
936
+ *
937
+ * @category Setters
938
+ */
939
+ Time.setSecond = second => self => _effect.Either.gen(function* () {
940
+ const validatedSecond = yield* (0, _effect.pipe)(second, _effectLib.MInputError.assertInRange({
941
+ min: 0,
942
+ max: 59,
943
+ minIncluded: true,
944
+ maxIncluded: true,
945
+ offset: 0,
946
+ name: "'second'"
947
+ }));
948
+ return _make({
949
+ ...self,
950
+ timestampOffset: self.timestampOffset + (validatedSecond - self.second) * SECOND_MS,
951
+ second: validatedSecond
952
+ });
953
+ });
954
+ /**
955
+ * If possible, returns a right of a copy of `self` with `millisecond` set to `millisecond`.
956
+ * Returns a left of an error otherwise. `millisecond` must be an integer greater than or equal to
957
+ * 0 and less than or equal to 999
958
+ *
959
+ * @category Setters
960
+ */
961
+ Time.setMillisecond = millisecond => self => _effect.Either.gen(function* () {
962
+ const validatedMillisecond = yield* (0, _effect.pipe)(millisecond, _effectLib.MInputError.assertInRange({
963
+ min: 0,
964
+ max: 999,
965
+ minIncluded: true,
966
+ maxIncluded: true,
967
+ offset: 0,
968
+ name: "'millisecond'"
969
+ }));
970
+ return _make({
971
+ ...self,
972
+ timestampOffset: self.timestampOffset + validatedMillisecond - self.millisecond,
973
+ millisecond: validatedMillisecond
974
+ });
975
+ });
976
+ /**
977
+ * Returns the `timestampOffset` property of `self`
978
+ *
979
+ * @category Destructors
980
+ */
981
+ Time.timestampOffset = /*#__PURE__*/_effect.Struct.get('timestampOffset');
982
+ /**
983
+ * Returns the `hour23` property of `self`
984
+ *
985
+ * @category Destructors
986
+ */
987
+ Time.hour23 = /*#__PURE__*/_effect.Struct.get('hour23');
988
+ /**
989
+ * Returns the `hour11` property of `self`
990
+ *
991
+ * @category Destructors
992
+ */
993
+ Time.hour11 = /*#__PURE__*/_effect.Struct.get('hour11');
994
+ /**
995
+ * Returns the `meridiem` property of `self`
996
+ *
997
+ * @category Destructors
998
+ */
999
+ Time.meridiem = /*#__PURE__*/_effect.Struct.get('meridiem');
1000
+ /**
1001
+ * Returns the `minute` property of `self`
1002
+ *
1003
+ * @category Destructors
1004
+ */
1005
+ Time.minute = /*#__PURE__*/_effect.Struct.get('minute');
1006
+ /**
1007
+ * Returns the `second` property of `self`
1008
+ *
1009
+ * @category Destructors
1010
+ */
1011
+ Time.second = /*#__PURE__*/_effect.Struct.get('second');
1012
+ /**
1013
+ * Returns the `millisecond` property of `self`
1014
+ *
1015
+ * @category Destructors
1016
+ */
1017
+ Time.millisecond = /*#__PURE__*/_effect.Struct.get('millisecond');
1018
+ const _formatter = /*#__PURE__*/(0, _effect.flow)(/*#__PURE__*/CVTemplate.toFormatter(/*#__PURE__*/CVTemplate.make(/*#__PURE__*/_fixedLengthToReal({
1019
+ ..._params,
1020
+ name: 'hour23',
1021
+ length: 2
1022
+ }), _sep.colon, /*#__PURE__*/_fixedLengthToReal({
1023
+ ..._params,
1024
+ name: 'minute',
1025
+ length: 2
1026
+ }), _sep.colon, /*#__PURE__*/_fixedLengthToReal({
1027
+ ..._params,
1028
+ name: 'second',
1029
+ length: 2
1030
+ }), _sep.dot, /*#__PURE__*/_fixedLengthToReal({
1031
+ ..._params,
1032
+ name: 'millisecond',
1033
+ length: 3
1034
+ }))), /*#__PURE__*/_effect.Either.getOrThrowWith(_effect.Function.identity));
1035
+ /**
1036
+ * Returns the ISO representation of this Gregorian Date
1037
+ *
1038
+ * @category Destructors
1039
+ */
1040
+ Time.getIsoString = _formatter;
1041
+ })(Time || (Time = {}));
1042
+ /**
1043
+ * Namespace for the data relative to the parts of a zone offset
1044
+ *
1045
+ * @category Models
1046
+ */
1047
+ var ZoneOffsetParts;
1048
+ (function (ZoneOffsetParts) {
1049
+ const _namespaceTag = moduleTag + 'ZoneOffsetParts/';
1050
+ const _TypeId = /*#__PURE__*/Symbol.for(_namespaceTag);
1051
+ /**
1052
+ * Type guard
1053
+ *
1054
+ * @category Guards
1055
+ */
1056
+ ZoneOffsetParts.has = u => _effect.Predicate.hasProperty(u, _TypeId);
1057
+ /** Proto */
1058
+ const proto = {
1059
+ [_TypeId]: _TypeId,
1060
+ ... /*#__PURE__*/_effectLib.MInspectable.BaseProto(_namespaceTag),
1061
+ ..._effectLib.MPipeable.BaseProto
1062
+ };
1063
+ ZoneOffsetParts._make = params => _effectLib.MTypes.objectFromDataAndProto(proto, params);
1064
+ /**
1065
+ * Builds a ZoneOffsetParts from `zoneOffset`
1066
+ *
1067
+ * @category Constructors
1068
+ */
1069
+ ZoneOffsetParts.fromZoneOffset = zoneOffset => {
1070
+ const zoneHour = Math.trunc(zoneOffset);
1071
+ const minutesSeconds = Math.abs(zoneOffset - zoneHour) * 60;
1072
+ const zoneMinute = Math.trunc(minutesSeconds);
1073
+ const zoneSecond = Math.trunc((minutesSeconds - zoneMinute) * 60);
1074
+ return ZoneOffsetParts._make({
1075
+ zoneHour,
1076
+ zoneMinute,
1077
+ zoneSecond
1078
+ });
1079
+ };
1080
+ /**
1081
+ * Tries to build a ZoneOffsetParts from `zoneHour`, `zoneMinute`, `zoneSecond`. Returns a `some`
1082
+ * if successful. A `none` otherwise.
1083
+ *
1084
+ * - `zoneHour` must be greater than or equal to -12 and less than or equal to 14.
1085
+ * - `zoneMinute` must be greater than or equal to 0 and less than or equal to 59.
1086
+ * - `zoneSecond` must be greater than or equal to 0 and less than or equal to 59.
1087
+ *
1088
+ * @category Constructors
1089
+ */
1090
+ ZoneOffsetParts.fromParts = ({
1091
+ zoneHour,
1092
+ zoneMinute,
1093
+ zoneSecond
1094
+ }) => _effect.Either.gen(function* () {
1095
+ const validatedHour = yield* (0, _effect.pipe)(zoneHour, _effectLib.MInputError.assertInRange({
1096
+ min: -12,
1097
+ max: 14,
1098
+ minIncluded: true,
1099
+ maxIncluded: true,
1100
+ offset: 0,
1101
+ name: "'zoneHour'"
1102
+ }));
1103
+ const validatedMinute = yield* (0, _effect.pipe)(zoneMinute, _effectLib.MInputError.assertInRange({
1104
+ min: 0,
1105
+ max: 59,
1106
+ minIncluded: true,
1107
+ maxIncluded: true,
1108
+ offset: 0,
1109
+ name: "'zoneMinute'"
1110
+ }));
1111
+ const validatedSecond = yield* (0, _effect.pipe)(zoneSecond, _effectLib.MInputError.assertInRange({
1112
+ min: 0,
1113
+ max: 59,
1114
+ minIncluded: true,
1115
+ maxIncluded: true,
1116
+ offset: 0,
1117
+ name: "'zoneSecond'"
1118
+ }));
1119
+ return ZoneOffsetParts._make({
1120
+ zoneHour: validatedHour,
1121
+ zoneMinute: validatedMinute,
1122
+ zoneSecond: validatedSecond
1123
+ });
1124
+ });
1125
+ /**
1126
+ * Returns the `zoneHour` property of `self`
1127
+ *
1128
+ * @category Destructors
1129
+ */
1130
+ ZoneOffsetParts.zoneHour = /*#__PURE__*/_effect.Struct.get('zoneHour');
1131
+ /**
1132
+ * Returns the `zoneMinute` property of `self`
1133
+ *
1134
+ * @category Destructors
1135
+ */
1136
+ ZoneOffsetParts.zoneMinute = /*#__PURE__*/_effect.Struct.get('zoneMinute');
1137
+ /**
1138
+ * Returns the `zoneSecond` property of `self`
1139
+ *
1140
+ * @category Destructors
1141
+ */
1142
+ ZoneOffsetParts.zoneSecond = /*#__PURE__*/_effect.Struct.get('zoneSecond');
1143
+ const _formatter = /*#__PURE__*/(0, _effect.flow)(/*#__PURE__*/CVTemplate.toFormatter(/*#__PURE__*/CVTemplate.make(/*#__PURE__*/_fixedLengthToReal({
1144
+ ..._params,
1145
+ name: 'zoneHour',
1146
+ length: 3,
1147
+ numberBase10Format: /*#__PURE__*/(0, _effect.pipe)(_integer, CVNumberBase10Format.withSignDisplay)
1148
+ }), _sep.colon, /*#__PURE__*/_fixedLengthToReal({
1149
+ ..._params,
1150
+ name: 'zoneMinute',
1151
+ length: 2
1152
+ }))), /*#__PURE__*/_effect.Either.getOrThrowWith(_effect.Function.identity));
1153
+ /**
1154
+ * Returns the ISO representation of this Gregorian Date
1155
+ *
1156
+ * @category Destructors
1157
+ */
1158
+ ZoneOffsetParts.getIsoString = _formatter;
1159
+ /**
1160
+ * Returns the value of `self` expressed in hours
1161
+ *
1162
+ * @category Destructors
1163
+ */
1164
+ ZoneOffsetParts.toHour = self => {
1165
+ const hour = self.zoneHour;
1166
+ const sign = _effectLib.MNumber.sign2(hour);
1167
+ return hour + sign * (self.zoneMinute / 60 + self.zoneSecond / 3600);
1168
+ };
1169
+ })(ZoneOffsetParts || (ZoneOffsetParts = {}));
1170
+ /**
1171
+ * Type guard
1172
+ *
1173
+ * @category Guards
1174
+ */
1175
+ const has = u => _effect.Predicate.hasProperty(u, _TypeId);
1176
+ /**
1177
+ * Equivalence
1178
+ *
1179
+ * @category Equivalences
1180
+ */
1181
+ exports.has = has;
1182
+ const equivalence = (self, that) => self.timestamp === that.timestamp;
1183
+ /** Proto */
1184
+ exports.equivalence = equivalence;
1185
+ const _TypeIdHash = /*#__PURE__*/_effect.Hash.hash(_TypeId);
1186
+ const proto = {
1187
+ [_TypeId]: _TypeId,
1188
+ [_effect.Equal.symbol](that) {
1189
+ return has(that) && equivalence(this, that);
1190
+ },
1191
+ [_effect.Hash.symbol]() {
1192
+ return (0, _effect.pipe)(this.timestamp, _effect.Hash.hash, _effect.Hash.combine(_TypeIdHash), _effect.Hash.cached(this));
1193
+ },
1194
+ [_effectLib.MInspectable.IdSymbol]() {
1195
+ return getIsoString(this);
1196
+ },
1197
+ ... /*#__PURE__*/_effectLib.MInspectable.BaseProto(moduleTag),
1198
+ ..._effectLib.MPipeable.BaseProto
1199
+ };
1200
+ /** Constructor */
1201
+ const _make = params => _effectLib.MTypes.objectFromDataAndProto(proto, params);
1202
+ /**
1203
+ * Returns the ISO representation of this DateTime
1204
+ *
1205
+ * @category Destructors
1206
+ */
1207
+ const getIsoString = self => GregorianDate.getIsoString(_gregorianDate(self)) + 'T' + Time.getIsoString(_time(self)) + ZoneOffsetParts.getIsoString(_zoneOffsetParts(self));
1208
+ exports.getIsoString = getIsoString;
1209
+ const _uncalculated = {
1210
+ gregorianDate: /*#__PURE__*/_effect.Option.none(),
1211
+ isoDate: /*#__PURE__*/_effect.Option.none(),
1212
+ time: /*#__PURE__*/_effect.Option.none(),
1213
+ zoneOffsetParts: /*#__PURE__*/_effect.Option.none()
1214
+ };
1215
+ /**
1216
+ * Constructor that creates a DateTime from a timestamp and a zoneOffset for which no calculations
1217
+ * have been carried out yet. The `_zonedTimestamp` field is automatically calculated. Does not
1218
+ * check any input parameters
1219
+ */
1220
+ const _uncalculatedFromTimestamp = (timestamp, zoneOffset) => _make({
1221
+ ..._uncalculated,
1222
+ timestamp,
1223
+ zoneOffset,
1224
+ _zonedTimestamp: timestamp + zoneOffset * HOUR_MS
1225
+ });
1226
+ /**
1227
+ * Constructor that creates a DateTime from a zonedTimestamp and a zoneOffset for which no
1228
+ * calculations have been carried out yet. The `timestamp` field is automatically calculated. Does
1229
+ * not check any input parameters
1230
+ */
1231
+ const _uncalculatedFromZonedTimestamp = (zonedTimestamp, zoneOffset) => _make({
1232
+ ..._uncalculated,
1233
+ timestamp: zonedTimestamp - zoneOffset * HOUR_MS,
1234
+ zoneOffset,
1235
+ _zonedTimestamp: zonedTimestamp
1236
+ });
1237
+ /** Instance of an uncalculated DateTime that represents 1/1/1970 00:00:00:000+0:00 */
1238
+ const _uncalculatedOrigin = /*#__PURE__*/_uncalculatedFromTimestamp(0, 0);
1239
+ /**
1240
+ * Tries to build a DateTime from `timestamp`, the number of milliseconds since 1/1/1970
1241
+ * 00:00:00:000+0:00, and `zoneOffset` which gives the offset between the local time and the UTC
1242
+ * time. Returns a `right` of a DateTime if successful.
1243
+ *
1244
+ * `timestamp` must be greater than or equal to MIN_TIMESTAMP and less than or equal to
1245
+ * MAX_TIMESTAMP.
1246
+ *
1247
+ * If `zoneOffset` is omitted, the local time zone offset of the machine this code is running on is
1248
+ * used.
1249
+ *
1250
+ * `zoneOffset` can be expressed as as a number of hours. In this case, it must be strictly greater
1251
+ * to -13 and strictly less than 15.
1252
+ *
1253
+ * It can also be expressed as an object containing three components:
1254
+ *
1255
+ * - `zoneHour` which must be greater than or equal to -12 and less than or equal to 14.
1256
+ * - `zoneMinute` which must be greater than or equal to 0 and less than or equal to 59.
1257
+ * - `zoneSecond` which must be greater than or equal to 0 and less than or equal to 59.
1258
+ *
1259
+ * Note that zoneHour=-0, zoneMinute=10, zoneSecond=0 is different from zoneHour=0, zoneMinute=10,
1260
+ * zoneSecond=0. The first corresponds to the string 'GMT-00:10', a negative 10-minute offset, the
1261
+ * second one to the string 'GMT+00:10', a positive 10-minute offset.
1262
+ *
1263
+ * `timestamp`, `zoneHour`, `zoneMinute` and `zoneSecond` should be integers. `zoneOffset`, when
1264
+ * expressed as a number of hours, does not need to be an integer.
1265
+ *
1266
+ * @category Constructors
1267
+ */
1268
+ const fromTimestamp = (timestamp, zoneOffset) => (0, _effect.pipe)(_uncalculatedOrigin, _setTimestamp(timestamp), _effect.Either.flatMap(setZoneOffsetKeepTimestamp(zoneOffset)));
1269
+ /**
1270
+ * Same as fromTimestamp but returns directly the DateTime or throws if it cannot be built
1271
+ *
1272
+ * @category Constructors
1273
+ */
1274
+ exports.fromTimestamp = fromTimestamp;
1275
+ const fromTimestampOrThrow = exports.fromTimestampOrThrow = /*#__PURE__*/(0, _effect.flow)(fromTimestamp, /*#__PURE__*/_effect.Either.getOrThrowWith(_effect.Function.identity));
1276
+ /**
1277
+ * Builds a DateTime using Date.now() as timestamp. `zoneOffset` is set to 0.
1278
+ *
1279
+ * @category Constructors
1280
+ */
1281
+ const now = () => _uncalculatedFromTimestamp(Date.now(), 0);
1282
+ /**
1283
+ * Tries to build a DateTime from the provided DateTime parts. Returns a `right` of this DateTime if
1284
+ * successful. Returns a `left` of an error otherwise.
1285
+ *
1286
+ * `year` must comprised in the range [MIN_FULL_YEAR, MAX_FULL_YEAR]. `ordinalDay` must be greater
1287
+ * than or equal to 1 and less than or equal to the number of days in the current year. `month` must
1288
+ * be greater than or equal to 1 (January) and less than or equal to 12 (December). `monthDay` must
1289
+ * be greater than or equal to 1 and less than or equal to the number of days in the current month.
1290
+ *
1291
+ * `isoYear` must be comprised in the range [MIN_FULL_YEAR, MAX_FULL_YEAR]. `isoWeek` must be
1292
+ * greater than or equal to 1 and less than or equal to the number of iso weeks in the current year.
1293
+ * `weekday` must be greater than or equal to 1 (monday) and less than or equal to 7 (sunday).
1294
+ *
1295
+ * If there is not sufficient information to determine the exact day of the year, i.e. none of the
1296
+ * three following tuples is fully determined [year, ordinalDay], [year, month, monthDay], [isoYear,
1297
+ * isoWeek, weekday], default values are determined in the following order (the first match stops
1298
+ * the process):
1299
+ *
1300
+ * - If `year` and `month` are set, `monthDay` is taken equal to 1.
1301
+ * - If `year` and `monthDay` are set, `month` is taken equal to 1.
1302
+ * - If `year` is set and both `month` and `monthDay` are undefined, the day is taken to be the first
1303
+ * one in the year.
1304
+ * - If `isoYear` and `isoWeek` are set, `weekday` is taken equal to 1.
1305
+ * - If `isoYear` and `weekday` are set, `isoWeek` is taken equal to 1.
1306
+ * - If `isoYear` is set and both `isoWeek` and `weekday` are undefined, the day is taken to be the
1307
+ * first one in the iso year.
1308
+ * - If both `year` and `isoYear` are undefined, an error is raised.
1309
+ *
1310
+ * `hour23` must be greater than or equal to 0 and less than or equal to 23. `hour11` must be
1311
+ * greater than or equal to 0 and less than or equal to 11. `meridiem` must be one of 0 (AM) or 12
1312
+ * (PM). If there is not sufficient information to determine the hour of the day, i.e. none of the
1313
+ * two following tuples is fully determined [hour23], [hour11, meridiem], default values are
1314
+ * determined as follows:
1315
+ *
1316
+ * - If `meridiem` is set, `hour11` is taken equal to 0.
1317
+ * - If `hour11` is set, `meridiem` is taken equal to 0.
1318
+ * - Otherwise, `meridiem` and `hour11` are taken equal to 0.
1319
+ *
1320
+ * `minute` must be greater than or equal to 0 and less than or equal to 59. If omitted, minute is
1321
+ * assumed to be 0.
1322
+ *
1323
+ * `second` must be greater than or equal to 0 and less than or equal to 59. If omitted, second is
1324
+ * assumed to be 0.
1325
+ *
1326
+ * `millisecond` must be greater than or equal to 0 and less than or equal to 999. If omitted,
1327
+ * millisecond is assumed to be 0.
1328
+ *
1329
+ * `zoneOffset` must be strictly greater to -13 and strictly less than 15. `zoneHour` must be
1330
+ * greater than or equal to -12 and less than or equal to 14. `zoneMinute` must be greater than or
1331
+ * equal to 0 and less than or equal to 59. `zoneSecond` must be greater than or equal to 0 and less
1332
+ * than or equal to 59.
1333
+ *
1334
+ * If there is not sufficient information to determine the exact time zone offset, i.e. none of the
1335
+ * two following tuples is fully determined [zoneOffset], [zoneHour, zoneMinute, zoneSecond],
1336
+ * default values are determined as follows :
1337
+ *
1338
+ * - If all parameters are undefined, the local time zone offset of the machine this code is running
1339
+ * on is used.
1340
+ * - If any of `zoneHour`, `zoneMinute`, `zoneSecond`, the undefined parameters are taken equal to 0.
1341
+ *
1342
+ * Note that zoneHour=-0, zoneMinute=10, zoneSecond=0 is different from zoneHour=0, zoneMinute=10,
1343
+ * zoneSecond=0. The first corresponds to the string 'GMT-00:10', a negative 10-minute offset, the
1344
+ * second one to the string 'GMT+00:10', a positive 10-minute offset.
1345
+ *
1346
+ * `year`, `ordinalDay`, `month`, `monthDay`, `isoYear`, `isoWeek`, `weekDay`, `hour23`, `hour11`,
1347
+ * `minute`, `second`, `millisecond`, `zoneHour`, `zoneMinute` and `zoneSecond` should be integers.
1348
+ * `zoneOffset` does not need to be an integer.
1349
+ *
1350
+ * All parameters must be coherent. For instance, `year=1970`, `month=1`, `monthDay=1`, `weekday=0`
1351
+ * `zoneHour=0`, `zoneMinute=0` and `zoneSecond=0` will trigger an error because 1/1/1970
1352
+ * 00:00:00:000+0:00 is a thursday. `hour23=13` and `meridiem=0` will also trigger an error.
1353
+ *
1354
+ * @category Constructors
1355
+ */
1356
+ exports.now = now;
1357
+ const fromParts = ({
1358
+ year,
1359
+ ordinalDay,
1360
+ month,
1361
+ monthDay,
1362
+ isoYear,
1363
+ isoWeek,
1364
+ weekday,
1365
+ hour23,
1366
+ hour11,
1367
+ meridiem,
1368
+ minute,
1369
+ second,
1370
+ millisecond,
1371
+ zoneOffset,
1372
+ zoneHour,
1373
+ zoneMinute,
1374
+ zoneSecond
1375
+ }) => _effect.Either.gen(function* () {
1376
+ const zonedOrigin = yield* _effect.Either.gen(function* () {
1377
+ if (zoneOffset !== undefined || zoneHour === undefined && zoneMinute === undefined && zoneSecond === undefined) {
1378
+ const result = yield* (0, _effect.pipe)(_uncalculatedOrigin, setZoneOffsetKeepParts(zoneOffset));
1379
+ if (zoneHour !== undefined) yield* (0, _effect.pipe)(zoneHour, _effectLib.MInputError.assertValue({
1380
+ expected: getZoneHour(result),
1381
+ name: "'zoneHour'"
1382
+ }));
1383
+ if (zoneMinute !== undefined) yield* (0, _effect.pipe)(zoneMinute, _effectLib.MInputError.assertValue({
1384
+ expected: getZoneMinute(result),
1385
+ name: "'zoneMinute'"
1386
+ }));
1387
+ if (zoneSecond !== undefined) yield* (0, _effect.pipe)(zoneSecond, _effectLib.MInputError.assertValue({
1388
+ expected: getZoneSecond(result),
1389
+ name: "'zoneSecond'"
1390
+ }));
1391
+ return result;
1392
+ }
1393
+ return yield* (0, _effect.pipe)(_uncalculatedOrigin, setZoneOffsetKeepParts({
1394
+ zoneHour: zoneHour ?? 0,
1395
+ zoneMinute: zoneMinute ?? 0,
1396
+ zoneSecond: zoneSecond ?? 0
1397
+ }));
1398
+ });
1399
+ const withHour = yield* _effect.Either.gen(function* () {
1400
+ if (hour23 !== undefined) {
1401
+ const result = yield* setHour23(hour23)(zonedOrigin);
1402
+ if (hour11 !== undefined) yield* (0, _effect.pipe)(hour11, _effectLib.MInputError.assertValue({
1403
+ expected: getHour11(result),
1404
+ name: "'hour11'"
1405
+ }));
1406
+ if (meridiem !== undefined) yield* (0, _effect.pipe)(meridiem, _effectLib.MInputError.assertValue({
1407
+ expected: getMeridiem(result),
1408
+ name: "'meridiem'"
1409
+ }));
1410
+ return result;
1411
+ }
1412
+ const withHour11 = hour11 !== undefined ? yield* setHour11(hour11)(zonedOrigin) : zonedOrigin;
1413
+ return meridiem === 12 ? setMeridiem(12)(withHour11) : withHour11;
1414
+ });
1415
+ const withMinute = minute !== undefined ? yield* setMinute(minute)(withHour) : withHour;
1416
+ const withSecond = second !== undefined ? yield* setSecond(second)(withMinute) : withMinute;
1417
+ const withMillisecond = millisecond !== undefined ? yield* setMillisecond(millisecond)(withSecond) : withSecond;
1418
+ const hasYear = year !== undefined;
1419
+ const hasIsoYear = isoYear !== undefined;
1420
+ const hasIsoWeek = isoWeek !== undefined;
1421
+ const hasWeekday = weekday !== undefined;
1422
+ if (hasYear && !(hasIsoYear && hasIsoWeek && hasWeekday)) {
1423
+ const withYear = yield* setYear(year)(withMillisecond);
1424
+ const withDay = yield* _effect.Either.gen(function* () {
1425
+ if (ordinalDay !== undefined) {
1426
+ const result = yield* setOrdinalDay(ordinalDay)(withYear);
1427
+ if (month !== undefined) yield* (0, _effect.pipe)(month, _effectLib.MInputError.assertValue({
1428
+ expected: getMonth(result),
1429
+ name: "'month'"
1430
+ }));
1431
+ if (monthDay !== undefined) yield* (0, _effect.pipe)(monthDay, _effectLib.MInputError.assertValue({
1432
+ expected: getMonthDay(result),
1433
+ name: "'monthDay'"
1434
+ }));
1435
+ return result;
1436
+ }
1437
+ const withMonth = month !== undefined ? yield* setMonth(month)(withYear) : withYear;
1438
+ return monthDay !== undefined ? yield* setMonthDay(monthDay)(withMonth) : withMonth;
1439
+ });
1440
+ if (hasIsoYear) yield* (0, _effect.pipe)(isoYear, _effectLib.MInputError.assertValue({
1441
+ expected: getIsoYear(withDay),
1442
+ name: "'isoYear'"
1443
+ }));
1444
+ if (hasIsoWeek) yield* (0, _effect.pipe)(isoWeek, _effectLib.MInputError.assertValue({
1445
+ expected: getIsoWeek(withDay),
1446
+ name: "'isoWeek'"
1447
+ }));
1448
+ if (hasWeekday) yield* (0, _effect.pipe)(weekday, _effectLib.MInputError.assertValue({
1449
+ expected: getWeekday(withDay),
1450
+ name: "'weekday'"
1451
+ }));
1452
+ return withDay;
1453
+ }
1454
+ if (!hasIsoYear) return yield* _effect.Either.left(new _effectLib.MInputError.Type({
1455
+ message: "One of 'year' and 'isoYear' must be be set"
1456
+ }));
1457
+ const withIsoYear = yield* setIsoYear(isoYear)(withMillisecond);
1458
+ const withIsoWeek = yield* setIsoWeek(isoWeek ?? 1)(withIsoYear);
1459
+ const withWeekday = yield* setWeekday(weekday ?? 1)(withIsoWeek);
1460
+ if (hasYear) yield* (0, _effect.pipe)(year, _effectLib.MInputError.assertValue({
1461
+ expected: getYear(withWeekday),
1462
+ name: "'year'"
1463
+ }));
1464
+ if (month !== undefined) yield* (0, _effect.pipe)(month, _effectLib.MInputError.assertValue({
1465
+ expected: getMonth(withWeekday),
1466
+ name: "'month'"
1467
+ }));
1468
+ if (monthDay !== undefined) yield* (0, _effect.pipe)(monthDay, _effectLib.MInputError.assertValue({
1469
+ expected: getMonthDay(withWeekday),
1470
+ name: "'monthDay'"
1471
+ }));
1472
+ if (ordinalDay !== undefined) yield* (0, _effect.pipe)(ordinalDay, _effectLib.MInputError.assertValue({
1473
+ expected: getOrdinalDay(withWeekday),
1474
+ name: "'ordinalDay'"
1475
+ }));
1476
+ return withWeekday;
1477
+ });
1478
+ /**
1479
+ * Same as fromParts but returns directly the DateTime or throws if it cannot be built
1480
+ *
1481
+ * @category Constructors
1482
+ */
1483
+ exports.fromParts = fromParts;
1484
+ const fromPartsOrThrow = exports.fromPartsOrThrow = /*#__PURE__*/(0, _effect.flow)(fromParts, /*#__PURE__*/_effect.Either.getOrThrowWith(_effect.Function.identity));
1485
+ /**
1486
+ * Builds a CVDateTime from a Javascript Date
1487
+ *
1488
+ * @category Constructors
1489
+ */
1490
+ const fromDate = date => fromTimestampOrThrow(date.getTime());
1491
+ /**
1492
+ * Builds a CVDateTime from an Effect DateTime
1493
+ *
1494
+ * @category Constructors
1495
+ */
1496
+ exports.fromDate = fromDate;
1497
+ const fromEffectDateTime = date => fromTimestampOrThrow(_effect.DateTime.toEpochMillis(date), _effect.DateTime.zonedOffset(date));
1498
+ /**
1499
+ * Builds a Javascript Date from a CVDateTime
1500
+ *
1501
+ * @category Conversions
1502
+ */
1503
+ exports.fromEffectDateTime = fromEffectDateTime;
1504
+ const toDate = self => new Date(timestamp(self));
1505
+ /**
1506
+ * Builds an Effect DateTime from a CVDateTime
1507
+ *
1508
+ * @category Conversions
1509
+ */
1510
+ exports.toDate = toDate;
1511
+ const toEffectDateTime = self => _effect.DateTime.unsafeMakeZoned(timestamp(self), {
1512
+ timeZone: self.zoneOffset
1513
+ });
1514
+ /**
1515
+ * Returns the timestamp of `self` as a number
1516
+ *
1517
+ * @category Getters
1518
+ */
1519
+ exports.toEffectDateTime = toEffectDateTime;
1520
+ const timestamp = exports.timestamp = /*#__PURE__*/_effect.Struct.get('timestamp');
1521
+ /** Returns the gregorianDate of `self` for the given time zone */
1522
+ const _gregorianDate = self => (0, _effect.pipe)(self.gregorianDate, _effect.Option.getOrElse(() => {
1523
+ const result = GregorianDate.fromTimestamp(self._zonedTimestamp);
1524
+ /* eslint-disable-next-line functional/immutable-data, functional/no-expression-statements */
1525
+ self.gregorianDate = _effect.Option.some(result);
1526
+ return result;
1527
+ }));
1528
+ /**
1529
+ * Returns the (Gregorian) year of `self` for the given time zone
1530
+ *
1531
+ * @category Getters
1532
+ */
1533
+ const getYear = exports.getYear = /*#__PURE__*/(0, _effect.flow)(_gregorianDate, GregorianDate.year);
1534
+ /**
1535
+ * Returns true if the (Gregorian) year of `self` for the given time zone is a leap year. Returns
1536
+ * false otherwise
1537
+ *
1538
+ * @category Getters
1539
+ */
1540
+ const yearIsLeap = exports.yearIsLeap = /*#__PURE__*/(0, _effect.flow)(_gregorianDate, GregorianDate.yearIsLeap);
1541
+ /**
1542
+ * Returns the ordinalDay of `self` for the given time zone
1543
+ *
1544
+ * @category Getters
1545
+ */
1546
+ const getOrdinalDay = exports.getOrdinalDay = /*#__PURE__*/(0, _effect.flow)(_gregorianDate, GregorianDate.ordinalDay);
1547
+ /**
1548
+ * Returns the month of `self` for the given time zone
1549
+ *
1550
+ * @category Getters
1551
+ */
1552
+ const getMonth = exports.getMonth = /*#__PURE__*/(0, _effect.flow)(_gregorianDate, GregorianDate.getMonth);
1553
+ /**
1554
+ * Returns the monthDay of `self` for the given time zone
1555
+ *
1556
+ * @category Getters
1557
+ */
1558
+ const getMonthDay = exports.getMonthDay = /*#__PURE__*/(0, _effect.flow)(_gregorianDate, GregorianDate.getMonthDay);
1559
+ /** Returns the isoDate of `self` for the given time zone */
1560
+ const _isoDate = self => (0, _effect.pipe)(self.isoDate, _effect.Option.getOrElse(() => {
1561
+ const result = (0, _effect.pipe)(self.gregorianDate, _effect.Option.map(IsoDate.fromGregorianDate), _effect.Option.getOrElse(() => IsoDate.fromTimestamp(self._zonedTimestamp)));
1562
+ /* eslint-disable-next-line functional/immutable-data, functional/no-expression-statements */
1563
+ self.isoDate = _effect.Option.some(result);
1564
+ return result;
1565
+ }));
1566
+ /**
1567
+ * Returns the isoYear of `self` for the given time zone
1568
+ *
1569
+ * @category Getters
1570
+ */
1571
+ const getIsoYear = exports.getIsoYear = /*#__PURE__*/(0, _effect.flow)(_isoDate, IsoDate.year);
1572
+ /**
1573
+ * Returns true if the isoYear of `self` for the given time zone is a long year. Returns false
1574
+ * otherwise
1575
+ *
1576
+ * @category Getters
1577
+ */
1578
+ const isoYearIsLong = exports.isoYearIsLong = /*#__PURE__*/(0, _effect.flow)(_isoDate, IsoDate.yearIsLong);
1579
+ /**
1580
+ * Returns the isoWeek of `self` for the given time zone
1581
+ *
1582
+ * @category Getters
1583
+ */
1584
+ const getIsoWeek = exports.getIsoWeek = /*#__PURE__*/(0, _effect.flow)(_isoDate, IsoDate.getIsoWeek);
1585
+ /**
1586
+ * Returns the weekday of `self` for the given time zone
1587
+ *
1588
+ * @category Getters
1589
+ */
1590
+ const getWeekday = exports.getWeekday = /*#__PURE__*/(0, _effect.flow)(_isoDate, IsoDate.getWeekday);
1591
+ /** Returns the time of `self` for the given time zone */
1592
+ const _time = self => (0, _effect.pipe)(self.time, _effect.Option.getOrElse(() => {
1593
+ const result = (0, _effect.pipe)(self._zonedTimestamp, _effectLib.MNumber.intModulo(DAY_MS), Time.fromTimestamp);
1594
+ /* eslint-disable-next-line functional/immutable-data, functional/no-expression-statements */
1595
+ self.time = _effect.Option.some(result);
1596
+ return result;
1597
+ }));
1598
+ /**
1599
+ * Returns the hour23 of `self` for the given time zone
1600
+ *
1601
+ * @category Getters
1602
+ */
1603
+ const getHour23 = exports.getHour23 = /*#__PURE__*/(0, _effect.flow)(_time, Time.hour23);
1604
+ /**
1605
+ * Returns the hour11 of `self` for the given time zone
1606
+ *
1607
+ * @category Getters
1608
+ */
1609
+ const getHour11 = exports.getHour11 = /*#__PURE__*/(0, _effect.flow)(_time, Time.hour11);
1610
+ /**
1611
+ * Returns the meridiem of `self` for the given time zone
1612
+ *
1613
+ * @category Getters
1614
+ */
1615
+ const getMeridiem = exports.getMeridiem = /*#__PURE__*/(0, _effect.flow)(_time, Time.meridiem);
1616
+ /**
1617
+ * Returns the minute of `self` for the given time zone
1618
+ *
1619
+ * @category Getters
1620
+ */
1621
+ const getMinute = exports.getMinute = /*#__PURE__*/(0, _effect.flow)(_time, Time.minute);
1622
+ /**
1623
+ * Returns the second of `self` for the given time zone
1624
+ *
1625
+ * @category Getters
1626
+ */
1627
+ const getSecond = exports.getSecond = /*#__PURE__*/(0, _effect.flow)(_time, Time.second);
1628
+ /**
1629
+ * Returns the millisecond of `self` for the given time zone
1630
+ *
1631
+ * @category Getters
1632
+ */
1633
+ const getMillisecond = exports.getMillisecond = /*#__PURE__*/(0, _effect.flow)(_time, Time.millisecond);
1634
+ /** Returns the zoneOffsetParts of `self` */
1635
+ const _zoneOffsetParts = self => (0, _effect.pipe)(self.zoneOffsetParts, _effect.Option.getOrElse(() => {
1636
+ const result = ZoneOffsetParts.fromZoneOffset(self.zoneOffset);
1637
+ /* eslint-disable-next-line functional/immutable-data, functional/no-expression-statements */
1638
+ self.zoneOffsetParts = _effect.Option.some(result);
1639
+ return result;
1640
+ }));
1641
+ /**
1642
+ * Returns the hour part of the zoneOffset of `self`
1643
+ *
1644
+ * @category Getters
1645
+ */
1646
+ const getZoneHour = exports.getZoneHour = /*#__PURE__*/(0, _effect.flow)(_zoneOffsetParts, ZoneOffsetParts.zoneHour);
1647
+ /**
1648
+ * Returns the minute part of the zoneOffset of `self`
1649
+ *
1650
+ * @category Getters
1651
+ */
1652
+ const getZoneMinute = exports.getZoneMinute = /*#__PURE__*/(0, _effect.flow)(_zoneOffsetParts, ZoneOffsetParts.zoneMinute);
1653
+ /**
1654
+ * Returns the minute part of the zoneOffset of `self`
1655
+ *
1656
+ * @category Getters
1657
+ */
1658
+ const getZoneSecond = exports.getZoneSecond = /*#__PURE__*/(0, _effect.flow)(_zoneOffsetParts, ZoneOffsetParts.zoneSecond);
1659
+ const _gregorianDateSetter = self => {
1660
+ const selfTimestamp = _gregorianDate(self).timestamp;
1661
+ return gregorianDate => {
1662
+ const offset = gregorianDate.timestamp - selfTimestamp;
1663
+ return (0, _effect.pipe)(self, _effectLib.MStruct.evolve({
1664
+ timestamp: _effect.Number.sum(offset),
1665
+ gregorianDate: (0, _effect.pipe)(gregorianDate, _effect.Option.some, _effect.Function.constant),
1666
+ isoDate: _effect.Function.constant(_effect.Option.none()),
1667
+ _zonedTimestamp: _effect.Number.sum(offset)
1668
+ }), _make);
1669
+ };
1670
+ };
1671
+ const _isoDateSetter = self => {
1672
+ const selfTimestamp = _isoDate(self).timestamp;
1673
+ return isoDate => {
1674
+ const offset = isoDate.timestamp - selfTimestamp;
1675
+ return (0, _effect.pipe)(self, _effectLib.MStruct.evolve({
1676
+ timestamp: _effect.Number.sum(offset),
1677
+ gregorianDate: _effect.Function.constant(_effect.Option.none()),
1678
+ isoDate: (0, _effect.pipe)(isoDate, _effect.Option.some, _effect.Function.constant),
1679
+ _zonedTimestamp: _effect.Number.sum(offset)
1680
+ }), _make);
1681
+ };
1682
+ };
1683
+ const _timeSetter = self => {
1684
+ const selfTimestampOffset = _time(self).timestampOffset;
1685
+ return time => {
1686
+ const offset = time.timestampOffset - selfTimestampOffset;
1687
+ return (0, _effect.pipe)(self, _effectLib.MStruct.evolve({
1688
+ timestamp: _effect.Number.sum(offset),
1689
+ time: (0, _effect.pipe)(time, _effect.Option.some, _effect.Function.constant),
1690
+ _zonedTimestamp: _effect.Number.sum(offset)
1691
+ }), _make);
1692
+ };
1693
+ };
1694
+ /**
1695
+ * If possible, returns a right of a DateTime having year `year` and the same `month`, `monthDay`,
1696
+ * `hour23`, `minute`, `second`, `millisecond` and `zoneOffset` as `self`. Returns a `left` of an
1697
+ * error otherwise. `year` must be an integer comprised in the range [MIN_FULL_YEAR,
1698
+ * MAX_FULL_YEAR].
1699
+ *
1700
+ * @category Setters
1701
+ */
1702
+ const setYear = year => self => (0, _effect.pipe)(self, _gregorianDate, GregorianDate.setYear(year), _effect.Either.map(_gregorianDateSetter(self)));
1703
+ /**
1704
+ * Same as setYear but returns directly a DateTime or throws in case of an error
1705
+ *
1706
+ * @category Setters
1707
+ */
1708
+ exports.setYear = setYear;
1709
+ const setYearOrThrow = exports.setYearOrThrow = /*#__PURE__*/(0, _effect.flow)(setYear, /*#__PURE__*/_effect.Function.compose(/*#__PURE__*/_effect.Either.getOrThrowWith(_effect.Function.identity)));
1710
+ /**
1711
+ * If possible, returns a right of a DateTime having ordinalDay `ordinalDay` and the same `year`,
1712
+ * `hour23`, `minute`, `second`, `millisecond` and `zoneOffset` as `self`. Returns a `left` of an
1713
+ * error otherwise. `ordinalDay` must be an integer greater than or equal to 1 and less than or
1714
+ * equal to the number of days in the current year
1715
+ *
1716
+ * @category Setters
1717
+ */
1718
+ const setOrdinalDay = ordinalDay => self => (0, _effect.pipe)(self, _gregorianDate, GregorianDate.setOrdinalDay(ordinalDay), _effect.Either.map(_gregorianDateSetter(self)));
1719
+ /**
1720
+ * Same as setOrdinalDay but returns directly a DateTime or throws in case of an error
1721
+ *
1722
+ * @category Setters
1723
+ */
1724
+ exports.setOrdinalDay = setOrdinalDay;
1725
+ const setOrdinalDayOrThrow = exports.setOrdinalDayOrThrow = /*#__PURE__*/(0, _effect.flow)(setOrdinalDay, /*#__PURE__*/_effect.Function.compose(/*#__PURE__*/_effect.Either.getOrThrowWith(_effect.Function.identity)));
1726
+ /**
1727
+ * If possible, returns a right of a DateTime having month `month` and the same `year`, `monthDay`,
1728
+ * `hour23`, `minute`, `second`, `millisecond` and `zoneOffset` as `self`. Returns a `left` of an
1729
+ * error otherwise. `month` must be an integer greater than or equal to 1 (January) and less than or
1730
+ * equal to 12 (December)
1731
+ *
1732
+ * @category Setters
1733
+ */
1734
+ const setMonth = month => self => (0, _effect.pipe)(self, _gregorianDate, GregorianDate.setMonth(month), _effect.Either.map(_gregorianDateSetter(self)));
1735
+ /**
1736
+ * Same as setMonth but returns directly a DateTime or throws in case of an error
1737
+ *
1738
+ * @category Setters
1739
+ */
1740
+ exports.setMonth = setMonth;
1741
+ const setMonthOrThrow = exports.setMonthOrThrow = /*#__PURE__*/(0, _effect.flow)(setMonth, /*#__PURE__*/_effect.Function.compose(/*#__PURE__*/_effect.Either.getOrThrowWith(_effect.Function.identity)));
1742
+ /**
1743
+ * If possible, returns a right of a DateTime having monthDay `monthDay` and the same `year`,
1744
+ * `month`, `hour23`, `minute`, `second`, `millisecond` and `zoneOffset` as `self`. Returns a `left`
1745
+ * of an error otherwise. `monthDay` must be an integer greater than or equal to 1 and less than or
1746
+ * equal to the number of days in the current month.
1747
+ *
1748
+ * @category Setters
1749
+ */
1750
+ const setMonthDay = monthDay => self => (0, _effect.pipe)(self, _gregorianDate, GregorianDate.setMonthDay(monthDay), _effect.Either.map(_gregorianDateSetter(self)));
1751
+ /**
1752
+ * Same as setMonthDay but returns directly a DateTime or throws in case of an error
1753
+ *
1754
+ * @category Setters
1755
+ */
1756
+ exports.setMonthDay = setMonthDay;
1757
+ const setMonthDayOrThrow = exports.setMonthDayOrThrow = /*#__PURE__*/(0, _effect.flow)(setMonthDay, /*#__PURE__*/_effect.Function.compose(/*#__PURE__*/_effect.Either.getOrThrowWith(_effect.Function.identity)));
1758
+ /**
1759
+ * If possible, returns a right of a DateTime having isoYear `isoYear` and the same `isoWeek`,
1760
+ * `weekday`, `hour23`, `minute`, `second`, `millisecond` and `zoneOffset` as `self`. Returns a
1761
+ * `left` of an error otherwise. `isoYear` must be an integer comprised in the range [MIN_FULL_YEAR,
1762
+ * MAX_FULL_YEAR].
1763
+ *
1764
+ * @category Setters
1765
+ */
1766
+ const setIsoYear = isoYear => self => (0, _effect.pipe)(self, _isoDate, IsoDate.setYear(isoYear), _effect.Either.map(_isoDateSetter(self)));
1767
+ /**
1768
+ * Same as setIsoYear but returns directly a DateTime or throws in case of an error
1769
+ *
1770
+ * @category Setters
1771
+ */
1772
+ exports.setIsoYear = setIsoYear;
1773
+ const setIsoYearOrThrow = exports.setIsoYearOrThrow = /*#__PURE__*/(0, _effect.flow)(setIsoYear, /*#__PURE__*/_effect.Function.compose(/*#__PURE__*/_effect.Either.getOrThrowWith(_effect.Function.identity)));
1774
+ /**
1775
+ * If possible, returns a right of a DateTime having isoWeek `isoWeek` and the same `isoYear`,
1776
+ * `weekday`, `hour23`, `minute`, `second`, `millisecond` and `zoneOffset` as `self`. Returns a
1777
+ * `left` of an error otherwise. `isoWeek` must be an integer greater than or equal to 1 and less
1778
+ * than or equal to the number of iso weeks in the current year.
1779
+ *
1780
+ * @category Setters
1781
+ */
1782
+ const setIsoWeek = isoWeek => self => (0, _effect.pipe)(self, _isoDate, IsoDate.setIsoWeek(isoWeek), _effect.Either.map(_isoDateSetter(self)));
1783
+ /**
1784
+ * Same as setIsoWeek but returns directly a DateTime or throws in case of an error
1785
+ *
1786
+ * @category Setters
1787
+ */
1788
+ exports.setIsoWeek = setIsoWeek;
1789
+ const setIsoWeekOrThrow = exports.setIsoWeekOrThrow = /*#__PURE__*/(0, _effect.flow)(setIsoWeek, /*#__PURE__*/_effect.Function.compose(/*#__PURE__*/_effect.Either.getOrThrowWith(_effect.Function.identity)));
1790
+ /**
1791
+ * If possible, returns a right of a DateTime having weekday `weekday` and the same `isoYear`,
1792
+ * `isoWeek`, `hour23`, `minute`, `second`, `millisecond` and `zoneOffset` as `self`. Returns a
1793
+ * `left` of an error otherwise. `weekday` must be an integer greater than or equal to 1 (monday)
1794
+ * and less than or equal to 7 (sunday).
1795
+ *
1796
+ * @category Setters
1797
+ */
1798
+ const setWeekday = weekday => self => (0, _effect.pipe)(self, _isoDate, IsoDate.setWeekday(weekday), _effect.Either.map(_isoDateSetter(self)));
1799
+ /**
1800
+ * Same as setWeekday but returns directly a DateTime or throws in case of an error
1801
+ *
1802
+ * @category Setters
1803
+ */
1804
+ exports.setWeekday = setWeekday;
1805
+ const setWeekdayOrThrow = exports.setWeekdayOrThrow = /*#__PURE__*/(0, _effect.flow)(setWeekday, /*#__PURE__*/_effect.Function.compose(/*#__PURE__*/_effect.Either.getOrThrowWith(_effect.Function.identity)));
1806
+ /**
1807
+ * If possible, returns a right of a DateTime having hour23 `hour23` and the same `year`,
1808
+ * `ordinalDay`, `minute`, `second`, `millisecond` and `zoneOffset` as `self`. Returns a `left` of
1809
+ * an error otherwise. `hour23` must be an integer greater than or equal to 0 and less than or equal
1810
+ * to 23
1811
+ *
1812
+ * @category Setters
1813
+ */
1814
+ const setHour23 = hour23 => self => (0, _effect.pipe)(self, _time, Time.setHour23(hour23), _effect.Either.map(_timeSetter(self)));
1815
+ /**
1816
+ * Same as setHour23 but returns directly a DateTime or throws in case of an error
1817
+ *
1818
+ * @category Setters
1819
+ */
1820
+ exports.setHour23 = setHour23;
1821
+ const setHour23OrThrow = exports.setHour23OrThrow = /*#__PURE__*/(0, _effect.flow)(setHour23, /*#__PURE__*/_effect.Function.compose(/*#__PURE__*/_effect.Either.getOrThrowWith(_effect.Function.identity)));
1822
+ /**
1823
+ * If possible, returns a right of a DateTime having hour11 `hour11` and the same `year`,
1824
+ * `ordinalDay`, `meridiem`, `minute`, `second`, `millisecond` and `zoneOffset` as `self`. Returns a
1825
+ * `left` of an error otherwise. `hour11` must be an integer greater than or equal to 0 and less
1826
+ * than or equal to 11.
1827
+ *
1828
+ * @category Setters
1829
+ */
1830
+ const setHour11 = hour11 => self => (0, _effect.pipe)(self, _time, Time.setHour11(hour11), _effect.Either.map(_timeSetter(self)));
1831
+ /**
1832
+ * Same as setHour11 but returns directly a DateTime or throws in case of an error
1833
+ *
1834
+ * @category Setters
1835
+ */
1836
+ exports.setHour11 = setHour11;
1837
+ const setHour11OrThrow = exports.setHour11OrThrow = /*#__PURE__*/(0, _effect.flow)(setHour11, /*#__PURE__*/_effect.Function.compose(/*#__PURE__*/_effect.Either.getOrThrowWith(_effect.Function.identity)));
1838
+ /**
1839
+ * Returns a DateTime having meridiem `meridiem` and the same `year`, `ordinalDay`, `hour11`,
1840
+ * `minute`, `second`, `millisecond` and `zoneOffset` as `self`
1841
+ *
1842
+ * @category Setters
1843
+ */
1844
+ const setMeridiem = meridiem => self => (0, _effect.pipe)(self, _time, Time.setMeridiem(meridiem), _timeSetter(self));
1845
+ /**
1846
+ * If possible, returns a right of a DateTime having minute `minute` and the same `year`,
1847
+ * `ordinalDay`, `hour23`, `second`, `millisecond` and `zoneOffset` as `self`. Returns a `left` of
1848
+ * an error otherwise. `minute` must be an integer greater than or equal to 0 and less than or equal
1849
+ * to 59
1850
+ *
1851
+ * @category Setters
1852
+ */
1853
+ exports.setMeridiem = setMeridiem;
1854
+ const setMinute = minute => self => (0, _effect.pipe)(self, _time, Time.setMinute(minute), _effect.Either.map(_timeSetter(self)));
1855
+ /**
1856
+ * Same as setMinute but returns directly a DateTime or throws in case of an error
1857
+ *
1858
+ * @category Setters
1859
+ */
1860
+ exports.setMinute = setMinute;
1861
+ const setMinuteOrThrow = exports.setMinuteOrThrow = /*#__PURE__*/(0, _effect.flow)(setMinute, /*#__PURE__*/_effect.Function.compose(/*#__PURE__*/_effect.Either.getOrThrowWith(_effect.Function.identity)));
1862
+ /**
1863
+ * If possible, returns a right of a DateTime having second `second` and the same `year`,
1864
+ * `ordinalDay`, `hour23`, `minute`, `millisecond` and `zoneOffset` as `self`. Returns a `left` of
1865
+ * an error otherwise. `second` must be an integer greater than or equal to 0 and less than or equal
1866
+ * to 59
1867
+ *
1868
+ * @category Setters
1869
+ */
1870
+ const setSecond = second => self => (0, _effect.pipe)(self, _time, Time.setSecond(second), _effect.Either.map(_timeSetter(self)));
1871
+ /**
1872
+ * Same as setSecond but returns directly a DateTime or throws in case of an error
1873
+ *
1874
+ * @category Setters
1875
+ */
1876
+ exports.setSecond = setSecond;
1877
+ const setSecondOrThrow = exports.setSecondOrThrow = /*#__PURE__*/(0, _effect.flow)(setSecond, /*#__PURE__*/_effect.Function.compose(/*#__PURE__*/_effect.Either.getOrThrowWith(_effect.Function.identity)));
1878
+ /**
1879
+ * If possible, returns a right of a DateTime having millisecond `millisecond` and the same `year`,
1880
+ * `ordinalDay`, `hour23`, `minute`, `second` and `zoneOffset` as `self`. Returns a `left` of an
1881
+ * error otherwise. `millisecond` must be an integer greater than or equal to 0 and less than or
1882
+ * equal to 999.
1883
+ *
1884
+ * @category Setters
1885
+ */
1886
+ const setMillisecond = millisecond => self => (0, _effect.pipe)(self, _time, Time.setMillisecond(millisecond), _effect.Either.map(_timeSetter(self)));
1887
+ /**
1888
+ * Same as setMillisecond but returns directly a DateTime or throws in case of an error
1889
+ *
1890
+ * @category Setters
1891
+ */
1892
+ exports.setMillisecond = setMillisecond;
1893
+ const setMillisecondOrThrow = exports.setMillisecondOrThrow = /*#__PURE__*/(0, _effect.flow)(setMillisecond, /*#__PURE__*/_effect.Function.compose(/*#__PURE__*/_effect.Either.getOrThrowWith(_effect.Function.identity)));
1894
+ /**
1895
+ * If possible, returns a right of a copy of `self` with timestamp set to `timestamp`. Returns a
1896
+ * `left` of an error otherwise. `timestamp` must be an integer comprised in the range
1897
+ * [MIN_TIMESTAMP, MAX_TIMESTAMP] representing the number of milliseconds since 1/1/1970
1898
+ * 00:00:00:000+0:00.
1899
+ */
1900
+ const _setTimestamp = timestamp => self => _effect.Either.gen(function* () {
1901
+ const validatedTimestamp = yield* (0, _effect.pipe)(timestamp, _effectLib.MInputError.assertInRange({
1902
+ min: MIN_TIMESTAMP,
1903
+ max: MAX_TIMESTAMP,
1904
+ minIncluded: true,
1905
+ maxIncluded: true,
1906
+ offset: 0,
1907
+ name: 'timestamp'
1908
+ }));
1909
+ return _uncalculatedFromTimestamp(validatedTimestamp, self.zoneOffset);
1910
+ });
1911
+ const _setZoneOffset = (keepTimestamp, zoneOffset = LOCAL_TIME_ZONE_OFFSET) => self => _effect.Either.gen(function* () {
1912
+ const buildFromZoneOffset = validatedZoneOffset => keepTimestamp ? _uncalculatedFromTimestamp(self.timestamp, validatedZoneOffset) : _uncalculatedFromZonedTimestamp(self._zonedTimestamp, validatedZoneOffset);
1913
+ if (_effectLib.MTypes.isPrimitive(zoneOffset)) {
1914
+ const validatedZoneOffset = yield* (0, _effect.pipe)(zoneOffset, _effectLib.MInputError.assertInRange({
1915
+ min: -13,
1916
+ max: 15,
1917
+ minIncluded: false,
1918
+ maxIncluded: false,
1919
+ offset: 0,
1920
+ name: "'zoneOffset'"
1921
+ }));
1922
+ return buildFromZoneOffset(validatedZoneOffset);
1923
+ }
1924
+ const zoneOffsetParts = yield* ZoneOffsetParts.fromParts(zoneOffset);
1925
+ const result = (0, _effect.pipe)(zoneOffsetParts, ZoneOffsetParts.toHour, buildFromZoneOffset);
1926
+ /* eslint-disable-next-line functional/immutable-data, functional/no-expression-statements */
1927
+ result.zoneOffsetParts = _effect.Option.some(zoneOffsetParts);
1928
+ return result;
1929
+ });
1930
+ /**
1931
+ * If possible, returns a right of a copy of `self` with the same timestamp and zoneOffset set to
1932
+ * `zoneOffset`.
1933
+ *
1934
+ * If `zoneOffset` is omitted, the local time zone offset of the machine this code is running on is
1935
+ * used.
1936
+ *
1937
+ * `zoneOffset` can be expressed as as a number of hours. In this case, it must be strictly greater
1938
+ * to -13 and strictly less than 15.
1939
+ *
1940
+ * It can also be expressed as an object containing three components:
1941
+ *
1942
+ * - `zoneHour` which must be greater than or equal to -12 and less than or equal to 14.
1943
+ * - `zoneMinute` which must be greater than or equal to 0 and less than or equal to 59.
1944
+ * - `zoneSecond` which must be greater than or equal to 0 and less than or equal to 59.
1945
+ *
1946
+ * `zoneHour`, `zoneMinute` and `zoneSecond` should be integers. `zoneOffset`, when expressed as a
1947
+ * number of hours, does not need to be an integer.
1948
+ *
1949
+ * @category Setters
1950
+ */
1951
+ const setZoneOffsetKeepTimestamp = zoneOffset => _setZoneOffset(true, zoneOffset);
1952
+ /**
1953
+ * Same as setZoneOffsetKeepTimestamp but returns directly a DateTime or throws in case of an error
1954
+ *
1955
+ * @category Setters
1956
+ */
1957
+ exports.setZoneOffsetKeepTimestamp = setZoneOffsetKeepTimestamp;
1958
+ const setZoneOffsetKeepTimestampOrThrow = exports.setZoneOffsetKeepTimestampOrThrow = /*#__PURE__*/(0, _effect.flow)(setZoneOffsetKeepTimestamp, /*#__PURE__*/_effect.Function.compose(/*#__PURE__*/_effect.Either.getOrThrowWith(_effect.Function.identity)));
1959
+ /**
1960
+ * If possible, returns a right of a copy of `self` with the same CVDateTime.Parts (except
1961
+ * zoneOffset) and zoneOffset set to `zoneOffset`.
1962
+ *
1963
+ * See setZoneOffsetKeepTimestamp for more details
1964
+ *
1965
+ * @category Setters
1966
+ */
1967
+ const setZoneOffsetKeepParts = zoneOffset => _setZoneOffset(false, zoneOffset);
1968
+ /**
1969
+ * Same as setZoneOffsetKeepTimestamp but returns directly a DateTime or throws in case of an error
1970
+ *
1971
+ * @category Setters
1972
+ */
1973
+ exports.setZoneOffsetKeepParts = setZoneOffsetKeepParts;
1974
+ const setZoneOffsetKeepPartsOrThrow = exports.setZoneOffsetKeepPartsOrThrow = /*#__PURE__*/(0, _effect.flow)(setZoneOffsetKeepParts, /*#__PURE__*/_effect.Function.compose(/*#__PURE__*/_effect.Either.getOrThrowWith(_effect.Function.identity)));
1975
+ /**
1976
+ * Returns true if self is the first day of a month in the given timezone
1977
+ *
1978
+ * @category Predicates
1979
+ */
1980
+ const isFirstMonthDay = self => getMonthDay(self) === 1;
1981
+ /**
1982
+ * Returns true if self is the last day of a month in the given timezone
1983
+ *
1984
+ * @category Predicates
1985
+ */
1986
+ exports.isFirstMonthDay = isFirstMonthDay;
1987
+ const isLastMonthDay = self => getMonthDay(self) === (0, _effect.pipe)(self, _gregorianDate, GregorianDate.getNumberOfDaysInMonth(getMonth(self)));
1988
+ /**
1989
+ * Returns true if self is the first day of a year in the given timezone
1990
+ *
1991
+ * @category Predicates
1992
+ */
1993
+ exports.isLastMonthDay = isLastMonthDay;
1994
+ const isFirstYearDay = self => getOrdinalDay(self) === 1;
1995
+ /**
1996
+ * Returns true if self is the last day of a year in the given timezone
1997
+ *
1998
+ * @category Predicates
1999
+ */
2000
+ exports.isFirstYearDay = isFirstYearDay;
2001
+ const isLastYearDay = self => getOrdinalDay(self) === (0, _effect.pipe)(self, _gregorianDate, GregorianDate.getYearDurationInDays);
2002
+ /**
2003
+ * Returns true if self is the first day of an iso year in the given timezone
2004
+ *
2005
+ * @category Predicates
2006
+ */
2007
+ exports.isLastYearDay = isLastYearDay;
2008
+ const isFirstIsoYearDay = self => getIsoWeek(self) === 1 && getWeekday(self) === 1;
2009
+ /**
2010
+ * Returns true if self is the last day of an iso year in the given timezone
2011
+ *
2012
+ * @category Predicates
2013
+ */
2014
+ exports.isFirstIsoYearDay = isFirstIsoYearDay;
2015
+ const isLastIsoYearDay = self => getIsoWeek(self) === (0, _effect.pipe)(self, _isoDate, IsoDate.getLastIsoWeek) && getWeekday(self) === 7;
2016
+ /**
2017
+ * Returns a copy of `self` where `monthDay` is set to the first day of the current month. All time
2018
+ * parts (`hour23`, `hour11`, `meridiem`, `minute`, `second`, `millisecond`) are left unchanged
2019
+ *
2020
+ * @category Offsetters
2021
+ */
2022
+ exports.isLastIsoYearDay = isLastIsoYearDay;
2023
+ const toFirstMonthDay = exports.toFirstMonthDay = /*#__PURE__*/setMonthDayOrThrow(1);
2024
+ /**
2025
+ * Returns a copy of `self` where `monthDay` is set to the last day of the current month. All time
2026
+ * parts (`hour23`, `hour11`, `meridiem`, `minute`, `second`, `millisecond`) are left unchanged
2027
+ *
2028
+ * @category Offsetters
2029
+ */
2030
+ const toLastMonthDay = self => setMonthDayOrThrow((0, _effect.pipe)(self, _gregorianDate, GregorianDate.getNumberOfDaysInMonth(getMonth(self))))(self);
2031
+ /**
2032
+ * Returns a copy of `self` where `ordinalDay` is set to the first day of the current year. All time
2033
+ * parts (`hour23`, `hour11`, `meridiem`, `minute`, `second`, `millisecond`) are left unchanged
2034
+ *
2035
+ * @category Offsetters
2036
+ */
2037
+ exports.toLastMonthDay = toLastMonthDay;
2038
+ const toFirstYearDay = self => setOrdinalDayOrThrow(1)(self);
2039
+ /**
2040
+ * Returns a copy of `self` where `ordinalDay` is set to the last day of the current year. All time
2041
+ * parts (`hour23`, `hour11`, `meridiem`, `minute`, `second`, `millisecond`) are left unchanged
2042
+ *
2043
+ * @category Offsetters
2044
+ */
2045
+ exports.toFirstYearDay = toFirstYearDay;
2046
+ const toLastYearDay = self => setOrdinalDayOrThrow((0, _effect.pipe)(self, _gregorianDate, GregorianDate.getYearDurationInDays))(self);
2047
+ /**
2048
+ * Returns a copy of `self` where `isoWeek` and `weekday` are set to 1. All time parts (`hour23`,
2049
+ * `hour11`, `meridiem`, `minute`, `second`, `millisecond`) are left unchanged
2050
+ *
2051
+ * @category Offsetters
2052
+ */
2053
+ exports.toLastYearDay = toLastYearDay;
2054
+ const toFirstIsoYearDay = exports.toFirstIsoYearDay = /*#__PURE__*/(0, _effect.flow)(/*#__PURE__*/setIsoWeekOrThrow(1), /*#__PURE__*/setWeekdayOrThrow(1));
2055
+ /**
2056
+ * Returns a copy of `self` where `isoWeek` is set to the last week of the current iso year.
2057
+ * `weekday` and all time parts (`hour23`, `hour11`, `meridiem`, `minute`, `second`, `millisecond`)
2058
+ * are left unchanged
2059
+ *
2060
+ * @category Offsetters
2061
+ */
2062
+ const toLastIsoYearWeek = self => (0, _effect.pipe)(self, setIsoWeekOrThrow((0, _effect.pipe)(self, _isoDate, IsoDate.getLastIsoWeek)));
2063
+ /**
2064
+ * Returns a copy of `self` where `isoWeek` is set to the last week of the current iso year and
2065
+ * `weekday` is set to 7. All time parts (`hour23`, `hour11`, `meridiem`, `minute`, `second`,
2066
+ * `millisecond`) are left unchanged
2067
+ *
2068
+ * @category Offsetters
2069
+ */
2070
+ exports.toLastIsoYearWeek = toLastIsoYearWeek;
2071
+ const toLastIsoYearDay = self => (0, _effect.pipe)(self, toLastIsoYearWeek, setWeekdayOrThrow(7));
2072
+ /**
2073
+ * If possible, returns a copy of `self` offset by `offset` years and having the same `month`,
2074
+ * `hour23`, `minute`, `second`, `millisecond` and `zoneOffset` as `self`. If `respectMonthEnd` is
2075
+ * true and `self` is on the last day of a month, the new DateTime object's monthDay will be the
2076
+ * last of the target month. Otherwise, it will be the same as `self`'s. Returns a `left` of an
2077
+ * error otherwise.
2078
+ *
2079
+ * @category Offsetters
2080
+ */
2081
+ exports.toLastIsoYearDay = toLastIsoYearDay;
2082
+ const offsetYears = (offset, respectMonthEnd) => offsetMonths(offset * 12, respectMonthEnd);
2083
+ /**
2084
+ * Same as offsetYears but returns directly a DateTime or throws in case of an error
2085
+ *
2086
+ * @category Setters
2087
+ */
2088
+ exports.offsetYears = offsetYears;
2089
+ const offsetYearsOrThrow = exports.offsetYearsOrThrow = /*#__PURE__*/(0, _effect.flow)(offsetYears, /*#__PURE__*/_effect.Function.compose(/*#__PURE__*/_effect.Either.getOrThrowWith(_effect.Function.identity)));
2090
+ /**
2091
+ * If possible, returns a copy of `self` offset by `offset` months and having the same `hour23`,
2092
+ * `minute`, `second`, `millisecond` and `zoneOffset` as `self`. If `respectMonthEnd` is true and
2093
+ * `self` is on the last day of a month, the new DateTime object's monthDay will be the last of the
2094
+ * target month. Otherwise, it will be the same as `self`'s. Returns a `left` of an error if the
2095
+ * DateTime object can
2096
+ *
2097
+ * @category Offsetters
2098
+ */
2099
+ const offsetMonths = (offset, respectMonthEnd) => self => {
2100
+ const [yearOffset, targetMonthIndex] = (0, _effect.pipe)(self, getMonth, _effect.Number.sum(offset - 1), _effectLib.MNumber.quotientAndRemainder(12));
2101
+ const offsetToLastMonthDay = respectMonthEnd && isLastMonthDay(self);
2102
+ return (0, _effect.pipe)(self, offsetToLastMonthDay ? setMonthDayOrThrow(1) : _effect.Function.identity, setMonthOrThrow(targetMonthIndex + 1), setYear(getYear(self) + yearOffset), _effect.Either.map(_effectLib.MFunction.fIfTrue({
2103
+ condition: offsetToLastMonthDay,
2104
+ f: toLastMonthDay
2105
+ })));
2106
+ };
2107
+ /**
2108
+ * Same as offsetMonths but returns directly a DateTime or throws in case of an error
2109
+ *
2110
+ * @category Setters
2111
+ */
2112
+ exports.offsetMonths = offsetMonths;
2113
+ const offsetMonthsOrThrow = exports.offsetMonthsOrThrow = /*#__PURE__*/(0, _effect.flow)(offsetMonths, /*#__PURE__*/_effect.Function.compose(/*#__PURE__*/_effect.Either.getOrThrowWith(_effect.Function.identity)));
2114
+ /**
2115
+ * Returns a copy of `self` offset by `offset` days
2116
+ *
2117
+ * @category Offsetters
2118
+ */
2119
+ const offsetDays = offset => offsetMilliseconds(offset * DAY_MS);
2120
+ /**
2121
+ * Same as offsetDays but returns directly a DateTime or throws in case of an error
2122
+ *
2123
+ * @category Setters
2124
+ */
2125
+ exports.offsetDays = offsetDays;
2126
+ const offsetDaysOrThrow = exports.offsetDaysOrThrow = /*#__PURE__*/(0, _effect.flow)(offsetDays, /*#__PURE__*/_effect.Function.compose(/*#__PURE__*/_effect.Either.getOrThrowWith(_effect.Function.identity)));
2127
+ /**
2128
+ * If possible, returns a copy of `self` offset by `offset` iso years and having the same `weekday`,
2129
+ * `hour23`, `minute`, `second`, `millisecond` and `zoneOffset` as `self`. If `respectYearEnd` is
2130
+ * true and `self` is on the last day of an iso year, the new DateTime object's isoWeek will be the
2131
+ * last of the target iso year. Otherwise, it will be the same as `self`'s. Returns a `left` of an
2132
+ * error otherwise.
2133
+ *
2134
+ * @category Offsetters
2135
+ */
2136
+ const offsetIsoYears = (offset, respectYearEnd) => self => {
2137
+ const offsetToLastIsoYearDay = respectYearEnd && isLastIsoYearDay(self);
2138
+ return (0, _effect.pipe)(self, offsetToLastIsoYearDay ? setIsoWeekOrThrow(1) : _effect.Function.identity, setIsoYear(getIsoYear(self) + offset), _effect.Either.map(_effectLib.MFunction.fIfTrue({
2139
+ condition: offsetToLastIsoYearDay,
2140
+ f: toLastIsoYearWeek
2141
+ })));
2142
+ };
2143
+ /**
2144
+ * Same as offsetIsoYears but returns directly a DateTime or throws in case of an error
2145
+ *
2146
+ * @category Setters
2147
+ */
2148
+ exports.offsetIsoYears = offsetIsoYears;
2149
+ const offsetIsoYearsOrThrow = exports.offsetIsoYearsOrThrow = /*#__PURE__*/(0, _effect.flow)(offsetIsoYears, /*#__PURE__*/_effect.Function.compose(/*#__PURE__*/_effect.Either.getOrThrowWith(_effect.Function.identity)));
2150
+ /**
2151
+ * Returns a copy of `self` offset by `offset` hours
2152
+ *
2153
+ * @category Offsetters
2154
+ */
2155
+ const offsetHours = offset => offsetMilliseconds(offset * HOUR_MS);
2156
+ /**
2157
+ * Same as offsetHours but returns directly a DateTime or throws in case of an error
2158
+ *
2159
+ * @category Setters
2160
+ */
2161
+ exports.offsetHours = offsetHours;
2162
+ const offsetHoursOrThrow = exports.offsetHoursOrThrow = /*#__PURE__*/(0, _effect.flow)(offsetHours, /*#__PURE__*/_effect.Function.compose(/*#__PURE__*/_effect.Either.getOrThrowWith(_effect.Function.identity)));
2163
+ /**
2164
+ * Returns a copy of `self` offset by `offset` minutes
2165
+ *
2166
+ * @category Offsetters
2167
+ */
2168
+ const offsetMinutes = offset => offsetMilliseconds(offset * MINUTE_MS);
2169
+ /**
2170
+ * Same as offsetMinutes but returns directly a DateTime or throws in case of an error
2171
+ *
2172
+ * @category Setters
2173
+ */
2174
+ exports.offsetMinutes = offsetMinutes;
2175
+ const offsetMinutesOrThrow = exports.offsetMinutesOrThrow = /*#__PURE__*/(0, _effect.flow)(offsetMinutes, /*#__PURE__*/_effect.Function.compose(/*#__PURE__*/_effect.Either.getOrThrowWith(_effect.Function.identity)));
2176
+ /**
2177
+ * Returns a copy of `self` offset by `offset` seconds
2178
+ *
2179
+ * @category Offsetters
2180
+ */
2181
+ const offsetSeconds = offset => offsetMilliseconds(offset * SECOND_MS);
2182
+ /**
2183
+ * Same as offsetSeconds but returns directly a DateTime or throws in case of an error
2184
+ *
2185
+ * @category Setters
2186
+ */
2187
+ exports.offsetSeconds = offsetSeconds;
2188
+ const offsetSecondsOrThrow = exports.offsetSecondsOrThrow = /*#__PURE__*/(0, _effect.flow)(offsetSeconds, /*#__PURE__*/_effect.Function.compose(/*#__PURE__*/_effect.Either.getOrThrowWith(_effect.Function.identity)));
2189
+ /**
2190
+ * Returns a copy of `self` offset by `offset` milliseconds
2191
+ *
2192
+ * @category Offsetters
2193
+ */
2194
+ const offsetMilliseconds = offset => self => _setTimestamp(timestamp(self) + offset)(self);
2195
+ /**
2196
+ * Same as offsetMilliseconds but returns directly a DateTime or throws in case of an error
2197
+ *
2198
+ * @category Setters
2199
+ */
2200
+ exports.offsetMilliseconds = offsetMilliseconds;
2201
+ const offsetMillisecondsOrThrow = exports.offsetMillisecondsOrThrow = /*#__PURE__*/(0, _effect.flow)(offsetMilliseconds, /*#__PURE__*/_effect.Function.compose(/*#__PURE__*/_effect.Either.getOrThrowWith(_effect.Function.identity)));
2202
+ //# sourceMappingURL=DateTime.js.map