esday 0.5.0 → 0.6.3

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 (382) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/LICENSE +21 -21
  3. package/README.md +63 -51
  4. package/chunks/AyQQ6US-.js +84 -0
  5. package/chunks/{Y32qdU_5.js → BkjWOpMU.js} +7 -1
  6. package/chunks/{MtjcOKi-.d.ts → C5qDMHT5.d.ts} +2 -2
  7. package/chunks/{DqhiVwLi.d.ts → CODi8AFH.d.ts} +63 -35
  8. package/chunks/CXWzCl3n.js +481 -0
  9. package/chunks/{BRRrAbUl.js → CdvTtmWL.js} +2 -2
  10. package/chunks/{DXHbH1CI.js → Shk32pTP.js} +1 -1
  11. package/chunks/{Cb5SvF6r.js → v_QBn7Xm.js} +1 -1
  12. package/chunks/xt8C2lbv.js +38 -0
  13. package/index.d.ts +3 -3
  14. package/index.js +1 -571
  15. package/locales/af.d.ts +1 -3
  16. package/locales/af.js +4 -2
  17. package/locales/am.d.ts +1 -3
  18. package/locales/am.js +4 -2
  19. package/locales/ar-dz.d.ts +1 -3
  20. package/locales/ar-dz.js +7 -9
  21. package/locales/ar-iq.d.ts +1 -3
  22. package/locales/ar-iq.js +7 -9
  23. package/locales/ar-kw.d.ts +1 -3
  24. package/locales/ar-kw.js +7 -9
  25. package/locales/ar-ly.d.ts +1 -3
  26. package/locales/ar-ly.js +7 -9
  27. package/locales/ar-ma.d.ts +1 -3
  28. package/locales/ar-ma.js +7 -9
  29. package/locales/ar-sa.d.ts +1 -3
  30. package/locales/ar-sa.js +7 -9
  31. package/locales/ar-tn.d.ts +1 -3
  32. package/locales/ar-tn.js +7 -9
  33. package/locales/ar.d.ts +1 -3
  34. package/locales/ar.js +197 -2
  35. package/locales/az.d.ts +1 -3
  36. package/locales/az.js +4 -2
  37. package/locales/be.d.ts +1 -3
  38. package/locales/be.js +55 -59
  39. package/locales/bg.d.ts +1 -3
  40. package/locales/bg.js +4 -2
  41. package/locales/bi.d.ts +1 -3
  42. package/locales/bi.js +4 -2
  43. package/locales/bm.d.ts +1 -3
  44. package/locales/bm.js +4 -2
  45. package/locales/bn-bd.d.ts +1 -3
  46. package/locales/bn-bd.js +7 -9
  47. package/locales/bn.d.ts +1 -3
  48. package/locales/bn.js +136 -2
  49. package/locales/bo.d.ts +1 -3
  50. package/locales/bo.js +4 -2
  51. package/locales/br.d.ts +1 -3
  52. package/locales/br.js +10 -9
  53. package/locales/bs.d.ts +1 -3
  54. package/locales/bs.js +4 -2
  55. package/locales/ca.d.ts +1 -3
  56. package/locales/ca.js +35 -36
  57. package/locales/cs.d.ts +1 -3
  58. package/locales/cs.js +38 -34
  59. package/locales/cv.d.ts +1 -3
  60. package/locales/cv.js +4 -2
  61. package/locales/cy.d.ts +1 -3
  62. package/locales/cy.js +4 -2
  63. package/locales/da.d.ts +1 -3
  64. package/locales/da.js +4 -2
  65. package/locales/de-at.d.ts +1 -3
  66. package/locales/de-at.js +7 -9
  67. package/locales/de-ch.d.ts +1 -3
  68. package/locales/de-ch.js +7 -9
  69. package/locales/de.d.ts +1 -3
  70. package/locales/de.js +130 -2
  71. package/locales/dv.d.ts +1 -3
  72. package/locales/dv.js +4 -2
  73. package/locales/el.d.ts +1 -3
  74. package/locales/el.js +4 -2
  75. package/locales/en-au.d.ts +1 -3
  76. package/locales/en-au.js +7 -8
  77. package/locales/en-ca.d.ts +1 -3
  78. package/locales/en-ca.js +7 -8
  79. package/locales/en-gb.d.ts +1 -3
  80. package/locales/en-gb.js +9 -8
  81. package/locales/en-ie.d.ts +1 -3
  82. package/locales/en-ie.js +7 -8
  83. package/locales/en-il.d.ts +1 -3
  84. package/locales/en-il.js +7 -8
  85. package/locales/en-in.d.ts +1 -3
  86. package/locales/en-in.js +7 -8
  87. package/locales/en-nz.d.ts +1 -3
  88. package/locales/en-nz.js +7 -8
  89. package/locales/en-sg.d.ts +1 -3
  90. package/locales/en-sg.js +7 -8
  91. package/locales/en-tt.d.ts +1 -3
  92. package/locales/en-tt.js +7 -8
  93. package/locales/en-us.d.ts +1 -3
  94. package/locales/en-us.js +7 -8
  95. package/locales/en.d.ts +1 -3
  96. package/locales/en.js +116 -2
  97. package/locales/eo.d.ts +1 -3
  98. package/locales/eo.js +4 -2
  99. package/locales/es-do.d.ts +1 -3
  100. package/locales/es-do.js +7 -9
  101. package/locales/es-mx.d.ts +1 -3
  102. package/locales/es-mx.js +7 -9
  103. package/locales/es-pr.d.ts +1 -3
  104. package/locales/es-pr.js +7 -9
  105. package/locales/es-us.d.ts +1 -3
  106. package/locales/es-us.js +7 -9
  107. package/locales/es.d.ts +1 -3
  108. package/locales/es.js +117 -2
  109. package/locales/et.d.ts +1 -3
  110. package/locales/et.js +6 -2
  111. package/locales/eu.d.ts +1 -3
  112. package/locales/eu.js +4 -2
  113. package/locales/fa.d.ts +1 -3
  114. package/locales/fa.js +4 -2
  115. package/locales/fi.d.ts +1 -3
  116. package/locales/fi.js +8 -2
  117. package/locales/fil.d.ts +1 -3
  118. package/locales/fil.js +4 -2
  119. package/locales/fo.d.ts +1 -3
  120. package/locales/fo.js +4 -2
  121. package/locales/fr-ca.d.ts +1 -3
  122. package/locales/fr-ca.js +7 -9
  123. package/locales/fr-ch.d.ts +1 -3
  124. package/locales/fr-ch.js +7 -9
  125. package/locales/fr.d.ts +1 -3
  126. package/locales/fr.js +109 -2
  127. package/locales/fy.d.ts +1 -3
  128. package/locales/fy.js +4 -2
  129. package/locales/ga.d.ts +1 -3
  130. package/locales/ga.js +4 -2
  131. package/locales/gd.d.ts +1 -3
  132. package/locales/gd.js +4 -2
  133. package/locales/gl.d.ts +1 -3
  134. package/locales/gl.js +4 -2
  135. package/locales/gom-deva.d.ts +1 -3
  136. package/locales/gom-deva.js +34 -32
  137. package/locales/gom-latn.d.ts +1 -3
  138. package/locales/gom-latn.js +34 -32
  139. package/locales/gu.d.ts +1 -3
  140. package/locales/gu.js +4 -2
  141. package/locales/he.d.ts +1 -3
  142. package/locales/he.js +8 -5
  143. package/locales/hi.d.ts +1 -3
  144. package/locales/hi.js +34 -35
  145. package/locales/hr.d.ts +1 -3
  146. package/locales/hr.js +10 -4
  147. package/locales/ht.d.ts +1 -3
  148. package/locales/ht.js +4 -2
  149. package/locales/hu.d.ts +1 -3
  150. package/locales/hu.js +6 -2
  151. package/locales/hy-am.d.ts +1 -3
  152. package/locales/hy-am.js +34 -35
  153. package/locales/id.d.ts +1 -3
  154. package/locales/id.js +4 -2
  155. package/locales/is.d.ts +1 -3
  156. package/locales/is.js +14 -2
  157. package/locales/it-ch.d.ts +1 -3
  158. package/locales/it-ch.js +4 -9
  159. package/locales/it.d.ts +1 -3
  160. package/locales/it.js +120 -2
  161. package/locales/ja.d.ts +1 -4
  162. package/locales/ja.js +4 -2
  163. package/locales/jv.d.ts +1 -3
  164. package/locales/jv.js +4 -2
  165. package/locales/ka.d.ts +1 -3
  166. package/locales/ka.js +25 -26
  167. package/locales/kk.d.ts +1 -3
  168. package/locales/kk.js +4 -2
  169. package/locales/km.d.ts +1 -3
  170. package/locales/km.js +4 -2
  171. package/locales/kn.d.ts +1 -3
  172. package/locales/kn.js +4 -2
  173. package/locales/ko.d.ts +1 -3
  174. package/locales/ko.js +5 -3
  175. package/locales/ku.d.ts +1 -3
  176. package/locales/ku.js +4 -2
  177. package/locales/ky.d.ts +1 -3
  178. package/locales/ky.js +4 -2
  179. package/locales/lb.d.ts +1 -3
  180. package/locales/lb.js +5 -2
  181. package/locales/lo.d.ts +1 -3
  182. package/locales/lo.js +4 -2
  183. package/locales/lt.d.ts +1 -3
  184. package/locales/lt.js +4 -2
  185. package/locales/lv.d.ts +1 -3
  186. package/locales/lv.js +4 -2
  187. package/locales/me.d.ts +1 -3
  188. package/locales/me.js +33 -33
  189. package/locales/mi.d.ts +1 -3
  190. package/locales/mi.js +4 -2
  191. package/locales/mk.d.ts +1 -3
  192. package/locales/mk.js +4 -2
  193. package/locales/ml.d.ts +1 -3
  194. package/locales/ml.js +4 -2
  195. package/locales/mn.d.ts +1 -3
  196. package/locales/mn.js +37 -16
  197. package/locales/mr.d.ts +1 -3
  198. package/locales/mr.js +16 -2
  199. package/locales/ms-my.d.ts +1 -3
  200. package/locales/ms-my.js +7 -9
  201. package/locales/ms.d.ts +1 -3
  202. package/locales/ms.js +107 -2
  203. package/locales/mt.d.ts +1 -3
  204. package/locales/mt.js +4 -2
  205. package/locales/my.d.ts +1 -3
  206. package/locales/my.js +4 -2
  207. package/locales/nb.d.ts +1 -3
  208. package/locales/nb.js +4 -2
  209. package/locales/ne.d.ts +1 -3
  210. package/locales/ne.js +4 -2
  211. package/locales/nl-be.d.ts +1 -3
  212. package/locales/nl-be.js +7 -9
  213. package/locales/nl.d.ts +1 -3
  214. package/locales/nl.js +107 -2
  215. package/locales/nn.d.ts +1 -3
  216. package/locales/nn.js +4 -2
  217. package/locales/oc-lnc.d.ts +1 -3
  218. package/locales/oc-lnc.js +35 -36
  219. package/locales/pa-in.d.ts +1 -3
  220. package/locales/pa-in.js +4 -2
  221. package/locales/pl.d.ts +1 -3
  222. package/locales/pl.js +5 -2
  223. package/locales/pt-br.d.ts +1 -3
  224. package/locales/pt-br.js +7 -9
  225. package/locales/pt.d.ts +1 -3
  226. package/locales/pt.js +109 -2
  227. package/locales/rn.d.ts +1 -3
  228. package/locales/rn.js +4 -2
  229. package/locales/ro.d.ts +1 -3
  230. package/locales/ro.js +4 -2
  231. package/locales/ru.d.ts +1 -4
  232. package/locales/ru.js +83 -82
  233. package/locales/rw.d.ts +1 -3
  234. package/locales/rw.js +4 -2
  235. package/locales/sd.d.ts +1 -3
  236. package/locales/sd.js +4 -2
  237. package/locales/se.d.ts +1 -3
  238. package/locales/se.js +4 -2
  239. package/locales/si.d.ts +1 -3
  240. package/locales/si.js +4 -2
  241. package/locales/sk.d.ts +1 -3
  242. package/locales/sk.js +8 -2
  243. package/locales/sl.d.ts +1 -3
  244. package/locales/sl.js +8 -2
  245. package/locales/sq.d.ts +1 -3
  246. package/locales/sq.js +4 -2
  247. package/locales/sr-cyrl.d.ts +1 -3
  248. package/locales/sr-cyrl.js +16 -15
  249. package/locales/sr.d.ts +1 -3
  250. package/locales/sr.js +185 -2
  251. package/locales/ss.d.ts +1 -3
  252. package/locales/ss.js +4 -2
  253. package/locales/sv-fi.d.ts +1 -3
  254. package/locales/sv-fi.js +7 -9
  255. package/locales/sv.d.ts +1 -3
  256. package/locales/sv.js +110 -2
  257. package/locales/sw.d.ts +1 -3
  258. package/locales/sw.js +4 -2
  259. package/locales/ta.d.ts +1 -3
  260. package/locales/ta.js +4 -2
  261. package/locales/te.d.ts +1 -3
  262. package/locales/te.js +4 -2
  263. package/locales/tet.d.ts +1 -3
  264. package/locales/tet.js +5 -4
  265. package/locales/tg.d.ts +1 -3
  266. package/locales/tg.js +34 -35
  267. package/locales/th.d.ts +1 -3
  268. package/locales/th.js +4 -2
  269. package/locales/tk.d.ts +1 -3
  270. package/locales/tk.js +5 -4
  271. package/locales/tl-ph.d.ts +1 -3
  272. package/locales/tl-ph.js +4 -2
  273. package/locales/tlh.d.ts +1 -3
  274. package/locales/tlh.js +5 -2
  275. package/locales/tr.d.ts +1 -3
  276. package/locales/tr.js +5 -4
  277. package/locales/tzl.d.ts +1 -3
  278. package/locales/tzl.js +4 -2
  279. package/locales/tzm-latn.d.ts +1 -3
  280. package/locales/tzm-latn.js +9 -9
  281. package/locales/tzm.d.ts +1 -3
  282. package/locales/tzm.js +107 -2
  283. package/locales/ug-cn.d.ts +1 -3
  284. package/locales/ug-cn.js +4 -2
  285. package/locales/uk.d.ts +1 -3
  286. package/locales/uk.js +37 -32
  287. package/locales/ur.d.ts +1 -3
  288. package/locales/ur.js +4 -2
  289. package/locales/uz-latn.d.ts +1 -3
  290. package/locales/uz-latn.js +9 -9
  291. package/locales/uz.d.ts +1 -3
  292. package/locales/uz.js +107 -2
  293. package/locales/vi.d.ts +1 -3
  294. package/locales/vi.js +4 -2
  295. package/locales/x-pseudo.d.ts +1 -3
  296. package/locales/x-pseudo.js +5 -4
  297. package/locales/yo.d.ts +1 -3
  298. package/locales/yo.js +4 -2
  299. package/locales/zh-cn.d.ts +1 -3
  300. package/locales/zh-cn.js +7 -9
  301. package/locales/zh-hk.d.ts +1 -3
  302. package/locales/zh-hk.js +7 -9
  303. package/locales/zh-mo.d.ts +1 -3
  304. package/locales/zh-mo.js +7 -9
  305. package/locales/zh-tw.d.ts +1 -3
  306. package/locales/zh-tw.js +7 -9
  307. package/locales/zh.d.ts +1 -4
  308. package/locales/zh.js +128 -2
  309. package/package.json +29 -23
  310. package/plugins/advancedFormat/index.d.ts +1 -3
  311. package/plugins/advancedFormat/index.js +4 -6
  312. package/plugins/advancedParse/index.d.ts +1 -3
  313. package/plugins/advancedParse/index.js +21 -20
  314. package/plugins/calendar/index.d.ts +2 -4
  315. package/plugins/calendar/index.js +1 -2
  316. package/plugins/dayOfYear/index.d.ts +1 -2
  317. package/plugins/dayOfYear/index.js +1 -2
  318. package/plugins/duration/index.d.ts +78 -0
  319. package/plugins/duration/index.js +477 -0
  320. package/plugins/isBetween/index.d.ts +1 -2
  321. package/plugins/isBetween/index.js +2 -3
  322. package/plugins/isLeapYear/index.d.ts +1 -2
  323. package/plugins/isLeapYear/index.js +1 -2
  324. package/plugins/isSameOrAfter/index.d.ts +1 -2
  325. package/plugins/isSameOrAfter/index.js +1 -2
  326. package/plugins/isSameOrBefore/index.d.ts +1 -2
  327. package/plugins/isSameOrBefore/index.js +1 -2
  328. package/plugins/isToday/index.d.ts +1 -2
  329. package/plugins/isToday/index.js +2 -3
  330. package/plugins/isTomorrow/index.d.ts +1 -2
  331. package/plugins/isTomorrow/index.js +2 -3
  332. package/plugins/isYesterday/index.d.ts +1 -2
  333. package/plugins/isYesterday/index.js +2 -3
  334. package/plugins/isoWeek/index.d.ts +1 -3
  335. package/plugins/isoWeek/index.js +13 -25
  336. package/plugins/locale/index.d.ts +103 -3
  337. package/plugins/locale/index.js +140 -6
  338. package/plugins/localeData/index.d.ts +1 -3
  339. package/plugins/localeData/index.js +18 -11
  340. package/plugins/localizedFormat/index.d.ts +1 -3
  341. package/plugins/localizedFormat/index.js +5 -10
  342. package/plugins/localizedParse/index.d.ts +1 -3
  343. package/plugins/localizedParse/index.js +40 -22
  344. package/plugins/minMax/index.d.ts +1 -2
  345. package/plugins/minMax/index.js +2 -3
  346. package/plugins/objectSupport/index.d.ts +1 -3
  347. package/plugins/objectSupport/index.js +33 -38
  348. package/plugins/pluralGetSet/index.d.ts +1 -3
  349. package/plugins/pluralGetSet/index.js +1 -2
  350. package/plugins/quarterOfYear/index.d.ts +1 -3
  351. package/plugins/quarterOfYear/index.js +11 -18
  352. package/plugins/relativeTime/index.d.ts +32 -44
  353. package/plugins/relativeTime/index.js +124 -91
  354. package/plugins/timezone/index.d.ts +6 -0
  355. package/plugins/timezone/index.js +456 -0
  356. package/plugins/toArray/index.d.ts +1 -2
  357. package/plugins/toArray/index.js +1 -2
  358. package/plugins/toObject/index.d.ts +1 -2
  359. package/plugins/toObject/index.js +1 -2
  360. package/plugins/utc/index.d.ts +1 -2
  361. package/plugins/utc/index.js +37 -39
  362. package/plugins/week/index.d.ts +1 -3
  363. package/plugins/week/index.js +17 -27
  364. package/chunks/B5f9poqo.js +0 -120
  365. package/chunks/BDssPbM_.js +0 -106
  366. package/chunks/BXRGSAJG.js +0 -128
  367. package/chunks/BeVgU2nj.js +0 -188
  368. package/chunks/BtmEtAW3.js +0 -43
  369. package/chunks/CQ57zhVp.js +0 -106
  370. package/chunks/CQJ0-ZuR.js +0 -106
  371. package/chunks/CWqzr5E5.js +0 -108
  372. package/chunks/Cg4ZI9v8.js +0 -180
  373. package/chunks/CoBtJ4c1.js +0 -144
  374. package/chunks/D009Z-ld.js +0 -109
  375. package/chunks/DMtTiWuY.js +0 -127
  376. package/chunks/Dixb5KKs.js +0 -116
  377. package/chunks/DjY7KvwG.js +0 -28
  378. package/chunks/GjKpN6U-.js +0 -135
  379. package/chunks/St35qgL0.d.ts +0 -103
  380. package/chunks/br7kModF.js +0 -110
  381. package/chunks/l2Rxo2H0.js +0 -106
  382. package/chunks/tfkJ5D3p.js +0 -115
@@ -0,0 +1,456 @@
1
+ import { p as constants_default } from "../../chunks/BkjWOpMU.js";
2
+ import { n as isEmptyObject, r as isObject } from "../../chunks/v_QBn7Xm.js";
3
+ import { n as normalizeUnitWithPlurals } from "../../chunks/AyQQ6US-.js";
4
+ import { t as esday } from "../../chunks/CXWzCl3n.js";
5
+
6
+ //#region src/plugins/timezone/timezone-util.ts
7
+ /**
8
+ * Cache for Intl.DateTimeFormat instances for formatting date and time
9
+ * used to improve performance.
10
+ * The key is a combination of timezone and timeZoneName.
11
+ */
12
+ const dtfCacheDateTime = {};
13
+ const dtfCacheTimezoneName = {};
14
+ const TzDefaultTimezoneLocale = "en-US";
15
+ /**
16
+ * Get a cached or newly created Intl.DateTimeFormat instance for date/time formats.
17
+ *
18
+ * This function caches Intl.DateTimeFormat objects since their creation
19
+ * is relatively slow. It returns a formatter configured for date and time values
20
+ * using the given timezone.
21
+ *
22
+ * @param timezone - The IANA timezone identifier (e.g., "Asia/Shanghai").
23
+ * @returns A cached or new Intl.DateTimeFormat instance.
24
+ */
25
+ function getDateTimeFormat(timezone) {
26
+ const formatOptions = {
27
+ hour12: false,
28
+ hourCycle: "h23",
29
+ year: "numeric",
30
+ month: "2-digit",
31
+ day: "2-digit",
32
+ hour: "2-digit",
33
+ minute: "2-digit",
34
+ second: "2-digit",
35
+ weekday: "short"
36
+ };
37
+ if (timezone.length > 0) formatOptions["timeZone"] = timezone;
38
+ const key = `${timezone}|formatDateTime`;
39
+ let dtf = dtfCacheDateTime[key];
40
+ if (!dtf) {
41
+ dtf = new Intl.DateTimeFormat("en-US", formatOptions);
42
+ dtfCacheDateTime[key] = dtf;
43
+ }
44
+ return dtf;
45
+ }
46
+ /**
47
+ * Get a cached or newly created Intl.DateTimeFormat instance for timezone name formats.
48
+ *
49
+ * This function caches Intl.DateTimeFormat objects since their creation
50
+ * is relatively slow. It returns a formatter configured for timezone names using
51
+ * the given timezone and locale name.
52
+ *
53
+ * @param timezone - The IANA timezone identifier (e.g., "Asia/Shanghai").
54
+ * @param localeName - Optional settings for the name of the locale to use.
55
+ * @returns A cached or new Intl.DateTimeFormat instance.
56
+ */
57
+ function getTimezoneNameFormat(timezone, localeName = TzDefaultTimezoneLocale) {
58
+ const formatOptions = {
59
+ year: "numeric",
60
+ month: "2-digit",
61
+ timeZoneName: "short"
62
+ };
63
+ if (timezone.length > 0) formatOptions["timeZone"] = timezone;
64
+ const key = `${timezone}|localeName|timezoneName`;
65
+ let dtf = dtfCacheTimezoneName[key];
66
+ if (!dtf) {
67
+ dtf = new Intl.DateTimeFormat(localeName, formatOptions);
68
+ dtfCacheTimezoneName[key] = dtf;
69
+ }
70
+ return dtf;
71
+ }
72
+
73
+ //#endregion
74
+ //#region src/plugins/timezone/index.ts
75
+ /**
76
+ * timezone plugin
77
+ *
78
+ * This plugin adds the 'tz' method to the EsDay class.
79
+ * This plugin adds the 'tz' method/object to the esday class with the methods 'setDefault', 'getDefault' and 'guess'.
80
+ *
81
+ * This plugin adds the formatting tokens 'z' and 'Z' to EsDay.
82
+ *
83
+ * This plugin requires the 'utc' plugin.
84
+ * When parsing with a locale then the 'advancedParse' plugin, the 'localizedParse' plugin
85
+ * and at least one registered locale.
86
+ * This plugin can handle the 'locale' plugin.
87
+ *
88
+ * esday parameters in '$conf' defined in timezone plugin:
89
+ * timezone name of the timezone of this instance
90
+ */
91
+ const UNIT_ARRAY_MAP = {
92
+ year: 0,
93
+ month: 1,
94
+ date: 2,
95
+ hour: 3,
96
+ minute: 4,
97
+ second: 5
98
+ };
99
+ const maxDstDiff = 7200 * 1e3;
100
+ const typeToPos = {
101
+ year: 0,
102
+ month: 1,
103
+ day: 2,
104
+ hour: 3,
105
+ minute: 4,
106
+ second: 5
107
+ };
108
+ const matchContainsOffset = /^(\d{4})[-/](\d{1,2})[-/](\d{0,2}).*(([+-]\d\d:?(\d\d)?)$|Z$)/;
109
+ /**
110
+ * Generate formatted date parts for a given timestamp and timezone.
111
+ *
112
+ * This function creates a Date object from the given timestamp,
113
+ * retrieves a cached or new Intl.DateTimeFormat instance using
114
+ * the provided timezone and returns the formatted parts
115
+ * (year, month, day-of-month, hour, minute, second, weekday)
116
+ *
117
+ * @param timestamp - The timestamp in milliseconds since the Unix epoch.
118
+ * @param timezone - The IANA timezone identifier (e.g., "Asia/Shanghai").
119
+ * @returns An array of formatted date parts.
120
+ */
121
+ function makeFormatPartsDateTime(timestamp, timezone) {
122
+ const dtf = getDateTimeFormat(timezone);
123
+ const date = new Date(timestamp);
124
+ return dtf.formatToParts(date);
125
+ }
126
+ /**
127
+ * Do we have to convert parsed instance to another timezone?
128
+ * @param input - input value to be parsed by plugin timezone
129
+ * @returns true: result of parsing of input value must be converted to timezone
130
+ */
131
+ function convertRequired(input) {
132
+ const requiresObjectSupport = isObject(input) && !(input instanceof Date) && input !== null && !isEmptyObject(input);
133
+ return typeof input !== "string" && !Array.isArray(input) && !requiresObjectSupport;
134
+ }
135
+ /**
136
+ * Convert en-US short weekday names to a number using values like Date.getDay() does.
137
+ * @param shortWeekdayName - short weekday name (in locale en-US)
138
+ * @returns - number indicating the weekday (0=Sunday, 1=Monday, ...)
139
+ */
140
+ function weekdayNameToNumber(shortWeekdayName) {
141
+ switch (shortWeekdayName) {
142
+ case "Sun": return 0;
143
+ case "Mon": return 1;
144
+ case "Tue": return 2;
145
+ case "Wed": return 3;
146
+ case "Thu": return 4;
147
+ case "Fri": return 5;
148
+ case "Sat": return 6;
149
+ default: return -1;
150
+ }
151
+ }
152
+ /**
153
+ * Get the date components (year, month, day ...) of the given timestamp,
154
+ * if formatted in the given timezone.
155
+ * The function returns an array with the values for
156
+ * [year, month, day-of-month, hour, minute, second, weekday].
157
+ * 'month' is 1..12; 'day-of-month' is 1..31, 'weekday' is 0..6.
158
+ * @param timestamp - timestamp to convert
159
+ * @param timezone - timezone to use for formatting
160
+ * @returns array of numbers with the date components of the timestamp in the timezone
161
+ */
162
+ function timestampToDateTimeComponents(timestamp, timezone) {
163
+ const formatResult = makeFormatPartsDateTime(timestamp, timezone);
164
+ const filled = [];
165
+ let weekdayNumber = -1;
166
+ for (let i = 0; i < formatResult.length; i += 1) {
167
+ const { type, value } = formatResult[i];
168
+ if (type === "weekday") {
169
+ weekdayNumber = weekdayNameToNumber(value);
170
+ continue;
171
+ }
172
+ const pos = typeToPos[type];
173
+ if (pos >= 0) filled[pos] = Number.parseInt(value, 10);
174
+ filled[6] = weekdayNumber;
175
+ }
176
+ return filled;
177
+ }
178
+ /**
179
+ * Get the formatted timezone name of the given timestamp, if formatted in
180
+ * the given timezone.
181
+ * The function returns the short name of the timezone using the given locale.
182
+ * 'month' is 1..12; 'day-of-month' is 1..31, 'weekday' is 0..6.
183
+ * @param timestamp - timestamp to convert
184
+ * @param timezone - timezone to use for conversion
185
+ * @param timezone - timezone to use for conversion
186
+ * @returns array of numbers with the date components of the timestamp in the timezone
187
+ */
188
+ function timestampToTimezoneName(timestamp, timezone, locale) {
189
+ const dtf = getTimezoneNameFormat(timezone, locale);
190
+ const date = new Date(timestamp);
191
+ const formatResult = dtf.formatToParts(date);
192
+ let timezoneNameShort = timezone;
193
+ /* istanbul ignore else -- @preserve */
194
+ if (formatResult.length >= 4 && formatResult[4].type === "timeZoneName") timezoneNameShort = formatResult[4].value;
195
+ return timezoneNameShort;
196
+ }
197
+ /**
198
+ * Calculate the new basic values for year, month etc. when using the "set" method.
199
+ * These values must be adjusted to the current timezone.
200
+ * @param dateComponents - array with the components of the formatted timestamp (year, month, ...)
201
+ * @param currentMs - milliseconds of the current timestamp (0..999)
202
+ * @param unit - normalized unit to set
203
+ * @param values - value to set (or values, if applicable e.g. for year)
204
+ * @returns literal object with year, month etc. after setting the new value(s)
205
+ */
206
+ function calculateBaseComponentsForSet(dateComponents, currentMs, unit, values) {
207
+ let year = dateComponents[0];
208
+ let month = dateComponents[1] - 1;
209
+ let day = dateComponents[2];
210
+ let hour = dateComponents[3];
211
+ let minute = dateComponents[4];
212
+ let second = dateComponents[5];
213
+ let ms = currentMs;
214
+ const mainValue = values[0];
215
+ if (unit === constants_default.YEAR) {
216
+ year = mainValue;
217
+ if (values.length > 1) month = values[1];
218
+ if (values.length > 2) day = values[2];
219
+ } else if (unit === constants_default.MONTH) {
220
+ month = mainValue;
221
+ if (values.length > 1) day = values[1];
222
+ } else if (unit === constants_default.DAY) {
223
+ const currentWeekday = dateComponents[6];
224
+ day += mainValue - currentWeekday;
225
+ } else if (unit === constants_default.DAY_OF_MONTH) day = mainValue;
226
+ else if (unit === constants_default.HOUR) hour = mainValue;
227
+ else if (unit === constants_default.MIN) minute = mainValue;
228
+ else if (unit === constants_default.SECOND) second = mainValue;
229
+ else if (unit === constants_default.MS) ms = mainValue;
230
+ if (unit === constants_default.YEAR || unit === constants_default.MONTH) {
231
+ const lastDay = new Date(Date.UTC(year, month + 1, 0)).getUTCDate();
232
+ if (day > lastDay) day = lastDay;
233
+ }
234
+ let valuesIndex = 1;
235
+ if (unit === constants_default.HOUR && values.length > valuesIndex) minute = values[valuesIndex++];
236
+ if ((unit === constants_default.HOUR || unit === constants_default.MIN) && values.length > valuesIndex) second = values[valuesIndex++];
237
+ if ((unit === constants_default.HOUR || unit === constants_default.MIN || unit === constants_default.SECOND) && values.length > valuesIndex) ms = values[valuesIndex++];
238
+ return {
239
+ year,
240
+ month,
241
+ day,
242
+ hour,
243
+ minute,
244
+ second,
245
+ ms
246
+ };
247
+ }
248
+ /**
249
+ * Gets the timezone of the given date formatted in the short form (e.g. 'PST')
250
+ * @param sourceDate - date to format the timezone for
251
+ * @returns the short form of the timezone of the given sourceDate
252
+ */
253
+ function formatTimezoneShort(sourceDate) {
254
+ const timezone = sourceDate.tz();
255
+ const localeName = sourceDate.locale?.() ?? esday.locale?.();
256
+ return timestampToTimezoneName(sourceDate.valueOf(), timezone, localeName);
257
+ }
258
+ const timezonePLugin = (_, dayClass, esdayFactory) => {
259
+ const noTimezone = "";
260
+ let defaultTimezone;
261
+ /**
262
+ * Get timezone offset for timestamp in given timezone
263
+ * @param timestamp - timestamp to use
264
+ * @param timezone - timezone to calculate offset for
265
+ * @returns utc offset for timestamp in given timezone
266
+ */
267
+ const tzOffset = (timestamp, timezone) => {
268
+ const filled = timestampToDateTimeComponents(timestamp, timezone);
269
+ const utcString = `${filled[0]}-${filled[1]}-${filled[2]} ${filled[3]}:${filled[4]}:${filled[5]}:000`;
270
+ const utcTs = esdayFactory.utc(utcString).valueOf();
271
+ let timestampAsEpoch = timestamp.valueOf();
272
+ const msOfTimestamp = timestampAsEpoch % 1e3;
273
+ timestampAsEpoch -= msOfTimestamp;
274
+ return (utcTs - timestampAsEpoch) / (60 * 1e3);
275
+ };
276
+ /**
277
+ * Move to the earlier date in an DST overlap, if we are in an overlap. Otherwise return input date.
278
+ * The return value is an literal object in the form of {timestampFixed, tzOffsetFixed, isInOverlap}.
279
+ * @param timestampOriginal - timestamp to be fixed
280
+ * @param tzOffsetOriginal - tzOffset of timestampOriginal
281
+ * @param timezone - timezone to use
282
+ * @returns literal object containing fixed date (or original date, if we are not in an overlap)
283
+ */
284
+ const fixOverlap = (timestampOriginal, tzOffsetOriginal, timezone) => {
285
+ let timestampFixed = timestampOriginal;
286
+ let tzOffsetFixed = tzOffsetOriginal;
287
+ let isInOverlap = false;
288
+ const tzOffsetPreDst = tzOffset(timestampOriginal - maxDstDiff, timezone);
289
+ if (tzOffsetPreDst > tzOffsetOriginal) {
290
+ timestampFixed = timestampOriginal - (tzOffsetPreDst - tzOffsetOriginal) * 60 * 1e3;
291
+ tzOffsetFixed = tzOffset(timestampFixed, timezone);
292
+ if (tzOffsetFixed === tzOffsetOriginal) {
293
+ timestampFixed = timestampOriginal;
294
+ tzOffsetFixed = tzOffsetOriginal;
295
+ } else isInOverlap = true;
296
+ }
297
+ return {
298
+ timestampFixed,
299
+ tzOffsetFixed,
300
+ isInOverlap
301
+ };
302
+ };
303
+ /**
304
+ * Change the timestamp and timezone offset of a timestamp to change the timezone while keeping the time value.
305
+ * @param timestampOriginal - timestamp to fix the offset for, if necessary
306
+ * @param tzOffsetSource - tzOffset of the originalTimestamp in the source timezone
307
+ * @param tzOffsetTarget - tzOffset of the originalTimestamp in the target timezone
308
+ * @param tzTarget - timezone to use
309
+ * @returns array with updated timestamp and fixed offset
310
+ */
311
+ const fixOffsetConvert = (timestampOriginal, tzOffsetSource, tzOffsetTarget, tzTarget) => {
312
+ const timestampGuess1 = timestampOriginal - (tzOffsetTarget - tzOffsetSource) * 60 * 1e3;
313
+ const tzOffsetGuess1 = tzOffset(timestampGuess1, tzTarget);
314
+ if (tzOffsetGuess1 === tzOffsetTarget) {
315
+ const { timestampFixed, tzOffsetFixed } = fixOverlap(timestampGuess1, tzOffsetGuess1, tzTarget);
316
+ return [timestampFixed, tzOffsetFixed];
317
+ }
318
+ const timestampGuess2 = timestampGuess1 - (tzOffsetGuess1 - tzOffsetTarget) * 60 * 1e3;
319
+ const tzOffsetGuess2 = tzOffset(timestampGuess2, tzTarget);
320
+ if (tzOffsetGuess2 === tzOffsetGuess1) return [timestampGuess2, tzOffsetGuess2];
321
+ else if (tzOffsetGuess1 < tzOffsetTarget) return [timestampGuess2, tzOffsetGuess2];
322
+ else return [timestampGuess1, tzOffsetGuess1];
323
+ };
324
+ esdayFactory.tz = (input, ...others) => {
325
+ let timezone = defaultTimezone;
326
+ if (others.length > 0) timezone = others.pop();
327
+ const parsedInput = esdayFactory.utc(input, ...others);
328
+ if (!parsedInput.isValid()) return parsedInput;
329
+ const offsetParsedInput = tzOffset(parsedInput.valueOf(), timezone ?? noTimezone);
330
+ if (convertRequired(input) || typeof input === "string" && matchContainsOffset.test(input)) return parsedInput.tz(timezone);
331
+ const [targetTimestamp, targetOffset] = fixOffsetConvert(parsedInput.valueOf(), 0, offsetParsedInput, timezone ?? noTimezone);
332
+ const result = esdayFactory.utc(targetTimestamp, ...others);
333
+ result["$conf"].utcOffset = targetOffset;
334
+ result["$conf"].localOffset = result.toDate().getTimezoneOffset();
335
+ result["$conf"].utc = targetOffset === 0;
336
+ if (result["$conf"].localeName !== void 0 && parsedInput["$conf"].localeName !== void 0) result["$conf"].localeName = parsedInput["$conf"].localeName;
337
+ result["$conf"].timezone = timezone;
338
+ return result;
339
+ };
340
+ esdayFactory.tz.guess = () => Intl.DateTimeFormat().resolvedOptions().timeZone;
341
+ esdayFactory.tz.setDefault = (timezone) => {
342
+ defaultTimezone = timezone;
343
+ };
344
+ esdayFactory.tz.getDefault = () => {
345
+ return defaultTimezone;
346
+ };
347
+ const proto = dayClass.prototype;
348
+ proto.tz = function(timezone, keepLocalTime) {
349
+ if (timezone === void 0) return this["$conf"].timezone;
350
+ const result = this.clone();
351
+ const tzOffsetTarget = tzOffset(this.valueOf(), timezone);
352
+ const localOffset = this.toDate().getTimezoneOffset();
353
+ result["$conf"].localOffset = localOffset;
354
+ result["$conf"].utcOffset = tzOffsetTarget;
355
+ result["$conf"].utc = tzOffsetTarget === 0;
356
+ result["$conf"].timezone = timezone;
357
+ if (keepLocalTime) {
358
+ const timestampSource = result.valueOf();
359
+ let tzOffsetSource = 0;
360
+ if (!this["$conf"].utc) tzOffsetSource = this["$conf"].timezone ? Number(this["$conf"].utcOffset) : -1 * localOffset;
361
+ const [timestampFixed, tzOffsetFixed] = fixOffsetConvert(timestampSource, tzOffsetSource, tzOffsetTarget, timezone);
362
+ result["$conf"].utcOffset = tzOffsetFixed;
363
+ result["$conf"].utc = tzOffsetFixed === 0;
364
+ if (timestampSource !== timestampFixed) result.$d = new Date(timestampFixed);
365
+ }
366
+ return result;
367
+ };
368
+ const oldValueOf = proto.valueOf;
369
+ proto.valueOf = function() {
370
+ if (this["$conf"]?.timezone) return this.$d.valueOf();
371
+ return oldValueOf.call(this);
372
+ };
373
+ const oldGet = proto.get;
374
+ proto.get = function(unit) {
375
+ const normalizedUnit = normalizeUnitWithPlurals(unit);
376
+ if (normalizedUnit === constants_default.QUARTER || normalizedUnit === constants_default.WEEK || normalizedUnit === constants_default.ISOWEEK || this["$conf"]?.utc) return oldGet.call(this, unit);
377
+ if (this["$conf"]?.timezone) {
378
+ const timezone = this["$conf"].timezone;
379
+ const dateComponents = timestampToDateTimeComponents(this.valueOf(), timezone);
380
+ if (normalizedUnit === constants_default.MS) return this["$d"].getUTCMilliseconds();
381
+ else if (normalizedUnit === constants_default.MONTH) return dateComponents[1] - 1;
382
+ else if (normalizedUnit === constants_default.DAY) return dateComponents[6];
383
+ else return dateComponents[UNIT_ARRAY_MAP[normalizedUnit]];
384
+ }
385
+ return oldGet.call(this, unit);
386
+ };
387
+ const old$set = proto["$set"];
388
+ proto["$set"] = function(unit, values) {
389
+ if (isObject(unit)) return old$set.call(this, unit, values);
390
+ const timezone = this["$conf"]?.timezone;
391
+ if (!timezone) return old$set.call(this, unit, values);
392
+ const normalizedUnit = normalizeUnitWithPlurals(unit);
393
+ const { year, month, day, hour, minute, second, ms } = calculateBaseComponentsForSet(timestampToDateTimeComponents(this.valueOf(), timezone), this.valueOf() % 1e3, normalizedUnit, values);
394
+ const utcAsLocal = Date.UTC(year, month, day, hour, minute, second, ms);
395
+ const [timestampFixed, tzOffsetFixed] = fixOffsetConvert(utcAsLocal, 0, tzOffset(utcAsLocal, timezone), timezone);
396
+ this.$d = new Date(timestampFixed);
397
+ this["$conf"].utcOffset = tzOffsetFixed;
398
+ this["$conf"].localOffset = this.$d.getTimezoneOffset();
399
+ this["$conf"].utc = tzOffsetFixed === 0;
400
+ return this;
401
+ };
402
+ const oldStartOf = dayClass.prototype.startOf;
403
+ proto.startOf = function(units) {
404
+ if (!this["$conf"] || !this["$conf"]["timezone"]) return oldStartOf.call(this, units);
405
+ const withoutTz = esdayFactory(this.format("YYYY-MM-DD HH:mm:ss:SSS"));
406
+ return oldStartOf.call(withoutTz, units).tz(this["$conf"]["timezone"], true);
407
+ };
408
+ const oldEndOf = dayClass.prototype.endOf;
409
+ proto.endOf = function(units) {
410
+ if (!this["$conf"] || !this["$conf"]["timezone"]) return oldEndOf.call(this, units);
411
+ const withoutTz = esdayFactory(this.format("YYYY-MM-DD HH:mm:ss:SSS"));
412
+ return oldEndOf.call(withoutTz, units).tz(this["$conf"]["timezone"], true);
413
+ };
414
+ const oldAdd = proto.add;
415
+ proto.add = function(value, unit) {
416
+ if (isObject(value) || unit === void 0) return oldAdd.call(this, value, unit);
417
+ const newValue = oldAdd.call(this, value, unit);
418
+ if (!this["$conf"].timezone) return newValue;
419
+ const timezone = this["$conf"]["timezone"];
420
+ const timestamp = newValue.valueOf();
421
+ const tzOldOffset = tzOffset(timestamp, timezone);
422
+ const normalizedUnit = normalizeUnitWithPlurals(unit);
423
+ const timeUnits = [
424
+ constants_default.HOUR,
425
+ constants_default.MIN,
426
+ constants_default.SECOND,
427
+ constants_default.MS
428
+ ];
429
+ const { isInOverlap } = fixOverlap(timestamp, tzOldOffset, timezone);
430
+ if (timeUnits.includes(normalizedUnit) && isInOverlap) {
431
+ newValue["$conf"].utcOffset = tzOldOffset;
432
+ newValue["$conf"].utc = tzOldOffset === 0;
433
+ return newValue;
434
+ }
435
+ const [timestampFixed, tzOffsetFixed] = fixOffsetConvert(timestamp, tzOldOffset, tzOffset(timestamp, timezone), timezone);
436
+ newValue.$d = new Date(timestampFixed);
437
+ newValue["$conf"].utcOffset = tzOffsetFixed;
438
+ newValue["$conf"].localOffset = newValue.$d.getTimezoneOffset();
439
+ newValue["$conf"].utc = tzOffsetFixed === 0;
440
+ return newValue;
441
+ };
442
+ const oldSubtract = proto.subtract;
443
+ proto.subtract = function(value, unit) {
444
+ if (isObject(value) || unit === void 0) return oldSubtract.call(this, value, unit);
445
+ if (this["$conf"].timezone) return proto.add.call(this, -value, unit);
446
+ return oldSubtract.call(this, value, unit);
447
+ };
448
+ const additionalTokens = {
449
+ z: formatTimezoneShort,
450
+ zz: formatTimezoneShort
451
+ };
452
+ esdayFactory.addFormatTokenDefinitions(additionalTokens);
453
+ };
454
+
455
+ //#endregion
456
+ export { timezonePLugin as default };
@@ -1,5 +1,4 @@
1
- import { EsDayPlugin } from "../../chunks/DqhiVwLi.js";
2
- import "../../chunks/MtjcOKi-.js";
1
+ import { o as EsDayPlugin } from "../../chunks/CODi8AFH.js";
3
2
 
4
3
  //#region src/plugins/toArray/index.d.ts
5
4
  declare module 'esday' {
@@ -12,7 +12,6 @@ const toArrayPlugin = (_, dayClass) => {
12
12
  ];
13
13
  };
14
14
  };
15
- var toArray_default = toArrayPlugin;
16
15
 
17
16
  //#endregion
18
- export { toArray_default as default };
17
+ export { toArrayPlugin as default };
@@ -1,5 +1,4 @@
1
- import { EsDayPlugin } from "../../chunks/DqhiVwLi.js";
2
- import "../../chunks/MtjcOKi-.js";
1
+ import { o as EsDayPlugin } from "../../chunks/CODi8AFH.js";
3
2
 
4
3
  //#region src/plugins/toObject/index.d.ts
5
4
  declare module 'esday' {
@@ -12,7 +12,6 @@ const toObjectPlugin = (_, dayClass) => {
12
12
  };
13
13
  };
14
14
  };
15
- var toObject_default = toObjectPlugin;
16
15
 
17
16
  //#endregion
18
- export { toObject_default as default };
17
+ export { toObjectPlugin as default };
@@ -1,7 +1,6 @@
1
- import { DateType, EsDayPlugin, SimpleType } from "../../chunks/DqhiVwLi.js";
1
+ import { h as SimpleType, o as EsDayPlugin, r as DateType } from "../../chunks/CODi8AFH.js";
2
2
 
3
3
  //#region src/plugins/utc/index.d.ts
4
-
5
4
  declare module 'esday' {
6
5
  interface EsDay {
7
6
  utc: (keepLocalTime?: boolean) => EsDay;
@@ -1,8 +1,8 @@
1
- import { constants_default } from "../../chunks/Y32qdU_5.js";
2
- import { isObject, isUndefined } from "../../chunks/Cb5SvF6r.js";
3
- import { normalizeUnitWithPlurals } from "../../chunks/DjY7KvwG.js";
4
- import { getUnitInDateUTC, setUnitInDateUTC } from "../../chunks/BtmEtAW3.js";
5
- import { createInstanceFromExist } from "../../chunks/DXHbH1CI.js";
1
+ import { p as constants_default } from "../../chunks/BkjWOpMU.js";
2
+ import { a as isUndefined, r as isObject } from "../../chunks/v_QBn7Xm.js";
3
+ import { n as normalizeUnitWithPlurals } from "../../chunks/AyQQ6US-.js";
4
+ import { a as setUnitInDateUTC, n as getUnitInDateUTC } from "../../chunks/xt8C2lbv.js";
5
+ import { t as createInstanceFromExist } from "../../chunks/Shk32pTP.js";
6
6
 
7
7
  //#region src/plugins/utc/index.ts
8
8
  const REGEX_VALID_OFFSET_FORMAT = /[+-]\d\d(?::?\d\d)?/g;
@@ -21,7 +21,7 @@ function offsetFromString(value = "") {
21
21
  }
22
22
  function utcOffsetGetImpl(that, defaultValue = NaN) {
23
23
  if (that["$conf"].utc) return 0;
24
- if (that["$conf"].offset !== void 0) return Number(that["$conf"].offset);
24
+ if (that["$conf"].utcOffset !== void 0) return Number(that["$conf"].utcOffset);
25
25
  return defaultValue;
26
26
  }
27
27
  function utcOffsetSetImpl(that, offset, keepLocalTime) {
@@ -38,15 +38,15 @@ function utcOffsetSetImpl(that, offset, keepLocalTime) {
38
38
  instance = instance.add(localTimezoneOffset, constants_default.MIN);
39
39
  instance["$conf"].utc = offsetAsMinutes === 0;
40
40
  }
41
- instance["$conf"].offset = offsetAsMinutes;
42
- instance["$conf"].tzOffset = localTimezoneOffset;
41
+ instance["$conf"].utcOffset = offsetAsMinutes;
42
+ instance["$conf"].localOffset = localTimezoneOffset;
43
43
  return instance;
44
44
  }
45
45
  if (offsetAsNumber !== 0) {
46
46
  const localTimezoneOffset = that["$conf"].utc ? that.toDate().getTimezoneOffset() : -1 * that.utcOffset();
47
47
  const instance = that.local().add(offsetAsMinutes + localTimezoneOffset, constants_default.MIN);
48
- instance["$conf"].offset = offsetAsMinutes;
49
- instance["$conf"].tzOffset = localTimezoneOffset;
48
+ instance["$conf"].utcOffset = offsetAsMinutes;
49
+ instance["$conf"].localOffset = localTimezoneOffset;
50
50
  return instance;
51
51
  }
52
52
  return that.utc();
@@ -55,9 +55,7 @@ function addUtc(that, value, units) {
55
55
  const $d = that["$d"];
56
56
  const unit = normalizeUnitWithPlurals(units);
57
57
  const instanceFactorySet = (multiplier) => {
58
- const newInstance = that.clone();
59
- newInstance["$d"].setUTCDate($d.getUTCDate() + Math.round(multiplier * value));
60
- return newInstance;
58
+ return that.set("date", that.get("date") + Math.round(multiplier * value));
61
59
  };
62
60
  switch (normalizeUnitWithPlurals(unit)) {
63
61
  case constants_default.YEAR: return that.set("year", that.get("year") + value);
@@ -82,13 +80,12 @@ function addUtc(that, value, units) {
82
80
  }
83
81
  const utcPlugin = (_, dayClass, dayFactory) => {
84
82
  dayFactory.utc = (d, ...others) => {
85
- const inst = dayFactory(d, ...others, { utc: true });
86
- return inst;
83
+ return dayFactory(d, ...others, { utc: true });
87
84
  };
88
85
  const proto = dayClass.prototype;
89
86
  proto.utc = function(keepLocalTime) {
90
87
  const inst = this.clone();
91
- inst["$d"] = this.toDate();
88
+ inst.$d = this.toDate();
92
89
  inst["$conf"].utc = true;
93
90
  if (keepLocalTime) return inst.add(this.utcOffset(), constants_default.MIN);
94
91
  return inst;
@@ -107,35 +104,33 @@ const utcPlugin = (_, dayClass, dayFactory) => {
107
104
  };
108
105
  proto.utcOffset = function(offset, keepLocalTime) {
109
106
  if (offset === void 0) {
110
- const defaultOffset = -Math.round(this["$d"].getTimezoneOffset());
107
+ const defaultOffset = -Math.round(this.$d.getTimezoneOffset());
111
108
  return utcOffsetGetImpl(this, defaultOffset);
112
109
  }
113
110
  return utcOffsetSetImpl(this, offset, keepLocalTime);
114
111
  };
115
112
  const oldValueOf = proto.valueOf;
116
113
  proto.valueOf = function() {
117
- if (this["$conf"].offset !== void 0) {
118
- const internalDate = this["$d"];
119
- const offsetToUse = Number(this["$conf"].tzOffset ?? internalDate.getTimezoneOffset());
120
- const addedOffset = Number(this["$conf"].offset) + offsetToUse;
114
+ if (this["$conf"].utcOffset !== void 0) {
115
+ const internalDate = this.$d;
116
+ const offsetToUse = Number(this["$conf"].localOffset ?? internalDate.getTimezoneOffset());
117
+ const addedOffset = Number(this["$conf"].utcOffset) + offsetToUse;
121
118
  return internalDate.valueOf() - addedOffset * constants_default.MILLISECONDS_A_MINUTE;
122
119
  }
123
120
  return oldValueOf.call(this);
124
121
  };
125
122
  const oldFormat = proto.format;
126
123
  proto.format = function(formatStr) {
127
- const UTC_FORMAT_DEFAULT = "YYYY-MM-DDTHH:mm:ss[Z]";
128
- const str = formatStr || (this["$conf"].utc ? UTC_FORMAT_DEFAULT : "");
129
- return oldFormat.call(this, str);
124
+ const activeFormatString = formatStr || (this["$conf"].utc ? "YYYY-MM-DDTHH:mm:ss[Z]" : "");
125
+ return oldFormat.call(this, activeFormatString);
130
126
  };
131
127
  const oldDateFromDateComponents = proto["dateFromDateComponents"];
132
128
  proto["dateFromDateComponents"] = function(Y, M, D, h, m, s, ms, offsetMs) {
133
129
  if (!this["$conf"].utc) return oldDateFromDateComponents(Y, M, D, h, m, s, ms, offsetMs);
134
130
  const parsedYearOrDefault = Y ?? (/* @__PURE__ */ new Date()).getFullYear();
135
- const parsedMonthOrDefault = M ?? (Y !== void 0 ? 1 : (/* @__PURE__ */ new Date()).getMonth() + 1);
136
131
  const dateComponents = {
137
132
  Y: parsedYearOrDefault,
138
- M: parsedMonthOrDefault - 1,
133
+ M: (M ?? (Y !== void 0 ? 1 : (/* @__PURE__ */ new Date()).getMonth() + 1)) - 1,
139
134
  D: D ?? 1,
140
135
  h: h ?? 0,
141
136
  m: m ?? 0,
@@ -156,39 +151,42 @@ const utcPlugin = (_, dayClass, dayFactory) => {
156
151
  proto.get = function(unit) {
157
152
  const normalizedUnit = normalizeUnitWithPlurals(unit);
158
153
  if (normalizedUnit === constants_default.QUARTER || normalizedUnit === constants_default.WEEK) return NaN;
159
- if (this["$conf"].utc) return getUnitInDateUTC(this["$d"], unit);
154
+ if (this["$conf"].utc) return getUnitInDateUTC(this.$d, unit);
160
155
  return oldGet.call(this, unit);
161
156
  };
162
157
  const old$set = proto["$set"];
163
158
  proto["$set"] = function(unit, values) {
164
- const utc = !!this["$conf"].utc;
165
- if (utc) {
166
- if (isObject(unit)) return this.clone();
167
- const $date = this["$d"];
159
+ if (!!this["$conf"].utc) {
160
+ if (isObject(unit)) return this;
161
+ const $date = this.$d;
168
162
  const normalizedUnit = normalizeUnitWithPlurals(unit);
169
163
  if (normalizedUnit === constants_default.DAY) setUnitInDateUTC($date, constants_default.DAY_OF_MONTH, this.date() + (values[0] - this.day()));
170
- else if (normalizedUnit !== constants_default.QUARTER && normalizedUnit !== constants_default.WEEK) {
171
- const typedUnit = normalizedUnit;
172
- setUnitInDateUTC($date, typedUnit, values);
173
- }
164
+ else if (normalizedUnit === constants_default.YEAR && values.length === 2) {
165
+ const originalDate = this.date();
166
+ setUnitInDateUTC($date, constants_default.YEAR, values);
167
+ if (originalDate > 0 && this.date() !== originalDate) setUnitInDateUTC($date, constants_default.DAY_OF_MONTH, 0);
168
+ } else if (normalizedUnit === constants_default.MONTH) {
169
+ const originalDate = values.length === 1 ? this.date() : values[1];
170
+ setUnitInDateUTC($date, constants_default.MONTH, values);
171
+ if (originalDate > 0 && this.date() !== originalDate) setUnitInDateUTC($date, constants_default.DAY_OF_MONTH, 0);
172
+ } else if (normalizedUnit !== constants_default.QUARTER && normalizedUnit !== constants_default.WEEK) setUnitInDateUTC($date, normalizedUnit, values);
174
173
  return this;
175
174
  }
176
175
  return old$set.call(this, unit, values);
177
176
  };
178
177
  const oldAdd = proto.add;
179
178
  proto.add = function(value, unit) {
180
- if (isObject(value) || unit === void 0) return this.clone();
179
+ if (isObject(value) || unit === void 0) return oldAdd.call(this, value, unit);
181
180
  if (this["$conf"].utc) return addUtc(this, value, unit);
182
181
  return oldAdd.call(this, value, unit);
183
182
  };
184
183
  const oldSubtract = proto.subtract;
185
184
  proto.subtract = function(value, unit) {
186
- if (isObject(value) || unit === void 0) return this.clone();
185
+ if (isObject(value) || unit === void 0) return oldSubtract.call(this, value, unit);
187
186
  if (this["$conf"].utc) return addUtc(this, -value, unit);
188
187
  return oldSubtract.call(this, value, unit);
189
188
  };
190
189
  };
191
- var utc_default = utcPlugin;
192
190
 
193
191
  //#endregion
194
- export { utc_default as default };
192
+ export { utcPlugin as default };