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