@react-fabric/date 1.0.0-beta.6 → 1.0.0-beta.60

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 (110) hide show
  1. package/README.md +2 -9
  2. package/{src/components/Date.module.css → css/_date.css} +5 -5
  3. package/{src/superdate/SuperDate.module.css → css/styles.css} +2 -8
  4. package/dist/cjs/components/DateHeader.js +16 -8
  5. package/dist/cjs/components/DatePage.js +2 -3
  6. package/dist/cjs/components/TimeSliders.js +5 -6
  7. package/dist/cjs/display/DateDisplay.js +24 -2
  8. package/dist/cjs/display/DateDuration.js +143 -0
  9. package/dist/cjs/hijri/DateConverter.js +154 -0
  10. package/dist/cjs/hijri/FormatDate.js +116 -0
  11. package/dist/cjs/hijri/HijriDate.js +531 -0
  12. package/dist/cjs/hijri/StringDateParser.js +74 -0
  13. package/dist/cjs/hijri/index.js +17 -1025
  14. package/dist/cjs/hijri/initializer.js +113 -0
  15. package/dist/cjs/hijri/locales.js +19 -0
  16. package/dist/cjs/hijri/safe.js +17 -0
  17. package/dist/cjs/i18n/ar.json.js +191 -3
  18. package/dist/cjs/i18n/en.json.js +63 -1
  19. package/dist/cjs/i18n/index.js +0 -6
  20. package/dist/cjs/index.js +13 -2
  21. package/dist/cjs/panels/DatePanel.js +26 -0
  22. package/dist/cjs/{superdate → panels}/EventPanel.js +2 -1
  23. package/dist/cjs/panels/RangePanel.js +23 -0
  24. package/dist/cjs/utils/dateUtil.js +1 -4
  25. package/dist/esm/components/DateHeader.js +16 -8
  26. package/dist/esm/components/DatePage.js +2 -3
  27. package/dist/esm/components/TimeSliders.js +5 -6
  28. package/dist/esm/display/DateDisplay.js +24 -2
  29. package/dist/esm/display/DateDuration.js +143 -0
  30. package/dist/esm/hijri/DateConverter.js +152 -0
  31. package/dist/esm/hijri/FormatDate.js +113 -0
  32. package/dist/esm/hijri/HijriDate.js +528 -0
  33. package/dist/esm/hijri/StringDateParser.js +74 -0
  34. package/dist/esm/hijri/index.js +17 -1025
  35. package/dist/esm/hijri/initializer.js +113 -0
  36. package/dist/esm/hijri/locales.js +18 -0
  37. package/dist/esm/hijri/safe.js +14 -0
  38. package/dist/esm/i18n/ar.json.js +191 -3
  39. package/dist/esm/i18n/en.json.js +63 -2
  40. package/dist/esm/i18n/index.js +0 -6
  41. package/dist/esm/index.js +6 -1
  42. package/dist/esm/panels/DatePanel.js +26 -0
  43. package/dist/esm/{superdate → panels}/EventPanel.js +2 -1
  44. package/dist/esm/panels/RangePanel.js +23 -0
  45. package/dist/esm/utils/dateUtil.js +1 -4
  46. package/dist/types/display/DateDisplay.d.ts +21 -3
  47. package/dist/types/display/DateDuration.d.ts +31 -0
  48. package/dist/types/hijri/DateConverter.d.ts +13 -0
  49. package/dist/types/hijri/FormatDate.d.ts +19 -0
  50. package/dist/types/hijri/HijriDate.d.ts +214 -0
  51. package/dist/types/hijri/StringDateParser.d.ts +11 -0
  52. package/dist/types/hijri/index.d.ts +2 -2
  53. package/dist/types/hijri/initializer.d.ts +129 -0
  54. package/dist/types/hijri/locales.d.ts +19 -0
  55. package/dist/types/hijri/safe.d.ts +3 -0
  56. package/dist/types/index.d.ts +6 -1
  57. package/dist/types/panels/DatePanel.d.ts +26 -0
  58. package/dist/types/panels/EventPanel.d.ts +17 -0
  59. package/dist/types/panels/RangePanel.d.ts +22 -0
  60. package/dist/types/types/index.d.ts +8 -40
  61. package/package.json +13 -16
  62. package/src/components/DateHeader.tsx +4 -8
  63. package/src/components/DatePage.tsx +2 -3
  64. package/src/components/TimeSliders.tsx +5 -6
  65. package/src/display/DateDisplay.tsx +32 -4
  66. package/src/display/DateDuration.tsx +180 -0
  67. package/src/hijri/DateConverter.js +175 -0
  68. package/src/hijri/FormatDate.js +134 -0
  69. package/src/hijri/HijriDate.js +477 -0
  70. package/src/hijri/StringDateParser.js +68 -0
  71. package/src/hijri/index.js +16 -1535
  72. package/src/hijri/initializer.js +96 -0
  73. package/src/hijri/locales.js +109 -0
  74. package/src/hijri/safe.js +16 -0
  75. package/src/i18n/ar.json +190 -1
  76. package/src/i18n/en.json +60 -0
  77. package/src/i18n/index.ts +0 -3
  78. package/src/index.ts +7 -1
  79. package/src/panels/DatePanel.tsx +26 -0
  80. package/src/{superdate → panels}/EventPanel.tsx +21 -3
  81. package/src/panels/RangePanel.tsx +23 -0
  82. package/src/types/index.ts +8 -43
  83. package/src/utils/dateUtil.ts +1 -5
  84. package/dist/cjs/components/Date.module.css +0 -1
  85. package/dist/cjs/i18n/superdate/ar.json.js +0 -86
  86. package/dist/cjs/i18n/superdate/en.json.js +0 -93
  87. package/dist/cjs/superdate/QuickSelect.js +0 -134
  88. package/dist/cjs/superdate/RelativeInput.js +0 -79
  89. package/dist/cjs/superdate/RelativePanel.js +0 -91
  90. package/dist/cjs/superdate/SuperDate.module.css +0 -1
  91. package/dist/cjs/superdate/Superdate.js +0 -177
  92. package/dist/esm/components/Date.module.css +0 -1
  93. package/dist/esm/i18n/superdate/ar.json.js +0 -79
  94. package/dist/esm/i18n/superdate/en.json.js +0 -85
  95. package/dist/esm/superdate/QuickSelect.js +0 -134
  96. package/dist/esm/superdate/RelativeInput.js +0 -79
  97. package/dist/esm/superdate/RelativePanel.js +0 -91
  98. package/dist/esm/superdate/SuperDate.module.css +0 -1
  99. package/dist/esm/superdate/Superdate.js +0 -176
  100. package/dist/types/superdate/EventPanel.d.ts +0 -4
  101. package/dist/types/superdate/QuickSelect.d.ts +0 -1
  102. package/dist/types/superdate/RelativeInput.d.ts +0 -1
  103. package/dist/types/superdate/RelativePanel.d.ts +0 -1
  104. package/dist/types/superdate/Superdate.d.ts +0 -17
  105. package/src/i18n/superdate/ar.json +0 -70
  106. package/src/i18n/superdate/en.json +0 -75
  107. package/src/superdate/QuickSelect.tsx +0 -121
  108. package/src/superdate/RelativeInput.tsx +0 -64
  109. package/src/superdate/RelativePanel.tsx +0 -103
  110. package/src/superdate/Superdate.tsx +0 -198
@@ -24,7 +24,6 @@
24
24
  import { useDebounce } from "@react-fabric/core";
25
25
  import classNames from "classnames";
26
26
  import { useCallback, useEffect, useRef, useState } from "react";
27
- import classes from "./Date.module.css";
28
27
 
29
28
  interface Props {
30
29
  hour: number;
@@ -80,7 +79,7 @@ export const TimeSlider = ({ hour = 0, minute = 0, onTimeChange }: Props) => {
80
79
  <div className="flex">
81
80
  <div
82
81
  className={classNames(
83
- classes.dateHeader,
82
+ "fabric-dateHeader",
84
83
  "flex-1 font-medium text-muted text-sm p-1 mx-px text-center bg-tint-50",
85
84
  )}
86
85
  >
@@ -88,18 +87,18 @@ export const TimeSlider = ({ hour = 0, minute = 0, onTimeChange }: Props) => {
88
87
  </div>
89
88
  <div
90
89
  className={classNames(
91
- classes.dateHeader,
90
+ "fabric-dateHeader",
92
91
  "flex-1 font-medium text-muted text-sm p-1 mx-px text-center bg-tint-50",
93
92
  )}
94
93
  >
95
94
  M
96
95
  </div>
97
96
  </div>
98
- <div className="flex flex-1 flex-nowrap overflow-hidden relative">
97
+ <div className="flex flex-1 flex-nowrap items-stretch overflow-hidden relative">
99
98
  <div
100
99
  className={classNames(
101
100
  "flex-1 overflow-auto scroll-hide snap-y snap-mandatory",
102
- classes.timeSlider,
101
+ "fabric-date-timeSlider",
103
102
  )}
104
103
  onScroll={calculateTime}
105
104
  ref={hourRef}
@@ -144,7 +143,7 @@ export const TimeSlider = ({ hour = 0, minute = 0, onTimeChange }: Props) => {
144
143
  <div
145
144
  className={classNames(
146
145
  "flex-1 overflow-auto scroll-hide snap-y snap-mandatory",
147
- classes.timeSlider,
146
+ "fabric-date-timeSlider",
148
147
  )}
149
148
  onScroll={calculateTime}
150
149
  ref={minuteRef}
@@ -22,7 +22,7 @@
22
22
  */
23
23
 
24
24
  import { Dropdown, Tooltip, useGlobals } from "@react-fabric/core";
25
- import { type MenuItemProps } from "@react-fabric/core/dist/types/components/menu/types";
25
+ import { type MenuProps } from "@react-fabric/core/dist/types/components/menu/types";
26
26
  import {
27
27
  type AriaProps,
28
28
  type ChildrenProp,
@@ -32,12 +32,13 @@ import {
32
32
  import { type ElementType } from "react";
33
33
  import { type DateLike } from "../types";
34
34
  import { DateUtil } from "../utils/dateUtil";
35
+ import classNames from "classnames";
35
36
 
36
37
  export interface Props
37
38
  extends CssProp,
38
39
  AriaProps,
39
40
  TestProps,
40
- Partial<ChildrenProp<ElementType<MenuItemProps>>> {
41
+ Partial<ChildrenProp<ElementType<MenuProps>>> {
41
42
  /**
42
43
  * date like value
43
44
  */
@@ -46,19 +47,40 @@ export interface Props
46
47
  * date format
47
48
  */
48
49
  format?: string;
50
+
51
+ showAlternateDate?: boolean;
49
52
  }
50
53
 
54
+ /**
55
+ * DateDisplay component to display a formatted gregorian or hijri date with optional tooltip and dropdown.
56
+ * It uses the current calendar and locale from the global context.
57
+ * It formats the date using the provided format or a default format.
58
+ * If `showAlternateDate` is true, it shows a tooltip with the formatted date.
59
+ * If `children` are provided, it wraps the date in a dropdown.
60
+ *
61
+ * @param {Object} props - The component props.
62
+ * @returns {JSX.Element} - The rendered component.
63
+ *
64
+ * @example
65
+ * ```jsx
66
+ * <DateDisplay date={new Date()} />
67
+ * ```
68
+ *
69
+ * @see {@link https://adarshpastakia.github.io/react-fabric/?path=/docs/date-date-display--docs}
70
+ */
51
71
  export const DateDisplay = ({
52
72
  date,
53
73
  className,
54
74
  format = "eee, PPpp",
55
75
  children,
76
+ showAlternateDate,
56
77
  ...aria
57
78
  }: Props) => {
58
79
  const { currentCalendar, currentLocale } = useGlobals();
59
80
 
60
81
  const dtLabel = (
61
82
  <Tooltip
83
+ disabled={!showAlternateDate}
62
84
  content={DateUtil.format(
63
85
  date,
64
86
  format,
@@ -66,7 +88,13 @@ export const DateDisplay = ({
66
88
  currentCalendar !== "hijri",
67
89
  )}
68
90
  >
69
- <span className={className} {...aria}>
91
+ <span
92
+ className={classNames(
93
+ className,
94
+ !!children && "underline decoration-dotted cursor-pointer",
95
+ )}
96
+ {...aria}
97
+ >
70
98
  {DateUtil.format(
71
99
  date,
72
100
  format,
@@ -78,7 +106,7 @@ export const DateDisplay = ({
78
106
  );
79
107
 
80
108
  return children ? (
81
- <Dropdown>
109
+ <Dropdown showArrow closeOnClick>
82
110
  {dtLabel}
83
111
  {children}
84
112
  </Dropdown>
@@ -0,0 +1,180 @@
1
+ /*
2
+ * React Fabric
3
+ * @version: 1.0.0
4
+ *
5
+ *
6
+ * The MIT License (MIT)
7
+ * Copyright (c) 2025 Adarsh Pastakia
8
+ *
9
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
10
+ * and associated documentation files (the "Software"), to deal in the Software without restriction,
11
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
12
+ * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
13
+ * subject to the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be included in all copies or substantial
16
+ * portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
19
+ * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ */
23
+
24
+ import { Dropdown, Tooltip } from "@react-fabric/core";
25
+ import { type MenuProps } from "@react-fabric/core/dist/types/components/menu/types";
26
+ import {
27
+ type AriaProps,
28
+ type ChildrenProp,
29
+ type CssProp,
30
+ type TestProps,
31
+ } from "@react-fabric/core/dist/types/types";
32
+ import { Format } from "@react-fabric/utilities";
33
+ import classNames from "classnames";
34
+ import { intervalToDuration, isBefore } from "date-fns";
35
+ import { useMemo, type ElementType } from "react";
36
+ import { useTranslation } from "react-i18next";
37
+ import { type DateLike } from "../types";
38
+ import { DateUtil } from "../utils/dateUtil";
39
+
40
+ export interface Props
41
+ extends CssProp,
42
+ AriaProps,
43
+ TestProps,
44
+ Partial<ChildrenProp<ElementType<MenuProps>>> {
45
+ /**
46
+ * date like value
47
+ */
48
+ date: DateLike;
49
+ /**
50
+ * date format
51
+ */
52
+ format?: string;
53
+ }
54
+
55
+ /**
56
+ * DateDuration component to display the duration from a given date to now.
57
+ * It calculates the difference in years, months, weeks, days, hours, minutes, and seconds,
58
+ * and displays it in a human-readable format.
59
+ * It uses the current locale for translations.
60
+ *
61
+ * @param {Props} props - The properties for the component.
62
+ * @returns {JSX.Element} The rendered component.
63
+ *
64
+ * @example
65
+ * ```jsx
66
+ * <DateDuration date={new Date("2020-01-01")} />
67
+ * ```
68
+ *
69
+ * @see {@link https://adarshpastakia.github.io/react-fabric/?path=/docs/date-date-display--docs}
70
+ */
71
+ export const DateDuration = ({
72
+ date,
73
+ children,
74
+ className,
75
+ format = "PPpp",
76
+ ...props
77
+ }: Props) => {
78
+ const { t } = useTranslation("date");
79
+
80
+ const interval = useMemo(() => {
81
+ return intervalToDuration({ start: new Date(date), end: new Date() });
82
+ }, [date]);
83
+
84
+ const label = useMemo(() => {
85
+ const before = isBefore(DateUtil.parseDate(date), new Date());
86
+ const tkey = before ? "relative.before" : "relative.after";
87
+ let part = "now";
88
+ let count = 0;
89
+ if (interval.years && interval.years > 0) {
90
+ part = "years";
91
+ count = interval.years;
92
+ if ((interval.months ?? 0) > 10) {
93
+ part = "yearsX";
94
+ count += 1;
95
+ }
96
+ } else if (interval.months && interval.months > 0) {
97
+ part = "months";
98
+ count = interval.months;
99
+ if (interval.months > 10) {
100
+ part = "yearsX";
101
+ count = 1;
102
+ } else if ((interval.weeks ?? 0) > 3) {
103
+ part = "monthsX";
104
+ count += 1;
105
+ }
106
+ } else if (interval.weeks && interval.weeks > 0) {
107
+ part = "weeks";
108
+ count = interval.weeks;
109
+ if (interval.weeks > 3) {
110
+ part = "monthsX";
111
+ count = 1;
112
+ } else if ((interval.days ?? 0) > 5) {
113
+ part = "weeksX";
114
+ count += 1;
115
+ }
116
+ } else if (interval.days && interval.days > 0) {
117
+ part = "days";
118
+ count = interval.days;
119
+ if (interval.days > 5) {
120
+ part = "weeksX";
121
+ count = 1;
122
+ } else if ((interval.hours ?? 0) > 20) {
123
+ part = "daysX";
124
+ count += 1;
125
+ }
126
+ } else if (interval.hours && interval.hours > 0) {
127
+ part = "hours";
128
+ count = interval.hours;
129
+ if (interval.hours > 20) {
130
+ part = "daysX";
131
+ count = 1;
132
+ } else if ((interval.minutes ?? 0) > 45) {
133
+ part = "hoursX";
134
+ count += 1;
135
+ }
136
+ } else if (interval.minutes && interval.minutes > 0) {
137
+ part = "minutes";
138
+ count = interval.minutes;
139
+ if (interval.minutes > 45) {
140
+ part = "hoursX";
141
+ count = 1;
142
+ } else if ((interval.seconds ?? 0) > 45) {
143
+ part = "minuteX";
144
+ count += 1;
145
+ }
146
+ } else if (interval.seconds && interval.seconds > 15) {
147
+ part = "seconds";
148
+ count = interval.seconds;
149
+ if (interval.seconds > 45) {
150
+ part = "minutesX";
151
+ count = 1;
152
+ }
153
+ }
154
+
155
+ return t(`${tkey}.${part}`, { count });
156
+ }, [interval, date]);
157
+
158
+ const dtLabel = (
159
+ <Tooltip content={Format.date(date, format)}>
160
+ <span
161
+ className={classNames(
162
+ className,
163
+ !!children && "underline decoration-dotted cursor-pointer",
164
+ )}
165
+ {...props}
166
+ >
167
+ {label}
168
+ </span>
169
+ </Tooltip>
170
+ );
171
+
172
+ return children ? (
173
+ <Dropdown showArrow closeOnClick>
174
+ {dtLabel}
175
+ {children}
176
+ </Dropdown>
177
+ ) : (
178
+ dtLabel
179
+ );
180
+ };
@@ -0,0 +1,175 @@
1
+ function intPart(floatNum) {
2
+ if (floatNum < -0.0000001) {
3
+ return Math.ceil(floatNum - 0.0000001)
4
+ }
5
+ return Math.floor(floatNum + 0.0000001)
6
+ }
7
+ var delta = 1
8
+
9
+ function GregToIsl(arg) {
10
+
11
+ let d = parseInt(arg.CDay.value)
12
+ let m = parseInt(arg.CMonth.value)
13
+ let y = parseInt(arg.CYear.value)
14
+ let jd, l, jd1, n, j, delta = 1;
15
+ if ((y > 1582) || ((y == 1582) && (m > 10)) || ((y == 1582) && (m == 10) && (d > 14))) {
16
+ //added delta=1 on jd to comply isna rulling 2007
17
+ jd = intPart((1461 * (y + 4800 + intPart((m - 14) / 12))) / 4) + intPart((367 * (m - 2 - 12 * (intPart((m - 14) / 12)))) / 12) -
18
+ intPart((3 * (intPart((y + 4900 + intPart((m - 14) / 12)) / 100))) / 4) + d - 32075 + delta
19
+ } else {
20
+ //added +1 on jd to comply isna rulling
21
+ jd = 367 * y - intPart((7 * (y + 5001 + intPart((m - 9) / 7))) / 4) + intPart((275 * m) / 9) + d + 1729777 + delta
22
+ }
23
+
24
+ //added -1 on jd1 to comply isna rulling
25
+ jd1 = jd - delta
26
+ l = jd - 1948440 + 10632
27
+ n = intPart((l - 1) / 10631)
28
+ l = l - 10631 * n + 354
29
+ j = (intPart((10985 - l) / 5316)) * (intPart((50 * l) / 17719)) + (intPart(l / 5670)) * (intPart((43 * l) / 15238))
30
+ l = l - (intPart((30 - j) / 15)) * (intPart((17719 * j) / 50)) - (intPart(j / 16)) * (intPart((15238 * j) / 43)) + 29
31
+ m = intPart((24 * l) / 709)
32
+ d = l - intPart((709 * m) / 24)
33
+ y = 30 * n + j - 30
34
+
35
+ return {
36
+ d,
37
+ m,
38
+ y,
39
+ dateOfWeek: jd1 % 7,
40
+ dayName:weekDay(jd1 % 7),
41
+ };
42
+
43
+ }
44
+
45
+ function IslToGreg(arg) {
46
+
47
+
48
+ let d = parseInt(arg.HDay.value)
49
+ let m = parseInt(arg.HMonth.value)
50
+ let y = parseInt(arg.HYear.value)
51
+ //added - delta=1 on jd to comply isna rulling
52
+ let jd = intPart((11 * y + 3) / 30) + 354 * y + 30 * m - intPart((m - 1) / 2) + d + 1948440 - 385 - delta
53
+
54
+ let l,n ,i ,j,k ;
55
+
56
+ if (jd > 2299160) {
57
+ l = jd + 68569
58
+ n = intPart((4 * l) / 146097)
59
+ l = l - intPart((146097 * n + 3) / 4)
60
+ i = intPart((4000 * (l + 1)) / 1461001)
61
+ l = l - intPart((1461 * i) / 4) + 31
62
+ j = intPart((80 * l) / 2447)
63
+ d = l - intPart((2447 * j) / 80)
64
+ l = intPart(j / 11)
65
+ m = j + 2 - 12 * l
66
+ y = 100 * (n - 49) + i + l
67
+ } else {
68
+ j = jd + 1402
69
+ k = intPart((j - 1) / 1461)
70
+ l = j - 1461 * k
71
+ n = intPart((l - 1) / 365) - intPart(l / 1461)
72
+ i = l - 365 * n + 30
73
+ j = intPart((80 * i) / 2447)
74
+ d = i - intPart((2447 * j) / 80)
75
+ i = intPart(j / 11)
76
+ m = j + 2 - 12 * i
77
+ y = 4 * k + n + i - 4716
78
+ }
79
+
80
+ //arg.CDay.value=d
81
+ //arg.CMonth.value=m
82
+ //arg.CYear.value=y
83
+
84
+ return {
85
+ d,
86
+ m,
87
+ y,
88
+ dateOfWeek: jd % 7,
89
+ dayName: weekDay(jd % 7),
90
+ };
91
+ }
92
+
93
+
94
+
95
+
96
+ export function weekDay(wdn) {
97
+ if (wdn == 0) {
98
+ return "Mon"
99
+ }
100
+ if (wdn == 1) {
101
+ return "Tue"
102
+ }
103
+ if (wdn == 2) {
104
+ return "Wed"
105
+ }
106
+ if (wdn == 3) {
107
+ return "Thu"
108
+ }
109
+ if (wdn == 4) {
110
+ return "Fri"
111
+ }
112
+ if (wdn == 5) {
113
+ return "Sat"
114
+ }
115
+ if (wdn == 6) {
116
+ return "Sun"
117
+ }
118
+ return ""
119
+
120
+ }
121
+
122
+ function GregToHijri(gregDate) {
123
+ const hijriDate = GregToIsl({
124
+ CDay: {
125
+ value: gregDate.getDate()
126
+ },
127
+ CYear: {
128
+ value: gregDate.getFullYear()
129
+ },
130
+ CMonth: {
131
+ value: gregDate.getMonth() + 1
132
+ }
133
+ });
134
+
135
+ return {
136
+ year: hijriDate.y,
137
+ month: hijriDate.m,
138
+ date: hijriDate.d,
139
+ hours: gregDate.getHours(),
140
+ minutes: gregDate.getMinutes(),
141
+ seconds: gregDate.getSeconds(),
142
+ milliseconds: gregDate.getMilliseconds(),
143
+ day: hijriDate.dateOfWeek,
144
+ dayName: hijriDate.dayName
145
+ };
146
+
147
+ };
148
+
149
+ function HijriToGreg(hijriDate) {
150
+ const gregDate = IslToGreg({
151
+ HDay: {
152
+ value: hijriDate._date || hijriDate.date
153
+ },
154
+ HYear: {
155
+ value: hijriDate._year || hijriDate.year
156
+ },
157
+ HMonth: {
158
+ value: hijriDate._month || hijriDate.month
159
+ }
160
+ });
161
+
162
+ return new Date(gregDate.y,
163
+ gregDate.m -1 ,
164
+ gregDate.d,
165
+ hijriDate.getHours(),
166
+ hijriDate.getMinutes() ,
167
+ hijriDate.getSeconds(),
168
+ hijriDate.getMilliseconds()
169
+ )
170
+
171
+ };
172
+
173
+ export {GregToHijri};
174
+
175
+ export {HijriToGreg};
@@ -0,0 +1,134 @@
1
+ import HijriDate from "./HijriDate";
2
+
3
+ const dateFormat = (function () {
4
+ const token =
5
+ /P{1,4}|p{1,4}|d{1,2}|e{3,6}|M{1,4}|yy(?:yy)?|([Hhms])\1?|[a]{1,4}|[LloSZ]|('at')|"[^"]*"|'[^']*'/g,
6
+ timezone =
7
+ /\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g,
8
+ timezoneClip = /[^-+\dA-Z]/g,
9
+ pad = function (val, len) {
10
+ val = String(val);
11
+ len = len || 2;
12
+ while (val.length < len) val = "0" + val;
13
+ return val;
14
+ };
15
+
16
+ // Regexes and supporting functions are cached through closure
17
+ return function (
18
+ date,
19
+ mask,
20
+ options = {
21
+ utc: false,
22
+ },
23
+ ) {
24
+ const { locales, defaultLocale } = HijriDate;
25
+ options.locale = options.locale || defaultLocale;
26
+ if (!locales[options.locale]) {
27
+ throw new Error(`Locale ${options.locale} is not supported yet .
28
+ Please, try to extend "HijriDate.locales" :
29
+ i.e: HijriDate.locales.${options.locale} = {dayNames:[..14 items..], monthNames:[..24 items..]}
30
+ `);
31
+ return;
32
+ }
33
+ // You can't provide utc if you skip other args (use the "UTC:" mask prefix)
34
+ if (
35
+ arguments.length == 1 &&
36
+ Object.prototype.toString.call(date) == "[object String]" &&
37
+ !/\d/.test(date)
38
+ ) {
39
+ mask = date;
40
+ date = undefined;
41
+ }
42
+
43
+ mask = String(masks[mask] || mask || masks["default"]);
44
+
45
+ // Allow setting the utc argument via the mask
46
+ if (mask.slice(0, 4) == "UTC:") {
47
+ mask = mask.slice(4);
48
+ options.utc = true;
49
+ }
50
+
51
+ var _ = options.utc ? "getUTC" : "get",
52
+ d = date[_ + "Date"](),
53
+ D = date[_ + "Day"](),
54
+ M = date[_ + "Month"](),
55
+ mIndex = date[_ + "MonthIndex"](),
56
+ y = date[_ + "FullYear"](),
57
+ H = date[_ + "Hours"](),
58
+ m = date[_ + "Minutes"](),
59
+ s = date[_ + "Seconds"](),
60
+ L = date[_ + "Milliseconds"](),
61
+ o = options.utc ? 0 : date.getTimezoneOffset(),
62
+ flags = {
63
+ d: d,
64
+ dd: pad(d),
65
+ ddd: locales[options.locale].dayNames[D === 7 ? 0 : D + 1],
66
+ dddd: locales[options.locale].dayNames[(D === 7 ? 0 : D + 1) + 7],
67
+ ee: locales[options.locale].dayNames[D],
68
+ eee: locales[options.locale].dayNames[D + 7],
69
+ eeee: locales[options.locale].dayNames[D + 14],
70
+ eeeeee: locales[options.locale].dayNames[D],
71
+ M,
72
+ MM: pad(M),
73
+ MMM: locales[options.locale].monthNames[mIndex],
74
+ MMMM: locales[options.locale].monthNames[mIndex + 12],
75
+ yy: String(y).slice(2),
76
+ yyyy: y,
77
+ h: H % 12 || 12,
78
+ hh: pad(H % 12 || 12),
79
+ H: H,
80
+ HH: pad(H),
81
+ m,
82
+ mm: pad(m),
83
+ s: s,
84
+ ss: pad(s),
85
+ l: pad(L, 3),
86
+ L: pad(L > 99 ? Math.round(L / 10) : L),
87
+ a: H < 12 ? locales[options.locale].am : locales[options.locale].pm,
88
+ aa: H < 12 ? locales[options.locale].am : locales[options.locale].pm,
89
+ aaa: H < 12 ? locales[options.locale].am : locales[options.locale].pm,
90
+ aaaa: H < 12 ? locales[options.locale].am : locales[options.locale].pm,
91
+ aaaaa: H < 12 ? locales[options.locale].am : locales[options.locale].pm,
92
+ "'at'": locales[options.locale].separator,
93
+ t: H < 12 ? "a" : "p",
94
+ tt: H < 12 ? "am" : "pm",
95
+ T: H < 12 ? "A" : "P",
96
+ TT: H < 12 ? "AM" : "PM",
97
+ // Z: options.utc ? "UTC" : (String(date).match(timezone) || [""]).pop().replace(timezoneClip, ""),
98
+ o:
99
+ (o > 0 ? "-" : "+") +
100
+ pad(Math.floor(Math.abs(o) / 60) * 100 + (Math.abs(o) % 60), 4),
101
+ S: ["th", "st", "nd", "rd"][
102
+ d % 10 > 3 ? 0 : (((d % 100) - (d % 10) != 10) * d) % 10
103
+ ],
104
+ };
105
+
106
+ return mask.replace(token, function ($0) {
107
+ if ($0 === "P") return `${flags.d}/${flags.M}/${flags.yyyy} `;
108
+ if ($0.startsWith("PP"))
109
+ return `${flags.MMM} ${flags.dd}, ${flags.yyyy} `;
110
+ if ($0 === "p") return `${flags.h}:${flags.m} ${flags.a}`;
111
+ if ($0.startsWith("pp"))
112
+ return `${flags.hh}:${flags.mm}:${flags.ss} ${flags.a}`;
113
+ return $0 in flags ? flags[$0] : $0.slice(1, $0.length - 1);
114
+ });
115
+ };
116
+ })();
117
+
118
+ // Some common format strings
119
+ export const masks = {
120
+ default: "ddd MMM dd yyyy HH:mm:ss",
121
+ shortDate: "M/d/yy",
122
+ mediumDate: "MMM d, yyyy",
123
+ longDate: "MMMM d, yyyy",
124
+ fullDate: "dddd, MMMM d, yyyy",
125
+ shortTime: "h:mm TT",
126
+ mediumTime: "h:mm:ss TT",
127
+ longTime: "h:mm:ss TT Z",
128
+ isoDate: "yyyy-MM-dd",
129
+ isoTime: "HH:mm:ss",
130
+ isoDateTime: "yyyy-MM-dd'T'HH:mm:ss",
131
+ isoUtcDateTime: "UTC:yyyy-MM-dd'T'HH:mm:ss'Z'",
132
+ };
133
+
134
+ export default dateFormat;