@react-fabric/date 1.0.0-beta.8 → 1.0.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 (139) 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/DateCell.js +5 -7
  5. package/dist/cjs/components/DateHeader.js +27 -20
  6. package/dist/cjs/components/DatePage.js +10 -12
  7. package/dist/cjs/components/DecadePage.js +3 -3
  8. package/dist/cjs/components/MonthPage.js +3 -3
  9. package/dist/cjs/components/TimeSliders.js +36 -35
  10. package/dist/cjs/components/YearPage.js +3 -3
  11. package/dist/cjs/display/DateDisplay.js +25 -8
  12. package/dist/cjs/display/DateDuration.js +155 -0
  13. package/dist/cjs/hijri/DateConverter.js +154 -0
  14. package/dist/cjs/hijri/FormatDate.js +116 -0
  15. package/dist/cjs/hijri/HijriDate.js +531 -0
  16. package/dist/cjs/hijri/StringDateParser.js +74 -0
  17. package/dist/cjs/hijri/index.js +15 -1025
  18. package/dist/cjs/hijri/initializer.js +113 -0
  19. package/dist/cjs/hijri/locales.js +19 -0
  20. package/dist/cjs/hijri/safe.js +17 -0
  21. package/dist/cjs/i18n/ar/date.json.js +213 -0
  22. package/dist/cjs/i18n/en/date.json.js +83 -0
  23. package/dist/cjs/i18n/index.js +4 -10
  24. package/dist/cjs/index.js +41 -2
  25. package/dist/cjs/panels/BasePanel.js +6 -5
  26. package/dist/cjs/panels/DatePanel.js +45 -21
  27. package/dist/cjs/{superdate → panels}/EventPanel.js +28 -12
  28. package/dist/cjs/panels/RangePanel.js +49 -19
  29. package/dist/cjs/utils/dateUtil.js +3 -5
  30. package/dist/esm/components/DateCell.js +6 -8
  31. package/dist/esm/components/DateHeader.js +28 -21
  32. package/dist/esm/components/DatePage.js +11 -13
  33. package/dist/esm/components/DecadePage.js +3 -3
  34. package/dist/esm/components/MonthPage.js +3 -3
  35. package/dist/esm/components/TimeSliders.js +38 -37
  36. package/dist/esm/components/YearPage.js +3 -3
  37. package/dist/esm/display/DateDisplay.js +26 -9
  38. package/dist/esm/display/DateDuration.js +155 -0
  39. package/dist/esm/hijri/DateConverter.js +152 -0
  40. package/dist/esm/hijri/FormatDate.js +113 -0
  41. package/dist/esm/hijri/HijriDate.js +528 -0
  42. package/dist/esm/hijri/StringDateParser.js +74 -0
  43. package/dist/esm/hijri/index.js +15 -1025
  44. package/dist/esm/hijri/initializer.js +113 -0
  45. package/dist/esm/hijri/locales.js +18 -0
  46. package/dist/esm/hijri/safe.js +14 -0
  47. package/dist/esm/i18n/ar/date.json.js +209 -0
  48. package/dist/esm/i18n/en/date.json.js +79 -0
  49. package/dist/esm/i18n/index.js +2 -8
  50. package/dist/esm/index.js +36 -1
  51. package/dist/esm/panels/BasePanel.js +6 -5
  52. package/dist/esm/panels/DatePanel.js +48 -24
  53. package/dist/esm/{superdate → panels}/EventPanel.js +29 -13
  54. package/dist/esm/panels/RangePanel.js +52 -22
  55. package/dist/esm/utils/dateUtil.js +4 -6
  56. package/dist/types/components/DateCell.d.ts +1 -1
  57. package/dist/types/components/DateHeader.d.ts +1 -1
  58. package/dist/types/components/DatePage.d.ts +1 -1
  59. package/dist/types/components/DecadePage.d.ts +1 -1
  60. package/dist/types/components/MonthPage.d.ts +1 -1
  61. package/dist/types/components/TimeSliders.d.ts +1 -1
  62. package/dist/types/components/YearPage.d.ts +1 -1
  63. package/dist/types/display/DateDisplay.d.ts +17 -4
  64. package/dist/types/display/DateDuration.d.ts +25 -0
  65. package/dist/types/hijri/DateConverter.d.ts +13 -0
  66. package/dist/types/hijri/FormatDate.d.ts +19 -0
  67. package/dist/types/hijri/HijriDate.d.ts +214 -0
  68. package/dist/types/hijri/StringDateParser.d.ts +11 -0
  69. package/dist/types/hijri/index.d.ts +2 -2
  70. package/dist/types/hijri/initializer.d.ts +129 -0
  71. package/dist/types/hijri/locales.d.ts +19 -0
  72. package/dist/types/hijri/safe.d.ts +3 -0
  73. package/dist/types/index.d.ts +32 -1
  74. package/dist/types/panels/BasePanel.d.ts +1 -1
  75. package/dist/types/panels/DatePanel.d.ts +22 -1
  76. package/dist/types/panels/EventPanel.d.ts +17 -0
  77. package/dist/types/panels/RangePanel.d.ts +19 -1
  78. package/dist/types/types/index.d.ts +8 -40
  79. package/package.json +14 -21
  80. package/src/components/DateCell.tsx +20 -75
  81. package/src/components/DateHeader.tsx +27 -78
  82. package/src/components/DatePage.tsx +11 -36
  83. package/src/components/DecadePage.tsx +2 -2
  84. package/src/components/MonthPage.tsx +2 -2
  85. package/src/components/TimeSliders.tsx +20 -60
  86. package/src/components/YearPage.tsx +2 -2
  87. package/src/display/DateDisplay.tsx +26 -38
  88. package/src/display/DateDuration.tsx +170 -0
  89. package/src/hijri/DateConverter.js +175 -0
  90. package/src/hijri/FormatDate.js +134 -0
  91. package/src/hijri/HijriDate.js +477 -0
  92. package/src/hijri/StringDateParser.js +68 -0
  93. package/src/hijri/index.js +16 -1535
  94. package/src/hijri/initializer.js +96 -0
  95. package/src/hijri/locales.js +109 -0
  96. package/src/hijri/safe.js +16 -0
  97. package/src/i18n/ar/date.json +203 -0
  98. package/src/i18n/en/date.json +73 -0
  99. package/src/i18n/index.ts +2 -5
  100. package/src/index.ts +29 -18
  101. package/src/panels/BasePanel.tsx +7 -10
  102. package/src/panels/DatePanel.tsx +41 -33
  103. package/src/{superdate → panels}/EventPanel.tsx +52 -53
  104. package/src/panels/RangePanel.tsx +54 -60
  105. package/src/types/index.ts +8 -43
  106. package/src/utils/dateUtil.ts +26 -82
  107. package/dist/cjs/components/Date.module.css +0 -1
  108. package/dist/cjs/i18n/ar.json.js +0 -25
  109. package/dist/cjs/i18n/en.json.js +0 -21
  110. package/dist/cjs/i18n/superdate/ar.json.js +0 -86
  111. package/dist/cjs/i18n/superdate/en.json.js +0 -93
  112. package/dist/cjs/superdate/QuickSelect.js +0 -134
  113. package/dist/cjs/superdate/RelativeInput.js +0 -79
  114. package/dist/cjs/superdate/RelativePanel.js +0 -91
  115. package/dist/cjs/superdate/SuperDate.module.css +0 -1
  116. package/dist/cjs/superdate/Superdate.js +0 -177
  117. package/dist/esm/components/Date.module.css +0 -1
  118. package/dist/esm/i18n/ar.json.js +0 -21
  119. package/dist/esm/i18n/en.json.js +0 -18
  120. package/dist/esm/i18n/superdate/ar.json.js +0 -79
  121. package/dist/esm/i18n/superdate/en.json.js +0 -85
  122. package/dist/esm/superdate/QuickSelect.js +0 -134
  123. package/dist/esm/superdate/RelativeInput.js +0 -79
  124. package/dist/esm/superdate/RelativePanel.js +0 -91
  125. package/dist/esm/superdate/SuperDate.module.css +0 -1
  126. package/dist/esm/superdate/Superdate.js +0 -176
  127. package/dist/types/superdate/EventPanel.d.ts +0 -4
  128. package/dist/types/superdate/QuickSelect.d.ts +0 -1
  129. package/dist/types/superdate/RelativeInput.d.ts +0 -1
  130. package/dist/types/superdate/RelativePanel.d.ts +0 -1
  131. package/dist/types/superdate/Superdate.d.ts +0 -17
  132. package/src/i18n/ar.json +0 -14
  133. package/src/i18n/en.json +0 -13
  134. package/src/i18n/superdate/ar.json +0 -70
  135. package/src/i18n/superdate/en.json +0 -75
  136. package/src/superdate/QuickSelect.tsx +0 -121
  137. package/src/superdate/RelativeInput.tsx +0 -64
  138. package/src/superdate/RelativePanel.tsx +0 -103
  139. package/src/superdate/Superdate.tsx +0 -198
@@ -21,23 +21,15 @@
21
21
  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
22
  */
23
23
 
24
- import { Dropdown, Tooltip, useGlobals } from "@react-fabric/core";
25
- import { type MenuItemProps } 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";
24
+ import { Dropdown, Tooltip, useApplicationContext } from "@react-fabric/core";
25
+ import { type MenuProps } from "@react-fabric/core/dist/types/components/menu/types";
26
+ import { type ChildrenProp, type CssProp, type TestProps } from "@react-fabric/core/dist/types/types";
27
+ import { cn } from "@react-fabric/utilities";
32
28
  import { type ElementType } from "react";
33
29
  import { type DateLike } from "../types";
34
30
  import { DateUtil } from "../utils/dateUtil";
35
31
 
36
- export interface Props
37
- extends CssProp,
38
- AriaProps,
39
- TestProps,
40
- Partial<ChildrenProp<ElementType<MenuItemProps>>> {
32
+ export interface Props extends CssProp, TestProps, Partial<ChildrenProp<ElementType<MenuProps>>> {
41
33
  /**
42
34
  * date like value
43
35
  */
@@ -46,43 +38,39 @@ export interface Props
46
38
  * date format
47
39
  */
48
40
  format?: string;
41
+
42
+ showAlternateDate?: boolean;
49
43
  }
50
44
 
51
- export const DateDisplay = ({
52
- date,
53
- className,
54
- format = "eee, PPpp",
55
- children,
56
- ...aria
57
- }: Props) => {
58
- const { currentCalendar, currentLocale } = useGlobals();
45
+ /**
46
+ * DateDisplay component to display a formatted gregorian or hijri date with optional tooltip and dropdown.
47
+ * It uses the current calendar and locale from the global context.
48
+ * It formats the date using the provided format or a default format.
49
+ * If `showAlternateDate` is true, it shows a tooltip with the formatted date.
50
+ * If `children` are provided, it wraps the date in a dropdown.
51
+ *
52
+ * @example
53
+ * ```jsx
54
+ * <DateDisplay date={new Date()} />
55
+ * ```
56
+ */
57
+ export function DateDisplay({ date, className, format = "eee, PPpp", children, showAlternateDate, ...aria }: Props) {
58
+ const { currentCalendar, currentLocale } = useApplicationContext();
59
59
 
60
60
  const dtLabel = (
61
- <Tooltip
62
- content={DateUtil.format(
63
- date,
64
- format,
65
- currentLocale,
66
- currentCalendar !== "hijri",
67
- )}
68
- >
69
- <span className={className} {...aria}>
70
- {DateUtil.format(
71
- date,
72
- format,
73
- currentLocale,
74
- currentCalendar === "hijri",
75
- )}
61
+ <Tooltip disabled={!showAlternateDate} content={DateUtil.format(date, format, currentLocale, currentCalendar !== "hijri")}>
62
+ <span className={cn(className, !!children && "underline decoration-dotted cursor-pointer")} {...aria}>
63
+ {DateUtil.format(date, format, currentLocale, currentCalendar === "hijri")}
76
64
  </span>
77
65
  </Tooltip>
78
66
  );
79
67
 
80
68
  return children ? (
81
- <Dropdown>
69
+ <Dropdown showArrow closeOnClick>
82
70
  {dtLabel}
83
71
  {children}
84
72
  </Dropdown>
85
73
  ) : (
86
74
  dtLabel
87
75
  );
88
- };
76
+ }
@@ -0,0 +1,170 @@
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 { type ChildrenProp, type CssProp, type TestProps } from "@react-fabric/core/dist/types/types";
27
+ import { cn, Format } from "@react-fabric/utilities";
28
+ import { intervalToDuration, isBefore } from "date-fns";
29
+ import { useEffect, useMemo, useState } from "react";
30
+ import { useTranslation } from "react-i18next";
31
+ import { type DateLike } from "../types";
32
+ import { DateUtil } from "../utils/dateUtil";
33
+
34
+ export interface Props extends CssProp, TestProps, Partial<ChildrenProp<MenuProps>> {
35
+ /**
36
+ * date like value
37
+ */
38
+ date: DateLike;
39
+ /**
40
+ * date format
41
+ */
42
+ format?: string;
43
+ }
44
+
45
+ /**
46
+ * DateDuration component to display the duration from a given date to now.
47
+ * It calculates the difference in years, months, weeks, days, hours, minutes, and seconds,
48
+ * and displays it in a human-readable format.
49
+ * It uses the current locale for translations.
50
+ *
51
+ * @example
52
+ * ```jsx
53
+ * <DateDuration date={new Date("2020-01-01")} />
54
+ * ```
55
+ */
56
+ export function DateDuration({ date, children, className, format = "PPpp", ...props }: Props) {
57
+ const { t } = useTranslation("date");
58
+ const [dateInterval, setDateInterval] = useState<ReturnType<typeof intervalToDuration>>(() => ({}));
59
+
60
+ useEffect(() => {
61
+ // eslint-disable-next-line @eslint-react/set-state-in-effect
62
+ setDateInterval(intervalToDuration({ start: new Date(date), end: new Date() }));
63
+ // update interval every minute
64
+ const tmr = setInterval(() => {
65
+ setDateInterval(intervalToDuration({ start: new Date(date), end: new Date() }));
66
+ }, 60 * 1000);
67
+ return () => clearInterval(tmr);
68
+ }, [date]);
69
+
70
+ const label = useMemo(() => {
71
+ const before = isBefore(DateUtil.parseDate(date), new Date());
72
+ const tkey = before ? "relative.before" : "relative.after";
73
+ let part = "now";
74
+ let count = 0;
75
+ if (dateInterval.years && dateInterval.years > 0) {
76
+ part = "years";
77
+ count = dateInterval.years;
78
+ if ((dateInterval.months ?? 0) > 10) {
79
+ part = "yearsX";
80
+ count += 1;
81
+ }
82
+ } else if (dateInterval.months && dateInterval.months > 0) {
83
+ part = "months";
84
+ count = dateInterval.months;
85
+ if (dateInterval.months > 10) {
86
+ part = "yearsX";
87
+ count = 1;
88
+ } else if ((dateInterval.weeks ?? 0) > 3) {
89
+ part = "monthsX";
90
+ count += 1;
91
+ }
92
+ } else if (dateInterval.weeks && dateInterval.weeks > 0) {
93
+ part = "weeks";
94
+ count = dateInterval.weeks;
95
+ if (dateInterval.weeks > 3) {
96
+ part = "monthsX";
97
+ count = 1;
98
+ } else if ((dateInterval.days ?? 0) > 5) {
99
+ part = "weeksX";
100
+ count += 1;
101
+ }
102
+ } else if (dateInterval.days && dateInterval.days > 0) {
103
+ part = "days";
104
+ count = dateInterval.days;
105
+ if (dateInterval.days > 5) {
106
+ part = "weeksX";
107
+ count = 1;
108
+ } else if ((dateInterval.hours ?? 0) > 20) {
109
+ part = "daysX";
110
+ count += 1;
111
+ }
112
+ } else if (dateInterval.hours && dateInterval.hours > 0) {
113
+ part = "hours";
114
+ count = dateInterval.hours;
115
+ if (dateInterval.hours > 20) {
116
+ part = "daysX";
117
+ count = 1;
118
+ } else if ((dateInterval.minutes ?? 0) > 45) {
119
+ part = "hoursX";
120
+ count += 1;
121
+ }
122
+ } else if (dateInterval.minutes && dateInterval.minutes > 0) {
123
+ part = "minutes";
124
+ count = dateInterval.minutes;
125
+ if (dateInterval.minutes > 45) {
126
+ part = "hoursX";
127
+ count = 1;
128
+ } else if ((dateInterval.seconds ?? 0) > 45) {
129
+ part = "minuteX";
130
+ count += 1;
131
+ }
132
+ } else if (dateInterval.seconds && dateInterval.seconds > 15) {
133
+ part = "seconds";
134
+ count = dateInterval.seconds;
135
+ if (dateInterval.seconds > 45) {
136
+ part = "minutesX";
137
+ count = 1;
138
+ }
139
+ }
140
+
141
+ return t(`${tkey}.${part}`, { count });
142
+ }, [
143
+ date,
144
+ dateInterval.days,
145
+ dateInterval.hours,
146
+ dateInterval.minutes,
147
+ dateInterval.months,
148
+ dateInterval.seconds,
149
+ dateInterval.weeks,
150
+ dateInterval.years,
151
+ t,
152
+ ]);
153
+
154
+ const dtLabel = (
155
+ <Tooltip content={Format.date(date, format)}>
156
+ <span className={cn(className, !!children && "underline decoration-dotted cursor-pointer")} {...props}>
157
+ {label}
158
+ </span>
159
+ </Tooltip>
160
+ );
161
+
162
+ return children ? (
163
+ <Dropdown showArrow closeOnClick>
164
+ {dtLabel}
165
+ {children}
166
+ </Dropdown>
167
+ ) : (
168
+ dtLabel
169
+ );
170
+ }
@@ -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;