@brainfish-ai/components 0.25.5 → 0.26.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (236) hide show
  1. package/dist/chat-search.d.ts +40 -3
  2. package/dist/esm/chunks/ChatSearch.Cqo4WF3n.js +95 -0
  3. package/dist/esm/chunks/ChatSearch.Cqo4WF3n.js.map +1 -0
  4. package/dist/esm/chunks/Conversation.UZ5rx7_0.js +22 -0
  5. package/dist/esm/chunks/{Conversation.BriXFYqU.js.map → Conversation.UZ5rx7_0.js.map} +1 -1
  6. package/dist/esm/chunks/FormattedMessage.D9xA6QsH.js +23 -0
  7. package/dist/esm/chunks/FormattedMessage.D9xA6QsH.js.map +1 -0
  8. package/dist/esm/chunks/MermaidDiagram.PRgXQ5Yh.js +2 -0
  9. package/dist/esm/chunks/{MermaidDiagram.xQ0CVFOI.js.map → MermaidDiagram.PRgXQ5Yh.js.map} +1 -1
  10. package/dist/esm/chunks/_commonjsHelpers.lGe4XDVY.js +2 -0
  11. package/dist/esm/chunks/_commonjsHelpers.lGe4XDVY.js.map +1 -0
  12. package/dist/esm/chunks/button.BYc5d6AZ.js +3 -0
  13. package/dist/esm/chunks/{button.DQL6gCAt.js.map → button.BYc5d6AZ.js.map} +1 -1
  14. package/dist/esm/chunks/chart.BDL2tf-S.js +10 -0
  15. package/dist/esm/chunks/{chart.4ZbtBMmR.js.map → chart.BDL2tf-S.js.map} +1 -1
  16. package/dist/esm/chunks/chat-logo.CqPppEb9.js +3 -0
  17. package/dist/esm/chunks/chat-logo.CqPppEb9.js.map +1 -0
  18. package/dist/esm/chunks/combobox.CxaWbDm9.js +6 -0
  19. package/dist/esm/chunks/{combobox.CJKym3Z1.js.map → combobox.CxaWbDm9.js.map} +1 -1
  20. package/dist/esm/chunks/dark.DuW7JuAk.js +2 -0
  21. package/dist/esm/chunks/{dark.Cq2RCgy4.js.map → dark.DuW7JuAk.js.map} +1 -1
  22. package/dist/esm/chunks/data-table.CJOR-1Kf.js +5 -0
  23. package/dist/esm/chunks/{data-table.DbcAYxMY.js.map → data-table.CJOR-1Kf.js.map} +1 -1
  24. package/dist/esm/chunks/date-picker.Bhplnvxn.js +4 -0
  25. package/dist/esm/chunks/{date-picker._cBTpdEK.js.map → date-picker.Bhplnvxn.js.map} +1 -1
  26. package/dist/esm/chunks/extends.DPdBf6DS.js +2 -0
  27. package/dist/esm/chunks/extends.DPdBf6DS.js.map +1 -0
  28. package/dist/esm/chunks/feature-flags.DOcVlPHk.js +3 -0
  29. package/dist/esm/chunks/{feature-flags.DeDEcnd1.js.map → feature-flags.DOcVlPHk.js.map} +1 -1
  30. package/dist/esm/chunks/feedback.BXKvlNz1.js +13 -0
  31. package/dist/esm/chunks/{feedback.W2OzN-5r.js.map → feedback.BXKvlNz1.js.map} +1 -1
  32. package/dist/esm/chunks/file-upload-status.4ukNFyi2.js +8 -0
  33. package/dist/esm/chunks/{file-upload-status.DP2iuttI.js.map → file-upload-status.4ukNFyi2.js.map} +1 -1
  34. package/dist/esm/chunks/filters.ita3UAnO.js +22 -0
  35. package/dist/esm/chunks/{filters.-7vSLEQ2.js.map → filters.ita3UAnO.js.map} +1 -1
  36. package/dist/esm/chunks/font-picker.BwEWBowG.js +6 -0
  37. package/dist/esm/chunks/{font-picker.DisEoE8a.js.map → font-picker.BwEWBowG.js.map} +1 -1
  38. package/dist/esm/chunks/formatDate.D2xEZm8f.js +2 -0
  39. package/dist/esm/chunks/{formatDate.CWN6IFKq.js.map → formatDate.D2xEZm8f.js.map} +1 -1
  40. package/dist/esm/chunks/formatNumber.DhVn228t.js +2 -0
  41. package/dist/esm/chunks/{formatNumber.Bm2k8QrT.js.map → formatNumber.DhVn228t.js.map} +1 -1
  42. package/dist/esm/chunks/generating-star.BN9p_FDu.js +7 -0
  43. package/dist/esm/chunks/generating-star.BN9p_FDu.js.map +1 -0
  44. package/dist/esm/chunks/header-nav.B4IJjted.js +10 -0
  45. package/dist/esm/chunks/{header-nav.b4hvOsKc.js.map → header-nav.B4IJjted.js.map} +1 -1
  46. package/dist/esm/chunks/header-pane.C1RWesOW.js +20 -0
  47. package/dist/esm/chunks/{header-pane.BV7xKJXV.js.map → header-pane.C1RWesOW.js.map} +1 -1
  48. package/dist/esm/chunks/hooks.BQTKhHSv.js +2 -0
  49. package/dist/esm/chunks/hooks.BQTKhHSv.js.map +1 -0
  50. package/dist/esm/chunks/index.uF4ME3WQ.js +4 -0
  51. package/dist/esm/chunks/{index.BqibIWDw.js.map → index.uF4ME3WQ.js.map} +1 -1
  52. package/dist/esm/chunks/input-with-tags.DrDDPxse.js +5 -0
  53. package/dist/esm/chunks/{input-with-tags.tg2nhPFv.js.map → input-with-tags.DrDDPxse.js.map} +1 -1
  54. package/dist/esm/chunks/logo.CketsPBx.js +5 -0
  55. package/dist/esm/chunks/{logo.D5BMN6Db.js.map → logo.CketsPBx.js.map} +1 -1
  56. package/dist/esm/chunks/primary.CMQbo1GJ.js +2 -0
  57. package/dist/esm/chunks/{primary.CtiRZbqq.js.map → primary.CMQbo1GJ.js.map} +1 -1
  58. package/dist/esm/chunks/review-list.qvxeqG9l.js +6 -0
  59. package/dist/esm/chunks/{review-list.BtSnfpSc.js.map → review-list.qvxeqG9l.js.map} +1 -1
  60. package/dist/esm/chunks/sidebar.IcJADYLR.js +25 -0
  61. package/dist/esm/chunks/sidebar.IcJADYLR.js.map +1 -0
  62. package/dist/esm/chunks/simpleSelect.DK1qZSXM.js +3 -0
  63. package/dist/esm/chunks/{simpleSelect.B1rktKkt.js.map → simpleSelect.DK1qZSXM.js.map} +1 -1
  64. package/dist/esm/chunks/status-badge.C-jt7Zs2.js +3 -0
  65. package/dist/esm/chunks/{status-badge.eFJ1PYeb.js.map → status-badge.C-jt7Zs2.js.map} +1 -1
  66. package/dist/esm/chunks/trend-value.BPBDBsk2.js +3 -0
  67. package/dist/esm/chunks/{trend-value.COSukPwk.js.map → trend-value.BPBDBsk2.js.map} +1 -1
  68. package/dist/esm/chunks/two-level-combobox.Bv2OQgjh.js +8 -0
  69. package/dist/esm/chunks/{two-level-combobox.BXs2z9u5.js.map → two-level-combobox.Bv2OQgjh.js.map} +1 -1
  70. package/dist/esm/chunks/useChartDateFormatters.Dx2h5AAm.js +2 -0
  71. package/dist/esm/chunks/{useChartDateFormatters.DS9ASgFO.js.map → useChartDateFormatters.Dx2h5AAm.js.map} +1 -1
  72. package/dist/esm/chunks/utils.C6Qu-kwd.js +2 -0
  73. package/dist/esm/chunks/{utils.Cwtlq8dh.js.map → utils.C6Qu-kwd.js.map} +1 -1
  74. package/dist/esm/colors.js +1 -169
  75. package/dist/esm/colors.js.map +1 -1
  76. package/dist/esm/components/article-suggestions-banner.js +4 -53
  77. package/dist/esm/components/article-suggestions-banner.js.map +1 -1
  78. package/dist/esm/components/articles-coverage.js +4 -116
  79. package/dist/esm/components/articles-coverage.js.map +1 -1
  80. package/dist/esm/components/articles-updated.js +4 -74
  81. package/dist/esm/components/articles-updated.js.map +1 -1
  82. package/dist/esm/components/breadcrumbs.js +3 -13
  83. package/dist/esm/components/breadcrumbs.js.map +1 -1
  84. package/dist/esm/components/chart-area-linear.js +6 -66
  85. package/dist/esm/components/chart-area-linear.js.map +1 -1
  86. package/dist/esm/components/chart-radial-stacked.js +2 -48
  87. package/dist/esm/components/chart-radial-stacked.js.map +1 -1
  88. package/dist/esm/components/chat-search.js +1 -1
  89. package/dist/esm/components/combobox.js +1 -1
  90. package/dist/esm/components/confirm-dialog.js +2 -47
  91. package/dist/esm/components/confirm-dialog.js.map +1 -1
  92. package/dist/esm/components/conversation.js +1 -1
  93. package/dist/esm/components/convos.js +27 -607
  94. package/dist/esm/components/convos.js.map +1 -1
  95. package/dist/esm/components/data-table.js +1 -1
  96. package/dist/esm/components/date-picker.js +1 -1
  97. package/dist/esm/components/discoveries-created.js +4 -64
  98. package/dist/esm/components/discoveries-created.js.map +1 -1
  99. package/dist/esm/components/feedback.js +1 -1
  100. package/dist/esm/components/file-upload.js +1 -1
  101. package/dist/esm/components/filter.js +1 -1
  102. package/dist/esm/components/font-picker.js +1 -1
  103. package/dist/esm/components/generating-star.js +1 -1
  104. package/dist/esm/components/input-with-tags.js +1 -1
  105. package/dist/esm/components/logo.js +1 -1
  106. package/dist/esm/components/markdown.js +1 -2
  107. package/dist/esm/components/markdown.js.map +1 -1
  108. package/dist/esm/components/metric-card.js +3 -29
  109. package/dist/esm/components/metric-card.js.map +1 -1
  110. package/dist/esm/components/select.js +1 -1
  111. package/dist/esm/components/trend-value.js +1 -1
  112. package/dist/esm/components/two-level-combobox.js +1 -1
  113. package/dist/esm/components/ui/accordion.js +7 -46
  114. package/dist/esm/components/ui/accordion.js.map +1 -1
  115. package/dist/esm/components/ui/alert-dialog.js +3 -114
  116. package/dist/esm/components/ui/alert-dialog.js.map +1 -1
  117. package/dist/esm/components/ui/alert.js +4 -103
  118. package/dist/esm/components/ui/alert.js.map +1 -1
  119. package/dist/esm/components/ui/avatar.js +7 -89
  120. package/dist/esm/components/ui/avatar.js.map +1 -1
  121. package/dist/esm/components/ui/badge.js +2 -26
  122. package/dist/esm/components/ui/badge.js.map +1 -1
  123. package/dist/esm/components/ui/breadcrumb.js +4 -60
  124. package/dist/esm/components/ui/breadcrumb.js.map +1 -1
  125. package/dist/esm/components/ui/button-group.js +4 -88
  126. package/dist/esm/components/ui/button-group.js.map +1 -1
  127. package/dist/esm/components/ui/button.js +1 -5
  128. package/dist/esm/components/ui/button.js.map +1 -1
  129. package/dist/esm/components/ui/calendar.js +2 -20
  130. package/dist/esm/components/ui/calendar.js.map +1 -1
  131. package/dist/esm/components/ui/card.js +1 -55
  132. package/dist/esm/components/ui/card.js.map +1 -1
  133. package/dist/esm/components/ui/collapsible.js +1 -33
  134. package/dist/esm/components/ui/collapsible.js.map +1 -1
  135. package/dist/esm/components/ui/combobox.js +1 -1
  136. package/dist/esm/components/ui/command.js +2 -79
  137. package/dist/esm/components/ui/command.js.map +1 -1
  138. package/dist/esm/components/ui/dialog.js +4 -60
  139. package/dist/esm/components/ui/dialog.js.map +1 -1
  140. package/dist/esm/components/ui/div-button.js +2 -61
  141. package/dist/esm/components/ui/div-button.js.map +1 -1
  142. package/dist/esm/components/ui/dropdown-menu.js +3 -114
  143. package/dist/esm/components/ui/dropdown-menu.js.map +1 -1
  144. package/dist/esm/components/ui/icon.js +2 -25
  145. package/dist/esm/components/ui/icon.js.map +1 -1
  146. package/dist/esm/components/ui/input.js +4 -47
  147. package/dist/esm/components/ui/input.js.map +1 -1
  148. package/dist/esm/components/ui/item.js +11 -140
  149. package/dist/esm/components/ui/item.js.map +1 -1
  150. package/dist/esm/components/ui/label.js +1 -19
  151. package/dist/esm/components/ui/label.js.map +1 -1
  152. package/dist/esm/components/ui/popover.js +1 -31
  153. package/dist/esm/components/ui/popover.js.map +1 -1
  154. package/dist/esm/components/ui/progress.js +2 -22
  155. package/dist/esm/components/ui/progress.js.map +1 -1
  156. package/dist/esm/components/ui/scroll-area.js +2 -32
  157. package/dist/esm/components/ui/scroll-area.js.map +1 -1
  158. package/dist/esm/components/ui/select.js +5 -66
  159. package/dist/esm/components/ui/select.js.map +1 -1
  160. package/dist/esm/components/ui/separator.js +1 -23
  161. package/dist/esm/components/ui/separator.js.map +1 -1
  162. package/dist/esm/components/ui/sheet.js +3 -62
  163. package/dist/esm/components/ui/sheet.js.map +1 -1
  164. package/dist/esm/components/ui/spinner.js +2 -17
  165. package/dist/esm/components/ui/spinner.js.map +1 -1
  166. package/dist/esm/components/ui/switch.js +2 -26
  167. package/dist/esm/components/ui/switch.js.map +1 -1
  168. package/dist/esm/components/ui/table.js +1 -82
  169. package/dist/esm/components/ui/table.js.map +1 -1
  170. package/dist/esm/components/ui/textarea.js +1 -33
  171. package/dist/esm/components/ui/textarea.js.map +1 -1
  172. package/dist/esm/components/ui/tooltip.js +3 -31
  173. package/dist/esm/components/ui/tooltip.js.map +1 -1
  174. package/dist/esm/global.css +1 -1
  175. package/dist/esm/index.js +1 -53
  176. package/dist/esm/index.js.map +1 -1
  177. package/dist/esm/layouts/full-layout.js +1 -1
  178. package/dist/esm/layouts/header-nav.js +1 -1
  179. package/dist/esm/layouts/sidebar.js +1 -1
  180. package/dist/esm/logos/microsoft-logo.js +6 -66
  181. package/dist/esm/logos/microsoft-logo.js.map +1 -1
  182. package/dist/esm/logos/microsoft-teams-logo.js +12 -112
  183. package/dist/esm/logos/microsoft-teams-logo.js.map +1 -1
  184. package/dist/esm/logos/slack-logo.js +3 -39
  185. package/dist/esm/logos/slack-logo.js.map +1 -1
  186. package/dist/esm/scenes/knowledge-review.js +17 -380
  187. package/dist/esm/scenes/knowledge-review.js.map +1 -1
  188. package/dist/esm/tailwind.preset.js +1 -1526
  189. package/dist/esm/tailwind.preset.js.map +1 -1
  190. package/dist/index.d.ts +48 -3
  191. package/dist/logo.d.ts +9 -0
  192. package/dist/stats.html +47 -46
  193. package/package.json +17 -18
  194. package/tailwind.preset.ts +1 -0
  195. package/dist/esm/chunks/ChatSearch.CL2VnSod.js +0 -6697
  196. package/dist/esm/chunks/ChatSearch.CL2VnSod.js.map +0 -1
  197. package/dist/esm/chunks/Conversation.BriXFYqU.js +0 -831
  198. package/dist/esm/chunks/FormattedMessage.CRbM-hF6.js +0 -39715
  199. package/dist/esm/chunks/FormattedMessage.CRbM-hF6.js.map +0 -1
  200. package/dist/esm/chunks/MermaidDiagram.xQ0CVFOI.js +0 -50
  201. package/dist/esm/chunks/_commonjsHelpers.BFTU3MAI.js +0 -8
  202. package/dist/esm/chunks/_commonjsHelpers.BFTU3MAI.js.map +0 -1
  203. package/dist/esm/chunks/button.DQL6gCAt.js +0 -48
  204. package/dist/esm/chunks/chart.4ZbtBMmR.js +0 -199
  205. package/dist/esm/chunks/combobox.CJKym3Z1.js +0 -95
  206. package/dist/esm/chunks/dark.Cq2RCgy4.js +0 -18
  207. package/dist/esm/chunks/data-table.DbcAYxMY.js +0 -102
  208. package/dist/esm/chunks/date-picker._cBTpdEK.js +0 -26
  209. package/dist/esm/chunks/extends.mO86zOh3.js +0 -12
  210. package/dist/esm/chunks/extends.mO86zOh3.js.map +0 -1
  211. package/dist/esm/chunks/feature-flags.DeDEcnd1.js +0 -22
  212. package/dist/esm/chunks/feedback.W2OzN-5r.js +0 -214
  213. package/dist/esm/chunks/file-upload-status.DP2iuttI.js +0 -141
  214. package/dist/esm/chunks/filters.-7vSLEQ2.js +0 -565
  215. package/dist/esm/chunks/font-picker.DisEoE8a.js +0 -181
  216. package/dist/esm/chunks/formatDate.CWN6IFKq.js +0 -952
  217. package/dist/esm/chunks/formatNumber.Bm2k8QrT.js +0 -10
  218. package/dist/esm/chunks/generating-star.DMDPNTaM.js +0 -1501
  219. package/dist/esm/chunks/generating-star.DMDPNTaM.js.map +0 -1
  220. package/dist/esm/chunks/header-nav.b4hvOsKc.js +0 -197
  221. package/dist/esm/chunks/header-pane.BV7xKJXV.js +0 -559
  222. package/dist/esm/chunks/hooks.m-nIJmio.js +0 -337
  223. package/dist/esm/chunks/hooks.m-nIJmio.js.map +0 -1
  224. package/dist/esm/chunks/index.BqibIWDw.js +0 -137
  225. package/dist/esm/chunks/input-with-tags.tg2nhPFv.js +0 -110
  226. package/dist/esm/chunks/logo.D5BMN6Db.js +0 -191
  227. package/dist/esm/chunks/primary.CtiRZbqq.js +0 -18
  228. package/dist/esm/chunks/review-list.BtSnfpSc.js +0 -117
  229. package/dist/esm/chunks/sidebar.PfXKnt9J.js +0 -803
  230. package/dist/esm/chunks/sidebar.PfXKnt9J.js.map +0 -1
  231. package/dist/esm/chunks/simpleSelect.B1rktKkt.js +0 -23
  232. package/dist/esm/chunks/status-badge.eFJ1PYeb.js +0 -18
  233. package/dist/esm/chunks/trend-value.COSukPwk.js +0 -51
  234. package/dist/esm/chunks/two-level-combobox.BXs2z9u5.js +0 -132
  235. package/dist/esm/chunks/useChartDateFormatters.DS9ASgFO.js +0 -11
  236. package/dist/esm/chunks/utils.Cwtlq8dh.js +0 -45
@@ -1,952 +0,0 @@
1
- /**
2
- * @module constants
3
- * @summary Useful constants
4
- * @description
5
- * Collection of useful date constants.
6
- *
7
- * The constants could be imported from `date-fns/constants`:
8
- *
9
- * ```ts
10
- * import { maxTime, minTime } from "./constants/date-fns/constants";
11
- *
12
- * function isAllowedTime(time) {
13
- * return time <= maxTime && time >= minTime;
14
- * }
15
- * ```
16
- */
17
-
18
-
19
- /**
20
- * @constant
21
- * @name daysInYear
22
- * @summary Days in 1 year.
23
- *
24
- * @description
25
- * How many days in a year.
26
- *
27
- * One years equals 365.2425 days according to the formula:
28
- *
29
- * > Leap year occurs every 4 years, except for years that are divisible by 100 and not divisible by 400.
30
- * > 1 mean year = (365+1/4-1/100+1/400) days = 365.2425 days
31
- */
32
- const daysInYear = 365.2425;
33
-
34
- /**
35
- * @constant
36
- * @name millisecondsInWeek
37
- * @summary Milliseconds in 1 week.
38
- */
39
- const millisecondsInWeek = 604800000;
40
-
41
- /**
42
- * @constant
43
- * @name millisecondsInDay
44
- * @summary Milliseconds in 1 day.
45
- */
46
- const millisecondsInDay = 86400000;
47
-
48
- /**
49
- * @constant
50
- * @name millisecondsInMinute
51
- * @summary Milliseconds in 1 minute
52
- */
53
- const millisecondsInMinute = 60000;
54
-
55
- /**
56
- * @constant
57
- * @name millisecondsInHour
58
- * @summary Milliseconds in 1 hour
59
- */
60
- const millisecondsInHour = 3600000;
61
-
62
- /**
63
- * @constant
64
- * @name secondsInHour
65
- * @summary Seconds in 1 hour.
66
- */
67
- const secondsInHour = 3600;
68
-
69
- /**
70
- * @constant
71
- * @name secondsInMinute
72
- * @summary Seconds in 1 minute.
73
- */
74
- const secondsInMinute = 60;
75
-
76
- /**
77
- * @constant
78
- * @name secondsInDay
79
- * @summary Seconds in 1 day.
80
- */
81
- const secondsInDay = secondsInHour * 24;
82
-
83
- /**
84
- * @constant
85
- * @name secondsInWeek
86
- * @summary Seconds in 1 week.
87
- */
88
- const secondsInWeek = secondsInDay * 7;
89
-
90
- /**
91
- * @constant
92
- * @name secondsInYear
93
- * @summary Seconds in 1 year.
94
- */
95
- const secondsInYear = secondsInDay * daysInYear;
96
-
97
- /**
98
- * @constant
99
- * @name secondsInMonth
100
- * @summary Seconds in 1 month
101
- */
102
- const secondsInMonth = secondsInYear / 12;
103
-
104
- /**
105
- * @constant
106
- * @name secondsInQuarter
107
- * @summary Seconds in 1 quarter.
108
- */
109
- const secondsInQuarter = secondsInMonth * 3;
110
-
111
- /**
112
- * @constant
113
- * @name constructFromSymbol
114
- * @summary Symbol enabling Date extensions to inherit properties from the reference date.
115
- *
116
- * The symbol is used to enable the `constructFrom` function to construct a date
117
- * using a reference date and a value. It allows to transfer extra properties
118
- * from the reference date to the new date. It's useful for extensions like
119
- * [`TZDate`](https://github.com/date-fns/tz) that accept a time zone as
120
- * a constructor argument.
121
- */
122
- const constructFromSymbol = Symbol.for("constructDateFrom");
123
-
124
- /**
125
- * @name constructFrom
126
- * @category Generic Helpers
127
- * @summary Constructs a date using the reference date and the value
128
- *
129
- * @description
130
- * The function constructs a new date using the constructor from the reference
131
- * date and the given value. It helps to build generic functions that accept
132
- * date extensions.
133
- *
134
- * It defaults to `Date` if the passed reference date is a number or a string.
135
- *
136
- * Starting from v3.7.0, it allows to construct a date using `[Symbol.for("constructDateFrom")]`
137
- * enabling to transfer extra properties from the reference date to the new date.
138
- * It's useful for extensions like [`TZDate`](https://github.com/date-fns/tz)
139
- * that accept a time zone as a constructor argument.
140
- *
141
- * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
142
- *
143
- * @param date - The reference date to take constructor from
144
- * @param value - The value to create the date
145
- *
146
- * @returns Date initialized using the given date and value
147
- *
148
- * @example
149
- * import { constructFrom } from "./constructFrom/date-fns";
150
- *
151
- * // A function that clones a date preserving the original type
152
- * function cloneDate<DateType extends Date>(date: DateType): DateType {
153
- * return constructFrom(
154
- * date, // Use constructor from the given date
155
- * date.getTime() // Use the date value to create a new date
156
- * );
157
- * }
158
- */
159
- function constructFrom(date, value) {
160
- if (typeof date === "function") return date(value);
161
-
162
- if (date && typeof date === "object" && constructFromSymbol in date)
163
- return date[constructFromSymbol](value);
164
-
165
- if (date instanceof Date) return new date.constructor(value);
166
-
167
- return new Date(value);
168
- }
169
-
170
- function normalizeDates(context, ...dates) {
171
- const normalize = constructFrom.bind(
172
- null,
173
- context || dates.find((date) => typeof date === "object"),
174
- );
175
- return dates.map(normalize);
176
- }
177
-
178
- /**
179
- * @name toDate
180
- * @category Common Helpers
181
- * @summary Convert the given argument to an instance of Date.
182
- *
183
- * @description
184
- * Convert the given argument to an instance of Date.
185
- *
186
- * If the argument is an instance of Date, the function returns its clone.
187
- *
188
- * If the argument is a number, it is treated as a timestamp.
189
- *
190
- * If the argument is none of the above, the function returns Invalid Date.
191
- *
192
- * Starting from v3.7.0, it clones a date using `[Symbol.for("constructDateFrom")]`
193
- * enabling to transfer extra properties from the reference date to the new date.
194
- * It's useful for extensions like [`TZDate`](https://github.com/date-fns/tz)
195
- * that accept a time zone as a constructor argument.
196
- *
197
- * **Note**: *all* Date arguments passed to any *date-fns* function is processed by `toDate`.
198
- *
199
- * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
200
- * @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
201
- *
202
- * @param argument - The value to convert
203
- *
204
- * @returns The parsed date in the local time zone
205
- *
206
- * @example
207
- * // Clone the date:
208
- * const result = toDate(new Date(2014, 1, 11, 11, 30, 30))
209
- * //=> Tue Feb 11 2014 11:30:30
210
- *
211
- * @example
212
- * // Convert the timestamp to date:
213
- * const result = toDate(1392098430000)
214
- * //=> Tue Feb 11 2014 11:30:30
215
- */
216
- function toDate(argument, context) {
217
- // [TODO] Get rid of `toDate` or `constructFrom`?
218
- return constructFrom(argument, argument);
219
- }
220
-
221
- /**
222
- * Google Chrome as of 67.0.3396.87 introduced timezones with offset that includes seconds.
223
- * They usually appear for dates that denote time before the timezones were introduced
224
- * (e.g. for 'Europe/Prague' timezone the offset is GMT+00:57:44 before 1 October 1891
225
- * and GMT+01:00:00 after that date)
226
- *
227
- * Date#getTimezoneOffset returns the offset in minutes and would return 57 for the example above,
228
- * which would lead to incorrect calculations.
229
- *
230
- * This function returns the timezone offset in milliseconds that takes seconds in account.
231
- */
232
- function getTimezoneOffsetInMilliseconds(date) {
233
- const _date = toDate(date);
234
- const utcDate = new Date(
235
- Date.UTC(
236
- _date.getFullYear(),
237
- _date.getMonth(),
238
- _date.getDate(),
239
- _date.getHours(),
240
- _date.getMinutes(),
241
- _date.getSeconds(),
242
- _date.getMilliseconds(),
243
- ),
244
- );
245
- utcDate.setUTCFullYear(_date.getFullYear());
246
- return +date - +utcDate;
247
- }
248
-
249
- /**
250
- * The {@link startOfDay} function options.
251
- */
252
-
253
- /**
254
- * @name startOfDay
255
- * @category Day Helpers
256
- * @summary Return the start of a day for the given date.
257
- *
258
- * @description
259
- * Return the start of a day for the given date.
260
- * The result will be in the local timezone.
261
- *
262
- * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
263
- * @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
264
- *
265
- * @param date - The original date
266
- * @param options - The options
267
- *
268
- * @returns The start of a day
269
- *
270
- * @example
271
- * // The start of a day for 2 September 2014 11:55:00:
272
- * const result = startOfDay(new Date(2014, 8, 2, 11, 55, 0))
273
- * //=> Tue Sep 02 2014 00:00:00
274
- */
275
- function startOfDay(date, options) {
276
- const _date = toDate(date);
277
- _date.setHours(0, 0, 0, 0);
278
- return _date;
279
- }
280
-
281
- /**
282
- * The {@link differenceInCalendarDays} function options.
283
- */
284
-
285
- /**
286
- * @name differenceInCalendarDays
287
- * @category Day Helpers
288
- * @summary Get the number of calendar days between the given dates.
289
- *
290
- * @description
291
- * Get the number of calendar days between the given dates. This means that the times are removed
292
- * from the dates and then the difference in days is calculated.
293
- *
294
- * @param laterDate - The later date
295
- * @param earlierDate - The earlier date
296
- * @param options - The options object
297
- *
298
- * @returns The number of calendar days
299
- *
300
- * @example
301
- * // How many calendar days are between
302
- * // 2 July 2011 23:00:00 and 2 July 2012 00:00:00?
303
- * const result = differenceInCalendarDays(
304
- * new Date(2012, 6, 2, 0, 0),
305
- * new Date(2011, 6, 2, 23, 0)
306
- * )
307
- * //=> 366
308
- * // How many calendar days are between
309
- * // 2 July 2011 23:59:00 and 3 July 2011 00:01:00?
310
- * const result = differenceInCalendarDays(
311
- * new Date(2011, 6, 3, 0, 1),
312
- * new Date(2011, 6, 2, 23, 59)
313
- * )
314
- * //=> 1
315
- */
316
- function differenceInCalendarDays(laterDate, earlierDate, options) {
317
- const [laterDate_, earlierDate_] = normalizeDates(
318
- options?.in,
319
- laterDate,
320
- earlierDate,
321
- );
322
-
323
- const laterStartOfDay = startOfDay(laterDate_);
324
- const earlierStartOfDay = startOfDay(earlierDate_);
325
-
326
- const laterTimestamp =
327
- +laterStartOfDay - getTimezoneOffsetInMilliseconds(laterStartOfDay);
328
- const earlierTimestamp =
329
- +earlierStartOfDay - getTimezoneOffsetInMilliseconds(earlierStartOfDay);
330
-
331
- // Round the number of days to the nearest integer because the number of
332
- // milliseconds in a day is not constant (e.g. it's different in the week of
333
- // the daylight saving time clock shift).
334
- return Math.round((laterTimestamp - earlierTimestamp) / millisecondsInDay);
335
- }
336
-
337
- /**
338
- * The {@link differenceInCalendarMonths} function options.
339
- */
340
-
341
- /**
342
- * @name differenceInCalendarMonths
343
- * @category Month Helpers
344
- * @summary Get the number of calendar months between the given dates.
345
- *
346
- * @description
347
- * Get the number of calendar months between the given dates.
348
- *
349
- * @param laterDate - The later date
350
- * @param earlierDate - The earlier date
351
- * @param options - An object with options
352
- *
353
- * @returns The number of calendar months
354
- *
355
- * @example
356
- * // How many calendar months are between 31 January 2014 and 1 September 2014?
357
- * const result = differenceInCalendarMonths(
358
- * new Date(2014, 8, 1),
359
- * new Date(2014, 0, 31)
360
- * )
361
- * //=> 8
362
- */
363
- function differenceInCalendarMonths(laterDate, earlierDate, options) {
364
- const [laterDate_, earlierDate_] = normalizeDates(
365
- options?.in,
366
- laterDate,
367
- earlierDate,
368
- );
369
-
370
- const yearsDiff = laterDate_.getFullYear() - earlierDate_.getFullYear();
371
- const monthsDiff = laterDate_.getMonth() - earlierDate_.getMonth();
372
-
373
- return yearsDiff * 12 + monthsDiff;
374
- }
375
-
376
- /**
377
- * The {@link getQuarter} function options.
378
- */
379
-
380
- /**
381
- * @name getQuarter
382
- * @category Quarter Helpers
383
- * @summary Get the year quarter of the given date.
384
- *
385
- * @description
386
- * Get the year quarter of the given date.
387
- *
388
- * @param date - The given date
389
- * @param options - An object with options
390
- *
391
- * @returns The quarter
392
- *
393
- * @example
394
- * // Which quarter is 2 July 2014?
395
- * const result = getQuarter(new Date(2014, 6, 2));
396
- * //=> 3
397
- */
398
- function getQuarter(date, options) {
399
- const _date = toDate(date);
400
- const quarter = Math.trunc(_date.getMonth() / 3) + 1;
401
- return quarter;
402
- }
403
-
404
- /**
405
- * The {@link differenceInCalendarQuarters} function options.
406
- */
407
-
408
- /**
409
- * @name differenceInCalendarQuarters
410
- * @category Quarter Helpers
411
- * @summary Get the number of calendar quarters between the given dates.
412
- *
413
- * @description
414
- * Get the number of calendar quarters between the given dates.
415
- *
416
- * @param laterDate - The later date
417
- * @param earlierDate - The earlier date
418
- * @param options - An object with options
419
- *
420
- * @returns The number of calendar quarters
421
- *
422
- * @example
423
- * // How many calendar quarters are between 31 December 2013 and 2 July 2014?
424
- * const result = differenceInCalendarQuarters(
425
- * new Date(2014, 6, 2),
426
- * new Date(2013, 11, 31)
427
- * )
428
- * //=> 3
429
- */
430
- function differenceInCalendarQuarters(laterDate, earlierDate, options) {
431
- const [laterDate_, earlierDate_] = normalizeDates(
432
- options?.in,
433
- laterDate,
434
- earlierDate,
435
- );
436
-
437
- const yearsDiff = laterDate_.getFullYear() - earlierDate_.getFullYear();
438
- const quartersDiff = getQuarter(laterDate_) - getQuarter(earlierDate_);
439
-
440
- return yearsDiff * 4 + quartersDiff;
441
- }
442
-
443
- let defaultOptions = {};
444
-
445
- function getDefaultOptions() {
446
- return defaultOptions;
447
- }
448
-
449
- /**
450
- * The {@link startOfWeek} function options.
451
- */
452
-
453
- /**
454
- * @name startOfWeek
455
- * @category Week Helpers
456
- * @summary Return the start of a week for the given date.
457
- *
458
- * @description
459
- * Return the start of a week for the given date.
460
- * The result will be in the local timezone.
461
- *
462
- * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
463
- * @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
464
- *
465
- * @param date - The original date
466
- * @param options - An object with options
467
- *
468
- * @returns The start of a week
469
- *
470
- * @example
471
- * // The start of a week for 2 September 2014 11:55:00:
472
- * const result = startOfWeek(new Date(2014, 8, 2, 11, 55, 0))
473
- * //=> Sun Aug 31 2014 00:00:00
474
- *
475
- * @example
476
- * // If the week starts on Monday, the start of the week for 2 September 2014 11:55:00:
477
- * const result = startOfWeek(new Date(2014, 8, 2, 11, 55, 0), { weekStartsOn: 1 })
478
- * //=> Mon Sep 01 2014 00:00:00
479
- */
480
- function startOfWeek(date, options) {
481
- const defaultOptions = getDefaultOptions();
482
- const weekStartsOn =
483
- defaultOptions.weekStartsOn ??
484
- defaultOptions.locale?.options?.weekStartsOn ??
485
- 0;
486
-
487
- const _date = toDate(date);
488
- const day = _date.getDay();
489
- const diff = (day < weekStartsOn ? 7 : 0) + day - weekStartsOn;
490
-
491
- _date.setDate(_date.getDate() - diff);
492
- _date.setHours(0, 0, 0, 0);
493
- return _date;
494
- }
495
-
496
- /**
497
- * The {@link differenceInCalendarWeeks} function options.
498
- */
499
-
500
- /**
501
- * @name differenceInCalendarWeeks
502
- * @category Week Helpers
503
- * @summary Get the number of calendar weeks between the given dates.
504
- *
505
- * @description
506
- * Get the number of calendar weeks between the given dates.
507
- *
508
- * @param laterDate - The later date
509
- * @param earlierDate - The earlier date
510
- * @param options - An object with options.
511
- *
512
- * @returns The number of calendar weeks
513
- *
514
- * @example
515
- * // How many calendar weeks are between 5 July 2014 and 20 July 2014?
516
- * const result = differenceInCalendarWeeks(
517
- * new Date(2014, 6, 20),
518
- * new Date(2014, 6, 5)
519
- * )
520
- * //=> 3
521
- *
522
- * @example
523
- * // If the week starts on Monday,
524
- * // how many calendar weeks are between 5 July 2014 and 20 July 2014?
525
- * const result = differenceInCalendarWeeks(
526
- * new Date(2014, 6, 20),
527
- * new Date(2014, 6, 5),
528
- * { weekStartsOn: 1 }
529
- * )
530
- * //=> 2
531
- */
532
- function differenceInCalendarWeeks(laterDate, earlierDate, options) {
533
- const [laterDate_, earlierDate_] = normalizeDates(
534
- options?.in,
535
- laterDate,
536
- earlierDate,
537
- );
538
-
539
- const laterStartOfWeek = startOfWeek(laterDate_);
540
- const earlierStartOfWeek = startOfWeek(earlierDate_);
541
-
542
- const laterTimestamp =
543
- +laterStartOfWeek - getTimezoneOffsetInMilliseconds(laterStartOfWeek);
544
- const earlierTimestamp =
545
- +earlierStartOfWeek - getTimezoneOffsetInMilliseconds(earlierStartOfWeek);
546
-
547
- return Math.round((laterTimestamp - earlierTimestamp) / millisecondsInWeek);
548
- }
549
-
550
- /**
551
- * The {@link differenceInCalendarYears} function options.
552
- */
553
-
554
- /**
555
- * @name differenceInCalendarYears
556
- * @category Year Helpers
557
- * @summary Get the number of calendar years between the given dates.
558
- *
559
- * @description
560
- * Get the number of calendar years between the given dates.
561
- *
562
- * @param laterDate - The later date
563
- * @param earlierDate - The earlier date
564
- * @param options - An object with options
565
-
566
- * @returns The number of calendar years
567
- *
568
- * @example
569
- * // How many calendar years are between 31 December 2013 and 11 February 2015?
570
- * const result = differenceInCalendarYears(
571
- * new Date(2015, 1, 11),
572
- * new Date(2013, 11, 31)
573
- * );
574
- * //=> 2
575
- */
576
- function differenceInCalendarYears(laterDate, earlierDate, options) {
577
- const [laterDate_, earlierDate_] = normalizeDates(
578
- options?.in,
579
- laterDate,
580
- earlierDate,
581
- );
582
- return laterDate_.getFullYear() - earlierDate_.getFullYear();
583
- }
584
-
585
- function getRoundingMethod(method) {
586
- return (number) => {
587
- const round = method ? Math[method] : Math.trunc;
588
- const result = round(number);
589
- // Prevent negative zero
590
- return result === 0 ? 0 : result;
591
- };
592
- }
593
-
594
- /**
595
- * The {@link differenceInHours} function options.
596
- */
597
-
598
- /**
599
- * @name differenceInHours
600
- * @category Hour Helpers
601
- * @summary Get the number of hours between the given dates.
602
- *
603
- * @description
604
- * Get the number of hours between the given dates.
605
- *
606
- * @param laterDate - The later date
607
- * @param earlierDate - The earlier date
608
- * @param options - An object with options.
609
- *
610
- * @returns The number of hours
611
- *
612
- * @example
613
- * // How many hours are between 2 July 2014 06:50:00 and 2 July 2014 19:00:00?
614
- * const result = differenceInHours(
615
- * new Date(2014, 6, 2, 19, 0),
616
- * new Date(2014, 6, 2, 6, 50)
617
- * )
618
- * //=> 12
619
- */
620
- function differenceInHours(laterDate, earlierDate, options) {
621
- const [laterDate_, earlierDate_] = normalizeDates(
622
- options?.in,
623
- laterDate,
624
- earlierDate,
625
- );
626
- const diff = (+laterDate_ - +earlierDate_) / millisecondsInHour;
627
- return getRoundingMethod(options?.roundingMethod)(diff);
628
- }
629
-
630
- /**
631
- * @name differenceInMilliseconds
632
- * @category Millisecond Helpers
633
- * @summary Get the number of milliseconds between the given dates.
634
- *
635
- * @description
636
- * Get the number of milliseconds between the given dates.
637
- *
638
- * @param laterDate - The later date
639
- * @param earlierDate - The earlier date
640
- *
641
- * @returns The number of milliseconds
642
- *
643
- * @example
644
- * // How many milliseconds are between
645
- * // 2 July 2014 12:30:20.600 and 2 July 2014 12:30:21.700?
646
- * const result = differenceInMilliseconds(
647
- * new Date(2014, 6, 2, 12, 30, 21, 700),
648
- * new Date(2014, 6, 2, 12, 30, 20, 600)
649
- * )
650
- * //=> 1100
651
- */
652
- function differenceInMilliseconds(laterDate, earlierDate) {
653
- return +toDate(laterDate) - +toDate(earlierDate);
654
- }
655
-
656
- /**
657
- * The {@link differenceInMinutes} function options.
658
- */
659
-
660
- /**
661
- * @name differenceInMinutes
662
- * @category Minute Helpers
663
- * @summary Get the number of minutes between the given dates.
664
- *
665
- * @description
666
- * Get the signed number of full (rounded towards 0) minutes between the given dates.
667
- *
668
- * @param dateLeft - The later date
669
- * @param dateRight - The earlier date
670
- * @param options - An object with options.
671
- *
672
- * @returns The number of minutes
673
- *
674
- * @example
675
- * // How many minutes are between 2 July 2014 12:07:59 and 2 July 2014 12:20:00?
676
- * const result = differenceInMinutes(
677
- * new Date(2014, 6, 2, 12, 20, 0),
678
- * new Date(2014, 6, 2, 12, 7, 59)
679
- * )
680
- * //=> 12
681
- *
682
- * @example
683
- * // How many minutes are between 10:01:59 and 10:00:00
684
- * const result = differenceInMinutes(
685
- * new Date(2000, 0, 1, 10, 0, 0),
686
- * new Date(2000, 0, 1, 10, 1, 59)
687
- * )
688
- * //=> -1
689
- */
690
- function differenceInMinutes(dateLeft, dateRight, options) {
691
- const diff =
692
- differenceInMilliseconds(dateLeft, dateRight) / millisecondsInMinute;
693
- return getRoundingMethod(options?.roundingMethod)(diff);
694
- }
695
-
696
- /**
697
- * The {@link differenceInSeconds} function options.
698
- */
699
-
700
- /**
701
- * @name differenceInSeconds
702
- * @category Second Helpers
703
- * @summary Get the number of seconds between the given dates.
704
- *
705
- * @description
706
- * Get the number of seconds between the given dates.
707
- *
708
- * @param laterDate - The later date
709
- * @param earlierDate - The earlier date
710
- * @param options - An object with options.
711
- *
712
- * @returns The number of seconds
713
- *
714
- * @example
715
- * // How many seconds are between
716
- * // 2 July 2014 12:30:07.999 and 2 July 2014 12:30:20.000?
717
- * const result = differenceInSeconds(
718
- * new Date(2014, 6, 2, 12, 30, 20, 0),
719
- * new Date(2014, 6, 2, 12, 30, 7, 999)
720
- * )
721
- * //=> 12
722
- */
723
- function differenceInSeconds(laterDate, earlierDate, options) {
724
- const diff = differenceInMilliseconds(laterDate, earlierDate) / 1000;
725
- return getRoundingMethod(options?.roundingMethod)(diff);
726
- }
727
-
728
- /**
729
- * The {@link intlFormatDistance} function options.
730
- */
731
-
732
- /**
733
- * The unit used to format the distance in {@link intlFormatDistance}.
734
- */
735
-
736
- /**
737
- * @name intlFormatDistance
738
- * @category Common Helpers
739
- * @summary Formats distance between two dates in a human-readable format
740
- * @description
741
- * The function calculates the difference between two dates and formats it as a human-readable string.
742
- *
743
- * The function will pick the most appropriate unit depending on the distance between dates. For example, if the distance is a few hours, it might return `x hours`. If the distance is a few months, it might return `x months`.
744
- *
745
- * You can also specify a unit to force using it regardless of the distance to get a result like `123456 hours`.
746
- *
747
- * See the table below for the unit picking logic:
748
- *
749
- * | Distance between dates | Result (past) | Result (future) |
750
- * | ---------------------- | -------------- | --------------- |
751
- * | 0 seconds | now | now |
752
- * | 1-59 seconds | X seconds ago | in X seconds |
753
- * | 1-59 minutes | X minutes ago | in X minutes |
754
- * | 1-23 hours | X hours ago | in X hours |
755
- * | 1 day | yesterday | tomorrow |
756
- * | 2-6 days | X days ago | in X days |
757
- * | 7 days | last week | next week |
758
- * | 8 days-1 month | X weeks ago | in X weeks |
759
- * | 1 month | last month | next month |
760
- * | 2-3 months | X months ago | in X months |
761
- * | 1 quarter | last quarter | next quarter |
762
- * | 2-3 quarters | X quarters ago | in X quarters |
763
- * | 1 year | last year | next year |
764
- * | 2+ years | X years ago | in X years |
765
- *
766
- * @param laterDate - The date
767
- * @param earlierDate - The date to compare with.
768
- * @param options - An object with options.
769
- * See MDN for details [Locale identification and negotiation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#locale_identification_and_negotiation)
770
- * The narrow one could be similar to the short one for some locales.
771
- *
772
- * @returns The distance in words according to language-sensitive relative time formatting.
773
- *
774
- * @throws `date` must not be Invalid Date
775
- * @throws `baseDate` must not be Invalid Date
776
- * @throws `options.unit` must not be invalid Unit
777
- * @throws `options.locale` must not be invalid locale
778
- * @throws `options.localeMatcher` must not be invalid localeMatcher
779
- * @throws `options.numeric` must not be invalid numeric
780
- * @throws `options.style` must not be invalid style
781
- *
782
- * @example
783
- * // What is the distance between the dates when the fist date is after the second?
784
- * intlFormatDistance(
785
- * new Date(1986, 3, 4, 11, 30, 0),
786
- * new Date(1986, 3, 4, 10, 30, 0)
787
- * )
788
- * //=> 'in 1 hour'
789
- *
790
- * // What is the distance between the dates when the fist date is before the second?
791
- * intlFormatDistance(
792
- * new Date(1986, 3, 4, 10, 30, 0),
793
- * new Date(1986, 3, 4, 11, 30, 0)
794
- * )
795
- * //=> '1 hour ago'
796
- *
797
- * @example
798
- * // Use the unit option to force the function to output the result in quarters. Without setting it, the example would return "next year"
799
- * intlFormatDistance(
800
- * new Date(1987, 6, 4, 10, 30, 0),
801
- * new Date(1986, 3, 4, 10, 30, 0),
802
- * { unit: 'quarter' }
803
- * )
804
- * //=> 'in 5 quarters'
805
- *
806
- * @example
807
- * // Use the locale option to get the result in Spanish. Without setting it, the example would return "in 1 hour".
808
- * intlFormatDistance(
809
- * new Date(1986, 3, 4, 11, 30, 0),
810
- * new Date(1986, 3, 4, 10, 30, 0),
811
- * { locale: 'es' }
812
- * )
813
- * //=> 'dentro de 1 hora'
814
- *
815
- * @example
816
- * // Use the numeric option to force the function to use numeric values. Without setting it, the example would return "tomorrow".
817
- * intlFormatDistance(
818
- * new Date(1986, 3, 5, 11, 30, 0),
819
- * new Date(1986, 3, 4, 11, 30, 0),
820
- * { numeric: 'always' }
821
- * )
822
- * //=> 'in 1 day'
823
- *
824
- * @example
825
- * // Use the style option to force the function to use short values. Without setting it, the example would return "in 2 years".
826
- * intlFormatDistance(
827
- * new Date(1988, 3, 4, 11, 30, 0),
828
- * new Date(1986, 3, 4, 11, 30, 0),
829
- * { style: 'short' }
830
- * )
831
- * //=> 'in 2 yr'
832
- */
833
- function intlFormatDistance(laterDate, earlierDate, options) {
834
- let value = 0;
835
- let unit;
836
-
837
- const [laterDate_, earlierDate_] = normalizeDates(
838
- options?.in,
839
- laterDate,
840
- earlierDate,
841
- );
842
-
843
- if (!options?.unit) {
844
- // Get the unit based on diffInSeconds calculations if no unit is specified
845
- const diffInSeconds = differenceInSeconds(laterDate_, earlierDate_); // The smallest unit
846
-
847
- if (Math.abs(diffInSeconds) < secondsInMinute) {
848
- value = differenceInSeconds(laterDate_, earlierDate_);
849
- unit = "second";
850
- } else if (Math.abs(diffInSeconds) < secondsInHour) {
851
- value = differenceInMinutes(laterDate_, earlierDate_);
852
- unit = "minute";
853
- } else if (
854
- Math.abs(diffInSeconds) < secondsInDay &&
855
- Math.abs(differenceInCalendarDays(laterDate_, earlierDate_)) < 1
856
- ) {
857
- value = differenceInHours(laterDate_, earlierDate_);
858
- unit = "hour";
859
- } else if (
860
- Math.abs(diffInSeconds) < secondsInWeek &&
861
- (value = differenceInCalendarDays(laterDate_, earlierDate_)) &&
862
- Math.abs(value) < 7
863
- ) {
864
- unit = "day";
865
- } else if (Math.abs(diffInSeconds) < secondsInMonth) {
866
- value = differenceInCalendarWeeks(laterDate_, earlierDate_);
867
- unit = "week";
868
- } else if (Math.abs(diffInSeconds) < secondsInQuarter) {
869
- value = differenceInCalendarMonths(laterDate_, earlierDate_);
870
- unit = "month";
871
- } else if (Math.abs(diffInSeconds) < secondsInYear) {
872
- if (differenceInCalendarQuarters(laterDate_, earlierDate_) < 4) {
873
- // To filter out cases that are less than a year but match 4 quarters
874
- value = differenceInCalendarQuarters(laterDate_, earlierDate_);
875
- unit = "quarter";
876
- } else {
877
- value = differenceInCalendarYears(laterDate_, earlierDate_);
878
- unit = "year";
879
- }
880
- } else {
881
- value = differenceInCalendarYears(laterDate_, earlierDate_);
882
- unit = "year";
883
- }
884
- } else {
885
- // Get the value if unit is specified
886
- unit = options?.unit;
887
- if (unit === "second") {
888
- value = differenceInSeconds(laterDate_, earlierDate_);
889
- } else if (unit === "minute") {
890
- value = differenceInMinutes(laterDate_, earlierDate_);
891
- } else if (unit === "hour") {
892
- value = differenceInHours(laterDate_, earlierDate_);
893
- } else if (unit === "day") {
894
- value = differenceInCalendarDays(laterDate_, earlierDate_);
895
- } else if (unit === "week") {
896
- value = differenceInCalendarWeeks(laterDate_, earlierDate_);
897
- } else if (unit === "month") {
898
- value = differenceInCalendarMonths(laterDate_, earlierDate_);
899
- } else if (unit === "quarter") {
900
- value = differenceInCalendarQuarters(laterDate_, earlierDate_);
901
- } else if (unit === "year") {
902
- value = differenceInCalendarYears(laterDate_, earlierDate_);
903
- }
904
- }
905
-
906
- const rtf = new Intl.RelativeTimeFormat(options?.locale, {
907
- numeric: "auto",
908
- ...options,
909
- });
910
-
911
- return rtf.format(value, unit);
912
- }
913
-
914
- function getLocale(locale) {
915
- const defaultLocale = "en-US";
916
- if (!locale) {
917
- if (typeof navigator !== "undefined") {
918
- locale = navigator.language;
919
- } else {
920
- locale = defaultLocale;
921
- }
922
- }
923
- return locale;
924
- }
925
- function formatDistance(timestamp, localeParam) {
926
- const locale = getLocale(localeParam);
927
- return intlFormatDistance(timestamp, /* @__PURE__ */ new Date(), { locale, style: "short" });
928
- }
929
- function formatDate(date, localeParam) {
930
- const locale = getLocale(localeParam);
931
- return date.toLocaleDateString(locale, {
932
- month: "short",
933
- day: "numeric",
934
- year: "numeric",
935
- hour: "numeric",
936
- minute: "2-digit",
937
- hour12: true
938
- });
939
- }
940
- function formatChartTick(value, locale = "en-US") {
941
- if (typeof value === "string") return value;
942
- if (!(value instanceof Date)) return "";
943
- return value.toLocaleDateString(locale, { month: "short", day: "numeric" });
944
- }
945
- function formatChartLabel(value, locale = "en-US") {
946
- if (typeof value === "string") return value;
947
- if (!(value instanceof Date)) return "";
948
- return value.toLocaleDateString(locale, { month: "long", day: "numeric", year: "numeric" });
949
- }
950
-
951
- export { formatChartLabel as a, formatDistance as b, formatDate as c, formatChartTick as f };
952
- //# sourceMappingURL=formatDate.CWN6IFKq.js.map