@react-fabric/date 1.0.0-beta.4 → 1.0.0-beta.40
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/DatePage.js +2 -3
- package/dist/cjs/components/TimeSliders.js +5 -6
- package/dist/cjs/display/DateDisplay.js +5 -1
- package/dist/cjs/hijri/DateConverter.js +154 -0
- package/dist/cjs/hijri/FormatDate.js +115 -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/index.js +0 -6
- package/dist/cjs/index.js +11 -2
- package/dist/cjs/{superdate → panels}/EventPanel.js +16 -4
- package/dist/cjs/utils/dateUtil.js +3 -3
- package/dist/esm/components/DatePage.js +2 -3
- package/dist/esm/components/TimeSliders.js +5 -6
- package/dist/esm/display/DateDisplay.js +5 -1
- package/dist/esm/hijri/DateConverter.js +152 -0
- package/dist/esm/hijri/FormatDate.js +112 -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/index.js +0 -6
- package/dist/esm/index.js +5 -1
- package/dist/esm/{superdate → panels}/EventPanel.js +17 -5
- package/dist/esm/utils/dateUtil.js +3 -3
- package/dist/types/display/DateDisplay.d.ts +2 -1
- 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 +5 -1
- package/dist/types/panels/EventPanel.d.ts +17 -0
- package/dist/types/types/index.d.ts +8 -35
- package/dist/types/utils/dateUtil.d.ts +1 -1
- package/package.json +8 -8
- package/src/components/DatePage.tsx +2 -3
- package/src/components/TimeSliders.tsx +5 -6
- package/src/display/DateDisplay.tsx +5 -1
- package/src/hijri/DateConverter.js +175 -0
- package/src/hijri/FormatDate.js +132 -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/index.ts +0 -3
- package/src/index.ts +6 -1
- package/src/{superdate → panels}/EventPanel.tsx +41 -6
- package/src/types/index.ts +8 -38
- package/src/utils/dateUtil.ts +4 -7
- 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 -169
- 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 -168
- 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 -186
package/dist/types/index.d.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import "./hijri";
|
|
2
2
|
import "./i18n";
|
|
3
|
+
export { DateHeader } from "./components/DateHeader";
|
|
4
|
+
export { DecadePage } from "./components/DecadePage";
|
|
5
|
+
export { YearPage } from "./components/YearPage";
|
|
3
6
|
export { DateDisplay } from "./display/DateDisplay";
|
|
4
7
|
export { DatePanel } from "./panels/DatePanel";
|
|
8
|
+
export { EventPanel } from "./panels/EventPanel";
|
|
5
9
|
export { RangePanel } from "./panels/RangePanel";
|
|
6
|
-
export { SuperDate } from "./superdate/Superdate";
|
|
7
10
|
export { DateUtil } from "./utils/dateUtil";
|
|
11
|
+
export * from "./types";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type EventType } from "../types";
|
|
2
|
+
export interface EventProps {
|
|
3
|
+
isHijri?: boolean;
|
|
4
|
+
/**
|
|
5
|
+
* list of calendar events
|
|
6
|
+
*/
|
|
7
|
+
events?: EventType[];
|
|
8
|
+
/**
|
|
9
|
+
* list of calendar events
|
|
10
|
+
*/
|
|
11
|
+
recurringEvents?: EventType[];
|
|
12
|
+
/**
|
|
13
|
+
* change handler
|
|
14
|
+
*/
|
|
15
|
+
onChange?: (value: string, dates: [string, string]) => void;
|
|
16
|
+
}
|
|
17
|
+
export declare const EventPanel: ({ isHijri, onChange, events, recurringEvents, }: EventProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type CssProp, type TestProps } from "@react-fabric/core/dist/types/types";
|
|
2
2
|
export type DateLike = Date | string | number;
|
|
3
3
|
export type DateParsed = Date | undefined;
|
|
4
4
|
export declare enum PageType {
|
|
@@ -18,6 +18,13 @@ export declare enum DatePart {
|
|
|
18
18
|
YEAR = "$year",
|
|
19
19
|
DECADE = "$decade"
|
|
20
20
|
}
|
|
21
|
+
export interface EventType<D = DateLike> {
|
|
22
|
+
label: string;
|
|
23
|
+
icon?: string;
|
|
24
|
+
start: D;
|
|
25
|
+
end: D;
|
|
26
|
+
hijri?: boolean;
|
|
27
|
+
}
|
|
21
28
|
export interface BaseProps {
|
|
22
29
|
min?: DateLike;
|
|
23
30
|
max?: DateLike;
|
|
@@ -34,37 +41,3 @@ export interface RangeProps extends BaseProps, CssProp, TestProps {
|
|
|
34
41
|
onChange?: (dates: [start: string, end: string]) => void;
|
|
35
42
|
presets?: Record<string, [DateLike, DateLike]>;
|
|
36
43
|
}
|
|
37
|
-
export interface EventType<D = DateLike> {
|
|
38
|
-
label: string;
|
|
39
|
-
icon?: string;
|
|
40
|
-
start: D;
|
|
41
|
-
end: D;
|
|
42
|
-
hijri?: boolean;
|
|
43
|
-
}
|
|
44
|
-
export interface PresetType {
|
|
45
|
-
value: string;
|
|
46
|
-
label: string;
|
|
47
|
-
}
|
|
48
|
-
export interface SuperDateProps {
|
|
49
|
-
as?: "button" | "chip";
|
|
50
|
-
color?: ColorType;
|
|
51
|
-
variant?: "solid" | "outline" | "link";
|
|
52
|
-
/**
|
|
53
|
-
* relative date value
|
|
54
|
-
*/
|
|
55
|
-
value?: string;
|
|
56
|
-
/**
|
|
57
|
-
* change handler
|
|
58
|
-
*/
|
|
59
|
-
onChange?: (value: string, dates: [string, string]) => void;
|
|
60
|
-
/**
|
|
61
|
-
* list of calendar events
|
|
62
|
-
*/
|
|
63
|
-
events?: EventType[];
|
|
64
|
-
/**
|
|
65
|
-
* list of relative presets
|
|
66
|
-
*
|
|
67
|
-
* {value:'$year-5|$year', label:'last 5 years'}
|
|
68
|
-
*/
|
|
69
|
-
presets?: PresetType[];
|
|
70
|
-
}
|
|
@@ -23,7 +23,7 @@ export declare namespace DateUtil {
|
|
|
23
23
|
const isSameMonth: (date: Date, compare: Date, isHijri?: boolean) => boolean;
|
|
24
24
|
const isSameYear: (date: Date, compare: Date, isHijri?: boolean) => boolean;
|
|
25
25
|
const isDisabled: (date: Date, page: PageType, min?: DateLike, max?: DateLike) => boolean;
|
|
26
|
-
const parseDate: (datelike:
|
|
26
|
+
const parseDate: (datelike: DateLike) => Date;
|
|
27
27
|
const parseRange: (datelike: string) => [Date, Date];
|
|
28
28
|
const relativeTooltip: (datelike?: string, isHijri?: boolean) => string;
|
|
29
29
|
const relativeLabel: (datelike?: string, isHijri?: boolean) => string | undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-fabric/date",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.40",
|
|
4
4
|
"description": "RUF: Date package",
|
|
5
5
|
"author": "Adarsh Pastakia <adarshpastakia@outlook.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -11,9 +11,11 @@
|
|
|
11
11
|
"types": "dist/types/index.d.ts",
|
|
12
12
|
"directories": {
|
|
13
13
|
"src": "src",
|
|
14
|
+
"styles": "css",
|
|
14
15
|
"test": "tests"
|
|
15
16
|
},
|
|
16
17
|
"files": [
|
|
18
|
+
"css",
|
|
17
19
|
"src",
|
|
18
20
|
"dist"
|
|
19
21
|
],
|
|
@@ -33,18 +35,16 @@
|
|
|
33
35
|
"watch": "npm-run-all -p watch:rollup watch:dts"
|
|
34
36
|
},
|
|
35
37
|
"dependencies": {
|
|
36
|
-
"@
|
|
37
|
-
"@react-fabric/
|
|
38
|
-
"@react-fabric/form": "^1.0.0-beta.4",
|
|
39
|
-
"@react-fabric/utilities": "^1.0.0-beta.4",
|
|
38
|
+
"@react-fabric/core": "^1.0.0-beta.40",
|
|
39
|
+
"@react-fabric/utilities": "^1.0.0-beta.40",
|
|
40
40
|
"classnames": "^2.5.1",
|
|
41
41
|
"date-fns": "^4.0.0",
|
|
42
42
|
"resize-observer-polyfill": "^1.5.1"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
45
|
"i18next": "^23.15.1",
|
|
46
|
-
"react": "
|
|
47
|
-
"react-dom": "
|
|
46
|
+
"react": "^19.0.0",
|
|
47
|
+
"react-dom": "^19.0.0",
|
|
48
48
|
"react-i18next": "^15.0.2"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
@@ -54,5 +54,5 @@
|
|
|
54
54
|
"node": ">=18.12.0",
|
|
55
55
|
"npm": ">=8.19.0"
|
|
56
56
|
},
|
|
57
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "ede05c84683697d85e28a0ae380cb9b74d693f51"
|
|
58
58
|
}
|
|
@@ -28,7 +28,6 @@ import { DateUtil } from "../utils/dateUtil";
|
|
|
28
28
|
import { DateCell, type DateCellProps } from "./DateCell";
|
|
29
29
|
import classNames from "classnames";
|
|
30
30
|
import { PageType } from "../types";
|
|
31
|
-
import classes from "./Date.module.css";
|
|
32
31
|
|
|
33
32
|
const rows = [0, 1, 2, 3, 4, 5];
|
|
34
33
|
const cols = [0, 1, 2, 3, 4, 5, 6];
|
|
@@ -57,7 +56,7 @@ export const DatePage = ({ pageDate, isHijri, ...props }: Props) => {
|
|
|
57
56
|
>
|
|
58
57
|
<div
|
|
59
58
|
className={classNames(
|
|
60
|
-
|
|
59
|
+
"fabric-dateHeader",
|
|
61
60
|
"px-1 text-center bg-tint-50 h-7",
|
|
62
61
|
)}
|
|
63
62
|
></div>
|
|
@@ -67,7 +66,7 @@ export const DatePage = ({ pageDate, isHijri, ...props }: Props) => {
|
|
|
67
66
|
<div
|
|
68
67
|
key={dt.toISOString()}
|
|
69
68
|
className={classNames(
|
|
70
|
-
|
|
69
|
+
"fabric-dateHeader",
|
|
71
70
|
"font-medium text-sm p-1 mx-px text-center text-muted bg-tint-50 h-7",
|
|
72
71
|
)}
|
|
73
72
|
>
|
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
146
|
+
"fabric-date-timeSlider",
|
|
148
147
|
)}
|
|
149
148
|
onScroll={calculateTime}
|
|
150
149
|
ref={minuteRef}
|
|
@@ -46,6 +46,8 @@ export interface Props
|
|
|
46
46
|
* date format
|
|
47
47
|
*/
|
|
48
48
|
format?: string;
|
|
49
|
+
|
|
50
|
+
showAlternateDate?: boolean;
|
|
49
51
|
}
|
|
50
52
|
|
|
51
53
|
export const DateDisplay = ({
|
|
@@ -53,12 +55,14 @@ export const DateDisplay = ({
|
|
|
53
55
|
className,
|
|
54
56
|
format = "eee, PPpp",
|
|
55
57
|
children,
|
|
58
|
+
showAlternateDate,
|
|
56
59
|
...aria
|
|
57
60
|
}: Props) => {
|
|
58
61
|
const { currentCalendar, currentLocale } = useGlobals();
|
|
59
62
|
|
|
60
63
|
const dtLabel = (
|
|
61
64
|
<Tooltip
|
|
65
|
+
disabled={!showAlternateDate}
|
|
62
66
|
content={DateUtil.format(
|
|
63
67
|
date,
|
|
64
68
|
format,
|
|
@@ -78,7 +82,7 @@ export const DateDisplay = ({
|
|
|
78
82
|
);
|
|
79
83
|
|
|
80
84
|
return children ? (
|
|
81
|
-
<Dropdown>
|
|
85
|
+
<Dropdown showArrow closeOnClick>
|
|
82
86
|
{dtLabel}
|
|
83
87
|
{children}
|
|
84
88
|
</Dropdown>
|
|
@@ -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,132 @@
|
|
|
1
|
+
const dateFormat = (function () {
|
|
2
|
+
const token =
|
|
3
|
+
/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,
|
|
4
|
+
timezone =
|
|
5
|
+
/\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g,
|
|
6
|
+
timezoneClip = /[^-+\dA-Z]/g,
|
|
7
|
+
pad = function (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 (
|
|
16
|
+
date,
|
|
17
|
+
mask,
|
|
18
|
+
options = {
|
|
19
|
+
utc: false,
|
|
20
|
+
},
|
|
21
|
+
) {
|
|
22
|
+
const { locales, defaultLocale } = require("./HijriDate").default;
|
|
23
|
+
options.locale = options.locale || defaultLocale;
|
|
24
|
+
if (!locales[options.locale]) {
|
|
25
|
+
throw new Error(`Locale ${options.locale} is not supported yet .
|
|
26
|
+
Please, try to extend "HijriDate.locales" :
|
|
27
|
+
i.e: HijriDate.locales.${options.locale} = {dayNames:[..14 items..], monthNames:[..24 items..]}
|
|
28
|
+
`);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
// You can't provide utc if you skip other args (use the "UTC:" mask prefix)
|
|
32
|
+
if (
|
|
33
|
+
arguments.length == 1 &&
|
|
34
|
+
Object.prototype.toString.call(date) == "[object String]" &&
|
|
35
|
+
!/\d/.test(date)
|
|
36
|
+
) {
|
|
37
|
+
mask = date;
|
|
38
|
+
date = undefined;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
mask = String(masks[mask] || mask || masks["default"]);
|
|
42
|
+
|
|
43
|
+
// Allow setting the utc argument via the mask
|
|
44
|
+
if (mask.slice(0, 4) == "UTC:") {
|
|
45
|
+
mask = mask.slice(4);
|
|
46
|
+
options.utc = true;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
var _ = options.utc ? "getUTC" : "get",
|
|
50
|
+
d = date[_ + "Date"](),
|
|
51
|
+
D = date[_ + "Day"](),
|
|
52
|
+
M = date[_ + "Month"](),
|
|
53
|
+
mIndex = date[_ + "MonthIndex"](),
|
|
54
|
+
y = date[_ + "FullYear"](),
|
|
55
|
+
H = date[_ + "Hours"](),
|
|
56
|
+
m = date[_ + "Minutes"](),
|
|
57
|
+
s = date[_ + "Seconds"](),
|
|
58
|
+
L = date[_ + "Milliseconds"](),
|
|
59
|
+
o = options.utc ? 0 : date.getTimezoneOffset(),
|
|
60
|
+
flags = {
|
|
61
|
+
d: d,
|
|
62
|
+
dd: pad(d),
|
|
63
|
+
ddd: locales[options.locale].dayNames[D === 7 ? 0 : D + 1],
|
|
64
|
+
dddd: locales[options.locale].dayNames[(D === 7 ? 0 : D + 1) + 7],
|
|
65
|
+
ee: locales[options.locale].dayNames[D],
|
|
66
|
+
eee: locales[options.locale].dayNames[D + 7],
|
|
67
|
+
eeee: locales[options.locale].dayNames[D + 14],
|
|
68
|
+
eeeeee: locales[options.locale].dayNames[D],
|
|
69
|
+
M,
|
|
70
|
+
MM: pad(M),
|
|
71
|
+
MMM: locales[options.locale].monthNames[mIndex],
|
|
72
|
+
MMMM: locales[options.locale].monthNames[mIndex + 12],
|
|
73
|
+
yy: String(y).slice(2),
|
|
74
|
+
yyyy: y,
|
|
75
|
+
h: H % 12 || 12,
|
|
76
|
+
hh: pad(H % 12 || 12),
|
|
77
|
+
H: H,
|
|
78
|
+
HH: pad(H),
|
|
79
|
+
m,
|
|
80
|
+
mm: pad(m),
|
|
81
|
+
s: s,
|
|
82
|
+
ss: pad(s),
|
|
83
|
+
l: pad(L, 3),
|
|
84
|
+
L: pad(L > 99 ? Math.round(L / 10) : L),
|
|
85
|
+
a: H < 12 ? locales[options.locale].am : locales[options.locale].pm,
|
|
86
|
+
aa: H < 12 ? locales[options.locale].am : locales[options.locale].pm,
|
|
87
|
+
aaa: H < 12 ? locales[options.locale].am : locales[options.locale].pm,
|
|
88
|
+
aaaa: H < 12 ? locales[options.locale].am : locales[options.locale].pm,
|
|
89
|
+
aaaaa: H < 12 ? locales[options.locale].am : locales[options.locale].pm,
|
|
90
|
+
"'at'": locales[options.locale].separator,
|
|
91
|
+
t: H < 12 ? "a" : "p",
|
|
92
|
+
tt: H < 12 ? "am" : "pm",
|
|
93
|
+
T: H < 12 ? "A" : "P",
|
|
94
|
+
TT: H < 12 ? "AM" : "PM",
|
|
95
|
+
// Z: options.utc ? "UTC" : (String(date).match(timezone) || [""]).pop().replace(timezoneClip, ""),
|
|
96
|
+
o:
|
|
97
|
+
(o > 0 ? "-" : "+") +
|
|
98
|
+
pad(Math.floor(Math.abs(o) / 60) * 100 + (Math.abs(o) % 60), 4),
|
|
99
|
+
S: ["th", "st", "nd", "rd"][
|
|
100
|
+
d % 10 > 3 ? 0 : (((d % 100) - (d % 10) != 10) * d) % 10
|
|
101
|
+
],
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
return mask.replace(token, function ($0) {
|
|
105
|
+
if ($0 === "P") return `${flags.d}/${flags.M}/${flags.yyyy} `;
|
|
106
|
+
if ($0.startsWith("PP"))
|
|
107
|
+
return `${flags.MMM} ${flags.dd}, ${flags.yyyy} `;
|
|
108
|
+
if ($0 === "p") return `${flags.h}:${flags.m} ${flags.a}`;
|
|
109
|
+
if ($0.startsWith("pp"))
|
|
110
|
+
return `${flags.hh}:${flags.mm}:${flags.ss} ${flags.a}`;
|
|
111
|
+
return $0 in flags ? flags[$0] : $0.slice(1, $0.length - 1);
|
|
112
|
+
});
|
|
113
|
+
};
|
|
114
|
+
})();
|
|
115
|
+
|
|
116
|
+
// Some common format strings
|
|
117
|
+
export const masks = {
|
|
118
|
+
default: "ddd MMM dd yyyy HH:mm:ss",
|
|
119
|
+
shortDate: "M/d/yy",
|
|
120
|
+
mediumDate: "MMM d, yyyy",
|
|
121
|
+
longDate: "MMMM d, yyyy",
|
|
122
|
+
fullDate: "dddd, MMMM d, yyyy",
|
|
123
|
+
shortTime: "h:mm TT",
|
|
124
|
+
mediumTime: "h:mm:ss TT",
|
|
125
|
+
longTime: "h:mm:ss TT Z",
|
|
126
|
+
isoDate: "yyyy-MM-dd",
|
|
127
|
+
isoTime: "HH:mm:ss",
|
|
128
|
+
isoDateTime: "yyyy-MM-dd'T'HH:mm:ss",
|
|
129
|
+
isoUtcDateTime: "UTC:yyyy-MM-dd'T'HH:mm:ss'Z'",
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
export default dateFormat;
|