@duplojs/utils 1.4.57 → 1.4.59

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 (319) hide show
  1. package/dist/array/group.cjs +11 -11
  2. package/dist/array/group.d.ts +1 -1
  3. package/dist/array/group.mjs +11 -11
  4. package/dist/clean/constraint/base.d.ts +6 -4
  5. package/dist/clean/constraint/defaultConstraint/index.d.ts +1 -0
  6. package/dist/clean/constraint/defaultConstraint/number.d.ts +6 -6
  7. package/dist/clean/constraint/defaultConstraint/string.d.ts +4 -4
  8. package/dist/clean/constraint/defaultConstraint/time.cjs +19 -0
  9. package/dist/clean/constraint/defaultConstraint/time.d.ts +61 -0
  10. package/dist/clean/constraint/defaultConstraint/time.mjs +16 -0
  11. package/dist/clean/constraint/set.d.ts +6 -4
  12. package/dist/clean/entity.d.ts +2 -1
  13. package/dist/clean/index.cjs +3 -0
  14. package/dist/clean/index.mjs +1 -0
  15. package/dist/clean/newType.d.ts +7 -5
  16. package/dist/clean/primitive/base.d.ts +25 -34
  17. package/dist/clean/primitive/operations/date/dateAddTime.d.ts +7 -11
  18. package/dist/clean/primitive/operations/date/dateGreaterThan.d.ts +9 -7
  19. package/dist/clean/primitive/operations/date/dateLessThan.d.ts +9 -7
  20. package/dist/clean/primitive/operations/date/dateMax.d.ts +3 -10
  21. package/dist/clean/primitive/operations/date/dateMin.d.ts +3 -10
  22. package/dist/clean/primitive/operations/date/dateSubtractTime.d.ts +7 -11
  23. package/dist/clean/primitive/operations/equal.cjs +1 -1
  24. package/dist/clean/primitive/operations/equal.d.ts +3 -3
  25. package/dist/clean/primitive/operations/equal.mjs +1 -1
  26. package/dist/clean/primitive/operations/sort.d.ts +8 -10
  27. package/dist/clean/primitive/operations/time/timeGreaterThan.d.ts +11 -9
  28. package/dist/clean/primitive/operations/time/timeLessThan.d.ts +11 -9
  29. package/dist/clean/primitive/operations/time/timeMax.cjs +2 -2
  30. package/dist/clean/primitive/operations/time/timeMax.d.ts +10 -17
  31. package/dist/clean/primitive/operations/time/timeMax.mjs +2 -2
  32. package/dist/clean/primitive/operations/time/timeMin.cjs +3 -3
  33. package/dist/clean/primitive/operations/time/timeMin.d.ts +10 -17
  34. package/dist/clean/primitive/operations/time/timeMin.mjs +3 -3
  35. package/dist/clean/unwrapEntity.cjs +13 -3
  36. package/dist/clean/unwrapEntity.d.ts +57 -5
  37. package/dist/clean/unwrapEntity.mjs +13 -3
  38. package/dist/common/index.d.ts +3 -4
  39. package/dist/common/kind.d.ts +1 -0
  40. package/dist/common/path.cjs +13 -13
  41. package/dist/common/path.d.ts +17 -11
  42. package/dist/common/path.mjs +13 -13
  43. package/dist/common/toRegExp.cjs +19 -0
  44. package/dist/common/toRegExp.d.ts +31 -0
  45. package/dist/common/toRegExp.mjs +17 -0
  46. package/dist/common/transformer.cjs +45 -0
  47. package/dist/common/transformer.d.ts +61 -0
  48. package/dist/common/transformer.mjs +40 -0
  49. package/dist/common/types/DeepReadonly.d.ts +1 -1
  50. package/dist/common/types/toLargeEnsemble.d.ts +2 -2
  51. package/dist/dataParser/error.cjs +4 -2
  52. package/dist/dataParser/error.d.ts +4 -2
  53. package/dist/dataParser/error.mjs +4 -2
  54. package/dist/dataParser/extended/date.d.ts +9 -4
  55. package/dist/dataParser/extended/time.d.ts +28 -12
  56. package/dist/dataParser/identifier.d.ts +20 -8
  57. package/dist/dataParser/parsers/date.cjs +16 -12
  58. package/dist/dataParser/parsers/date.d.ts +15 -9
  59. package/dist/dataParser/parsers/date.mjs +16 -12
  60. package/dist/dataParser/parsers/time/checkers/max.cjs +3 -0
  61. package/dist/dataParser/parsers/time/checkers/max.d.ts +28 -0
  62. package/dist/dataParser/parsers/time/checkers/max.mjs +3 -0
  63. package/dist/dataParser/parsers/time/checkers/min.cjs +3 -0
  64. package/dist/dataParser/parsers/time/checkers/min.d.ts +28 -0
  65. package/dist/dataParser/parsers/time/checkers/min.mjs +3 -0
  66. package/dist/dataParser/parsers/time/index.cjs +14 -10
  67. package/dist/dataParser/parsers/time/index.d.ts +15 -9
  68. package/dist/dataParser/parsers/time/index.mjs +14 -10
  69. package/dist/date/applyTimezone.cjs +4 -4
  70. package/dist/date/applyTimezone.d.ts +18 -16
  71. package/dist/date/applyTimezone.mjs +2 -2
  72. package/dist/date/closestTo.cjs +6 -2
  73. package/dist/date/closestTo.d.ts +15 -15
  74. package/dist/date/closestTo.mjs +6 -2
  75. package/dist/date/constants.cjs +4 -4
  76. package/dist/date/constants.d.ts +2 -2
  77. package/dist/date/constants.mjs +3 -3
  78. package/dist/date/create.cjs +20 -10
  79. package/dist/date/create.d.ts +24 -38
  80. package/dist/date/create.mjs +21 -11
  81. package/dist/date/createOrThrow.d.ts +18 -20
  82. package/dist/date/createTime.cjs +16 -7
  83. package/dist/date/createTime.d.ts +19 -18
  84. package/dist/date/createTime.mjs +17 -8
  85. package/dist/date/createTimeOrThrow.d.ts +17 -20
  86. package/dist/date/each.cjs +6 -4
  87. package/dist/date/each.d.ts +21 -19
  88. package/dist/date/each.mjs +6 -4
  89. package/dist/date/format.d.ts +17 -15
  90. package/dist/date/formatTime.d.ts +17 -16
  91. package/dist/date/getTimezoneOffset.cjs +6 -3
  92. package/dist/date/getTimezoneOffset.d.ts +17 -18
  93. package/dist/date/getTimezoneOffset.mjs +6 -3
  94. package/dist/date/getters/getDayOfMonth.cjs +3 -3
  95. package/dist/date/getters/getDayOfMonth.d.ts +20 -14
  96. package/dist/date/getters/getDayOfMonth.mjs +3 -3
  97. package/dist/date/getters/getDayOfWeek.cjs +3 -3
  98. package/dist/date/getters/getDayOfWeek.d.ts +15 -12
  99. package/dist/date/getters/getDayOfWeek.mjs +3 -3
  100. package/dist/date/getters/getDayOfYear.cjs +6 -6
  101. package/dist/date/getters/getDayOfYear.d.ts +21 -13
  102. package/dist/date/getters/getDayOfYear.mjs +6 -6
  103. package/dist/date/getters/getFirstDayOfMonth.cjs +2 -3
  104. package/dist/date/getters/getFirstDayOfMonth.d.ts +16 -10
  105. package/dist/date/getters/getFirstDayOfMonth.mjs +2 -3
  106. package/dist/date/getters/getFirstDayOfWeek.cjs +2 -3
  107. package/dist/date/getters/getFirstDayOfWeek.d.ts +17 -10
  108. package/dist/date/getters/getFirstDayOfWeek.mjs +2 -3
  109. package/dist/date/getters/getHour.cjs +3 -3
  110. package/dist/date/getters/getHour.d.ts +16 -14
  111. package/dist/date/getters/getHour.mjs +3 -3
  112. package/dist/date/getters/getLastDayOfMonth.cjs +2 -3
  113. package/dist/date/getters/getLastDayOfMonth.d.ts +16 -10
  114. package/dist/date/getters/getLastDayOfMonth.mjs +2 -3
  115. package/dist/date/getters/getLastDayOfWeek.cjs +2 -3
  116. package/dist/date/getters/getLastDayOfWeek.d.ts +17 -10
  117. package/dist/date/getters/getLastDayOfWeek.mjs +2 -3
  118. package/dist/date/getters/getMilliseconds.cjs +2 -2
  119. package/dist/date/getters/getMilliseconds.d.ts +11 -9
  120. package/dist/date/getters/getMilliseconds.mjs +2 -2
  121. package/dist/date/getters/getMinute.cjs +3 -3
  122. package/dist/date/getters/getMinute.d.ts +17 -15
  123. package/dist/date/getters/getMinute.mjs +3 -3
  124. package/dist/date/getters/getMonth.cjs +3 -3
  125. package/dist/date/getters/getMonth.d.ts +20 -15
  126. package/dist/date/getters/getMonth.mjs +3 -3
  127. package/dist/date/getters/getSecond.cjs +3 -3
  128. package/dist/date/getters/getSecond.d.ts +17 -15
  129. package/dist/date/getters/getSecond.mjs +3 -3
  130. package/dist/date/getters/getWeekOfYear.cjs +12 -11
  131. package/dist/date/getters/getWeekOfYear.d.ts +17 -11
  132. package/dist/date/getters/getWeekOfYear.mjs +12 -11
  133. package/dist/date/getters/getYear.cjs +3 -3
  134. package/dist/date/getters/getYear.d.ts +16 -15
  135. package/dist/date/getters/getYear.mjs +3 -3
  136. package/dist/date/index.cjs +12 -6
  137. package/dist/date/index.d.ts +5 -2
  138. package/dist/date/index.mjs +6 -3
  139. package/dist/date/is.cjs +3 -8
  140. package/dist/date/is.d.ts +9 -14
  141. package/dist/date/is.mjs +3 -8
  142. package/dist/date/isSafeTimeValue.d.ts +9 -13
  143. package/dist/date/isSafeTimestamp.d.ts +7 -16
  144. package/dist/date/isSerializedTheDate.cjs +20 -0
  145. package/dist/date/isSerializedTheDate.d.ts +31 -0
  146. package/dist/date/isSerializedTheDate.mjs +18 -0
  147. package/dist/date/isSerializedTheTime.cjs +20 -0
  148. package/dist/date/isSerializedTheTime.d.ts +31 -0
  149. package/dist/date/isSerializedTheTime.mjs +18 -0
  150. package/dist/date/isTime.cjs +3 -8
  151. package/dist/date/isTime.d.ts +7 -14
  152. package/dist/date/isTime.mjs +3 -8
  153. package/dist/date/kind.cjs +9 -0
  154. package/dist/date/kind.d.ts +1 -0
  155. package/dist/date/kind.mjs +7 -0
  156. package/dist/date/makeSafeTimeValue.d.ts +12 -11
  157. package/dist/date/makeSafeTimestamp.d.ts +12 -11
  158. package/dist/date/max.cjs +2 -2
  159. package/dist/date/max.d.ts +13 -13
  160. package/dist/date/max.mjs +2 -2
  161. package/dist/date/maxTime.cjs +2 -2
  162. package/dist/date/maxTime.d.ts +13 -21
  163. package/dist/date/maxTime.mjs +2 -2
  164. package/dist/date/min.cjs +2 -2
  165. package/dist/date/min.d.ts +13 -13
  166. package/dist/date/min.mjs +2 -2
  167. package/dist/date/minTime.cjs +2 -2
  168. package/dist/date/minTime.d.ts +13 -21
  169. package/dist/date/minTime.mjs +2 -2
  170. package/dist/date/now.cjs +3 -1
  171. package/dist/date/now.d.ts +9 -7
  172. package/dist/date/now.mjs +3 -1
  173. package/dist/date/operators/addDays.cjs +3 -5
  174. package/dist/date/operators/addDays.d.ts +14 -11
  175. package/dist/date/operators/addDays.mjs +3 -5
  176. package/dist/date/operators/addHours.cjs +3 -5
  177. package/dist/date/operators/addHours.d.ts +14 -11
  178. package/dist/date/operators/addHours.mjs +3 -5
  179. package/dist/date/operators/addMilliseconds.cjs +3 -5
  180. package/dist/date/operators/addMilliseconds.d.ts +14 -11
  181. package/dist/date/operators/addMilliseconds.mjs +3 -5
  182. package/dist/date/operators/addMinutes.cjs +3 -5
  183. package/dist/date/operators/addMinutes.d.ts +14 -11
  184. package/dist/date/operators/addMinutes.mjs +3 -5
  185. package/dist/date/operators/addMonths.cjs +2 -2
  186. package/dist/date/operators/addMonths.d.ts +13 -13
  187. package/dist/date/operators/addMonths.mjs +2 -2
  188. package/dist/date/operators/addSeconds.cjs +3 -5
  189. package/dist/date/operators/addSeconds.d.ts +14 -11
  190. package/dist/date/operators/addSeconds.mjs +3 -5
  191. package/dist/date/operators/addTime.cjs +13 -6
  192. package/dist/date/operators/addTime.d.ts +20 -18
  193. package/dist/date/operators/addTime.mjs +13 -6
  194. package/dist/date/operators/addWeeks.cjs +6 -5
  195. package/dist/date/operators/addWeeks.d.ts +14 -11
  196. package/dist/date/operators/addWeeks.mjs +6 -5
  197. package/dist/date/operators/addYears.cjs +2 -2
  198. package/dist/date/operators/addYears.d.ts +13 -13
  199. package/dist/date/operators/addYears.mjs +2 -2
  200. package/dist/date/operators/between.d.ts +11 -11
  201. package/dist/date/operators/betweenThan.d.ts +11 -11
  202. package/dist/date/operators/betweenThanTime.d.ts +18 -22
  203. package/dist/date/operators/betweenTime.d.ts +17 -21
  204. package/dist/date/operators/greater.d.ts +12 -9
  205. package/dist/date/operators/greaterThan.d.ts +14 -11
  206. package/dist/date/operators/greaterThanTime.d.ts +17 -21
  207. package/dist/date/operators/greaterTime.d.ts +16 -20
  208. package/dist/date/operators/less.d.ts +12 -9
  209. package/dist/date/operators/lessThan.d.ts +13 -10
  210. package/dist/date/operators/lessThanTime.d.ts +17 -21
  211. package/dist/date/operators/lessTime.d.ts +16 -20
  212. package/dist/date/operators/subtractDays.cjs +3 -5
  213. package/dist/date/operators/subtractDays.d.ts +14 -11
  214. package/dist/date/operators/subtractDays.mjs +3 -5
  215. package/dist/date/operators/subtractHours.cjs +3 -5
  216. package/dist/date/operators/subtractHours.d.ts +14 -11
  217. package/dist/date/operators/subtractHours.mjs +3 -5
  218. package/dist/date/operators/subtractMilliseconds.cjs +3 -5
  219. package/dist/date/operators/subtractMilliseconds.d.ts +14 -11
  220. package/dist/date/operators/subtractMilliseconds.mjs +3 -5
  221. package/dist/date/operators/subtractMinutes.cjs +3 -5
  222. package/dist/date/operators/subtractMinutes.d.ts +14 -11
  223. package/dist/date/operators/subtractMinutes.mjs +3 -5
  224. package/dist/date/operators/subtractMonths.cjs +2 -2
  225. package/dist/date/operators/subtractMonths.d.ts +17 -11
  226. package/dist/date/operators/subtractMonths.mjs +2 -2
  227. package/dist/date/operators/subtractSeconds.cjs +3 -5
  228. package/dist/date/operators/subtractSeconds.d.ts +14 -11
  229. package/dist/date/operators/subtractSeconds.mjs +3 -5
  230. package/dist/date/operators/subtractTime.cjs +13 -6
  231. package/dist/date/operators/subtractTime.d.ts +20 -18
  232. package/dist/date/operators/subtractTime.mjs +13 -6
  233. package/dist/date/operators/subtractWeeks.cjs +3 -5
  234. package/dist/date/operators/subtractWeeks.d.ts +14 -11
  235. package/dist/date/operators/subtractWeeks.mjs +3 -5
  236. package/dist/date/operators/subtractYears.cjs +2 -2
  237. package/dist/date/operators/subtractYears.d.ts +17 -11
  238. package/dist/date/operators/subtractYears.mjs +2 -2
  239. package/dist/date/round.cjs +2 -2
  240. package/dist/date/round.d.ts +11 -14
  241. package/dist/date/round.mjs +2 -2
  242. package/dist/date/serialize.cjs +14 -0
  243. package/dist/date/serialize.d.ts +41 -0
  244. package/dist/date/serialize.mjs +12 -0
  245. package/dist/date/sort.cjs +2 -2
  246. package/dist/date/sort.d.ts +16 -15
  247. package/dist/date/sort.mjs +2 -2
  248. package/dist/date/sortTimes.cjs +2 -2
  249. package/dist/date/sortTimes.d.ts +15 -21
  250. package/dist/date/sortTimes.mjs +2 -2
  251. package/dist/date/theDate.cjs +124 -0
  252. package/dist/date/theDate.d.ts +114 -0
  253. package/dist/date/theDate.mjs +122 -0
  254. package/dist/date/theTime.cjs +36 -0
  255. package/dist/date/theTime.d.ts +53 -0
  256. package/dist/date/theTime.mjs +34 -0
  257. package/dist/date/timezone.cjs +3 -0
  258. package/dist/date/timezone.d.ts +27 -0
  259. package/dist/date/timezone.mjs +3 -0
  260. package/dist/date/toISOString.cjs +5 -2
  261. package/dist/date/toISOString.d.ts +12 -10
  262. package/dist/date/toISOString.mjs +5 -2
  263. package/dist/date/toNative.cjs +4 -0
  264. package/dist/date/toNative.d.ts +12 -10
  265. package/dist/date/toNative.mjs +4 -0
  266. package/dist/date/toTimeValue.cjs +6 -2
  267. package/dist/date/toTimeValue.d.ts +14 -12
  268. package/dist/date/toTimeValue.mjs +6 -2
  269. package/dist/date/toTimestamp.cjs +5 -3
  270. package/dist/date/toTimestamp.d.ts +11 -9
  271. package/dist/date/toTimestamp.mjs +6 -4
  272. package/dist/date/today.cjs +3 -1
  273. package/dist/date/today.d.ts +14 -7
  274. package/dist/date/today.mjs +3 -1
  275. package/dist/date/tomorrow.cjs +2 -1
  276. package/dist/date/tomorrow.d.ts +12 -7
  277. package/dist/date/tomorrow.mjs +2 -1
  278. package/dist/date/types/index.d.ts +2 -2
  279. package/dist/date/types/serializedTheDate.d.ts +1 -0
  280. package/dist/date/types/serializedTheTime.d.ts +42 -0
  281. package/dist/date/types/spoolingDate.d.ts +2 -1
  282. package/dist/date/yesterday.cjs +2 -1
  283. package/dist/date/yesterday.d.ts +12 -7
  284. package/dist/date/yesterday.mjs +2 -1
  285. package/dist/generator/asyncGroup.cjs +31 -0
  286. package/dist/generator/asyncGroup.d.ts +39 -0
  287. package/dist/generator/asyncGroup.mjs +29 -0
  288. package/dist/generator/group.cjs +39 -0
  289. package/dist/generator/group.d.ts +101 -0
  290. package/dist/generator/group.mjs +36 -0
  291. package/dist/generator/index.cjs +5 -0
  292. package/dist/generator/index.d.ts +3 -0
  293. package/dist/generator/index.mjs +2 -0
  294. package/dist/index.cjs +7 -6
  295. package/dist/index.mjs +2 -3
  296. package/dist/metadata.json +94 -40
  297. package/dist/object/entries.cjs +7 -2
  298. package/dist/object/entries.mjs +7 -2
  299. package/dist/object/keys.cjs +7 -2
  300. package/dist/object/keys.d.ts +1 -1
  301. package/dist/object/keys.mjs +7 -2
  302. package/package.json +1 -1
  303. package/dist/common/toJSON.cjs +0 -37
  304. package/dist/common/toJSON.d.ts +0 -44
  305. package/dist/common/toJSON.mjs +0 -35
  306. package/dist/common/toString.cjs +0 -10
  307. package/dist/common/toString.d.ts +0 -17
  308. package/dist/common/toString.mjs +0 -8
  309. package/dist/common/toTransform.cjs +0 -37
  310. package/dist/common/toTransform.d.ts +0 -50
  311. package/dist/common/toTransform.mjs +0 -35
  312. package/dist/date/createTheDate.cjs +0 -13
  313. package/dist/date/createTheDate.d.ts +0 -28
  314. package/dist/date/createTheDate.mjs +0 -11
  315. package/dist/date/createTheTime.cjs +0 -13
  316. package/dist/date/createTheTime.d.ts +0 -25
  317. package/dist/date/createTheTime.mjs +0 -11
  318. package/dist/date/types/theDate.d.ts +0 -11
  319. package/dist/date/types/theTime.d.ts +0 -10
@@ -1,31 +1,34 @@
1
- import { type TheDate, type Timezone } from "..";
1
+ import type { SerializedTheDate } from "../types";
2
+ import { type TheDate } from "../theDate";
3
+ import type { Timezone } from "../timezone";
2
4
  /**
3
- * Returns the day of week of a date.
5
+ * Returns the day of week (`0` to `6`) for a date in a target timezone.
4
6
  *
5
- * Signature: `getDayOfWeek(input, timezone)` → returns a value
7
+ * Signature: `getDayOfWeek(input, timezone?)` → `number`
6
8
  *
7
- * If timezone is omitted, UTC is used.
8
- *
9
- * The input value is not mutated.
9
+ * `input` accepts `TheDate` or `SerializedTheDate`. If `timezone` is omitted, UTC is used.
10
10
  *
11
11
  * ```ts
12
12
  * const input = D.create("2024-06-17");
13
- * const result = D.getDayOfWeek(input);
14
- * // result: 1
13
+ * const utcWeekday = D.getDayOfWeek(input);
14
+ * // utcWeekday: 1
15
15
  *
16
- * const result2 = D.getDayOfWeek(input, "Europe/London");
17
- * // result2: 1
16
+ * const tokyoWeekday = D.getDayOfWeek(input, "Asia/Tokyo");
17
+ * // tokyoWeekday: 1
18
18
  *
19
19
  * pipe(
20
20
  * input,
21
21
  * D.getDayOfWeek,
22
- * ); // result: 1
22
+ * ); // 1
23
23
  *
24
24
  * ```
25
25
  *
26
+ * @remarks
27
+ * - Returned mapping is: `0` Sunday, `1` Monday, ..., `6` Saturday.
28
+ *
26
29
  * @see https://utils.duplojs.dev/en/v1/api/date/getDayOfWeek
27
30
  *
28
31
  * @namespace D
29
32
  *
30
33
  */
31
- export declare function getDayOfWeek<GenericInput extends TheDate>(input: GenericInput, timezone?: Timezone): number;
34
+ export declare function getDayOfWeek<GenericInput extends TheDate | SerializedTheDate>(input: GenericInput, timezone?: Timezone): number;
@@ -13,15 +13,15 @@ const weekdayMapper = {
13
13
  * {@include date/getDayOfWeek/index.md}
14
14
  */
15
15
  function getDayOfWeek(input, timezone = "UTC") {
16
- const nativeDate = toNative(input);
16
+ const date = toNative(input);
17
17
  if (timezone === "UTC") {
18
- return nativeDate.getUTCDay();
18
+ return date.getUTCDay();
19
19
  }
20
20
  const formatter = new Intl.DateTimeFormat("en-US", {
21
21
  timeZone: timezone,
22
22
  weekday: "long",
23
23
  });
24
- const weekday = formatter.format(nativeDate);
24
+ const weekday = formatter.format(date);
25
25
  return weekdayMapper[weekday];
26
26
  }
27
27
 
@@ -1,20 +1,20 @@
1
1
  'use strict';
2
2
 
3
- var constants = require('../constants.cjs');
4
3
  var toNative = require('../toNative.cjs');
4
+ var constants = require('../constants.cjs');
5
5
 
6
6
  /**
7
7
  * {@include date/getDayOfYear/index.md}
8
8
  */
9
9
  function getDayOfYear(input, timezone = "UTC") {
10
- const nativeDate = toNative.toNative(input);
10
+ const date = toNative.toNative(input);
11
11
  let year = 0;
12
12
  let month = 0;
13
13
  let day = 0;
14
14
  if (timezone === "UTC") {
15
- year = nativeDate.getUTCFullYear();
16
- month = nativeDate.getUTCMonth();
17
- day = nativeDate.getUTCDate();
15
+ year = date.getUTCFullYear();
16
+ month = date.getUTCMonth();
17
+ day = date.getUTCDate();
18
18
  }
19
19
  else {
20
20
  const parts = new Intl.DateTimeFormat("en-US", {
@@ -22,7 +22,7 @@ function getDayOfYear(input, timezone = "UTC") {
22
22
  day: "numeric",
23
23
  year: "numeric",
24
24
  month: "numeric",
25
- }).formatToParts(nativeDate);
25
+ }).formatToParts(date);
26
26
  const partsMap = new Map(parts.map((part) => [part.type, part.value]));
27
27
  year = Number(partsMap.get("year"));
28
28
  month = Number(partsMap.get("month")) - 1;
@@ -1,28 +1,36 @@
1
- import { type TheDate, type Timezone } from "..";
1
+ import type { SerializedTheDate } from "../types";
2
+ import { type TheDate } from "../theDate";
3
+ import type { Timezone } from "../timezone";
2
4
  /**
3
- * Returns the day of year of a date.
5
+ * Returns the day number in the year (`1` to `365`/`366`) for a date in a target timezone.
4
6
  *
5
- * Signature: `getDayOfYear(input, timezone)` → returns a value
7
+ * Signature: `getDayOfYear(input, timezone?)` → `number`
6
8
  *
7
- * If timezone is omitted, UTC is used.
8
- *
9
- * The input value is not mutated.
9
+ * `input` accepts `TheDate` or `SerializedTheDate`. If `timezone` is omitted, UTC is used.
10
10
  *
11
11
  * ```ts
12
- * const input = D.create("2024-12-31");
13
- * const result = D.getDayOfYear(input, "Australia/Sydney");
14
- * // result: 366
12
+ * const input = D.create("2024-12-31", {
13
+ * hour: "23",
14
+ * minute: "30",
15
+ * });
16
+ * const utcDayOfYear = D.getDayOfYear(input);
17
+ * // utcDayOfYear: 366
18
+ *
19
+ * const sydneyDayOfYear = D.getDayOfYear(input, "Australia/Sydney");
20
+ * // sydneyDayOfYear: 1
15
21
  *
16
22
  * pipe(
17
23
  * input,
18
- * (value) => D.getDayOfYear(value, "Australia/Sydney"),
19
- * ); // result: 366
20
- *
24
+ * (value) => D.getDayOfYear(value, "UTC"),
25
+ * ); // 366
21
26
  * ```
22
27
  *
28
+ * @remarks
29
+ * - Leap years produce values up to `366`.
30
+ *
23
31
  * @see https://utils.duplojs.dev/en/v1/api/date/getDayOfYear
24
32
  *
25
33
  * @namespace D
26
34
  *
27
35
  */
28
- export declare function getDayOfYear<GenericInput extends TheDate>(input: GenericInput, timezone?: Timezone): number;
36
+ export declare function getDayOfYear<GenericInput extends TheDate | SerializedTheDate>(input: GenericInput, timezone?: Timezone): number;
@@ -1,18 +1,18 @@
1
- import { millisecondsInOneDay } from '../constants.mjs';
2
1
  import { toNative } from '../toNative.mjs';
2
+ import { millisecondsInOneDay } from '../constants.mjs';
3
3
 
4
4
  /**
5
5
  * {@include date/getDayOfYear/index.md}
6
6
  */
7
7
  function getDayOfYear(input, timezone = "UTC") {
8
- const nativeDate = toNative(input);
8
+ const date = toNative(input);
9
9
  let year = 0;
10
10
  let month = 0;
11
11
  let day = 0;
12
12
  if (timezone === "UTC") {
13
- year = nativeDate.getUTCFullYear();
14
- month = nativeDate.getUTCMonth();
15
- day = nativeDate.getUTCDate();
13
+ year = date.getUTCFullYear();
14
+ month = date.getUTCMonth();
15
+ day = date.getUTCDate();
16
16
  }
17
17
  else {
18
18
  const parts = new Intl.DateTimeFormat("en-US", {
@@ -20,7 +20,7 @@ function getDayOfYear(input, timezone = "UTC") {
20
20
  day: "numeric",
21
21
  year: "numeric",
22
22
  month: "numeric",
23
- }).formatToParts(nativeDate);
23
+ }).formatToParts(date);
24
24
  const partsMap = new Map(parts.map((part) => [part.type, part.value]));
25
25
  year = Number(partsMap.get("year"));
26
26
  month = Number(partsMap.get("month")) - 1;
@@ -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
  /**
@@ -9,9 +10,7 @@ function getFirstDayOfMonth(input) {
9
10
  const nativeDate = toNative.toNative(input);
10
11
  nativeDate.setUTCDate(1);
11
12
  nativeDate.setUTCHours(0, 0, 0, 0);
12
- const timestamp = nativeDate.getTime();
13
- const isNegative = timestamp < 0;
14
- return `date${Math.abs(timestamp)}${isNegative ? "-" : "+"}`;
13
+ return theDate.TheDate.new(nativeDate.getTime());
15
14
  }
16
15
 
17
16
  exports.getFirstDayOfMonth = getFirstDayOfMonth;
@@ -1,26 +1,32 @@
1
- import type { TheDate } from "../types";
1
+ import type { SerializedTheDate } from "../types";
2
+ import { TheDate } from "../theDate";
2
3
  /**
3
- * Returns the first day of month of a date.
4
+ * Returns the first day of the month for a date.
4
5
  *
5
- * Signature: `getFirstDayOfMonth(input)` → returns a value
6
+ * Signature: `getFirstDayOfMonth(input)` → `TheDate`
6
7
  *
7
- * The input value is not mutated.
8
+ * `input` accepts `TheDate` or `SerializedTheDate`.
8
9
  *
9
10
  * ```ts
10
11
  * const input = D.create("2024-06-19");
11
- * const result = D.getFirstDayOfMonth(input);
12
- * // result: "date1717200000000+" (1 June 2024)
12
+ * const firstDay = D.getFirstDayOfMonth(input);
13
+ * // firstDay: TheDate
14
+ *
15
+ * const serialized = D.serialize(firstDay);
16
+ * // serialized: SerializedTheDate
13
17
  *
14
18
  * pipe(
15
- * input,
19
+ * serialized,
16
20
  * D.getFirstDayOfMonth,
17
- * ); // result: "date1717200000000+" (1 June 2024)
18
- *
21
+ * ); // TheDate
19
22
  * ```
20
23
  *
24
+ * @remarks
25
+ * - The returned date is normalized to `00:00:00.000` in UTC.
26
+ *
21
27
  * @see https://utils.duplojs.dev/en/v1/api/date/getFirstDayOfMonth
22
28
  *
23
29
  * @namespace D
24
30
  *
25
31
  */
26
- export declare function getFirstDayOfMonth(input: TheDate): TheDate;
32
+ export declare function getFirstDayOfMonth<GenericInput extends TheDate | SerializedTheDate>(input: GenericInput): TheDate;
@@ -1,3 +1,4 @@
1
+ import { TheDate } from '../theDate.mjs';
1
2
  import { toNative } from '../toNative.mjs';
2
3
 
3
4
  /**
@@ -7,9 +8,7 @@ function getFirstDayOfMonth(input) {
7
8
  const nativeDate = toNative(input);
8
9
  nativeDate.setUTCDate(1);
9
10
  nativeDate.setUTCHours(0, 0, 0, 0);
10
- const timestamp = nativeDate.getTime();
11
- const isNegative = timestamp < 0;
12
- return `date${Math.abs(timestamp)}${isNegative ? "-" : "+"}`;
11
+ return TheDate.new(nativeDate.getTime());
13
12
  }
14
13
 
15
14
  export { getFirstDayOfMonth };
@@ -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
  /**
@@ -11,9 +12,7 @@ function getFirstDayOfWeek(input) {
11
12
  const daysToMonday = dayOfWeek === 0 ? -6 : 1 - dayOfWeek;
12
13
  nativeDate.setUTCHours(0, 0, 0, 0);
13
14
  nativeDate.setUTCDate(nativeDate.getUTCDate() + daysToMonday);
14
- const timestamp = nativeDate.getTime();
15
- const isNegative = timestamp < 0;
16
- return `date${Math.abs(timestamp)}${isNegative ? "-" : "+"}`;
15
+ return theDate.TheDate.new(nativeDate.getTime());
17
16
  }
18
17
 
19
18
  exports.getFirstDayOfWeek = getFirstDayOfWeek;
@@ -1,26 +1,33 @@
1
- import type { TheDate } from "../types";
1
+ import type { SerializedTheDate } from "../types";
2
+ import { TheDate } from "../theDate";
2
3
  /**
3
- * Returns the first day of week of a date.
4
+ * Returns the first day of the week for a date.
4
5
  *
5
- * Signature: `getFirstDayOfWeek(input)` → returns a value
6
+ * Signature: `getFirstDayOfWeek(input)` → `TheDate`
6
7
  *
7
- * The input value is not mutated.
8
+ * `input` accepts `TheDate` or `SerializedTheDate`.
8
9
  *
9
10
  * ```ts
10
11
  * const input = D.create("2024-06-19");
11
- * const result = D.getFirstDayOfWeek(input);
12
- * // result: "date1718668800000+" (monday 17 june 2024)
12
+ * const firstDay = D.getFirstDayOfWeek(input);
13
+ * // firstDay: TheDate
14
+ *
15
+ * const serialized = D.serialize(firstDay);
16
+ * // serialized: SerializedTheDate
13
17
  *
14
18
  * pipe(
15
- * input,
19
+ * serialized,
16
20
  * D.getFirstDayOfWeek,
17
- * ); // result: "date1718668800000+" (monday 17 june 2024)
18
- *
21
+ * ); // TheDate
19
22
  * ```
20
23
  *
24
+ * @remarks
25
+ * - The week starts on Monday.
26
+ * - The returned date is normalized to `00:00:00.000` in UTC.
27
+ *
21
28
  * @see https://utils.duplojs.dev/en/v1/api/date/getFirstDayOfWeek
22
29
  *
23
30
  * @namespace D
24
31
  *
25
32
  */
26
- export declare function getFirstDayOfWeek(input: TheDate): TheDate;
33
+ export declare function getFirstDayOfWeek<GenericInput extends TheDate | SerializedTheDate>(input: GenericInput): TheDate;
@@ -1,3 +1,4 @@
1
+ import { TheDate } from '../theDate.mjs';
1
2
  import { toNative } from '../toNative.mjs';
2
3
 
3
4
  /**
@@ -9,9 +10,7 @@ function getFirstDayOfWeek(input) {
9
10
  const daysToMonday = dayOfWeek === 0 ? -6 : 1 - dayOfWeek;
10
11
  nativeDate.setUTCHours(0, 0, 0, 0);
11
12
  nativeDate.setUTCDate(nativeDate.getUTCDate() + daysToMonday);
12
- const timestamp = nativeDate.getTime();
13
- const isNegative = timestamp < 0;
14
- return `date${Math.abs(timestamp)}${isNegative ? "-" : "+"}`;
13
+ return TheDate.new(nativeDate.getTime());
15
14
  }
16
15
 
17
16
  export { getFirstDayOfWeek };
@@ -6,16 +6,16 @@ var toNative = require('../toNative.cjs');
6
6
  * {@include date/getHour/index.md}
7
7
  */
8
8
  function getHour(input, timezone = "UTC") {
9
- const nativeDate = toNative.toNative(input);
9
+ const date = toNative.toNative(input);
10
10
  if (timezone === "UTC") {
11
- return nativeDate.getUTCHours();
11
+ return date.getUTCHours();
12
12
  }
13
13
  const formatter = new Intl.DateTimeFormat("en-US", {
14
14
  timeZone: timezone,
15
15
  hour: "numeric",
16
16
  hour12: false,
17
17
  });
18
- return Number(formatter.format(nativeDate));
18
+ return Number(formatter.format(date));
19
19
  }
20
20
 
21
21
  exports.getHour = getHour;
@@ -1,25 +1,27 @@
1
- import { type TheDate, type Timezone } from "..";
1
+ import type { SerializedTheDate } from "../types";
2
+ import { type TheDate } from "../theDate";
3
+ import type { Timezone } from "../timezone";
2
4
  /**
3
- * Returns the hour of a date.
5
+ * Returns the hour (`0` to `23`) for a date in a target timezone.
4
6
  *
5
- * Signature: `getHour(input, timezone)` → returns a value
7
+ * Signature: `getHour(input, timezone?)` → `number`
6
8
  *
7
- * If timezone is omitted, UTC is used.
8
- *
9
- * The input value is not mutated.
9
+ * `input` accepts `TheDate` or `SerializedTheDate`. If `timezone` is omitted, UTC is used.
10
10
  *
11
11
  * ```ts
12
- * const input = D.create("2024-06-20");
13
- * const result = D.getHour(input);
14
- * // result: 0
12
+ * const input = D.create("2024-06-20", {
13
+ * hour: "00",
14
+ * });
15
+ * const utcHour = D.getHour(input);
16
+ * // utcHour: 0
15
17
  *
16
- * const result2 = D.getHour(input, "America/Los_Angeles");
17
- * // result2: 17
18
+ * const laHour = D.getHour(input, "America/Los_Angeles");
19
+ * // laHour: 17
18
20
  *
19
21
  * pipe(
20
22
  * input,
21
- * D.getHour,
22
- * ); // result: 0
23
+ * (value) => D.getHour(value, "UTC"),
24
+ * ); // 0
23
25
  *
24
26
  * ```
25
27
  *
@@ -28,4 +30,4 @@ import { type TheDate, type Timezone } from "..";
28
30
  * @namespace D
29
31
  *
30
32
  */
31
- export declare function getHour<GenericInput extends TheDate>(input: GenericInput, timezone?: Timezone): number;
33
+ export declare function getHour<GenericInput extends TheDate | SerializedTheDate>(input: GenericInput, timezone?: Timezone): number;
@@ -4,16 +4,16 @@ import { toNative } from '../toNative.mjs';
4
4
  * {@include date/getHour/index.md}
5
5
  */
6
6
  function getHour(input, timezone = "UTC") {
7
- const nativeDate = toNative(input);
7
+ const date = toNative(input);
8
8
  if (timezone === "UTC") {
9
- return nativeDate.getUTCHours();
9
+ return date.getUTCHours();
10
10
  }
11
11
  const formatter = new Intl.DateTimeFormat("en-US", {
12
12
  timeZone: timezone,
13
13
  hour: "numeric",
14
14
  hour12: false,
15
15
  });
16
- return Number(formatter.format(nativeDate));
16
+ return Number(formatter.format(date));
17
17
  }
18
18
 
19
19
  export { getHour };
@@ -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
  /**
@@ -9,9 +10,7 @@ function getLastDayOfMonth(input) {
9
10
  const nativeDate = toNative.toNative(input);
10
11
  nativeDate.setUTCMonth(nativeDate.getUTCMonth() + 1, 0);
11
12
  nativeDate.setUTCHours(23, 59, 59, 999);
12
- const timestamp = nativeDate.getTime();
13
- const isNegative = timestamp < 0;
14
- return `date${Math.abs(timestamp)}${isNegative ? "-" : "+"}`;
13
+ return theDate.TheDate.new(nativeDate.getTime());
15
14
  }
16
15
 
17
16
  exports.getLastDayOfMonth = getLastDayOfMonth;
@@ -1,26 +1,32 @@
1
- import type { TheDate } from "../types";
1
+ import type { SerializedTheDate } from "../types";
2
+ import { TheDate } from "../theDate";
2
3
  /**
3
- * Returns the last day of month of a date.
4
+ * Returns the last day of the month for a date.
4
5
  *
5
- * Signature: `getLastDayOfMonth(input)` → returns a value
6
+ * Signature: `getLastDayOfMonth(input)` → `TheDate`
6
7
  *
7
- * The input value is not mutated.
8
+ * `input` accepts `TheDate` or `SerializedTheDate`.
8
9
  *
9
10
  * ```ts
10
11
  * const input = D.create("2024-06-19");
11
- * const result = D.getLastDayOfMonth(input);
12
- * // result: "date1719532800000+" (30 June 2024)
12
+ * const lastDay = D.getLastDayOfMonth(input);
13
+ * // lastDay: TheDate
14
+ *
15
+ * const serialized = D.serialize(lastDay);
16
+ * // serialized: SerializedTheDate
13
17
  *
14
18
  * pipe(
15
- * input,
19
+ * serialized,
16
20
  * D.getLastDayOfMonth,
17
- * ); // result: "date1719532800000+" (30 June 2024)
18
- *
21
+ * ); // TheDate
19
22
  * ```
20
23
  *
24
+ * @remarks
25
+ * - The returned date is normalized to `23:59:59.999` in UTC.
26
+ *
21
27
  * @see https://utils.duplojs.dev/en/v1/api/date/getLastDayOfMonth
22
28
  *
23
29
  * @namespace D
24
30
  *
25
31
  */
26
- export declare function getLastDayOfMonth(input: TheDate): TheDate;
32
+ export declare function getLastDayOfMonth<GenericInput extends TheDate | SerializedTheDate>(input: GenericInput): TheDate;
@@ -1,3 +1,4 @@
1
+ import { TheDate } from '../theDate.mjs';
1
2
  import { toNative } from '../toNative.mjs';
2
3
 
3
4
  /**
@@ -7,9 +8,7 @@ function getLastDayOfMonth(input) {
7
8
  const nativeDate = toNative(input);
8
9
  nativeDate.setUTCMonth(nativeDate.getUTCMonth() + 1, 0);
9
10
  nativeDate.setUTCHours(23, 59, 59, 999);
10
- const timestamp = nativeDate.getTime();
11
- const isNegative = timestamp < 0;
12
- return `date${Math.abs(timestamp)}${isNegative ? "-" : "+"}`;
11
+ return TheDate.new(nativeDate.getTime());
13
12
  }
14
13
 
15
14
  export { getLastDayOfMonth };
@@ -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
  /**
@@ -11,9 +12,7 @@ function getLastDayOfWeek(input) {
11
12
  const daysToSunday = dayOfWeek === 0 ? 0 : 7 - dayOfWeek;
12
13
  nativeDate.setUTCDate(nativeDate.getUTCDate() + daysToSunday);
13
14
  nativeDate.setUTCHours(23, 59, 59, 999);
14
- const timestamp = nativeDate.getTime();
15
- const isNegative = timestamp < 0;
16
- return `date${Math.abs(timestamp)}${isNegative ? "-" : "+"}`;
15
+ return theDate.TheDate.new(nativeDate.getTime());
17
16
  }
18
17
 
19
18
  exports.getLastDayOfWeek = getLastDayOfWeek;
@@ -1,26 +1,33 @@
1
- import type { TheDate } from "../types";
1
+ import type { SerializedTheDate } from "../types";
2
+ import { TheDate } from "../theDate";
2
3
  /**
3
- * Returns the last day of week of a date.
4
+ * Returns the last day of the week for a date.
4
5
  *
5
- * Signature: `getLastDayOfWeek(input)` → returns a value
6
+ * Signature: `getLastDayOfWeek(input)` → `TheDate`
6
7
  *
7
- * The input value is not mutated.
8
+ * `input` accepts `TheDate` or `SerializedTheDate`.
8
9
  *
9
10
  * ```ts
10
11
  * const input = D.create("2024-06-19");
11
- * const result = D.getLastDayOfWeek(input);
12
- * // result: "date1719187200000+" (Sunday 23 june 2024)
12
+ * const lastDay = D.getLastDayOfWeek(input);
13
+ * // lastDay: TheDate
14
+ *
15
+ * const serialized = D.serialize(lastDay);
16
+ * // serialized: SerializedTheDate
13
17
  *
14
18
  * pipe(
15
- * input,
19
+ * serialized,
16
20
  * D.getLastDayOfWeek,
17
- * ); // result: "date1719187200000+" (Sunday 23 june 2024)
18
- *
21
+ * ); // TheDate
19
22
  * ```
20
23
  *
24
+ * @remarks
25
+ * - The week ends on Sunday.
26
+ * - The returned date is normalized to `23:59:59.999` in UTC.
27
+ *
21
28
  * @see https://utils.duplojs.dev/en/v1/api/date/getLastDayOfWeek
22
29
  *
23
30
  * @namespace D
24
31
  *
25
32
  */
26
- export declare function getLastDayOfWeek(input: TheDate): TheDate;
33
+ export declare function getLastDayOfWeek<GenericInput extends TheDate | SerializedTheDate>(input: GenericInput): TheDate;
@@ -1,3 +1,4 @@
1
+ import { TheDate } from '../theDate.mjs';
1
2
  import { toNative } from '../toNative.mjs';
2
3
 
3
4
  /**
@@ -9,9 +10,7 @@ function getLastDayOfWeek(input) {
9
10
  const daysToSunday = dayOfWeek === 0 ? 0 : 7 - dayOfWeek;
10
11
  nativeDate.setUTCDate(nativeDate.getUTCDate() + daysToSunday);
11
12
  nativeDate.setUTCHours(23, 59, 59, 999);
12
- const timestamp = nativeDate.getTime();
13
- const isNegative = timestamp < 0;
14
- return `date${Math.abs(timestamp)}${isNegative ? "-" : "+"}`;
13
+ return TheDate.new(nativeDate.getTime());
15
14
  }
16
15
 
17
16
  export { getLastDayOfWeek };
@@ -6,8 +6,8 @@ var toNative = require('../toNative.cjs');
6
6
  * {@include date/getMilliseconds/index.md}
7
7
  */
8
8
  function getMilliseconds(input) {
9
- const nativeDate = toNative.toNative(input);
10
- return nativeDate.getUTCMilliseconds();
9
+ const date = toNative.toNative(input);
10
+ return date.getUTCMilliseconds();
11
11
  }
12
12
 
13
13
  exports.getMilliseconds = getMilliseconds;
@@ -1,10 +1,11 @@
1
- import { type TheDate } from "..";
1
+ import type { SerializedTheDate } from "../types";
2
+ import { type TheDate } from "../theDate";
2
3
  /**
3
- * Returns the milliseconds of a date.
4
+ * Returns the milliseconds part (`0` to `999`) of a date.
4
5
  *
5
- * Signature: `getMilliseconds(input)` → returns a value
6
+ * Signature: `getMilliseconds(input)` → `number`
6
7
  *
7
- * The input value is not mutated.
8
+ * `input` accepts `TheDate` or `SerializedTheDate`.
8
9
  *
9
10
  * ```ts
10
11
  * const input = D.create("2024-06-20", {
@@ -13,19 +14,20 @@ import { type TheDate } from "..";
13
14
  * second: "56",
14
15
  * millisecond: "789",
15
16
  * });
16
- * const result = D.getMilliseconds(input);
17
- * // result: 789
17
+ * const milliseconds = D.getMilliseconds(input);
18
+ * // milliseconds: 789
18
19
  *
19
20
  * pipe(
20
21
  * input,
21
22
  * D.getMilliseconds,
22
- * ); // result: 789
23
- *
24
23
  * ```
25
24
  *
25
+ * @remarks
26
+ * - Value is always read in UTC.
27
+ *
26
28
  * @see https://utils.duplojs.dev/en/v1/api/date/getMilliseconds
27
29
  *
28
30
  * @namespace D
29
31
  *
30
32
  */
31
- export declare function getMilliseconds<GenericInput extends TheDate>(input: GenericInput): number;
33
+ export declare function getMilliseconds<GenericInput extends TheDate | SerializedTheDate>(input: GenericInput): number;
@@ -4,8 +4,8 @@ import { toNative } from '../toNative.mjs';
4
4
  * {@include date/getMilliseconds/index.md}
5
5
  */
6
6
  function getMilliseconds(input) {
7
- const nativeDate = toNative(input);
8
- return nativeDate.getUTCMilliseconds();
7
+ const date = toNative(input);
8
+ return date.getUTCMilliseconds();
9
9
  }
10
10
 
11
11
  export { getMilliseconds };