@duplojs/utils 1.4.57 → 1.4.58

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 (293) hide show
  1. package/dist/clean/constraint/base.d.ts +6 -4
  2. package/dist/clean/constraint/defaultConstraint/index.d.ts +1 -0
  3. package/dist/clean/constraint/defaultConstraint/number.d.ts +6 -6
  4. package/dist/clean/constraint/defaultConstraint/string.d.ts +4 -4
  5. package/dist/clean/constraint/defaultConstraint/time.cjs +19 -0
  6. package/dist/clean/constraint/defaultConstraint/time.d.ts +61 -0
  7. package/dist/clean/constraint/defaultConstraint/time.mjs +16 -0
  8. package/dist/clean/constraint/set.d.ts +6 -4
  9. package/dist/clean/entity.d.ts +2 -1
  10. package/dist/clean/index.cjs +3 -0
  11. package/dist/clean/index.mjs +1 -0
  12. package/dist/clean/newType.d.ts +7 -5
  13. package/dist/clean/primitive/base.d.ts +25 -34
  14. package/dist/clean/primitive/operations/date/dateAddTime.d.ts +7 -11
  15. package/dist/clean/primitive/operations/date/dateGreaterThan.d.ts +9 -7
  16. package/dist/clean/primitive/operations/date/dateLessThan.d.ts +9 -7
  17. package/dist/clean/primitive/operations/date/dateMax.d.ts +3 -10
  18. package/dist/clean/primitive/operations/date/dateMin.d.ts +3 -10
  19. package/dist/clean/primitive/operations/date/dateSubtractTime.d.ts +7 -11
  20. package/dist/clean/primitive/operations/equal.cjs +1 -1
  21. package/dist/clean/primitive/operations/equal.d.ts +3 -3
  22. package/dist/clean/primitive/operations/equal.mjs +1 -1
  23. package/dist/clean/primitive/operations/sort.d.ts +8 -10
  24. package/dist/clean/primitive/operations/time/timeGreaterThan.d.ts +11 -9
  25. package/dist/clean/primitive/operations/time/timeLessThan.d.ts +11 -9
  26. package/dist/clean/primitive/operations/time/timeMax.cjs +2 -2
  27. package/dist/clean/primitive/operations/time/timeMax.d.ts +10 -17
  28. package/dist/clean/primitive/operations/time/timeMax.mjs +2 -2
  29. package/dist/clean/primitive/operations/time/timeMin.cjs +3 -3
  30. package/dist/clean/primitive/operations/time/timeMin.d.ts +10 -17
  31. package/dist/clean/primitive/operations/time/timeMin.mjs +3 -3
  32. package/dist/clean/unwrapEntity.cjs +13 -3
  33. package/dist/clean/unwrapEntity.d.ts +57 -5
  34. package/dist/clean/unwrapEntity.mjs +13 -3
  35. package/dist/common/index.d.ts +2 -4
  36. package/dist/common/kind.d.ts +1 -0
  37. package/dist/common/transformer.cjs +45 -0
  38. package/dist/common/transformer.d.ts +61 -0
  39. package/dist/common/transformer.mjs +40 -0
  40. package/dist/common/types/DeepReadonly.d.ts +1 -1
  41. package/dist/common/types/toLargeEnsemble.d.ts +2 -2
  42. package/dist/dataParser/extended/date.d.ts +9 -4
  43. package/dist/dataParser/extended/time.d.ts +28 -12
  44. package/dist/dataParser/identifier.d.ts +20 -8
  45. package/dist/dataParser/parsers/date.cjs +16 -12
  46. package/dist/dataParser/parsers/date.d.ts +15 -9
  47. package/dist/dataParser/parsers/date.mjs +16 -12
  48. package/dist/dataParser/parsers/time/checkers/max.cjs +3 -0
  49. package/dist/dataParser/parsers/time/checkers/max.d.ts +28 -0
  50. package/dist/dataParser/parsers/time/checkers/max.mjs +3 -0
  51. package/dist/dataParser/parsers/time/checkers/min.cjs +3 -0
  52. package/dist/dataParser/parsers/time/checkers/min.d.ts +28 -0
  53. package/dist/dataParser/parsers/time/checkers/min.mjs +3 -0
  54. package/dist/dataParser/parsers/time/index.cjs +14 -10
  55. package/dist/dataParser/parsers/time/index.d.ts +15 -9
  56. package/dist/dataParser/parsers/time/index.mjs +14 -10
  57. package/dist/date/applyTimezone.cjs +4 -4
  58. package/dist/date/applyTimezone.d.ts +18 -16
  59. package/dist/date/applyTimezone.mjs +2 -2
  60. package/dist/date/closestTo.cjs +6 -2
  61. package/dist/date/closestTo.d.ts +15 -15
  62. package/dist/date/closestTo.mjs +6 -2
  63. package/dist/date/constants.cjs +4 -4
  64. package/dist/date/constants.d.ts +2 -2
  65. package/dist/date/constants.mjs +3 -3
  66. package/dist/date/create.cjs +20 -10
  67. package/dist/date/create.d.ts +24 -38
  68. package/dist/date/create.mjs +21 -11
  69. package/dist/date/createOrThrow.d.ts +18 -20
  70. package/dist/date/createTime.cjs +16 -7
  71. package/dist/date/createTime.d.ts +19 -18
  72. package/dist/date/createTime.mjs +17 -8
  73. package/dist/date/createTimeOrThrow.d.ts +17 -20
  74. package/dist/date/each.cjs +6 -4
  75. package/dist/date/each.d.ts +21 -19
  76. package/dist/date/each.mjs +6 -4
  77. package/dist/date/format.d.ts +17 -15
  78. package/dist/date/formatTime.d.ts +17 -16
  79. package/dist/date/getTimezoneOffset.cjs +6 -3
  80. package/dist/date/getTimezoneOffset.d.ts +17 -18
  81. package/dist/date/getTimezoneOffset.mjs +6 -3
  82. package/dist/date/getters/getDayOfMonth.cjs +3 -3
  83. package/dist/date/getters/getDayOfMonth.d.ts +20 -14
  84. package/dist/date/getters/getDayOfMonth.mjs +3 -3
  85. package/dist/date/getters/getDayOfWeek.cjs +3 -3
  86. package/dist/date/getters/getDayOfWeek.d.ts +15 -12
  87. package/dist/date/getters/getDayOfWeek.mjs +3 -3
  88. package/dist/date/getters/getDayOfYear.cjs +6 -6
  89. package/dist/date/getters/getDayOfYear.d.ts +21 -13
  90. package/dist/date/getters/getDayOfYear.mjs +6 -6
  91. package/dist/date/getters/getFirstDayOfMonth.cjs +2 -3
  92. package/dist/date/getters/getFirstDayOfMonth.d.ts +16 -10
  93. package/dist/date/getters/getFirstDayOfMonth.mjs +2 -3
  94. package/dist/date/getters/getFirstDayOfWeek.cjs +2 -3
  95. package/dist/date/getters/getFirstDayOfWeek.d.ts +17 -10
  96. package/dist/date/getters/getFirstDayOfWeek.mjs +2 -3
  97. package/dist/date/getters/getHour.cjs +3 -3
  98. package/dist/date/getters/getHour.d.ts +16 -14
  99. package/dist/date/getters/getHour.mjs +3 -3
  100. package/dist/date/getters/getLastDayOfMonth.cjs +2 -3
  101. package/dist/date/getters/getLastDayOfMonth.d.ts +16 -10
  102. package/dist/date/getters/getLastDayOfMonth.mjs +2 -3
  103. package/dist/date/getters/getLastDayOfWeek.cjs +2 -3
  104. package/dist/date/getters/getLastDayOfWeek.d.ts +17 -10
  105. package/dist/date/getters/getLastDayOfWeek.mjs +2 -3
  106. package/dist/date/getters/getMilliseconds.cjs +2 -2
  107. package/dist/date/getters/getMilliseconds.d.ts +11 -9
  108. package/dist/date/getters/getMilliseconds.mjs +2 -2
  109. package/dist/date/getters/getMinute.cjs +3 -3
  110. package/dist/date/getters/getMinute.d.ts +17 -15
  111. package/dist/date/getters/getMinute.mjs +3 -3
  112. package/dist/date/getters/getMonth.cjs +3 -3
  113. package/dist/date/getters/getMonth.d.ts +20 -15
  114. package/dist/date/getters/getMonth.mjs +3 -3
  115. package/dist/date/getters/getSecond.cjs +3 -3
  116. package/dist/date/getters/getSecond.d.ts +17 -15
  117. package/dist/date/getters/getSecond.mjs +3 -3
  118. package/dist/date/getters/getWeekOfYear.cjs +12 -11
  119. package/dist/date/getters/getWeekOfYear.d.ts +17 -11
  120. package/dist/date/getters/getWeekOfYear.mjs +12 -11
  121. package/dist/date/getters/getYear.cjs +3 -3
  122. package/dist/date/getters/getYear.d.ts +16 -15
  123. package/dist/date/getters/getYear.mjs +3 -3
  124. package/dist/date/index.cjs +12 -6
  125. package/dist/date/index.d.ts +5 -2
  126. package/dist/date/index.mjs +6 -3
  127. package/dist/date/is.cjs +3 -8
  128. package/dist/date/is.d.ts +9 -14
  129. package/dist/date/is.mjs +3 -8
  130. package/dist/date/isSafeTimeValue.d.ts +9 -13
  131. package/dist/date/isSafeTimestamp.d.ts +7 -16
  132. package/dist/date/isSerializedTheDate.cjs +20 -0
  133. package/dist/date/isSerializedTheDate.d.ts +31 -0
  134. package/dist/date/isSerializedTheDate.mjs +18 -0
  135. package/dist/date/isSerializedTheTime.cjs +20 -0
  136. package/dist/date/isSerializedTheTime.d.ts +31 -0
  137. package/dist/date/isSerializedTheTime.mjs +18 -0
  138. package/dist/date/isTime.cjs +3 -8
  139. package/dist/date/isTime.d.ts +7 -14
  140. package/dist/date/isTime.mjs +3 -8
  141. package/dist/date/kind.cjs +9 -0
  142. package/dist/date/kind.d.ts +1 -0
  143. package/dist/date/kind.mjs +7 -0
  144. package/dist/date/makeSafeTimeValue.d.ts +12 -11
  145. package/dist/date/makeSafeTimestamp.d.ts +12 -11
  146. package/dist/date/max.cjs +2 -2
  147. package/dist/date/max.d.ts +13 -13
  148. package/dist/date/max.mjs +2 -2
  149. package/dist/date/maxTime.cjs +2 -2
  150. package/dist/date/maxTime.d.ts +13 -21
  151. package/dist/date/maxTime.mjs +2 -2
  152. package/dist/date/min.cjs +2 -2
  153. package/dist/date/min.d.ts +13 -13
  154. package/dist/date/min.mjs +2 -2
  155. package/dist/date/minTime.cjs +2 -2
  156. package/dist/date/minTime.d.ts +13 -21
  157. package/dist/date/minTime.mjs +2 -2
  158. package/dist/date/now.cjs +3 -1
  159. package/dist/date/now.d.ts +9 -7
  160. package/dist/date/now.mjs +3 -1
  161. package/dist/date/operators/addDays.cjs +3 -5
  162. package/dist/date/operators/addDays.d.ts +14 -11
  163. package/dist/date/operators/addDays.mjs +3 -5
  164. package/dist/date/operators/addHours.cjs +3 -5
  165. package/dist/date/operators/addHours.d.ts +14 -11
  166. package/dist/date/operators/addHours.mjs +3 -5
  167. package/dist/date/operators/addMilliseconds.cjs +3 -5
  168. package/dist/date/operators/addMilliseconds.d.ts +14 -11
  169. package/dist/date/operators/addMilliseconds.mjs +3 -5
  170. package/dist/date/operators/addMinutes.cjs +3 -5
  171. package/dist/date/operators/addMinutes.d.ts +14 -11
  172. package/dist/date/operators/addMinutes.mjs +3 -5
  173. package/dist/date/operators/addMonths.cjs +2 -2
  174. package/dist/date/operators/addMonths.d.ts +13 -13
  175. package/dist/date/operators/addMonths.mjs +2 -2
  176. package/dist/date/operators/addSeconds.cjs +3 -5
  177. package/dist/date/operators/addSeconds.d.ts +14 -11
  178. package/dist/date/operators/addSeconds.mjs +3 -5
  179. package/dist/date/operators/addTime.cjs +13 -6
  180. package/dist/date/operators/addTime.d.ts +20 -18
  181. package/dist/date/operators/addTime.mjs +13 -6
  182. package/dist/date/operators/addWeeks.cjs +6 -5
  183. package/dist/date/operators/addWeeks.d.ts +14 -11
  184. package/dist/date/operators/addWeeks.mjs +6 -5
  185. package/dist/date/operators/addYears.cjs +2 -2
  186. package/dist/date/operators/addYears.d.ts +13 -13
  187. package/dist/date/operators/addYears.mjs +2 -2
  188. package/dist/date/operators/between.d.ts +11 -11
  189. package/dist/date/operators/betweenThan.d.ts +11 -11
  190. package/dist/date/operators/betweenThanTime.d.ts +18 -22
  191. package/dist/date/operators/betweenTime.d.ts +17 -21
  192. package/dist/date/operators/greater.d.ts +12 -9
  193. package/dist/date/operators/greaterThan.d.ts +14 -11
  194. package/dist/date/operators/greaterThanTime.d.ts +17 -21
  195. package/dist/date/operators/greaterTime.d.ts +16 -20
  196. package/dist/date/operators/less.d.ts +12 -9
  197. package/dist/date/operators/lessThan.d.ts +13 -10
  198. package/dist/date/operators/lessThanTime.d.ts +17 -21
  199. package/dist/date/operators/lessTime.d.ts +16 -20
  200. package/dist/date/operators/subtractDays.cjs +3 -5
  201. package/dist/date/operators/subtractDays.d.ts +14 -11
  202. package/dist/date/operators/subtractDays.mjs +3 -5
  203. package/dist/date/operators/subtractHours.cjs +3 -5
  204. package/dist/date/operators/subtractHours.d.ts +14 -11
  205. package/dist/date/operators/subtractHours.mjs +3 -5
  206. package/dist/date/operators/subtractMilliseconds.cjs +3 -5
  207. package/dist/date/operators/subtractMilliseconds.d.ts +14 -11
  208. package/dist/date/operators/subtractMilliseconds.mjs +3 -5
  209. package/dist/date/operators/subtractMinutes.cjs +3 -5
  210. package/dist/date/operators/subtractMinutes.d.ts +14 -11
  211. package/dist/date/operators/subtractMinutes.mjs +3 -5
  212. package/dist/date/operators/subtractMonths.cjs +2 -2
  213. package/dist/date/operators/subtractMonths.d.ts +17 -11
  214. package/dist/date/operators/subtractMonths.mjs +2 -2
  215. package/dist/date/operators/subtractSeconds.cjs +3 -5
  216. package/dist/date/operators/subtractSeconds.d.ts +14 -11
  217. package/dist/date/operators/subtractSeconds.mjs +3 -5
  218. package/dist/date/operators/subtractTime.cjs +13 -6
  219. package/dist/date/operators/subtractTime.d.ts +20 -18
  220. package/dist/date/operators/subtractTime.mjs +13 -6
  221. package/dist/date/operators/subtractWeeks.cjs +3 -5
  222. package/dist/date/operators/subtractWeeks.d.ts +14 -11
  223. package/dist/date/operators/subtractWeeks.mjs +3 -5
  224. package/dist/date/operators/subtractYears.cjs +2 -2
  225. package/dist/date/operators/subtractYears.d.ts +17 -11
  226. package/dist/date/operators/subtractYears.mjs +2 -2
  227. package/dist/date/round.cjs +2 -2
  228. package/dist/date/round.d.ts +11 -14
  229. package/dist/date/round.mjs +2 -2
  230. package/dist/date/serialize.cjs +14 -0
  231. package/dist/date/serialize.d.ts +41 -0
  232. package/dist/date/serialize.mjs +12 -0
  233. package/dist/date/sort.cjs +2 -2
  234. package/dist/date/sort.d.ts +16 -15
  235. package/dist/date/sort.mjs +2 -2
  236. package/dist/date/sortTimes.cjs +2 -2
  237. package/dist/date/sortTimes.d.ts +15 -21
  238. package/dist/date/sortTimes.mjs +2 -2
  239. package/dist/date/theDate.cjs +124 -0
  240. package/dist/date/theDate.d.ts +114 -0
  241. package/dist/date/theDate.mjs +122 -0
  242. package/dist/date/theTime.cjs +36 -0
  243. package/dist/date/theTime.d.ts +53 -0
  244. package/dist/date/theTime.mjs +34 -0
  245. package/dist/date/timezone.cjs +3 -0
  246. package/dist/date/timezone.d.ts +27 -0
  247. package/dist/date/timezone.mjs +3 -0
  248. package/dist/date/toISOString.cjs +5 -2
  249. package/dist/date/toISOString.d.ts +12 -10
  250. package/dist/date/toISOString.mjs +5 -2
  251. package/dist/date/toNative.cjs +4 -0
  252. package/dist/date/toNative.d.ts +12 -10
  253. package/dist/date/toNative.mjs +4 -0
  254. package/dist/date/toTimeValue.cjs +6 -2
  255. package/dist/date/toTimeValue.d.ts +14 -12
  256. package/dist/date/toTimeValue.mjs +6 -2
  257. package/dist/date/toTimestamp.cjs +5 -3
  258. package/dist/date/toTimestamp.d.ts +11 -9
  259. package/dist/date/toTimestamp.mjs +6 -4
  260. package/dist/date/today.cjs +3 -1
  261. package/dist/date/today.d.ts +14 -7
  262. package/dist/date/today.mjs +3 -1
  263. package/dist/date/tomorrow.cjs +2 -1
  264. package/dist/date/tomorrow.d.ts +12 -7
  265. package/dist/date/tomorrow.mjs +2 -1
  266. package/dist/date/types/index.d.ts +2 -2
  267. package/dist/date/types/serializedTheDate.d.ts +1 -0
  268. package/dist/date/types/serializedTheTime.d.ts +42 -0
  269. package/dist/date/types/spoolingDate.d.ts +2 -1
  270. package/dist/date/yesterday.cjs +2 -1
  271. package/dist/date/yesterday.d.ts +12 -7
  272. package/dist/date/yesterday.mjs +2 -1
  273. package/dist/index.cjs +5 -6
  274. package/dist/index.mjs +1 -3
  275. package/dist/metadata.json +73 -46
  276. package/package.json +1 -1
  277. package/dist/common/toJSON.cjs +0 -37
  278. package/dist/common/toJSON.d.ts +0 -44
  279. package/dist/common/toJSON.mjs +0 -35
  280. package/dist/common/toString.cjs +0 -10
  281. package/dist/common/toString.d.ts +0 -17
  282. package/dist/common/toString.mjs +0 -8
  283. package/dist/common/toTransform.cjs +0 -37
  284. package/dist/common/toTransform.d.ts +0 -50
  285. package/dist/common/toTransform.mjs +0 -35
  286. package/dist/date/createTheDate.cjs +0 -13
  287. package/dist/date/createTheDate.d.ts +0 -28
  288. package/dist/date/createTheDate.mjs +0 -11
  289. package/dist/date/createTheTime.cjs +0 -13
  290. package/dist/date/createTheTime.d.ts +0 -25
  291. package/dist/date/createTheTime.mjs +0 -11
  292. package/dist/date/types/theDate.d.ts +0 -11
  293. package/dist/date/types/theTime.d.ts +0 -10
@@ -1,29 +1,35 @@
1
- import type { TheDate } from "../types";
1
+ import { TheDate } from "../theDate";
2
+ import type { SerializedTheDate } from "../types";
2
3
  /**
3
- * Subtracts years from a date.
4
+ * Subtracts a number of calendar years from a date.
4
5
  *
5
6
  * **Supported call styles:**
6
- * - Classic: `subtractYears(input, year)` → returns a value
7
- * - Curried: `subtractYears(year)` → returns a function waiting for the input
7
+ * - Classic: `subtractYears(input, year)` → `TheDate`
8
+ * - Curried: `subtractYears(year)` → `(input) => TheDate`
8
9
  *
9
- * The input value is not mutated.
10
+ * `input` accepts `TheDate` or `SerializedTheDate`.
10
11
  *
11
12
  * ```ts
12
13
  * const input = D.create("2024-06-20");
13
14
  * const result = D.subtractYears(input, 1);
14
- * // result: "date1687219200000+"
15
+ * // result: TheDate
16
+ *
17
+ * const serialized = D.serialize(result);
18
+ * // serialized: SerializedTheDate
15
19
  *
16
20
  * pipe(
17
- * input,
21
+ * serialized,
18
22
  * D.subtractYears(1),
19
- * ); // result: "date1687219200000+"
20
- *
23
+ * ); // TheDate
21
24
  * ```
22
25
  *
26
+ * @remarks
27
+ * - Uses UTC year arithmetic (`Date#setUTCFullYear` behavior).
28
+ *
23
29
  * @see https://utils.duplojs.dev/en/v1/api/date/subtractYears
24
30
  *
25
31
  * @namespace D
26
32
  *
27
33
  */
28
- export declare function subtractYears<GenericInput extends TheDate, GenericYear extends number>(year: GenericYear): (input: GenericInput) => TheDate;
29
- export declare function subtractYears<GenericInput extends TheDate, GenericYear extends number>(input: GenericInput, year: GenericYear): TheDate;
34
+ export declare function subtractYears<GenericInput extends TheDate | SerializedTheDate, GenericYear extends number>(year: GenericYear): (input: GenericInput) => TheDate;
35
+ export declare function subtractYears<GenericInput extends TheDate | SerializedTheDate, GenericYear extends number>(input: GenericInput, year: GenericYear): TheDate;
@@ -1,4 +1,4 @@
1
- import { createTheDate } from '../createTheDate.mjs';
1
+ import { TheDate } from '../theDate.mjs';
2
2
  import { toNative } from '../toNative.mjs';
3
3
 
4
4
  function subtractYears(...args) {
@@ -9,7 +9,7 @@ function subtractYears(...args) {
9
9
  const [input, year] = args;
10
10
  const date = toNative(input);
11
11
  date.setUTCFullYear(date.getUTCFullYear() - year);
12
- return createTheDate(date.getTime());
12
+ return TheDate.new(date.getTime());
13
13
  }
14
14
 
15
15
  export { subtractYears };
@@ -1,5 +1,6 @@
1
1
  'use strict';
2
2
 
3
+ var theDate = require('./theDate.cjs');
3
4
  var toNative = require('./toNative.cjs');
4
5
 
5
6
  const stepMapper = {
@@ -19,8 +20,7 @@ const stepMapper = {
19
20
  function round(input, unit = "day") {
20
21
  const date = toNative.toNative(input);
21
22
  const timestamp = stepMapper[unit](date);
22
- const isNegative = timestamp < 0;
23
- return `date${Math.abs(timestamp)}${isNegative ? "-" : "+"}`;
23
+ return theDate.TheDate.new(timestamp);
24
24
  }
25
25
 
26
26
  exports.round = round;
@@ -1,11 +1,12 @@
1
- import type { TheDate, Unit } from "./types";
1
+ import { TheDate } from "./theDate";
2
+ import type { SerializedTheDate, Unit } from "./types";
2
3
  export type RoundUnit = Exclude<Unit, "millisecond">;
3
4
  /**
4
- * Rounds a date to a unit.
5
+ * Rounds down a date to a UTC unit boundary.
5
6
  *
6
- * Signature: `round(input, unit)` → returns a value
7
+ * Signature: `round(input, unit?)` → `TheDate`
7
8
  *
8
- * The input value is not mutated.
9
+ * `input` accepts `TheDate` or `SerializedTheDate`. Default `unit` is `"day"`.
9
10
  *
10
11
  * ```ts
11
12
  * const input = D.create("2024-06-20", {
@@ -14,25 +15,21 @@ export type RoundUnit = Exclude<Unit, "millisecond">;
14
15
  * second: "56",
15
16
  * millisecond: "789",
16
17
  * });
17
- * const result = D.round(input);
18
- * // result: "date1718841600000+"
19
18
  *
20
- * const result2 = D.round(input, "month");
21
- * // result2: "date1717200000000+"
19
+ * const byDay = D.round(input);
20
+ * // byDay: TheDate
22
21
  *
23
- * pipe(
24
- * input,
25
- * D.round,
26
- * ); // result: "date1718841600000+"
22
+ * const byMonth = D.round(input, "month");
23
+ * // byMonth: TheDate
27
24
  *
28
25
  * ```
29
26
  *
30
27
  * @remarks
31
- * - Rounds using the provided unit.
28
+ * - Supported units: `second`, `minute`, `hour`, `day`, `month`, `year`.
32
29
  *
33
30
  * @see https://utils.duplojs.dev/en/v1/api/date/round
34
31
  *
35
32
  * @namespace D
36
33
  *
37
34
  */
38
- export declare function round(input: TheDate, unit?: RoundUnit): `date${number}-` | `date${number}+`;
35
+ export declare function round(input: (TheDate | SerializedTheDate), unit?: RoundUnit): TheDate;
@@ -1,3 +1,4 @@
1
+ import { TheDate } from './theDate.mjs';
1
2
  import { toNative } from './toNative.mjs';
2
3
 
3
4
  const stepMapper = {
@@ -17,8 +18,7 @@ const stepMapper = {
17
18
  function round(input, unit = "day") {
18
19
  const date = toNative(input);
19
20
  const timestamp = stepMapper[unit](date);
20
- const isNegative = timestamp < 0;
21
- return `date${Math.abs(timestamp)}${isNegative ? "-" : "+"}`;
21
+ return TheDate.new(timestamp);
22
22
  }
23
23
 
24
24
  export { round };
@@ -0,0 +1,14 @@
1
+ 'use strict';
2
+
3
+ var theDate = require('./theDate.cjs');
4
+
5
+ function serialize(input) {
6
+ if (input instanceof theDate.TheDate) {
7
+ const timestamp = input.getTime();
8
+ return `date${Math.abs(timestamp)}${timestamp > 0 ? "+" : "-"}`;
9
+ }
10
+ const number = input.toNative();
11
+ return `time${Math.abs(number)}${number > 0 ? "+" : "-"}`;
12
+ }
13
+
14
+ exports.serialize = serialize;
@@ -0,0 +1,41 @@
1
+ import { TheDate } from "./theDate";
2
+ import type { TheTime } from "./theTime";
3
+ import type { SerializedTheTime } from "./types";
4
+ import { type SerializedTheDate } from "./types/serializedTheDate";
5
+ /**
6
+ * Serializes immutable date values into their string literal formats.
7
+ *
8
+ * Supported call styles:
9
+ * - Classic: `serialize(input)` where `input` is `TheDate` or `TheTime`
10
+ * - Curried: not supported
11
+ *
12
+ * `TheDate` values are serialized to `SerializedTheDate` (`date${number}${"+" | "-"}`), and `TheTime` values are serialized to `SerializedTheTime` (`time${number}${"+" | "-"}`).
13
+ *
14
+ * ```ts
15
+ * const inputDate = D.create("2024-06-20");
16
+ * const resultDate = D.serialize(inputDate);
17
+ * // resultDate: SerializedTheDate
18
+ *
19
+ * const inputTime = D.createTime(4, "day");
20
+ * const resultTime = D.serialize(inputTime);
21
+ * // resultTime: SerializedTheTime
22
+ *
23
+ * const resultDate2 = D.serialize(
24
+ * D.create("2025-10-20"),
25
+ * );
26
+ * // resultDate2: SerializedTheDate
27
+ *
28
+ * ```
29
+ *
30
+ * @remarks
31
+ * - This function is the string bridge between immutable classes (`TheDate`, `TheTime`) and serialized literal types (`SerializedTheDate`, `SerializedTheTime`).
32
+ *
33
+ * @see https://utils.duplojs.dev/en/v1/api/date/serialize
34
+ * @see https://utils.duplojs.dev/en/v1/api/date/theDate
35
+ * @see https://utils.duplojs.dev/en/v1/api/date/theTime
36
+ *
37
+ * @namespace D
38
+ *
39
+ */
40
+ export declare function serialize(input: TheDate): SerializedTheDate;
41
+ export declare function serialize(input: TheTime): SerializedTheTime;
@@ -0,0 +1,12 @@
1
+ import { TheDate } from './theDate.mjs';
2
+
3
+ function serialize(input) {
4
+ if (input instanceof TheDate) {
5
+ const timestamp = input.getTime();
6
+ return `date${Math.abs(timestamp)}${timestamp > 0 ? "+" : "-"}`;
7
+ }
8
+ const number = input.toNative();
9
+ return `time${Math.abs(number)}${number > 0 ? "+" : "-"}`;
10
+ }
11
+
12
+ export { serialize };
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var createOrThrow = require('./createOrThrow.cjs');
4
3
  var toTimestamp = require('./toTimestamp.cjs');
4
+ var theDate = require('./theDate.cjs');
5
5
 
6
6
  function sort(...args) {
7
7
  if (args.length === 1) {
@@ -14,7 +14,7 @@ function sort(...args) {
14
14
  .sort(type === "DSC"
15
15
  ? (first, second) => second - first
16
16
  : (first, second) => first - second)
17
- .map(createOrThrow.createOrThrow);
17
+ .map(theDate.TheDate.new);
18
18
  }
19
19
 
20
20
  exports.sort = sort;
@@ -1,33 +1,34 @@
1
- import { type SortType } from "../common";
2
- import { type TheDate } from "./types";
1
+ import type { SortType } from "../common/types/sortType";
2
+ import { TheDate } from "./theDate";
3
+ import type { SerializedTheDate } from "./types";
3
4
  /**
4
- * Sorts dates in ascending or descending order.
5
+ * Sorts date values and returns normalized `TheDate[]`.
5
6
  *
6
7
  * **Supported call styles:**
7
- * - Classic: `sort(array, type)` → returns a value
8
- * - Curried: `sort(type)` → returns a function waiting for the input
9
- *
10
- * The input value is not mutated.
8
+ * - Classic: `sort(array, type)` → `TheDate[]`
9
+ * - Curried: `sort(type)` → `(array) => TheDate[]`
11
10
  *
12
11
  * ```ts
13
- * const input = [D.tomorrow(), D.yesterday(), D.today()] as const;
12
+ * const input = [
13
+ * D.create("2024-06-03"),
14
+ * "date1717286400000+",
15
+ * D.create("2024-06-01"),
16
+ * ] as const;
14
17
  *
15
- * const result = D.sort(input, "ASC");
18
+ * const asc = D.sort(input, "ASC");
19
+ * // asc: TheDate[]
16
20
  *
17
21
  * pipe(
18
22
  * input,
19
- * D.sort("ASC"),
20
- * );
21
- *
22
23
  * ```
23
24
  *
24
25
  * @remarks
25
- * - Sort order uses "ASC" or "DSC".
26
+ * - `type` is `"ASC"` or `"DSC"`.
26
27
  *
27
28
  * @see https://utils.duplojs.dev/en/v1/api/date/sort
28
29
  *
29
30
  * @namespace D
30
31
  *
31
32
  */
32
- export declare function sort<GenericArray extends readonly TheDate[]>(type: SortType): (array: GenericArray) => TheDate[];
33
- export declare function sort<GenericArray extends readonly TheDate[]>(array: GenericArray, type: SortType): TheDate[];
33
+ export declare function sort<GenericArray extends readonly (TheDate | SerializedTheDate)[]>(type: SortType): (array: GenericArray) => TheDate[];
34
+ export declare function sort<GenericArray extends readonly (TheDate | SerializedTheDate)[]>(array: GenericArray, type: SortType): TheDate[];
@@ -1,5 +1,5 @@
1
- import { createOrThrow } from './createOrThrow.mjs';
2
1
  import { toTimestamp } from './toTimestamp.mjs';
2
+ import { TheDate } from './theDate.mjs';
3
3
 
4
4
  function sort(...args) {
5
5
  if (args.length === 1) {
@@ -12,7 +12,7 @@ function sort(...args) {
12
12
  .sort(type === "DSC"
13
13
  ? (first, second) => second - first
14
14
  : (first, second) => first - second)
15
- .map(createOrThrow);
15
+ .map(TheDate.new);
16
16
  }
17
17
 
18
18
  export { sort };
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var createTheTime = require('./createTheTime.cjs');
4
3
  var toTimeValue = require('./toTimeValue.cjs');
4
+ var theTime = require('./theTime.cjs');
5
5
 
6
6
  function sortTimes(...args) {
7
7
  if (args.length === 1) {
@@ -14,7 +14,7 @@ function sortTimes(...args) {
14
14
  .sort(type === "DSC"
15
15
  ? (first, second) => second - first
16
16
  : (first, second) => first - second)
17
- .map(createTheTime.createTheTime);
17
+ .map(theTime.TheTime.new);
18
18
  }
19
19
 
20
20
  exports.sortTimes = sortTimes;
@@ -1,40 +1,34 @@
1
- import { type SortType } from "../common";
2
- import { type TheTime } from "./types";
1
+ import type { SortType } from "../common/types/sortType";
2
+ import { TheTime } from "./theTime";
3
+ import type { SerializedTheTime } from "./types/serializedTheTime";
3
4
  /**
4
- * Sorts time values in ascending or descending order.
5
+ * Sorts duration values and returns normalized `TheTime[]`.
5
6
  *
6
7
  * **Supported call styles:**
7
- * - Classic: `sortTimes(array, type)` → returns a value
8
- * - Curried: `sortTimes(type)` → returns a function waiting for the input
9
- *
10
- * The input value is not mutated.
8
+ * - Classic: `sortTimes(array, type)` → `TheTime[]`
9
+ * - Curried: `sortTimes(type)` → `(array) => TheTime[]`
11
10
  *
12
11
  * ```ts
13
12
  * const input = [
14
- * D.createTheTime(3_000),
15
- * D.createTheTime(1_000),
16
- * D.createTheTime(2_000),
17
- * ];
18
- *
19
- * const result = D.sortTimes(input, "ASC");
20
- * // result: ["time1000+", "time2000+", "time3000+"]
13
+ * D.createTime(3_000, "millisecond"),
14
+ * "time1000+",
15
+ * D.createTime(2_000, "millisecond"),
16
+ * ] as const;
21
17
  *
22
- * const result2 = D.sortTimes(input, "DSC");
23
- * // result2: ["time3000+", "time2000+", "time1000+"]
18
+ * const asc = D.sortTimes(input, "ASC");
19
+ * // asc: TheTime[]
24
20
  *
25
21
  * pipe(
26
22
  * input,
27
- * D.sortTimes("ASC"),
28
- * ); // result: ["time1000+", "time2000+", "time3000+"]
29
23
  * ```
30
24
  *
31
25
  * @remarks
32
- * - Sort order uses "ASC" or "DSC".
26
+ * - `type` is `"ASC"` or `"DSC"`.
33
27
  *
34
28
  * @see https://utils.duplojs.dev/en/v1/api/date/sortTimes
35
29
  *
36
30
  * @namespace D
37
31
  *
38
32
  */
39
- export declare function sortTimes<GenericArray extends readonly TheTime[]>(type: SortType): (array: GenericArray) => TheTime[];
40
- export declare function sortTimes<GenericArray extends readonly TheTime[]>(array: GenericArray, type: SortType): TheTime[];
33
+ export declare function sortTimes<GenericArray extends readonly (TheTime | SerializedTheTime)[]>(type: SortType): (array: GenericArray) => TheTime[];
34
+ export declare function sortTimes<GenericArray extends readonly (TheTime | SerializedTheTime)[]>(array: GenericArray, type: SortType): TheTime[];
@@ -1,5 +1,5 @@
1
- import { createTheTime } from './createTheTime.mjs';
2
1
  import { toTimeValue } from './toTimeValue.mjs';
2
+ import { TheTime } from './theTime.mjs';
3
3
 
4
4
  function sortTimes(...args) {
5
5
  if (args.length === 1) {
@@ -12,7 +12,7 @@ function sortTimes(...args) {
12
12
  .sort(type === "DSC"
13
13
  ? (first, second) => second - first
14
14
  : (first, second) => first - second)
15
- .map(createTheTime);
15
+ .map(TheTime.new);
16
16
  }
17
17
 
18
18
  export { sortTimes };
@@ -0,0 +1,124 @@
1
+ 'use strict';
2
+
3
+ var kind = require('../common/kind.cjs');
4
+ var kind$1 = require('./kind.cjs');
5
+ var makeSafeTimestamp = require('./makeSafeTimestamp.cjs');
6
+ var serialize = require('./serialize.cjs');
7
+
8
+ const defaultKindValue = {};
9
+ /**
10
+ * {@include date/theDate/index.md}
11
+ */
12
+ class TheDate extends kind.kindHeritage("the-date", kind$1.createDateKind("the-date"), Date) {
13
+ constructor(timestamp) {
14
+ super(defaultKindValue, [timestamp]);
15
+ }
16
+ toNative() {
17
+ return new Date(this.getTime());
18
+ }
19
+ toString() {
20
+ return serialize.serialize(this);
21
+ }
22
+ toJSON() {
23
+ return serialize.serialize(this);
24
+ }
25
+ /**
26
+ * @deprecated this method does not work on ImmutableDate
27
+ */
28
+ setDate(_date) {
29
+ return this.getTime();
30
+ }
31
+ /**
32
+ * @deprecated this method does not work on ImmutableDate
33
+ */
34
+ setFullYear(_year, _month, _date) {
35
+ return this.getTime();
36
+ }
37
+ /**
38
+ * @deprecated this method does not work on ImmutableDate
39
+ */
40
+ setHours(_hours, _min, _sec, _ms) {
41
+ return this.getTime();
42
+ }
43
+ /**
44
+ * @deprecated this method does not work on ImmutableDate
45
+ */
46
+ setMilliseconds(_ms) {
47
+ return this.getTime();
48
+ }
49
+ /**
50
+ * @deprecated this method does not work on ImmutableDate
51
+ */
52
+ setMinutes(_min, _sec, _ms) {
53
+ return this.getTime();
54
+ }
55
+ /**
56
+ * @deprecated this method does not work on ImmutableDate
57
+ */
58
+ setMonth(_month, _date) {
59
+ return this.getTime();
60
+ }
61
+ /**
62
+ * @deprecated this method does not work on ImmutableDate
63
+ */
64
+ setSeconds(_sec, _ms) {
65
+ return this.getTime();
66
+ }
67
+ /**
68
+ * @deprecated this method does not work on ImmutableDate
69
+ */
70
+ setTime(_time) {
71
+ return this.getTime();
72
+ }
73
+ /**
74
+ * @deprecated this method does not work on ImmutableDate
75
+ */
76
+ setUTCDate(_date) {
77
+ return this.getTime();
78
+ }
79
+ /**
80
+ * @deprecated this method does not work on ImmutableDate
81
+ */
82
+ setUTCFullYear(_year, _month, _date) {
83
+ return this.getTime();
84
+ }
85
+ /**
86
+ * @deprecated this method does not work on ImmutableDate
87
+ */
88
+ setUTCHours(_hours, _min, _sec, _ms) {
89
+ return this.getTime();
90
+ }
91
+ /**
92
+ * @deprecated this method does not work on ImmutableDate
93
+ */
94
+ setUTCMilliseconds(_ms) {
95
+ return this.getTime();
96
+ }
97
+ /**
98
+ * @deprecated this method does not work on ImmutableDate
99
+ */
100
+ setUTCMinutes(_min, _sec, _ms) {
101
+ return this.getTime();
102
+ }
103
+ /**
104
+ * @deprecated this method does not work on ImmutableDate
105
+ */
106
+ setUTCMonth(_month, _date) {
107
+ return this.getTime();
108
+ }
109
+ /**
110
+ * @deprecated this method does not work on ImmutableDate
111
+ */
112
+ setUTCSeconds(_sec, _ms) {
113
+ return this.getTime();
114
+ }
115
+ /**
116
+ * @internal
117
+ * @deprecated use DDate.create | DDate.createOrThrow function
118
+ */
119
+ static "new"(timestamp) {
120
+ return new TheDate(makeSafeTimestamp.makeSafeTimestamp(timestamp));
121
+ }
122
+ }
123
+
124
+ exports.TheDate = TheDate;
@@ -0,0 +1,114 @@
1
+ import type { SerializedTheDate } from "./types/serializedTheDate";
2
+ declare const TheDate_base: new (params: {
3
+ "@DuplojsUtilsDate/the-date"?: unknown;
4
+ }, parentParams: readonly [value: string | number | Date]) => Date & import("../common/kind").Kind<import("../common/kind").KindDefinition<"the-date", unknown>, unknown> & import("../common/kind").Kind<import("../common/kind").KindDefinition<"@DuplojsUtilsDate/the-date", unknown>, unknown>;
5
+ /**
6
+ * Represents an immutable date-time object (`TheDate`) based on UTC.
7
+ *
8
+ * Signature: `TheDate` → immutable class extending `Date`
9
+ *
10
+ * `TheDate` solves two recurring problems: accidental mutation of native `Date`, and ambiguity between object dates and transport formats. You manipulate a stable object in code, and serialize it explicitly when you need to cross process boundaries.
11
+ *
12
+ * ```ts
13
+ * const theDate = D.create("2025-10-20");
14
+ * // theDate: TheDate
15
+ *
16
+ * const timestamp = theDate.getTime();
17
+ * // timestamp: number
18
+ *
19
+ * const nativeDate = theDate.toNative();
20
+ * // nativeDate: Date
21
+ *
22
+ * const serialized = D.serialize(theDate);
23
+ * // serialized: SerializedTheDate
24
+ *
25
+ * const yearInParis = D.getYear(theDate, "Europe/Paris");
26
+ * // yearInParis: number
27
+ *
28
+ * const datePlusOneDay = D.addDays(theDate, 1);
29
+ * // datePlusOneDay: TheDate
30
+ *
31
+ * const iso = D.toISOString(theDate);
32
+ * // iso: string
33
+ *
34
+ * ```
35
+ *
36
+ * @remarks
37
+ * - `TheDate` is immutable: mutation methods from `Date` are intentionally disabled.
38
+ * - Use `D.serialize(theDate)` to convert to `SerializedTheDate`.
39
+ * - Use `D.create(...)` / `D.createOrThrow(...)` to construct instances.
40
+ *
41
+ * @see https://utils.duplojs.dev/en/v1/api/date/theDate
42
+ * @see https://utils.duplojs.dev/en/v1/api/date/serialize
43
+ * @see https://utils.duplojs.dev/en/v1/api/date/create
44
+ *
45
+ * @namespace D
46
+ *
47
+ */
48
+ export declare class TheDate extends TheDate_base {
49
+ private constructor();
50
+ toNative(): Date;
51
+ toString(): SerializedTheDate;
52
+ toJSON(): SerializedTheDate;
53
+ /**
54
+ * @deprecated this method does not work on ImmutableDate
55
+ */
56
+ setDate(_date: number): number;
57
+ /**
58
+ * @deprecated this method does not work on ImmutableDate
59
+ */
60
+ setFullYear(_year: number, _month?: number, _date?: number): number;
61
+ /**
62
+ * @deprecated this method does not work on ImmutableDate
63
+ */
64
+ setHours(_hours: number, _min?: number, _sec?: number, _ms?: number): number;
65
+ /**
66
+ * @deprecated this method does not work on ImmutableDate
67
+ */
68
+ setMilliseconds(_ms: number): number;
69
+ /**
70
+ * @deprecated this method does not work on ImmutableDate
71
+ */
72
+ setMinutes(_min: number, _sec?: number, _ms?: number): number;
73
+ /**
74
+ * @deprecated this method does not work on ImmutableDate
75
+ */
76
+ setMonth(_month: number, _date?: number): number;
77
+ /**
78
+ * @deprecated this method does not work on ImmutableDate
79
+ */
80
+ setSeconds(_sec: number, _ms?: number): number;
81
+ /**
82
+ * @deprecated this method does not work on ImmutableDate
83
+ */
84
+ setTime(_time: number): number;
85
+ /**
86
+ * @deprecated this method does not work on ImmutableDate
87
+ */
88
+ setUTCDate(_date: number): number;
89
+ /**
90
+ * @deprecated this method does not work on ImmutableDate
91
+ */
92
+ setUTCFullYear(_year: number, _month?: number, _date?: number): number;
93
+ /**
94
+ * @deprecated this method does not work on ImmutableDate
95
+ */
96
+ setUTCHours(_hours: number, _min?: number, _sec?: number, _ms?: number): number;
97
+ /**
98
+ * @deprecated this method does not work on ImmutableDate
99
+ */
100
+ setUTCMilliseconds(_ms: number): number;
101
+ /**
102
+ * @deprecated this method does not work on ImmutableDate
103
+ */
104
+ setUTCMinutes(_min: number, _sec?: number, _ms?: number): number;
105
+ /**
106
+ * @deprecated this method does not work on ImmutableDate
107
+ */
108
+ setUTCMonth(_month: number, _date?: number): number;
109
+ /**
110
+ * @deprecated this method does not work on ImmutableDate
111
+ */
112
+ setUTCSeconds(_sec: number, _ms?: number): number;
113
+ }
114
+ export {};