@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.
- package/README.md +2 -9
- package/{src/components/Date.module.css → css/_date.css} +5 -5
- package/{src/superdate/SuperDate.module.css → css/styles.css} +2 -8
- package/dist/cjs/components/DateHeader.js +16 -8
- package/dist/cjs/components/DatePage.js +2 -3
- package/dist/cjs/components/TimeSliders.js +5 -6
- package/dist/cjs/display/DateDisplay.js +24 -2
- package/dist/cjs/display/DateDuration.js +143 -0
- package/dist/cjs/hijri/DateConverter.js +154 -0
- package/dist/cjs/hijri/FormatDate.js +116 -0
- package/dist/cjs/hijri/HijriDate.js +531 -0
- package/dist/cjs/hijri/StringDateParser.js +74 -0
- package/dist/cjs/hijri/index.js +17 -1025
- package/dist/cjs/hijri/initializer.js +113 -0
- package/dist/cjs/hijri/locales.js +19 -0
- package/dist/cjs/hijri/safe.js +17 -0
- package/dist/cjs/i18n/ar.json.js +191 -3
- package/dist/cjs/i18n/en.json.js +63 -1
- package/dist/cjs/i18n/index.js +0 -6
- package/dist/cjs/index.js +13 -2
- package/dist/cjs/panels/DatePanel.js +26 -0
- package/dist/cjs/{superdate → panels}/EventPanel.js +2 -1
- package/dist/cjs/panels/RangePanel.js +23 -0
- package/dist/cjs/utils/dateUtil.js +1 -4
- package/dist/esm/components/DateHeader.js +16 -8
- package/dist/esm/components/DatePage.js +2 -3
- package/dist/esm/components/TimeSliders.js +5 -6
- package/dist/esm/display/DateDisplay.js +24 -2
- package/dist/esm/display/DateDuration.js +143 -0
- package/dist/esm/hijri/DateConverter.js +152 -0
- package/dist/esm/hijri/FormatDate.js +113 -0
- package/dist/esm/hijri/HijriDate.js +528 -0
- package/dist/esm/hijri/StringDateParser.js +74 -0
- package/dist/esm/hijri/index.js +17 -1025
- package/dist/esm/hijri/initializer.js +113 -0
- package/dist/esm/hijri/locales.js +18 -0
- package/dist/esm/hijri/safe.js +14 -0
- package/dist/esm/i18n/ar.json.js +191 -3
- package/dist/esm/i18n/en.json.js +63 -2
- package/dist/esm/i18n/index.js +0 -6
- package/dist/esm/index.js +6 -1
- package/dist/esm/panels/DatePanel.js +26 -0
- package/dist/esm/{superdate → panels}/EventPanel.js +2 -1
- package/dist/esm/panels/RangePanel.js +23 -0
- package/dist/esm/utils/dateUtil.js +1 -4
- package/dist/types/display/DateDisplay.d.ts +21 -3
- package/dist/types/display/DateDuration.d.ts +31 -0
- package/dist/types/hijri/DateConverter.d.ts +13 -0
- package/dist/types/hijri/FormatDate.d.ts +19 -0
- package/dist/types/hijri/HijriDate.d.ts +214 -0
- package/dist/types/hijri/StringDateParser.d.ts +11 -0
- package/dist/types/hijri/index.d.ts +2 -2
- package/dist/types/hijri/initializer.d.ts +129 -0
- package/dist/types/hijri/locales.d.ts +19 -0
- package/dist/types/hijri/safe.d.ts +3 -0
- package/dist/types/index.d.ts +6 -1
- package/dist/types/panels/DatePanel.d.ts +26 -0
- package/dist/types/panels/EventPanel.d.ts +17 -0
- package/dist/types/panels/RangePanel.d.ts +22 -0
- package/dist/types/types/index.d.ts +8 -40
- package/package.json +13 -16
- package/src/components/DateHeader.tsx +4 -8
- package/src/components/DatePage.tsx +2 -3
- package/src/components/TimeSliders.tsx +5 -6
- package/src/display/DateDisplay.tsx +32 -4
- package/src/display/DateDuration.tsx +180 -0
- package/src/hijri/DateConverter.js +175 -0
- package/src/hijri/FormatDate.js +134 -0
- package/src/hijri/HijriDate.js +477 -0
- package/src/hijri/StringDateParser.js +68 -0
- package/src/hijri/index.js +16 -1535
- package/src/hijri/initializer.js +96 -0
- package/src/hijri/locales.js +109 -0
- package/src/hijri/safe.js +16 -0
- package/src/i18n/ar.json +190 -1
- package/src/i18n/en.json +60 -0
- package/src/i18n/index.ts +0 -3
- package/src/index.ts +7 -1
- package/src/panels/DatePanel.tsx +26 -0
- package/src/{superdate → panels}/EventPanel.tsx +21 -3
- package/src/panels/RangePanel.tsx +23 -0
- package/src/types/index.ts +8 -43
- package/src/utils/dateUtil.ts +1 -5
- package/dist/cjs/components/Date.module.css +0 -1
- package/dist/cjs/i18n/superdate/ar.json.js +0 -86
- package/dist/cjs/i18n/superdate/en.json.js +0 -93
- package/dist/cjs/superdate/QuickSelect.js +0 -134
- package/dist/cjs/superdate/RelativeInput.js +0 -79
- package/dist/cjs/superdate/RelativePanel.js +0 -91
- package/dist/cjs/superdate/SuperDate.module.css +0 -1
- package/dist/cjs/superdate/Superdate.js +0 -177
- package/dist/esm/components/Date.module.css +0 -1
- package/dist/esm/i18n/superdate/ar.json.js +0 -79
- package/dist/esm/i18n/superdate/en.json.js +0 -85
- package/dist/esm/superdate/QuickSelect.js +0 -134
- package/dist/esm/superdate/RelativeInput.js +0 -79
- package/dist/esm/superdate/RelativePanel.js +0 -91
- package/dist/esm/superdate/SuperDate.module.css +0 -1
- package/dist/esm/superdate/Superdate.js +0 -176
- package/dist/types/superdate/EventPanel.d.ts +0 -4
- package/dist/types/superdate/QuickSelect.d.ts +0 -1
- package/dist/types/superdate/RelativeInput.d.ts +0 -1
- package/dist/types/superdate/RelativePanel.d.ts +0 -1
- package/dist/types/superdate/Superdate.d.ts +0 -17
- package/src/i18n/superdate/ar.json +0 -70
- package/src/i18n/superdate/en.json +0 -75
- package/src/superdate/QuickSelect.tsx +0 -121
- package/src/superdate/RelativeInput.tsx +0 -64
- package/src/superdate/RelativePanel.tsx +0 -103
- package/src/superdate/Superdate.tsx +0 -198
|
@@ -4,7 +4,6 @@ import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
|
4
4
|
import { useDebounce } from '@react-fabric/core';
|
|
5
5
|
import classNames from 'classnames';
|
|
6
6
|
import { useRef, useState, useEffect, useCallback } from 'react';
|
|
7
|
-
import classes from './Date.module.css';
|
|
8
7
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
9
8
|
|
|
10
9
|
var TimeSlider = function TimeSlider(_ref) {
|
|
@@ -58,16 +57,16 @@ var TimeSlider = function TimeSlider(_ref) {
|
|
|
58
57
|
children: [/*#__PURE__*/jsxs("div", {
|
|
59
58
|
className: "flex",
|
|
60
59
|
children: [/*#__PURE__*/jsx("div", {
|
|
61
|
-
className: classNames(
|
|
60
|
+
className: classNames("fabric-dateHeader", "flex-1 font-medium text-muted text-sm p-1 mx-px text-center bg-tint-50"),
|
|
62
61
|
children: "H"
|
|
63
62
|
}), /*#__PURE__*/jsx("div", {
|
|
64
|
-
className: classNames(
|
|
63
|
+
className: classNames("fabric-dateHeader", "flex-1 font-medium text-muted text-sm p-1 mx-px text-center bg-tint-50"),
|
|
65
64
|
children: "M"
|
|
66
65
|
})]
|
|
67
66
|
}), /*#__PURE__*/jsxs("div", {
|
|
68
|
-
className: "flex flex-1 flex-nowrap overflow-hidden relative",
|
|
67
|
+
className: "flex flex-1 flex-nowrap items-stretch overflow-hidden relative",
|
|
69
68
|
children: [/*#__PURE__*/jsxs("div", {
|
|
70
|
-
className: classNames("flex-1 overflow-auto scroll-hide snap-y snap-mandatory",
|
|
69
|
+
className: classNames("flex-1 overflow-auto scroll-hide snap-y snap-mandatory", "fabric-date-timeSlider"),
|
|
71
70
|
onScroll: calculateTime,
|
|
72
71
|
ref: hourRef,
|
|
73
72
|
children: [/*#__PURE__*/jsx("div", {
|
|
@@ -92,7 +91,7 @@ var TimeSlider = function TimeSlider(_ref) {
|
|
|
92
91
|
className: "w-full"
|
|
93
92
|
})]
|
|
94
93
|
}), /*#__PURE__*/jsxs("div", {
|
|
95
|
-
className: classNames("flex-1 overflow-auto scroll-hide snap-y snap-mandatory",
|
|
94
|
+
className: classNames("flex-1 overflow-auto scroll-hide snap-y snap-mandatory", "fabric-date-timeSlider"),
|
|
96
95
|
onScroll: calculateTime,
|
|
97
96
|
ref: minuteRef,
|
|
98
97
|
children: [/*#__PURE__*/jsx("div", {
|
|
@@ -4,30 +4,52 @@ import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
|
4
4
|
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
|
|
5
5
|
import { useGlobals, Tooltip, Dropdown } from '@react-fabric/core';
|
|
6
6
|
import { DateUtil } from '../utils/dateUtil.js';
|
|
7
|
+
import classNames from 'classnames';
|
|
7
8
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
8
9
|
|
|
9
|
-
var _excluded = ["date", "className", "format", "children"];
|
|
10
|
+
var _excluded = ["date", "className", "format", "children", "showAlternateDate"];
|
|
10
11
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
11
12
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
13
|
+
/**
|
|
14
|
+
* DateDisplay component to display a formatted gregorian or hijri date with optional tooltip and dropdown.
|
|
15
|
+
* It uses the current calendar and locale from the global context.
|
|
16
|
+
* It formats the date using the provided format or a default format.
|
|
17
|
+
* If `showAlternateDate` is true, it shows a tooltip with the formatted date.
|
|
18
|
+
* If `children` are provided, it wraps the date in a dropdown.
|
|
19
|
+
*
|
|
20
|
+
* @param {Object} props - The component props.
|
|
21
|
+
* @returns {JSX.Element} - The rendered component.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```jsx
|
|
25
|
+
* <DateDisplay date={new Date()} />
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @see {@link https://adarshpastakia.github.io/react-fabric/?path=/docs/date-date-display--docs}
|
|
29
|
+
*/
|
|
12
30
|
var DateDisplay = function DateDisplay(_ref) {
|
|
13
31
|
var date = _ref.date,
|
|
14
32
|
className = _ref.className,
|
|
15
33
|
_ref$format = _ref.format,
|
|
16
34
|
format = _ref$format === void 0 ? "eee, PPpp" : _ref$format,
|
|
17
35
|
children = _ref.children,
|
|
36
|
+
showAlternateDate = _ref.showAlternateDate,
|
|
18
37
|
aria = _objectWithoutProperties(_ref, _excluded);
|
|
19
38
|
var _useGlobals = useGlobals(),
|
|
20
39
|
currentCalendar = _useGlobals.currentCalendar,
|
|
21
40
|
currentLocale = _useGlobals.currentLocale;
|
|
22
41
|
var dtLabel = /*#__PURE__*/jsx(Tooltip, {
|
|
42
|
+
disabled: !showAlternateDate,
|
|
23
43
|
content: DateUtil.format(date, format, currentLocale, currentCalendar !== "hijri"),
|
|
24
44
|
children: /*#__PURE__*/jsx("span", _objectSpread(_objectSpread({
|
|
25
|
-
className: className
|
|
45
|
+
className: classNames(className, !!children && "underline decoration-dotted cursor-pointer")
|
|
26
46
|
}, aria), {}, {
|
|
27
47
|
children: DateUtil.format(date, format, currentLocale, currentCalendar === "hijri")
|
|
28
48
|
}))
|
|
29
49
|
});
|
|
30
50
|
return children ? /*#__PURE__*/jsxs(Dropdown, {
|
|
51
|
+
showArrow: true,
|
|
52
|
+
closeOnClick: true,
|
|
31
53
|
children: [dtLabel, children]
|
|
32
54
|
}) : dtLabel;
|
|
33
55
|
};
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
4
|
+
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
|
|
5
|
+
import { Tooltip, Dropdown } from '@react-fabric/core';
|
|
6
|
+
import { Format } from '@react-fabric/utilities';
|
|
7
|
+
import classNames from 'classnames';
|
|
8
|
+
import { intervalToDuration, isBefore } from 'date-fns';
|
|
9
|
+
import { useMemo } from 'react';
|
|
10
|
+
import { useTranslation } from 'react-i18next';
|
|
11
|
+
import { DateUtil } from '../utils/dateUtil.js';
|
|
12
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
13
|
+
|
|
14
|
+
var _excluded = ["date", "children", "className", "format"];
|
|
15
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
16
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
17
|
+
/**
|
|
18
|
+
* DateDuration component to display the duration from a given date to now.
|
|
19
|
+
* It calculates the difference in years, months, weeks, days, hours, minutes, and seconds,
|
|
20
|
+
* and displays it in a human-readable format.
|
|
21
|
+
* It uses the current locale for translations.
|
|
22
|
+
*
|
|
23
|
+
* @param {Props} props - The properties for the component.
|
|
24
|
+
* @returns {JSX.Element} The rendered component.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```jsx
|
|
28
|
+
* <DateDuration date={new Date("2020-01-01")} />
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* @see {@link https://adarshpastakia.github.io/react-fabric/?path=/docs/date-date-display--docs}
|
|
32
|
+
*/
|
|
33
|
+
var DateDuration = function DateDuration(_ref) {
|
|
34
|
+
var date = _ref.date,
|
|
35
|
+
children = _ref.children,
|
|
36
|
+
className = _ref.className,
|
|
37
|
+
_ref$format = _ref.format,
|
|
38
|
+
format = _ref$format === void 0 ? "PPpp" : _ref$format,
|
|
39
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
40
|
+
var _useTranslation = useTranslation("date"),
|
|
41
|
+
t = _useTranslation.t;
|
|
42
|
+
var interval = useMemo(function () {
|
|
43
|
+
return intervalToDuration({
|
|
44
|
+
start: new Date(date),
|
|
45
|
+
end: new Date()
|
|
46
|
+
});
|
|
47
|
+
}, [date]);
|
|
48
|
+
var label = useMemo(function () {
|
|
49
|
+
var before = isBefore(DateUtil.parseDate(date), new Date());
|
|
50
|
+
var tkey = before ? "relative.before" : "relative.after";
|
|
51
|
+
var part = "now";
|
|
52
|
+
var count = 0;
|
|
53
|
+
if (interval.years && interval.years > 0) {
|
|
54
|
+
var _interval$months;
|
|
55
|
+
part = "years";
|
|
56
|
+
count = interval.years;
|
|
57
|
+
if (((_interval$months = interval.months) !== null && _interval$months !== void 0 ? _interval$months : 0) > 10) {
|
|
58
|
+
part = "yearsX";
|
|
59
|
+
count += 1;
|
|
60
|
+
}
|
|
61
|
+
} else if (interval.months && interval.months > 0) {
|
|
62
|
+
var _interval$weeks;
|
|
63
|
+
part = "months";
|
|
64
|
+
count = interval.months;
|
|
65
|
+
if (interval.months > 10) {
|
|
66
|
+
part = "yearsX";
|
|
67
|
+
count = 1;
|
|
68
|
+
} else if (((_interval$weeks = interval.weeks) !== null && _interval$weeks !== void 0 ? _interval$weeks : 0) > 3) {
|
|
69
|
+
part = "monthsX";
|
|
70
|
+
count += 1;
|
|
71
|
+
}
|
|
72
|
+
} else if (interval.weeks && interval.weeks > 0) {
|
|
73
|
+
var _interval$days;
|
|
74
|
+
part = "weeks";
|
|
75
|
+
count = interval.weeks;
|
|
76
|
+
if (interval.weeks > 3) {
|
|
77
|
+
part = "monthsX";
|
|
78
|
+
count = 1;
|
|
79
|
+
} else if (((_interval$days = interval.days) !== null && _interval$days !== void 0 ? _interval$days : 0) > 5) {
|
|
80
|
+
part = "weeksX";
|
|
81
|
+
count += 1;
|
|
82
|
+
}
|
|
83
|
+
} else if (interval.days && interval.days > 0) {
|
|
84
|
+
var _interval$hours;
|
|
85
|
+
part = "days";
|
|
86
|
+
count = interval.days;
|
|
87
|
+
if (interval.days > 5) {
|
|
88
|
+
part = "weeksX";
|
|
89
|
+
count = 1;
|
|
90
|
+
} else if (((_interval$hours = interval.hours) !== null && _interval$hours !== void 0 ? _interval$hours : 0) > 20) {
|
|
91
|
+
part = "daysX";
|
|
92
|
+
count += 1;
|
|
93
|
+
}
|
|
94
|
+
} else if (interval.hours && interval.hours > 0) {
|
|
95
|
+
var _interval$minutes;
|
|
96
|
+
part = "hours";
|
|
97
|
+
count = interval.hours;
|
|
98
|
+
if (interval.hours > 20) {
|
|
99
|
+
part = "daysX";
|
|
100
|
+
count = 1;
|
|
101
|
+
} else if (((_interval$minutes = interval.minutes) !== null && _interval$minutes !== void 0 ? _interval$minutes : 0) > 45) {
|
|
102
|
+
part = "hoursX";
|
|
103
|
+
count += 1;
|
|
104
|
+
}
|
|
105
|
+
} else if (interval.minutes && interval.minutes > 0) {
|
|
106
|
+
var _interval$seconds;
|
|
107
|
+
part = "minutes";
|
|
108
|
+
count = interval.minutes;
|
|
109
|
+
if (interval.minutes > 45) {
|
|
110
|
+
part = "hoursX";
|
|
111
|
+
count = 1;
|
|
112
|
+
} else if (((_interval$seconds = interval.seconds) !== null && _interval$seconds !== void 0 ? _interval$seconds : 0) > 45) {
|
|
113
|
+
part = "minuteX";
|
|
114
|
+
count += 1;
|
|
115
|
+
}
|
|
116
|
+
} else if (interval.seconds && interval.seconds > 15) {
|
|
117
|
+
part = "seconds";
|
|
118
|
+
count = interval.seconds;
|
|
119
|
+
if (interval.seconds > 45) {
|
|
120
|
+
part = "minutesX";
|
|
121
|
+
count = 1;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return t("".concat(tkey, ".").concat(part), {
|
|
125
|
+
count: count
|
|
126
|
+
});
|
|
127
|
+
}, [interval, date]);
|
|
128
|
+
var dtLabel = /*#__PURE__*/jsx(Tooltip, {
|
|
129
|
+
content: Format.date(date, format),
|
|
130
|
+
children: /*#__PURE__*/jsx("span", _objectSpread(_objectSpread({
|
|
131
|
+
className: classNames(className, !!children && "underline decoration-dotted cursor-pointer")
|
|
132
|
+
}, props), {}, {
|
|
133
|
+
children: label
|
|
134
|
+
}))
|
|
135
|
+
});
|
|
136
|
+
return children ? /*#__PURE__*/jsxs(Dropdown, {
|
|
137
|
+
showArrow: true,
|
|
138
|
+
closeOnClick: true,
|
|
139
|
+
children: [dtLabel, children]
|
|
140
|
+
}) : dtLabel;
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
export { DateDuration };
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
function intPart(floatNum) {
|
|
4
|
+
if (floatNum < -0.0000001) {
|
|
5
|
+
return Math.ceil(floatNum - 0.0000001);
|
|
6
|
+
}
|
|
7
|
+
return Math.floor(floatNum + 0.0000001);
|
|
8
|
+
}
|
|
9
|
+
var delta = 1;
|
|
10
|
+
function GregToIsl(arg) {
|
|
11
|
+
var d = parseInt(arg.CDay.value);
|
|
12
|
+
var m = parseInt(arg.CMonth.value);
|
|
13
|
+
var y = parseInt(arg.CYear.value);
|
|
14
|
+
var jd,
|
|
15
|
+
l,
|
|
16
|
+
jd1,
|
|
17
|
+
n,
|
|
18
|
+
j,
|
|
19
|
+
delta = 1;
|
|
20
|
+
if (y > 1582 || y == 1582 && m > 10 || y == 1582 && m == 10 && d > 14) {
|
|
21
|
+
//added delta=1 on jd to comply isna rulling 2007
|
|
22
|
+
jd = intPart(1461 * (y + 4800 + intPart((m - 14) / 12)) / 4) + intPart(367 * (m - 2 - 12 * intPart((m - 14) / 12)) / 12) - intPart(3 * intPart((y + 4900 + intPart((m - 14) / 12)) / 100) / 4) + d - 32075 + delta;
|
|
23
|
+
} else {
|
|
24
|
+
//added +1 on jd to comply isna rulling
|
|
25
|
+
jd = 367 * y - intPart(7 * (y + 5001 + intPart((m - 9) / 7)) / 4) + intPart(275 * m / 9) + d + 1729777 + delta;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
//added -1 on jd1 to comply isna rulling
|
|
29
|
+
jd1 = jd - delta;
|
|
30
|
+
l = jd - 1948440 + 10632;
|
|
31
|
+
n = intPart((l - 1) / 10631);
|
|
32
|
+
l = l - 10631 * n + 354;
|
|
33
|
+
j = intPart((10985 - l) / 5316) * intPart(50 * l / 17719) + intPart(l / 5670) * intPart(43 * l / 15238);
|
|
34
|
+
l = l - intPart((30 - j) / 15) * intPart(17719 * j / 50) - intPart(j / 16) * intPart(15238 * j / 43) + 29;
|
|
35
|
+
m = intPart(24 * l / 709);
|
|
36
|
+
d = l - intPart(709 * m / 24);
|
|
37
|
+
y = 30 * n + j - 30;
|
|
38
|
+
return {
|
|
39
|
+
d: d,
|
|
40
|
+
m: m,
|
|
41
|
+
y: y,
|
|
42
|
+
dateOfWeek: jd1 % 7,
|
|
43
|
+
dayName: weekDay(jd1 % 7)
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function IslToGreg(arg) {
|
|
47
|
+
var d = parseInt(arg.HDay.value);
|
|
48
|
+
var m = parseInt(arg.HMonth.value);
|
|
49
|
+
var y = parseInt(arg.HYear.value);
|
|
50
|
+
//added - delta=1 on jd to comply isna rulling
|
|
51
|
+
var jd = intPart((11 * y + 3) / 30) + 354 * y + 30 * m - intPart((m - 1) / 2) + d + 1948440 - 385 - delta;
|
|
52
|
+
var l, n, i, j, k;
|
|
53
|
+
if (jd > 2299160) {
|
|
54
|
+
l = jd + 68569;
|
|
55
|
+
n = intPart(4 * l / 146097);
|
|
56
|
+
l = l - intPart((146097 * n + 3) / 4);
|
|
57
|
+
i = intPart(4000 * (l + 1) / 1461001);
|
|
58
|
+
l = l - intPart(1461 * i / 4) + 31;
|
|
59
|
+
j = intPart(80 * l / 2447);
|
|
60
|
+
d = l - intPart(2447 * j / 80);
|
|
61
|
+
l = intPart(j / 11);
|
|
62
|
+
m = j + 2 - 12 * l;
|
|
63
|
+
y = 100 * (n - 49) + i + l;
|
|
64
|
+
} else {
|
|
65
|
+
j = jd + 1402;
|
|
66
|
+
k = intPart((j - 1) / 1461);
|
|
67
|
+
l = j - 1461 * k;
|
|
68
|
+
n = intPart((l - 1) / 365) - intPart(l / 1461);
|
|
69
|
+
i = l - 365 * n + 30;
|
|
70
|
+
j = intPart(80 * i / 2447);
|
|
71
|
+
d = i - intPart(2447 * j / 80);
|
|
72
|
+
i = intPart(j / 11);
|
|
73
|
+
m = j + 2 - 12 * i;
|
|
74
|
+
y = 4 * k + n + i - 4716;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
//arg.CDay.value=d
|
|
78
|
+
//arg.CMonth.value=m
|
|
79
|
+
//arg.CYear.value=y
|
|
80
|
+
|
|
81
|
+
return {
|
|
82
|
+
d: d,
|
|
83
|
+
m: m,
|
|
84
|
+
y: y,
|
|
85
|
+
dateOfWeek: jd % 7,
|
|
86
|
+
dayName: weekDay(jd % 7)
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
function weekDay(wdn) {
|
|
90
|
+
if (wdn == 0) {
|
|
91
|
+
return "Mon";
|
|
92
|
+
}
|
|
93
|
+
if (wdn == 1) {
|
|
94
|
+
return "Tue";
|
|
95
|
+
}
|
|
96
|
+
if (wdn == 2) {
|
|
97
|
+
return "Wed";
|
|
98
|
+
}
|
|
99
|
+
if (wdn == 3) {
|
|
100
|
+
return "Thu";
|
|
101
|
+
}
|
|
102
|
+
if (wdn == 4) {
|
|
103
|
+
return "Fri";
|
|
104
|
+
}
|
|
105
|
+
if (wdn == 5) {
|
|
106
|
+
return "Sat";
|
|
107
|
+
}
|
|
108
|
+
if (wdn == 6) {
|
|
109
|
+
return "Sun";
|
|
110
|
+
}
|
|
111
|
+
return "";
|
|
112
|
+
}
|
|
113
|
+
function GregToHijri(gregDate) {
|
|
114
|
+
var hijriDate = GregToIsl({
|
|
115
|
+
CDay: {
|
|
116
|
+
value: gregDate.getDate()
|
|
117
|
+
},
|
|
118
|
+
CYear: {
|
|
119
|
+
value: gregDate.getFullYear()
|
|
120
|
+
},
|
|
121
|
+
CMonth: {
|
|
122
|
+
value: gregDate.getMonth() + 1
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
return {
|
|
126
|
+
year: hijriDate.y,
|
|
127
|
+
month: hijriDate.m,
|
|
128
|
+
date: hijriDate.d,
|
|
129
|
+
hours: gregDate.getHours(),
|
|
130
|
+
minutes: gregDate.getMinutes(),
|
|
131
|
+
seconds: gregDate.getSeconds(),
|
|
132
|
+
milliseconds: gregDate.getMilliseconds(),
|
|
133
|
+
day: hijriDate.dateOfWeek,
|
|
134
|
+
dayName: hijriDate.dayName
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
function HijriToGreg(hijriDate) {
|
|
138
|
+
var gregDate = IslToGreg({
|
|
139
|
+
HDay: {
|
|
140
|
+
value: hijriDate._date || hijriDate.date
|
|
141
|
+
},
|
|
142
|
+
HYear: {
|
|
143
|
+
value: hijriDate._year || hijriDate.year
|
|
144
|
+
},
|
|
145
|
+
HMonth: {
|
|
146
|
+
value: hijriDate._month || hijriDate.month
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
return new Date(gregDate.y, gregDate.m - 1, gregDate.d, hijriDate.getHours(), hijriDate.getMinutes(), hijriDate.getSeconds(), hijriDate.getMilliseconds());
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export { GregToHijri, HijriToGreg, weekDay };
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import HijriDate from './HijriDate.js';
|
|
4
|
+
|
|
5
|
+
var dateFormat = function () {
|
|
6
|
+
var token = /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,
|
|
7
|
+
pad = function pad(val, len) {
|
|
8
|
+
val = String(val);
|
|
9
|
+
len = len || 2;
|
|
10
|
+
while (val.length < len) val = "0" + val;
|
|
11
|
+
return val;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
// Regexes and supporting functions are cached through closure
|
|
15
|
+
return function (date, mask) {
|
|
16
|
+
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
|
|
17
|
+
utc: false
|
|
18
|
+
};
|
|
19
|
+
var locales = HijriDate.locales,
|
|
20
|
+
defaultLocale = HijriDate.defaultLocale;
|
|
21
|
+
options.locale = options.locale || defaultLocale;
|
|
22
|
+
if (!locales[options.locale]) {
|
|
23
|
+
throw new Error("Locale ".concat(options.locale, " is not supported yet .\n Please, try to extend \"HijriDate.locales\" :\n i.e: HijriDate.locales.").concat(options.locale, " = {dayNames:[..14 items..], monthNames:[..24 items..]}\n "));
|
|
24
|
+
}
|
|
25
|
+
// You can't provide utc if you skip other args (use the "UTC:" mask prefix)
|
|
26
|
+
if (arguments.length == 1 && Object.prototype.toString.call(date) == "[object String]" && !/\d/.test(date)) {
|
|
27
|
+
mask = date;
|
|
28
|
+
date = undefined;
|
|
29
|
+
}
|
|
30
|
+
mask = String(masks[mask] || mask || masks["default"]);
|
|
31
|
+
|
|
32
|
+
// Allow setting the utc argument via the mask
|
|
33
|
+
if (mask.slice(0, 4) == "UTC:") {
|
|
34
|
+
mask = mask.slice(4);
|
|
35
|
+
options.utc = true;
|
|
36
|
+
}
|
|
37
|
+
var _ = options.utc ? "getUTC" : "get",
|
|
38
|
+
d = date[_ + "Date"](),
|
|
39
|
+
D = date[_ + "Day"](),
|
|
40
|
+
M = date[_ + "Month"](),
|
|
41
|
+
mIndex = date[_ + "MonthIndex"](),
|
|
42
|
+
y = date[_ + "FullYear"](),
|
|
43
|
+
H = date[_ + "Hours"](),
|
|
44
|
+
m = date[_ + "Minutes"](),
|
|
45
|
+
s = date[_ + "Seconds"](),
|
|
46
|
+
L = date[_ + "Milliseconds"](),
|
|
47
|
+
o = options.utc ? 0 : date.getTimezoneOffset(),
|
|
48
|
+
flags = {
|
|
49
|
+
d: d,
|
|
50
|
+
dd: pad(d),
|
|
51
|
+
ddd: locales[options.locale].dayNames[D === 7 ? 0 : D + 1],
|
|
52
|
+
dddd: locales[options.locale].dayNames[(D === 7 ? 0 : D + 1) + 7],
|
|
53
|
+
ee: locales[options.locale].dayNames[D],
|
|
54
|
+
eee: locales[options.locale].dayNames[D + 7],
|
|
55
|
+
eeee: locales[options.locale].dayNames[D + 14],
|
|
56
|
+
eeeeee: locales[options.locale].dayNames[D],
|
|
57
|
+
M: M,
|
|
58
|
+
MM: pad(M),
|
|
59
|
+
MMM: locales[options.locale].monthNames[mIndex],
|
|
60
|
+
MMMM: locales[options.locale].monthNames[mIndex + 12],
|
|
61
|
+
yy: String(y).slice(2),
|
|
62
|
+
yyyy: y,
|
|
63
|
+
h: H % 12 || 12,
|
|
64
|
+
hh: pad(H % 12 || 12),
|
|
65
|
+
H: H,
|
|
66
|
+
HH: pad(H),
|
|
67
|
+
m: m,
|
|
68
|
+
mm: pad(m),
|
|
69
|
+
s: s,
|
|
70
|
+
ss: pad(s),
|
|
71
|
+
l: pad(L, 3),
|
|
72
|
+
L: pad(L > 99 ? Math.round(L / 10) : L),
|
|
73
|
+
a: H < 12 ? locales[options.locale].am : locales[options.locale].pm,
|
|
74
|
+
aa: H < 12 ? locales[options.locale].am : locales[options.locale].pm,
|
|
75
|
+
aaa: H < 12 ? locales[options.locale].am : locales[options.locale].pm,
|
|
76
|
+
aaaa: H < 12 ? locales[options.locale].am : locales[options.locale].pm,
|
|
77
|
+
aaaaa: H < 12 ? locales[options.locale].am : locales[options.locale].pm,
|
|
78
|
+
"'at'": locales[options.locale].separator,
|
|
79
|
+
t: H < 12 ? "a" : "p",
|
|
80
|
+
tt: H < 12 ? "am" : "pm",
|
|
81
|
+
T: H < 12 ? "A" : "P",
|
|
82
|
+
TT: H < 12 ? "AM" : "PM",
|
|
83
|
+
// Z: options.utc ? "UTC" : (String(date).match(timezone) || [""]).pop().replace(timezoneClip, ""),
|
|
84
|
+
o: (o > 0 ? "-" : "+") + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4),
|
|
85
|
+
S: ["th", "st", "nd", "rd"][d % 10 > 3 ? 0 : (d % 100 - d % 10 != 10) * d % 10]
|
|
86
|
+
};
|
|
87
|
+
return mask.replace(token, function ($0) {
|
|
88
|
+
if ($0 === "P") return "".concat(flags.d, "/").concat(flags.M, "/").concat(flags.yyyy, " ");
|
|
89
|
+
if ($0.startsWith("PP")) return "".concat(flags.MMM, " ").concat(flags.dd, ", ").concat(flags.yyyy, " ");
|
|
90
|
+
if ($0 === "p") return "".concat(flags.h, ":").concat(flags.m, " ").concat(flags.a);
|
|
91
|
+
if ($0.startsWith("pp")) return "".concat(flags.hh, ":").concat(flags.mm, ":").concat(flags.ss, " ").concat(flags.a);
|
|
92
|
+
return $0 in flags ? flags[$0] : $0.slice(1, $0.length - 1);
|
|
93
|
+
});
|
|
94
|
+
};
|
|
95
|
+
}();
|
|
96
|
+
|
|
97
|
+
// Some common format strings
|
|
98
|
+
var masks = {
|
|
99
|
+
"default": "ddd MMM dd yyyy HH:mm:ss",
|
|
100
|
+
shortDate: "M/d/yy",
|
|
101
|
+
mediumDate: "MMM d, yyyy",
|
|
102
|
+
longDate: "MMMM d, yyyy",
|
|
103
|
+
fullDate: "dddd, MMMM d, yyyy",
|
|
104
|
+
shortTime: "h:mm TT",
|
|
105
|
+
mediumTime: "h:mm:ss TT",
|
|
106
|
+
longTime: "h:mm:ss TT Z",
|
|
107
|
+
isoDate: "yyyy-MM-dd",
|
|
108
|
+
isoTime: "HH:mm:ss",
|
|
109
|
+
isoDateTime: "yyyy-MM-dd'T'HH:mm:ss",
|
|
110
|
+
isoUtcDateTime: "UTC:yyyy-MM-dd'T'HH:mm:ss'Z'"
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
export { dateFormat as default, masks };
|