@react-fabric/date 1.0.0-beta.9 → 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.
- 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/DateCell.js +5 -7
- package/dist/cjs/components/DateHeader.js +27 -20
- package/dist/cjs/components/DatePage.js +10 -12
- package/dist/cjs/components/DecadePage.js +3 -3
- package/dist/cjs/components/MonthPage.js +3 -3
- package/dist/cjs/components/TimeSliders.js +36 -35
- package/dist/cjs/components/YearPage.js +3 -3
- package/dist/cjs/display/DateDisplay.js +25 -8
- package/dist/cjs/display/DateDuration.js +155 -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 +15 -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/date.json.js +213 -0
- package/dist/cjs/i18n/en/date.json.js +83 -0
- package/dist/cjs/i18n/index.js +4 -10
- package/dist/cjs/index.js +41 -2
- package/dist/cjs/panels/BasePanel.js +6 -5
- package/dist/cjs/panels/DatePanel.js +45 -21
- package/dist/cjs/{superdate → panels}/EventPanel.js +28 -12
- package/dist/cjs/panels/RangePanel.js +49 -19
- package/dist/cjs/utils/dateUtil.js +3 -5
- package/dist/esm/components/DateCell.js +6 -8
- package/dist/esm/components/DateHeader.js +28 -21
- package/dist/esm/components/DatePage.js +11 -13
- package/dist/esm/components/DecadePage.js +3 -3
- package/dist/esm/components/MonthPage.js +3 -3
- package/dist/esm/components/TimeSliders.js +38 -37
- package/dist/esm/components/YearPage.js +3 -3
- package/dist/esm/display/DateDisplay.js +26 -9
- package/dist/esm/display/DateDuration.js +155 -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 +15 -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/date.json.js +209 -0
- package/dist/esm/i18n/en/date.json.js +79 -0
- package/dist/esm/i18n/index.js +2 -8
- package/dist/esm/index.js +36 -1
- package/dist/esm/panels/BasePanel.js +6 -5
- package/dist/esm/panels/DatePanel.js +48 -24
- package/dist/esm/{superdate → panels}/EventPanel.js +29 -13
- package/dist/esm/panels/RangePanel.js +52 -22
- package/dist/esm/utils/dateUtil.js +4 -6
- package/dist/types/components/DateCell.d.ts +1 -1
- package/dist/types/components/DateHeader.d.ts +1 -1
- package/dist/types/components/DatePage.d.ts +1 -1
- package/dist/types/components/DecadePage.d.ts +1 -1
- package/dist/types/components/MonthPage.d.ts +1 -1
- package/dist/types/components/TimeSliders.d.ts +1 -1
- package/dist/types/components/YearPage.d.ts +1 -1
- package/dist/types/display/DateDisplay.d.ts +17 -4
- package/dist/types/display/DateDuration.d.ts +25 -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 +32 -1
- package/dist/types/panels/BasePanel.d.ts +1 -1
- package/dist/types/panels/DatePanel.d.ts +22 -1
- package/dist/types/panels/EventPanel.d.ts +17 -0
- package/dist/types/panels/RangePanel.d.ts +19 -1
- package/dist/types/types/index.d.ts +8 -40
- package/package.json +14 -21
- package/src/components/DateCell.tsx +20 -75
- package/src/components/DateHeader.tsx +27 -78
- package/src/components/DatePage.tsx +11 -36
- package/src/components/DecadePage.tsx +2 -2
- package/src/components/MonthPage.tsx +2 -2
- package/src/components/TimeSliders.tsx +20 -60
- package/src/components/YearPage.tsx +2 -2
- package/src/display/DateDisplay.tsx +26 -38
- package/src/display/DateDuration.tsx +170 -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/date.json +203 -0
- package/src/i18n/en/date.json +73 -0
- package/src/i18n/index.ts +2 -5
- package/src/index.ts +29 -18
- package/src/panels/BasePanel.tsx +7 -10
- package/src/panels/DatePanel.tsx +41 -33
- package/src/{superdate → panels}/EventPanel.tsx +52 -53
- package/src/panels/RangePanel.tsx +54 -60
- package/src/types/index.ts +8 -43
- package/src/utils/dateUtil.ts +26 -82
- package/dist/cjs/components/Date.module.css +0 -1
- package/dist/cjs/i18n/ar.json.js +0 -25
- package/dist/cjs/i18n/en.json.js +0 -21
- 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/ar.json.js +0 -21
- package/dist/esm/i18n/en.json.js +0 -18
- 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/ar.json +0 -14
- package/src/i18n/en.json +0 -13
- 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
|
@@ -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 };
|
|
@@ -0,0 +1,528 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import _typeof from '@babel/runtime/helpers/typeof';
|
|
4
|
+
import _classCallCheck from '@babel/runtime/helpers/classCallCheck';
|
|
5
|
+
import _createClass from '@babel/runtime/helpers/createClass';
|
|
6
|
+
import { HijriToGreg, weekDay } from './DateConverter.js';
|
|
7
|
+
import Initializer from './initializer.js';
|
|
8
|
+
import dateFormat from './FormatDate.js';
|
|
9
|
+
import { en, ar } from './locales.js';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
The class which handles Hijri 🌙 instances
|
|
13
|
+
|
|
14
|
+
@example new HijriDate(); //now
|
|
15
|
+
new HijriDate(1438, 12, 10) ; // يوم عيد الأضحى لسنة ١٤٣٨
|
|
16
|
+
new HijriDate(1438,7, 20, 18, 50, 44, 333); // Monday Rajab 20 1438 18:50:44
|
|
17
|
+
new HijriDate({year:1355, hours:17}); // Tue Muharram 01 1355 17:00:00
|
|
18
|
+
new HijriDate(1484408713014);
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
new HijriDate().toGregorian(); // === new Date();
|
|
22
|
+
new Date().toHijri(); // === new HijriDate();
|
|
23
|
+
*/
|
|
24
|
+
var HijriDate = /*#__PURE__*/function () {
|
|
25
|
+
/**
|
|
26
|
+
*
|
|
27
|
+
* @param {number} time numeric value of the specified date as the number of milliseconds since Shawwal 23, 1389, 00:00:00 UTC (January 1, 1970, 00:00:00 UTC)
|
|
28
|
+
* @example new HijriDate(1435454346342) // Sunday Ramadan 12 1436 04:19:06
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @param {number} year the hijri year .
|
|
33
|
+
* @param {number} month [1, 12] range .
|
|
34
|
+
* @param {number} [date=1] the date of the month🌔 ∈ {1, 30} .
|
|
35
|
+
* @param {number} [hours=0] ⏰ ∈ {0, 23} .
|
|
36
|
+
* @param {number} [minutes=0] 🕔 ∈ {0,59} .
|
|
37
|
+
* @param {number} [seconds=0] 🕰 ∈ {0,59} .
|
|
38
|
+
* @param {number} [milliseconds 0] 🕰 ∈ {0,999} .
|
|
39
|
+
*
|
|
40
|
+
* @example new HijriDate(1450, 3) ; //Sun Rabee1 01 1450 00:00:00
|
|
41
|
+
new HijriDate(1450, 3, 5) ; //Thu Rabee1 05 1450 00:00:00
|
|
42
|
+
new HijriDate(1450, 3, 5, 17) ; //Thu Rabee1 05 1450 17:00:00
|
|
43
|
+
new HijriDate(1450, 3, 5, 16, 44) ; //Thu Rabee1 05 1450 16:44:00
|
|
44
|
+
new HijriDate(1450, 3, 5, 16, 44, 58) ; //Thu Rabee1 05 1450 16:44:58
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* @param {string} date stringified date
|
|
49
|
+
* @param {string} [format = 'yyyy/mm/dd'] a compatible format with the date passed as string in the 1ˢᵗ argument.
|
|
50
|
+
* @example new HijriDate('10-09-1538', 'dd-mm-yyyy'); // Thu Rmdn 10 1538 00:00:00
|
|
51
|
+
new HijriDate('100 years since 04-1348','100 years since mm-yyyy' ); // Wed Rab2 01 1338 00:00:00
|
|
52
|
+
*/
|
|
53
|
+
/**
|
|
54
|
+
* @param {Object} dateProps literal object contains date properties .
|
|
55
|
+
* @param {number} dateProps.year the year is required .
|
|
56
|
+
* @param {number} [dateProps.month = 1] [1, 12] range .
|
|
57
|
+
* @param {number} [dateProps.date = 1] the date of the month🌔 ∈ {1, 30} .
|
|
58
|
+
* @param {number} [dateProps.hours = 0] ⏰ ∈ {0, 23} .
|
|
59
|
+
* @param {number} [dateProps.minutes = 0] 🕔 ∈ {0,59} .
|
|
60
|
+
* @param {number} [dateProps.seconds = 0] 🕰 ∈ {0,59} .
|
|
61
|
+
* @param {number} [dateProps.milliseconds = 0] 🕰 ∈ {0,999} .
|
|
62
|
+
*
|
|
63
|
+
* @example new HijriDate({year: 1430, minutes: 54}) // 01-01-1430 00:54:00
|
|
64
|
+
new HijriDate({year: 1504, hours: 17, seconds:44}) // 01-01-1504 17:00:44
|
|
65
|
+
*/
|
|
66
|
+
function HijriDate() {
|
|
67
|
+
_classCallCheck(this, HijriDate);
|
|
68
|
+
return this.init.apply(this, arguments);
|
|
69
|
+
}
|
|
70
|
+
return _createClass(HijriDate, [{
|
|
71
|
+
key: "init",
|
|
72
|
+
value: function init() {
|
|
73
|
+
var _this = this;
|
|
74
|
+
var props = {};
|
|
75
|
+
if (!arguments.length) {
|
|
76
|
+
props = Initializer.initDefault();
|
|
77
|
+
} else {
|
|
78
|
+
try {
|
|
79
|
+
var methodNameSuffix = Array.from(arguments).map(function (arg) {
|
|
80
|
+
return _typeof(arg);
|
|
81
|
+
}).join('_');
|
|
82
|
+
props = Initializer['init_' + methodNameSuffix].apply(Initializer, arguments);
|
|
83
|
+
} catch (e) {
|
|
84
|
+
throw new TypeError(hijriTypeErrorMessage + '\n--- Details:\n' + e);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
Object.keys(props).forEach(function (prop) {
|
|
88
|
+
_this['_' + prop] = props[prop];
|
|
89
|
+
});
|
|
90
|
+
this.__proxy__ = HijriToGreg(this);
|
|
91
|
+
this.initDayOfWeek();
|
|
92
|
+
return this;
|
|
93
|
+
}
|
|
94
|
+
}, {
|
|
95
|
+
key: "initDayOfWeek",
|
|
96
|
+
value: function initDayOfWeek() {
|
|
97
|
+
if (!this.__proxy__) return;
|
|
98
|
+
this._day = this._day || this.__proxy__.getDay();
|
|
99
|
+
this._dayName = this._dayName || weekDay(this._day);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Get the year
|
|
103
|
+
* @returns {number} the year
|
|
104
|
+
*/
|
|
105
|
+
}, {
|
|
106
|
+
key: "year",
|
|
107
|
+
get: function get() {
|
|
108
|
+
return this._year;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Set the year
|
|
113
|
+
* @param {number} newYear year modifier of the instance.
|
|
114
|
+
* @returns {undefined} nothing
|
|
115
|
+
*
|
|
116
|
+
* @example const d1 = new HijriDate(1399, 10, 25);
|
|
117
|
+
d1.year += 2;
|
|
118
|
+
assertEqual(d1.year === 1401);
|
|
119
|
+
*/,
|
|
120
|
+
set: function set(newYear) {
|
|
121
|
+
this._year = newYear;
|
|
122
|
+
this.updateProxy();
|
|
123
|
+
}
|
|
124
|
+
}, {
|
|
125
|
+
key: "month",
|
|
126
|
+
get: function get() {
|
|
127
|
+
return this._month;
|
|
128
|
+
},
|
|
129
|
+
set: function set(newMonth) {
|
|
130
|
+
this._month = newMonth;
|
|
131
|
+
this.updateProxy();
|
|
132
|
+
}
|
|
133
|
+
}, {
|
|
134
|
+
key: "date",
|
|
135
|
+
get: function get() {
|
|
136
|
+
return this._date;
|
|
137
|
+
},
|
|
138
|
+
set: function set(newDate) {
|
|
139
|
+
this._date = newDate;
|
|
140
|
+
this.updateProxy();
|
|
141
|
+
}
|
|
142
|
+
//---time getters and setters
|
|
143
|
+
}, {
|
|
144
|
+
key: "time",
|
|
145
|
+
get: function get() {
|
|
146
|
+
return this.__proxy__.getTime();
|
|
147
|
+
},
|
|
148
|
+
set: function set(newTime) {
|
|
149
|
+
var _this2 = this;
|
|
150
|
+
var props = Initializer.init_number(newTime);
|
|
151
|
+
Object.keys(props).forEach(function (prop) {
|
|
152
|
+
_this2['_' + prop] = props[prop];
|
|
153
|
+
});
|
|
154
|
+
this.__proxy__ = new Date(newTime);
|
|
155
|
+
}
|
|
156
|
+
}, {
|
|
157
|
+
key: "hours",
|
|
158
|
+
get: function get() {
|
|
159
|
+
return this._hours || 0;
|
|
160
|
+
},
|
|
161
|
+
set: function set(hours) {
|
|
162
|
+
this._hours = hours;
|
|
163
|
+
this.updateProxy();
|
|
164
|
+
}
|
|
165
|
+
}, {
|
|
166
|
+
key: "minutes",
|
|
167
|
+
get: function get() {
|
|
168
|
+
return this._minutes || 0;
|
|
169
|
+
},
|
|
170
|
+
set: function set(minutes) {
|
|
171
|
+
this._minutes = minutes;
|
|
172
|
+
this.updateProxy();
|
|
173
|
+
}
|
|
174
|
+
}, {
|
|
175
|
+
key: "seconds",
|
|
176
|
+
get: function get() {
|
|
177
|
+
return this._seconds || 0;
|
|
178
|
+
},
|
|
179
|
+
set: function set(seconds) {
|
|
180
|
+
this._seconds = seconds;
|
|
181
|
+
this.updateProxy();
|
|
182
|
+
}
|
|
183
|
+
}, {
|
|
184
|
+
key: "milliseconds",
|
|
185
|
+
get: function get() {
|
|
186
|
+
return this._milliseconds || 0;
|
|
187
|
+
},
|
|
188
|
+
set: function set(milliseconds) {
|
|
189
|
+
this._milliseconds = milliseconds;
|
|
190
|
+
this.updateProxy();
|
|
191
|
+
}
|
|
192
|
+
}, {
|
|
193
|
+
key: "timezoneOffset",
|
|
194
|
+
get: function get() {
|
|
195
|
+
return this.__proxy__.getTimezoneOffset();
|
|
196
|
+
}
|
|
197
|
+
}, {
|
|
198
|
+
key: "day",
|
|
199
|
+
get: function get() {
|
|
200
|
+
return this._day;
|
|
201
|
+
}
|
|
202
|
+
}, {
|
|
203
|
+
key: "dayName",
|
|
204
|
+
get: function get() {
|
|
205
|
+
return this._dayName;
|
|
206
|
+
}
|
|
207
|
+
}, {
|
|
208
|
+
key: "getFullYear",
|
|
209
|
+
value: function getFullYear() {
|
|
210
|
+
return this.year;
|
|
211
|
+
}
|
|
212
|
+
}, {
|
|
213
|
+
key: "getMonthIndex",
|
|
214
|
+
value: function getMonthIndex() {
|
|
215
|
+
return this.month - 1;
|
|
216
|
+
}
|
|
217
|
+
}, {
|
|
218
|
+
key: "getMonth",
|
|
219
|
+
value: function getMonth() {
|
|
220
|
+
return this.month;
|
|
221
|
+
}
|
|
222
|
+
}, {
|
|
223
|
+
key: "getDate",
|
|
224
|
+
value: function getDate() {
|
|
225
|
+
return this.date;
|
|
226
|
+
}
|
|
227
|
+
}, {
|
|
228
|
+
key: "getDay",
|
|
229
|
+
value: function getDay() {
|
|
230
|
+
return this.day;
|
|
231
|
+
}
|
|
232
|
+
}, {
|
|
233
|
+
key: "getHours",
|
|
234
|
+
value: function getHours() {
|
|
235
|
+
return this.hours;
|
|
236
|
+
}
|
|
237
|
+
}, {
|
|
238
|
+
key: "getMinutes",
|
|
239
|
+
value: function getMinutes() {
|
|
240
|
+
return this.minutes;
|
|
241
|
+
}
|
|
242
|
+
}, {
|
|
243
|
+
key: "getSeconds",
|
|
244
|
+
value: function getSeconds() {
|
|
245
|
+
return this.seconds;
|
|
246
|
+
}
|
|
247
|
+
}, {
|
|
248
|
+
key: "getMilliseconds",
|
|
249
|
+
value: function getMilliseconds() {
|
|
250
|
+
return this.milliseconds;
|
|
251
|
+
}
|
|
252
|
+
}, {
|
|
253
|
+
key: "getTime",
|
|
254
|
+
value: function getTime() {
|
|
255
|
+
return this.time;
|
|
256
|
+
}
|
|
257
|
+
}, {
|
|
258
|
+
key: "getTimezoneOffset",
|
|
259
|
+
value: function getTimezoneOffset() {
|
|
260
|
+
return this.timezoneOffset;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* This method adds 1 day (24 hours) to the instance.
|
|
265
|
+
* @returns {HijriDate} the instance itself after adding 1 day.
|
|
266
|
+
*/
|
|
267
|
+
}, {
|
|
268
|
+
key: "addDay",
|
|
269
|
+
value: function addDay() {
|
|
270
|
+
return this.addHours(24);
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* This method adds n day(s) to the instance.
|
|
274
|
+
* @param {number} days number of days to add .
|
|
275
|
+
* @returns {HijriDate} the instance itself after adding n day(s).
|
|
276
|
+
*/
|
|
277
|
+
}, {
|
|
278
|
+
key: "addDays",
|
|
279
|
+
value: function addDays(days) {
|
|
280
|
+
var _this3 = this;
|
|
281
|
+
if (typeof days === 'number') Array.from({
|
|
282
|
+
length: days
|
|
283
|
+
}, function (v, k) {
|
|
284
|
+
return k + 1;
|
|
285
|
+
}).forEach(function (i) {
|
|
286
|
+
return _this3.addDay();
|
|
287
|
+
});
|
|
288
|
+
return this;
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* TODO
|
|
292
|
+
*/
|
|
293
|
+
}, {
|
|
294
|
+
key: "addHours",
|
|
295
|
+
value: function addHours(n) {
|
|
296
|
+
return this.addMinutes(n * 60);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* TODO
|
|
301
|
+
*/
|
|
302
|
+
}, {
|
|
303
|
+
key: "addMinutes",
|
|
304
|
+
value: function addMinutes(n) {
|
|
305
|
+
return this.addSeconds(n * 60);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* TODO
|
|
310
|
+
*/
|
|
311
|
+
}, {
|
|
312
|
+
key: "addSeconds",
|
|
313
|
+
value: function addSeconds(n) {
|
|
314
|
+
return this.addMilliseconds(1000 * n);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* TODO
|
|
319
|
+
*/
|
|
320
|
+
}, {
|
|
321
|
+
key: "addMilliseconds",
|
|
322
|
+
value: function addMilliseconds(n) {
|
|
323
|
+
this.time += n;
|
|
324
|
+
return this;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* TODO
|
|
329
|
+
*/
|
|
330
|
+
}, {
|
|
331
|
+
key: "subtractDays",
|
|
332
|
+
value: function subtractDays(days) {
|
|
333
|
+
var _this4 = this;
|
|
334
|
+
Array.from({
|
|
335
|
+
length: days
|
|
336
|
+
}, function (v, k) {
|
|
337
|
+
return k + 1;
|
|
338
|
+
}).forEach(function (i) {
|
|
339
|
+
return _this4.subtractDay();
|
|
340
|
+
});
|
|
341
|
+
return this;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* TODO
|
|
346
|
+
*/
|
|
347
|
+
}, {
|
|
348
|
+
key: "subtractDay",
|
|
349
|
+
value: function subtractDay() {
|
|
350
|
+
return this.subtractHours(24);
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* TODO
|
|
355
|
+
*/
|
|
356
|
+
}, {
|
|
357
|
+
key: "subtractHours",
|
|
358
|
+
value: function subtractHours(n) {
|
|
359
|
+
return this.subtractMinutes(n * 60);
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* TODO
|
|
364
|
+
*/
|
|
365
|
+
}, {
|
|
366
|
+
key: "subtractMinutes",
|
|
367
|
+
value: function subtractMinutes(n) {
|
|
368
|
+
return this.subtractSeconds(n * 60);
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* TODO
|
|
373
|
+
*/
|
|
374
|
+
}, {
|
|
375
|
+
key: "subtractSeconds",
|
|
376
|
+
value: function subtractSeconds(n) {
|
|
377
|
+
return this.subtractMilliseconds(1000 * n);
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* TODO
|
|
382
|
+
*/
|
|
383
|
+
}, {
|
|
384
|
+
key: "subtractMilliseconds",
|
|
385
|
+
value: function subtractMilliseconds(n) {
|
|
386
|
+
return this.addMilliseconds(-n);
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* TODO
|
|
391
|
+
*/
|
|
392
|
+
}, {
|
|
393
|
+
key: "updateProxy",
|
|
394
|
+
value: function updateProxy() {
|
|
395
|
+
this.__proxy__ = HijriToGreg(this);
|
|
396
|
+
return this;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
/**
|
|
400
|
+
* TODO
|
|
401
|
+
*/
|
|
402
|
+
}, {
|
|
403
|
+
key: "toGregorian",
|
|
404
|
+
value: function toGregorian() {
|
|
405
|
+
return this.__proxy__;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* TODO
|
|
410
|
+
*/
|
|
411
|
+
}, {
|
|
412
|
+
key: "format",
|
|
413
|
+
value: function format(mask, options) {
|
|
414
|
+
return dateFormat.apply(void 0, [this].concat(Array.prototype.slice.call(arguments)));
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* TODO
|
|
419
|
+
*/
|
|
420
|
+
}, {
|
|
421
|
+
key: "ignoreTime",
|
|
422
|
+
value: function ignoreTime() {
|
|
423
|
+
this.hours = 0;
|
|
424
|
+
this.minutes = 0;
|
|
425
|
+
this.seconds = 0;
|
|
426
|
+
this.milliseconds = 0;
|
|
427
|
+
this.updateProxy();
|
|
428
|
+
return this;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* TODO
|
|
433
|
+
*/
|
|
434
|
+
}, {
|
|
435
|
+
key: "clone",
|
|
436
|
+
value: function clone() {
|
|
437
|
+
return new HijriDate(this.time);
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
/**
|
|
441
|
+
* TODO
|
|
442
|
+
*/
|
|
443
|
+
}, {
|
|
444
|
+
key: "is",
|
|
445
|
+
value: function is() {
|
|
446
|
+
var _arguments = arguments,
|
|
447
|
+
_this5 = this;
|
|
448
|
+
if (!arguments.length) throw new Error("function cannot be called without arguments");
|
|
449
|
+
if (arguments.length === 1 && _typeof(arguments[0]) === 'object' && Object.keys(arguments[0]).length) return Object.keys(arguments[0]).every(function (prop) {
|
|
450
|
+
return parseInt(_arguments[0][prop]) === parseInt(_this5[prop]);
|
|
451
|
+
});
|
|
452
|
+
return Array.from(arguments).every(function (arg, i) {
|
|
453
|
+
return arg === _this5[dateProps[i]];
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
/**
|
|
458
|
+
* TODO
|
|
459
|
+
*/
|
|
460
|
+
}, {
|
|
461
|
+
key: "isToday",
|
|
462
|
+
value: function isToday() {
|
|
463
|
+
return HijriDate.today().time == this.clone().ignoreTime().time;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
/**
|
|
467
|
+
* TODO
|
|
468
|
+
*/
|
|
469
|
+
}, {
|
|
470
|
+
key: "isYesterday",
|
|
471
|
+
value: function isYesterday() {
|
|
472
|
+
return HijriDate.yesterday().time == this.clone().ignoreTime().time;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
/**
|
|
476
|
+
* TODO
|
|
477
|
+
*/
|
|
478
|
+
}, {
|
|
479
|
+
key: "isTomorrow",
|
|
480
|
+
value: function isTomorrow() {
|
|
481
|
+
return HijriDate.tomorrow().time == this.clone().ignoreTime().time;
|
|
482
|
+
}
|
|
483
|
+
}, {
|
|
484
|
+
key: "valueOf",
|
|
485
|
+
value: function valueOf() {
|
|
486
|
+
return this.getTime();
|
|
487
|
+
}
|
|
488
|
+
}, {
|
|
489
|
+
key: "toString",
|
|
490
|
+
value: function toString() {
|
|
491
|
+
return this.format('default');
|
|
492
|
+
}
|
|
493
|
+
}], [{
|
|
494
|
+
key: "now",
|
|
495
|
+
value: function now() {
|
|
496
|
+
return Date.now();
|
|
497
|
+
}
|
|
498
|
+
}, {
|
|
499
|
+
key: "today",
|
|
500
|
+
value: function today() {
|
|
501
|
+
return new HijriDate().ignoreTime();
|
|
502
|
+
}
|
|
503
|
+
}, {
|
|
504
|
+
key: "yesterday",
|
|
505
|
+
value: function yesterday() {
|
|
506
|
+
return this.today().subtractDay();
|
|
507
|
+
}
|
|
508
|
+
}, {
|
|
509
|
+
key: "tomorrow",
|
|
510
|
+
value: function tomorrow() {
|
|
511
|
+
return this.today().addDay();
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
////TODO
|
|
515
|
+
// static addDay() {
|
|
516
|
+
//
|
|
517
|
+
// }
|
|
518
|
+
}]);
|
|
519
|
+
}();
|
|
520
|
+
HijriDate.locales = {
|
|
521
|
+
ar: ar,
|
|
522
|
+
en: en
|
|
523
|
+
};
|
|
524
|
+
HijriDate.defaultLocale = 'ar';
|
|
525
|
+
var hijriTypeErrorMessage = "\n Wrong call of constructor !\n Please, try to use of the following constructors:\n \u21E2 new HijriDate() ; //current date\n or\n \u21E2 new HijriDate(year, month, day [, hour][, minutes][, seconds][, milliseconds]);\n .i.e: new HijriDate(1438, 12, 23)\n or\n \u21E2 new HijriDate(date[, format])\n .i.e: new HijriDate('1438-12-23', 'yyyy-mm-dd')\n ";
|
|
526
|
+
var dateProps = ['year', 'month', 'date', 'hours', 'minutes', 'seconds', 'milliseconds'];
|
|
527
|
+
|
|
528
|
+
export { dateProps, HijriDate as default };
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import _classCallCheck from '@babel/runtime/helpers/classCallCheck';
|
|
4
|
+
import _createClass from '@babel/runtime/helpers/createClass';
|
|
5
|
+
|
|
6
|
+
var StringDateParser = /*#__PURE__*/function () {
|
|
7
|
+
function StringDateParser() {
|
|
8
|
+
_classCallCheck(this, StringDateParser);
|
|
9
|
+
}
|
|
10
|
+
return _createClass(StringDateParser, null, [{
|
|
11
|
+
key: "extract",
|
|
12
|
+
value: function extract(string, format, formatChunk) {
|
|
13
|
+
var ignoreCase = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
|
|
14
|
+
var targetFormat = ignoreCase ? format.toLowerCase() : format;
|
|
15
|
+
if (targetFormat.includes(formatChunk)) {
|
|
16
|
+
return parseInt(string.substr(targetFormat.indexOf(formatChunk), formatChunk.length));
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}, {
|
|
20
|
+
key: "extractYear",
|
|
21
|
+
value: function extractYear(dateString, format) {
|
|
22
|
+
var year = this.extract.apply(this, Array.prototype.slice.call(arguments).concat(['yyyy']));
|
|
23
|
+
if (!year) {
|
|
24
|
+
year = this.extract.apply(this, Array.prototype.slice.call(arguments).concat(['yy']));
|
|
25
|
+
if (year) year = Number('14' + year);
|
|
26
|
+
}
|
|
27
|
+
return year;
|
|
28
|
+
}
|
|
29
|
+
}, {
|
|
30
|
+
key: "extractMonth",
|
|
31
|
+
value: function extractMonth(dateString, format) {
|
|
32
|
+
var month = this.extract.apply(this, Array.prototype.slice.call(arguments).concat(['mm', false]));
|
|
33
|
+
if (month) return month;
|
|
34
|
+
return 1;
|
|
35
|
+
}
|
|
36
|
+
}, {
|
|
37
|
+
key: "extractDate",
|
|
38
|
+
value: function extractDate(dateString, format) {
|
|
39
|
+
var date = this.extract.apply(this, Array.prototype.slice.call(arguments).concat(['dd', false]));
|
|
40
|
+
if (date) return date;
|
|
41
|
+
return 1;
|
|
42
|
+
}
|
|
43
|
+
}, {
|
|
44
|
+
key: "extractHours",
|
|
45
|
+
value: function extractHours(dateString, format) {
|
|
46
|
+
var hours = this.extract.apply(this, Array.prototype.slice.call(arguments).concat(['hh']));
|
|
47
|
+
if (hours) return hours;
|
|
48
|
+
return 0;
|
|
49
|
+
}
|
|
50
|
+
}, {
|
|
51
|
+
key: "extractMinutes",
|
|
52
|
+
value: function extractMinutes(dateString, format) {
|
|
53
|
+
var minutes = this.extract.apply(this, Array.prototype.slice.call(arguments).concat(['MM', false]));
|
|
54
|
+
if (minutes) return minutes;
|
|
55
|
+
return 0;
|
|
56
|
+
}
|
|
57
|
+
}, {
|
|
58
|
+
key: "extractSeconds",
|
|
59
|
+
value: function extractSeconds(dateString, format) {
|
|
60
|
+
var seconds = this.extract.apply(this, Array.prototype.slice.call(arguments).concat(['ss', false]));
|
|
61
|
+
if (seconds) return seconds;
|
|
62
|
+
return 0;
|
|
63
|
+
}
|
|
64
|
+
}, {
|
|
65
|
+
key: "extractMilliseconds",
|
|
66
|
+
value: function extractMilliseconds(dateString, format) {
|
|
67
|
+
var milliseconds = this.extract.apply(this, Array.prototype.slice.call(arguments).concat(['SS', false]));
|
|
68
|
+
if (milliseconds) return milliseconds;
|
|
69
|
+
return 0;
|
|
70
|
+
}
|
|
71
|
+
}]);
|
|
72
|
+
}();
|
|
73
|
+
|
|
74
|
+
export { StringDateParser as default };
|