hijri-date-time-picker 1.0.0 → 1.0.2
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/LICENSE +21 -21
- package/README.md +185 -183
- package/dist/LICENSE +21 -0
- package/dist/README.md +185 -0
- package/dist/demo.d.ts +5 -1
- package/dist/demo.js +213 -173
- package/dist/esm2022/hijri-date-time-picker.mjs +5 -0
- package/dist/esm2022/index.mjs +3 -0
- package/dist/esm2022/lib/hijri-date-picker.component.mjs +606 -0
- package/dist/esm2022/lib/hijri-date-picker.types.mjs +22 -0
- package/dist/fesm2022/hijri-date-time-picker.mjs +634 -0
- package/dist/fesm2022/hijri-date-time-picker.mjs.map +1 -0
- package/dist/lib/hijri-date-picker.component.d.ts +8 -6
- package/dist/lib/hijri-date-picker.component.js +245 -118
- package/dist/lib/hijri-date-picker.types.d.ts +4 -4
- package/dist/lib/hijri-date-picker.types.js +66 -10
- package/package.json +48 -47
|
@@ -7,31 +7,33 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
|
-
import { Component, Input, Output, EventEmitter } from
|
|
11
|
-
import { CommonModule } from
|
|
12
|
-
import HijriDate, { toHijri } from
|
|
13
|
-
import { GREGORIAN_MONTHS_EN, GREGORIAN_MONTHS_AR, HIJRI_MONTHS_EN, HIJRI_MONTHS_AR, WEEKDAY_NAMES_EN, WEEKDAY_NAMES_AR } from
|
|
10
|
+
import { Component, Input, Output, EventEmitter, } from "@angular/core";
|
|
11
|
+
import { CommonModule } from "@angular/common";
|
|
12
|
+
import HijriDate, { toHijri } from "hijri-date/lib/safe";
|
|
13
|
+
import { GREGORIAN_MONTHS_EN, GREGORIAN_MONTHS_AR, HIJRI_MONTHS_EN, HIJRI_MONTHS_AR, WEEKDAY_NAMES_EN, WEEKDAY_NAMES_AR, } from "./hijri-date-picker.types";
|
|
14
14
|
let HijriDatePickerComponent = class HijriDatePickerComponent {
|
|
15
15
|
// Mode & Configuration
|
|
16
16
|
canChangeMode = true;
|
|
17
|
-
mode =
|
|
18
|
-
dir =
|
|
19
|
-
locale =
|
|
17
|
+
mode = "greg";
|
|
18
|
+
dir = "ltr";
|
|
19
|
+
locale = "en";
|
|
20
20
|
// Validation
|
|
21
21
|
futureValidation = true;
|
|
22
22
|
futureYearsLimit = 10;
|
|
23
23
|
isRequired = false;
|
|
24
|
+
minDate; // Minimum selectable date
|
|
25
|
+
maxDate; // Maximum selectable date
|
|
24
26
|
// Selection
|
|
25
27
|
multiple = false;
|
|
26
28
|
showConfirmButton = false;
|
|
27
29
|
initialSelectedDate; // For single selection mode - bind initial date
|
|
28
30
|
initialSelectedDates; // For multiple selection mode - bind initial dates
|
|
29
31
|
// Labels
|
|
30
|
-
submitTextButton =
|
|
31
|
-
todaysDateText =
|
|
32
|
-
ummAlQuraDateText =
|
|
33
|
-
yearSelectLabel =
|
|
34
|
-
monthSelectLabel =
|
|
32
|
+
submitTextButton = "Submit";
|
|
33
|
+
todaysDateText = "Today";
|
|
34
|
+
ummAlQuraDateText = "Umm Al-Qura Calendar";
|
|
35
|
+
yearSelectLabel = "Year";
|
|
36
|
+
monthSelectLabel = "Month";
|
|
35
37
|
// Display Options
|
|
36
38
|
todaysDateSection = true;
|
|
37
39
|
markToday = true;
|
|
@@ -42,7 +44,7 @@ let HijriDatePickerComponent = class HijriDatePickerComponent {
|
|
|
42
44
|
styles = {};
|
|
43
45
|
// Time Configuration
|
|
44
46
|
enableTime = false;
|
|
45
|
-
timeFormat =
|
|
47
|
+
timeFormat = "24";
|
|
46
48
|
minuteStep = 1;
|
|
47
49
|
enableSeconds = false;
|
|
48
50
|
defaultTime;
|
|
@@ -61,12 +63,15 @@ let HijriDatePickerComponent = class HijriDatePickerComponent {
|
|
|
61
63
|
months = [];
|
|
62
64
|
weekdays = [];
|
|
63
65
|
// Time state
|
|
64
|
-
selectedTime = {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
66
|
+
selectedTime = (() => {
|
|
67
|
+
const now = new Date();
|
|
68
|
+
return {
|
|
69
|
+
hours: now.getHours(),
|
|
70
|
+
minutes: now.getMinutes(),
|
|
71
|
+
seconds: now.getSeconds(),
|
|
72
|
+
};
|
|
73
|
+
})();
|
|
74
|
+
isPM = new Date().getHours() >= 12;
|
|
70
75
|
ngOnInit() {
|
|
71
76
|
this.initializeCalendar();
|
|
72
77
|
this.initializeSelectedDates();
|
|
@@ -74,22 +79,50 @@ let HijriDatePickerComponent = class HijriDatePickerComponent {
|
|
|
74
79
|
this.updateLocaleData();
|
|
75
80
|
this.generateYears();
|
|
76
81
|
this.generateCalendar();
|
|
82
|
+
this.submitTextButton = this.locale === "ar" ? "تأكيد" : "Submit";
|
|
83
|
+
this.todaysDateText = this.locale === "ar" ? "اليوم" : "Today";
|
|
84
|
+
this.ummAlQuraDateText =
|
|
85
|
+
this.locale === "ar" ? "تقويم أم القرى" : "Umm Al-Qura Calendar";
|
|
86
|
+
this.yearSelectLabel = this.locale === "ar" ? "السنة" : "Year";
|
|
87
|
+
this.monthSelectLabel = this.locale === "ar" ? "الشهر" : "Month";
|
|
77
88
|
}
|
|
78
89
|
ngOnChanges(changes) {
|
|
79
|
-
if (changes[
|
|
90
|
+
if (changes["mode"] || changes["locale"]) {
|
|
80
91
|
this.updateLocaleData();
|
|
81
92
|
this.generateCalendar();
|
|
82
93
|
}
|
|
83
94
|
// Handle changes to initial selected dates
|
|
84
|
-
if (changes[
|
|
95
|
+
if (changes["initialSelectedDate"] || changes["initialSelectedDates"]) {
|
|
85
96
|
this.initializeSelectedDates();
|
|
86
97
|
this.generateCalendar();
|
|
87
98
|
}
|
|
99
|
+
// Handle changes to minDate or maxDate
|
|
100
|
+
if (changes["minDate"] || changes["maxDate"]) {
|
|
101
|
+
this.generateYears();
|
|
102
|
+
this.generateCalendar();
|
|
103
|
+
}
|
|
88
104
|
}
|
|
89
105
|
initializeCalendar() {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
this.
|
|
106
|
+
// If initialSelectedDate is provided, use it to set the calendar month
|
|
107
|
+
let targetDate;
|
|
108
|
+
if (!this.multiple && this.initialSelectedDate) {
|
|
109
|
+
targetDate = this.initialSelectedDate;
|
|
110
|
+
}
|
|
111
|
+
else if (this.multiple &&
|
|
112
|
+
this.initialSelectedDates &&
|
|
113
|
+
this.initialSelectedDates.length > 0) {
|
|
114
|
+
targetDate = this.initialSelectedDates[0];
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
targetDate = new Date();
|
|
118
|
+
}
|
|
119
|
+
// Set Gregorian calendar to the target date's month
|
|
120
|
+
this.currentYear = targetDate.getFullYear();
|
|
121
|
+
this.currentMonth = targetDate.getMonth();
|
|
122
|
+
// Set Hijri calendar to the target date's month
|
|
123
|
+
const hijriDate = toHijri(targetDate);
|
|
124
|
+
this.currentHijriYear = hijriDate.getFullYear();
|
|
125
|
+
this.currentHijriMonth = hijriDate.getMonth();
|
|
93
126
|
}
|
|
94
127
|
initializeSelectedDates() {
|
|
95
128
|
// Handle single selection mode
|
|
@@ -97,8 +130,10 @@ let HijriDatePickerComponent = class HijriDatePickerComponent {
|
|
|
97
130
|
this.selectedDates = [this.createSelectedDate(this.initialSelectedDate)];
|
|
98
131
|
}
|
|
99
132
|
// Handle multiple selection mode
|
|
100
|
-
if (this.multiple &&
|
|
101
|
-
this.
|
|
133
|
+
if (this.multiple &&
|
|
134
|
+
this.initialSelectedDates &&
|
|
135
|
+
this.initialSelectedDates.length > 0) {
|
|
136
|
+
this.selectedDates = this.initialSelectedDates.map((date) => this.createSelectedDate(date));
|
|
102
137
|
}
|
|
103
138
|
}
|
|
104
139
|
initializeTime() {
|
|
@@ -110,10 +145,10 @@ let HijriDatePickerComponent = class HijriDatePickerComponent {
|
|
|
110
145
|
this.selectedTime = {
|
|
111
146
|
hours: this.defaultTime.hours,
|
|
112
147
|
minutes: this.defaultTime.minutes,
|
|
113
|
-
seconds: this.defaultTime.seconds || 0
|
|
148
|
+
seconds: this.defaultTime.seconds || 0,
|
|
114
149
|
};
|
|
115
150
|
// Set AM/PM for 12-hour format
|
|
116
|
-
if (this.timeFormat ===
|
|
151
|
+
if (this.timeFormat === "12") {
|
|
117
152
|
this.isPM = this.selectedTime.hours >= 12;
|
|
118
153
|
}
|
|
119
154
|
}
|
|
@@ -123,26 +158,46 @@ let HijriDatePickerComponent = class HijriDatePickerComponent {
|
|
|
123
158
|
this.selectedTime = {
|
|
124
159
|
hours: now.getHours(),
|
|
125
160
|
minutes: now.getMinutes(),
|
|
126
|
-
seconds: now.getSeconds()
|
|
161
|
+
seconds: now.getSeconds(),
|
|
127
162
|
};
|
|
128
163
|
this.isPM = this.selectedTime.hours >= 12;
|
|
129
164
|
}
|
|
130
165
|
}
|
|
131
166
|
updateLocaleData() {
|
|
132
167
|
// Update weekday names
|
|
133
|
-
this.weekdays = this.locale ===
|
|
168
|
+
this.weekdays = this.locale === "ar" ? WEEKDAY_NAMES_AR : WEEKDAY_NAMES_EN;
|
|
134
169
|
// Update month names based on mode and locale
|
|
135
|
-
if (this.mode ===
|
|
136
|
-
this.months = this.locale ===
|
|
170
|
+
if (this.mode === "hijri") {
|
|
171
|
+
this.months = this.locale === "ar" ? HIJRI_MONTHS_AR : HIJRI_MONTHS_EN;
|
|
137
172
|
}
|
|
138
173
|
else {
|
|
139
|
-
this.months =
|
|
174
|
+
this.months =
|
|
175
|
+
this.locale === "ar" ? GREGORIAN_MONTHS_AR : GREGORIAN_MONTHS_EN;
|
|
140
176
|
}
|
|
141
177
|
}
|
|
142
178
|
generateYears() {
|
|
143
|
-
const currentYear = this.mode ===
|
|
144
|
-
|
|
145
|
-
|
|
179
|
+
const currentYear = this.mode === "hijri" ? this.currentHijriYear : this.currentYear;
|
|
180
|
+
let startYear = currentYear - 100;
|
|
181
|
+
let endYear = currentYear + this.futureYearsLimit;
|
|
182
|
+
// Adjust year range based on minDate and maxDate
|
|
183
|
+
if (this.mode === "greg") {
|
|
184
|
+
if (this.minDate) {
|
|
185
|
+
startYear = Math.max(startYear, this.minDate.getFullYear());
|
|
186
|
+
}
|
|
187
|
+
if (this.maxDate) {
|
|
188
|
+
endYear = Math.min(endYear, this.maxDate.getFullYear());
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
else if (this.mode === "hijri") {
|
|
192
|
+
if (this.minDate) {
|
|
193
|
+
const minHijri = toHijri(this.minDate);
|
|
194
|
+
startYear = Math.max(startYear, minHijri.getFullYear());
|
|
195
|
+
}
|
|
196
|
+
if (this.maxDate) {
|
|
197
|
+
const maxHijri = toHijri(this.maxDate);
|
|
198
|
+
endYear = Math.min(endYear, maxHijri.getFullYear());
|
|
199
|
+
}
|
|
200
|
+
}
|
|
146
201
|
this.years = [];
|
|
147
202
|
for (let year = startYear; year <= endYear; year++) {
|
|
148
203
|
this.years.push(year);
|
|
@@ -150,7 +205,7 @@ let HijriDatePickerComponent = class HijriDatePickerComponent {
|
|
|
150
205
|
}
|
|
151
206
|
generateCalendar() {
|
|
152
207
|
this.calendarDays = [];
|
|
153
|
-
if (this.mode ===
|
|
208
|
+
if (this.mode === "hijri") {
|
|
154
209
|
this.generateHijriCalendar();
|
|
155
210
|
}
|
|
156
211
|
else {
|
|
@@ -178,7 +233,7 @@ let HijriDatePickerComponent = class HijriDatePickerComponent {
|
|
|
178
233
|
isToday,
|
|
179
234
|
isDisabled,
|
|
180
235
|
isSelected,
|
|
181
|
-
disabled: false
|
|
236
|
+
disabled: false,
|
|
182
237
|
});
|
|
183
238
|
}
|
|
184
239
|
}
|
|
@@ -206,7 +261,7 @@ let HijriDatePickerComponent = class HijriDatePickerComponent {
|
|
|
206
261
|
isToday,
|
|
207
262
|
isDisabled,
|
|
208
263
|
isSelected,
|
|
209
|
-
disabled: false
|
|
264
|
+
disabled: false,
|
|
210
265
|
});
|
|
211
266
|
}
|
|
212
267
|
}
|
|
@@ -221,11 +276,28 @@ let HijriDatePickerComponent = class HijriDatePickerComponent {
|
|
|
221
276
|
}
|
|
222
277
|
}
|
|
223
278
|
isSameDay(date1, date2) {
|
|
224
|
-
return date1.getFullYear() === date2.getFullYear() &&
|
|
279
|
+
return (date1.getFullYear() === date2.getFullYear() &&
|
|
225
280
|
date1.getMonth() === date2.getMonth() &&
|
|
226
|
-
date1.getDate() === date2.getDate();
|
|
281
|
+
date1.getDate() === date2.getDate());
|
|
227
282
|
}
|
|
228
283
|
isDateDisabled(date) {
|
|
284
|
+
// Check minDate constraint
|
|
285
|
+
if (this.minDate) {
|
|
286
|
+
const minDateOnly = new Date(this.minDate.getFullYear(), this.minDate.getMonth(), this.minDate.getDate());
|
|
287
|
+
const dateOnly = new Date(date.getFullYear(), date.getMonth(), date.getDate());
|
|
288
|
+
if (dateOnly < minDateOnly) {
|
|
289
|
+
return true;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
// Check maxDate constraint
|
|
293
|
+
if (this.maxDate) {
|
|
294
|
+
const maxDateOnly = new Date(this.maxDate.getFullYear(), this.maxDate.getMonth(), this.maxDate.getDate());
|
|
295
|
+
const dateOnly = new Date(date.getFullYear(), date.getMonth(), date.getDate());
|
|
296
|
+
if (dateOnly > maxDateOnly) {
|
|
297
|
+
return true;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
// Check futureValidation constraint
|
|
229
301
|
if (this.futureValidation) {
|
|
230
302
|
const maxDate = new Date();
|
|
231
303
|
maxDate.setFullYear(maxDate.getFullYear() + this.futureYearsLimit);
|
|
@@ -234,7 +306,7 @@ let HijriDatePickerComponent = class HijriDatePickerComponent {
|
|
|
234
306
|
return false;
|
|
235
307
|
}
|
|
236
308
|
isDateSelected(date) {
|
|
237
|
-
return this.selectedDates.some(selected => this.isSameDay(selected.gregorian, date));
|
|
309
|
+
return this.selectedDates.some((selected) => this.isSameDay(selected.gregorian, date));
|
|
238
310
|
}
|
|
239
311
|
onDayClick(dayInfo) {
|
|
240
312
|
if (dayInfo.disabled || dayInfo.isDisabled) {
|
|
@@ -242,12 +314,23 @@ let HijriDatePickerComponent = class HijriDatePickerComponent {
|
|
|
242
314
|
}
|
|
243
315
|
const selectedDate = this.createSelectedDate(dayInfo.date);
|
|
244
316
|
if (this.multiple) {
|
|
245
|
-
const index = this.selectedDates.findIndex(d => this.isSameDay(d.gregorian, dayInfo.date));
|
|
317
|
+
const index = this.selectedDates.findIndex((d) => this.isSameDay(d.gregorian, dayInfo.date));
|
|
246
318
|
if (index > -1) {
|
|
319
|
+
// Remove the clicked date if already selected
|
|
247
320
|
this.selectedDates.splice(index, 1);
|
|
248
321
|
}
|
|
249
322
|
else {
|
|
250
|
-
|
|
323
|
+
// If we already have 2 or more dates, clear and start new range
|
|
324
|
+
if (this.selectedDates.length >= 2) {
|
|
325
|
+
this.selectedDates = [selectedDate];
|
|
326
|
+
}
|
|
327
|
+
else {
|
|
328
|
+
this.selectedDates.push(selectedDate);
|
|
329
|
+
// Auto-fill range if exactly 2 dates are selected
|
|
330
|
+
if (this.selectedDates.length === 2) {
|
|
331
|
+
this.fillDateRange();
|
|
332
|
+
}
|
|
333
|
+
}
|
|
251
334
|
}
|
|
252
335
|
if (!this.showConfirmButton) {
|
|
253
336
|
this.dateSelected.emit([...this.selectedDates]);
|
|
@@ -261,12 +344,31 @@ let HijriDatePickerComponent = class HijriDatePickerComponent {
|
|
|
261
344
|
}
|
|
262
345
|
this.generateCalendar();
|
|
263
346
|
}
|
|
347
|
+
fillDateRange() {
|
|
348
|
+
if (this.selectedDates.length !== 2)
|
|
349
|
+
return;
|
|
350
|
+
// Sort the two dates
|
|
351
|
+
const dates = [...this.selectedDates].sort((a, b) => a.gregorian.getTime() - b.gregorian.getTime());
|
|
352
|
+
const startDate = dates[0].gregorian;
|
|
353
|
+
const endDate = dates[1].gregorian;
|
|
354
|
+
// Clear current selection
|
|
355
|
+
this.selectedDates = [];
|
|
356
|
+
// Fill all dates between start and end (inclusive)
|
|
357
|
+
const currentDate = new Date(startDate);
|
|
358
|
+
while (currentDate <= endDate) {
|
|
359
|
+
const dateToAdd = new Date(currentDate);
|
|
360
|
+
this.selectedDates.push(this.createSelectedDate(dateToAdd));
|
|
361
|
+
currentDate.setDate(currentDate.getDate() + 1);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
264
364
|
createSelectedDate(date) {
|
|
265
|
-
|
|
365
|
+
// Create a new Date object to avoid mutating the original
|
|
366
|
+
const dateObj = new Date(date.getFullYear(), date.getMonth(), date.getDate());
|
|
367
|
+
const hijriDate = toHijri(dateObj);
|
|
266
368
|
// If time is enabled, set the time on the date object
|
|
267
369
|
if (this.enableTime) {
|
|
268
370
|
let hours24 = this.selectedTime.hours;
|
|
269
|
-
if (this.timeFormat ===
|
|
371
|
+
if (this.timeFormat === "12") {
|
|
270
372
|
if (this.isPM && this.selectedTime.hours !== 12) {
|
|
271
373
|
hours24 = this.selectedTime.hours + 12;
|
|
272
374
|
}
|
|
@@ -274,48 +376,54 @@ let HijriDatePickerComponent = class HijriDatePickerComponent {
|
|
|
274
376
|
hours24 = 0;
|
|
275
377
|
}
|
|
276
378
|
}
|
|
277
|
-
|
|
379
|
+
dateObj.setHours(hours24, this.selectedTime.minutes, this.selectedTime.seconds);
|
|
278
380
|
}
|
|
279
381
|
return {
|
|
280
|
-
gregorian:
|
|
382
|
+
gregorian: dateObj,
|
|
281
383
|
hijri: {
|
|
282
384
|
year: hijriDate.getFullYear(),
|
|
283
385
|
month: hijriDate.getMonth(),
|
|
284
|
-
day: hijriDate.getDate()
|
|
386
|
+
day: hijriDate.getDate(),
|
|
285
387
|
},
|
|
286
|
-
time: this.enableTime
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
388
|
+
time: this.enableTime
|
|
389
|
+
? {
|
|
390
|
+
hours: dateObj.getHours(),
|
|
391
|
+
minutes: dateObj.getMinutes(),
|
|
392
|
+
seconds: dateObj.getSeconds(),
|
|
393
|
+
}
|
|
394
|
+
: undefined,
|
|
291
395
|
formatted: {
|
|
292
|
-
gregorian: this.formatGregorianDate(
|
|
396
|
+
gregorian: this.formatGregorianDate(dateObj),
|
|
293
397
|
hijri: this.formatHijriDate(hijriDate),
|
|
294
|
-
time: this.enableTime
|
|
295
|
-
|
|
398
|
+
time: this.enableTime
|
|
399
|
+
? this.formatTime(dateObj.getHours(), dateObj.getMinutes(), dateObj.getSeconds())
|
|
400
|
+
: undefined,
|
|
401
|
+
},
|
|
296
402
|
};
|
|
297
403
|
}
|
|
298
404
|
formatGregorianDate(date) {
|
|
299
405
|
const day = date.getDate();
|
|
300
|
-
const month = this.locale ===
|
|
406
|
+
const month = this.locale === "ar"
|
|
407
|
+
? GREGORIAN_MONTHS_AR[date.getMonth()]
|
|
408
|
+
: GREGORIAN_MONTHS_EN[date.getMonth()];
|
|
301
409
|
const year = date.getFullYear();
|
|
302
|
-
return this.locale ===
|
|
410
|
+
return this.locale === "ar"
|
|
303
411
|
? `${day} ${month} ${year}`
|
|
304
412
|
: `${month} ${day}, ${year}`;
|
|
305
413
|
}
|
|
306
414
|
formatHijriDate(hijriDate) {
|
|
307
415
|
const day = hijriDate.getDate();
|
|
308
|
-
const month = this.locale ===
|
|
416
|
+
const month = this.locale === "ar"
|
|
309
417
|
? HIJRI_MONTHS_AR[hijriDate.getMonth()]
|
|
310
418
|
: HIJRI_MONTHS_EN[hijriDate.getMonth()];
|
|
311
419
|
const year = hijriDate.getFullYear();
|
|
312
|
-
return this.locale ===
|
|
420
|
+
return this.locale === "ar"
|
|
313
421
|
? `${day} ${month} ${year} هـ`
|
|
314
422
|
: `${day} ${month} ${year} AH`;
|
|
315
423
|
}
|
|
316
424
|
onYearChange(event) {
|
|
317
425
|
const year = parseInt(event.target.value);
|
|
318
|
-
if (this.mode ===
|
|
426
|
+
if (this.mode === "hijri") {
|
|
319
427
|
this.currentHijriYear = year;
|
|
320
428
|
}
|
|
321
429
|
else {
|
|
@@ -325,7 +433,7 @@ let HijriDatePickerComponent = class HijriDatePickerComponent {
|
|
|
325
433
|
}
|
|
326
434
|
onMonthChange(event) {
|
|
327
435
|
const month = parseInt(event.target.value);
|
|
328
|
-
if (this.mode ===
|
|
436
|
+
if (this.mode === "hijri") {
|
|
329
437
|
this.currentHijriMonth = month;
|
|
330
438
|
}
|
|
331
439
|
else {
|
|
@@ -334,7 +442,7 @@ let HijriDatePickerComponent = class HijriDatePickerComponent {
|
|
|
334
442
|
this.generateCalendar();
|
|
335
443
|
}
|
|
336
444
|
previousMonth() {
|
|
337
|
-
if (this.mode ===
|
|
445
|
+
if (this.mode === "hijri") {
|
|
338
446
|
if (this.currentHijriMonth === 0) {
|
|
339
447
|
this.currentHijriMonth = 11;
|
|
340
448
|
this.currentHijriYear--;
|
|
@@ -355,7 +463,7 @@ let HijriDatePickerComponent = class HijriDatePickerComponent {
|
|
|
355
463
|
this.generateCalendar();
|
|
356
464
|
}
|
|
357
465
|
nextMonth() {
|
|
358
|
-
if (this.mode ===
|
|
466
|
+
if (this.mode === "hijri") {
|
|
359
467
|
if (this.currentHijriMonth === 11) {
|
|
360
468
|
this.currentHijriMonth = 0;
|
|
361
469
|
this.currentHijriYear++;
|
|
@@ -379,7 +487,7 @@ let HijriDatePickerComponent = class HijriDatePickerComponent {
|
|
|
379
487
|
if (!this.canChangeMode) {
|
|
380
488
|
return;
|
|
381
489
|
}
|
|
382
|
-
this.mode = this.mode ===
|
|
490
|
+
this.mode = this.mode === "greg" ? "hijri" : "greg";
|
|
383
491
|
this.updateLocaleData();
|
|
384
492
|
this.generateYears();
|
|
385
493
|
this.generateCalendar();
|
|
@@ -402,43 +510,54 @@ let HijriDatePickerComponent = class HijriDatePickerComponent {
|
|
|
402
510
|
}
|
|
403
511
|
// Time handling methods
|
|
404
512
|
incrementTime(type) {
|
|
405
|
-
if (type ===
|
|
406
|
-
const max = this.timeFormat ===
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
513
|
+
if (type === "hours") {
|
|
514
|
+
const max = this.timeFormat === "12" ? 12 : 23;
|
|
515
|
+
const min = this.timeFormat === "12" ? 1 : 0;
|
|
516
|
+
this.selectedTime.hours =
|
|
517
|
+
this.selectedTime.hours >= max ? min : this.selectedTime.hours + 1;
|
|
518
|
+
}
|
|
519
|
+
else if (type === "minutes") {
|
|
520
|
+
this.selectedTime.minutes =
|
|
521
|
+
this.selectedTime.minutes + this.minuteStep > 59
|
|
522
|
+
? 0
|
|
523
|
+
: this.selectedTime.minutes + this.minuteStep;
|
|
524
|
+
}
|
|
525
|
+
else if (type === "seconds") {
|
|
526
|
+
this.selectedTime.seconds =
|
|
527
|
+
this.selectedTime.seconds + 1 > 59 ? 0 : this.selectedTime.seconds + 1;
|
|
414
528
|
}
|
|
415
529
|
this.updateSelectedDateTime();
|
|
416
530
|
}
|
|
417
531
|
decrementTime(type) {
|
|
418
|
-
if (type ===
|
|
419
|
-
const min = this.timeFormat ===
|
|
420
|
-
const max = this.timeFormat ===
|
|
421
|
-
this.selectedTime.hours =
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
532
|
+
if (type === "hours") {
|
|
533
|
+
const min = this.timeFormat === "12" ? 1 : 0;
|
|
534
|
+
const max = this.timeFormat === "12" ? 12 : 23;
|
|
535
|
+
this.selectedTime.hours =
|
|
536
|
+
this.selectedTime.hours - 1 < min ? max : this.selectedTime.hours - 1;
|
|
537
|
+
}
|
|
538
|
+
else if (type === "minutes") {
|
|
539
|
+
this.selectedTime.minutes =
|
|
540
|
+
this.selectedTime.minutes - this.minuteStep < 0
|
|
541
|
+
? 59
|
|
542
|
+
: this.selectedTime.minutes - this.minuteStep;
|
|
543
|
+
}
|
|
544
|
+
else if (type === "seconds") {
|
|
545
|
+
this.selectedTime.seconds =
|
|
546
|
+
this.selectedTime.seconds - 1 < 0 ? 59 : this.selectedTime.seconds - 1;
|
|
428
547
|
}
|
|
429
548
|
this.updateSelectedDateTime();
|
|
430
549
|
}
|
|
431
550
|
onTimeChange(type, event) {
|
|
432
551
|
const value = parseInt(event.target.value) || 0;
|
|
433
|
-
if (type ===
|
|
434
|
-
const min = this.timeFormat ===
|
|
435
|
-
const max = this.timeFormat ===
|
|
552
|
+
if (type === "hours") {
|
|
553
|
+
const min = this.timeFormat === "12" ? 1 : 0;
|
|
554
|
+
const max = this.timeFormat === "12" ? 12 : 23;
|
|
436
555
|
this.selectedTime.hours = Math.max(min, Math.min(max, value));
|
|
437
556
|
}
|
|
438
|
-
else if (type ===
|
|
557
|
+
else if (type === "minutes") {
|
|
439
558
|
this.selectedTime.minutes = Math.max(0, Math.min(59, value));
|
|
440
559
|
}
|
|
441
|
-
else if (type ===
|
|
560
|
+
else if (type === "seconds") {
|
|
442
561
|
this.selectedTime.seconds = Math.max(0, Math.min(59, value));
|
|
443
562
|
}
|
|
444
563
|
this.updateSelectedDateTime();
|
|
@@ -448,21 +567,21 @@ let HijriDatePickerComponent = class HijriDatePickerComponent {
|
|
|
448
567
|
this.updateSelectedDateTime();
|
|
449
568
|
}
|
|
450
569
|
formatTime(hours, minutes, seconds) {
|
|
451
|
-
if (this.timeFormat ===
|
|
570
|
+
if (this.timeFormat === "12") {
|
|
452
571
|
const displayHours = hours % 12 || 12;
|
|
453
|
-
const ampm = hours >= 12 ?
|
|
454
|
-
const minutesStr = minutes.toString().padStart(2,
|
|
572
|
+
const ampm = hours >= 12 ? "PM" : "AM";
|
|
573
|
+
const minutesStr = minutes.toString().padStart(2, "0");
|
|
455
574
|
if (this.enableSeconds) {
|
|
456
|
-
const secondsStr = seconds.toString().padStart(2,
|
|
575
|
+
const secondsStr = seconds.toString().padStart(2, "0");
|
|
457
576
|
return `${displayHours}:${minutesStr}:${secondsStr} ${ampm}`;
|
|
458
577
|
}
|
|
459
578
|
return `${displayHours}:${minutesStr} ${ampm}`;
|
|
460
579
|
}
|
|
461
580
|
else {
|
|
462
|
-
const hoursStr = hours.toString().padStart(2,
|
|
463
|
-
const minutesStr = minutes.toString().padStart(2,
|
|
581
|
+
const hoursStr = hours.toString().padStart(2, "0");
|
|
582
|
+
const minutesStr = minutes.toString().padStart(2, "0");
|
|
464
583
|
if (this.enableSeconds) {
|
|
465
|
-
const secondsStr = seconds.toString().padStart(2,
|
|
584
|
+
const secondsStr = seconds.toString().padStart(2, "0");
|
|
466
585
|
return `${hoursStr}:${minutesStr}:${secondsStr}`;
|
|
467
586
|
}
|
|
468
587
|
return `${hoursStr}:${minutesStr}`;
|
|
@@ -474,7 +593,7 @@ let HijriDatePickerComponent = class HijriDatePickerComponent {
|
|
|
474
593
|
}
|
|
475
594
|
// Convert 12-hour to 24-hour if needed
|
|
476
595
|
let hours24 = this.selectedTime.hours;
|
|
477
|
-
if (this.timeFormat ===
|
|
596
|
+
if (this.timeFormat === "12") {
|
|
478
597
|
if (this.isPM && this.selectedTime.hours !== 12) {
|
|
479
598
|
hours24 = this.selectedTime.hours + 12;
|
|
480
599
|
}
|
|
@@ -483,7 +602,7 @@ let HijriDatePickerComponent = class HijriDatePickerComponent {
|
|
|
483
602
|
}
|
|
484
603
|
}
|
|
485
604
|
// Update all selected dates with new time
|
|
486
|
-
this.selectedDates = this.selectedDates.map(selectedDate => {
|
|
605
|
+
this.selectedDates = this.selectedDates.map((selectedDate) => {
|
|
487
606
|
const newDate = new Date(selectedDate.gregorian);
|
|
488
607
|
newDate.setHours(hours24, this.selectedTime.minutes, this.selectedTime.seconds);
|
|
489
608
|
return {
|
|
@@ -492,30 +611,30 @@ let HijriDatePickerComponent = class HijriDatePickerComponent {
|
|
|
492
611
|
time: {
|
|
493
612
|
hours: hours24,
|
|
494
613
|
minutes: this.selectedTime.minutes,
|
|
495
|
-
seconds: this.selectedTime.seconds
|
|
614
|
+
seconds: this.selectedTime.seconds,
|
|
496
615
|
},
|
|
497
616
|
formatted: {
|
|
498
617
|
...selectedDate.formatted,
|
|
499
|
-
time: this.formatTime(hours24, this.selectedTime.minutes, this.selectedTime.seconds)
|
|
500
|
-
}
|
|
618
|
+
time: this.formatTime(hours24, this.selectedTime.minutes, this.selectedTime.seconds),
|
|
619
|
+
},
|
|
501
620
|
};
|
|
502
621
|
});
|
|
503
622
|
}
|
|
504
623
|
getCustomStyles() {
|
|
505
624
|
return {
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
625
|
+
"--primary-color": this.styles.primaryColor || "#4f46e5",
|
|
626
|
+
"--secondary-color": this.styles.secondaryColor || "#818cf8",
|
|
627
|
+
"--background-color": this.styles.backgroundColor || "#ffffff",
|
|
628
|
+
"--text-color": this.styles.textColor || "#1f2937",
|
|
629
|
+
"--selected-date-color": this.styles.selectedDateColor || "#ffffff",
|
|
630
|
+
"--selected-date-background": this.styles.selectedDateBackground || "#4f46e5",
|
|
631
|
+
"--today-color": this.styles.todayColor || "#10b981",
|
|
632
|
+
"--disabled-color": this.styles.disabledColor || "#d1d5db",
|
|
633
|
+
"--border-color": this.styles.borderColor || "#e5e7eb",
|
|
634
|
+
"--hover-color": this.styles.hoverColor || "#f3f4f6",
|
|
635
|
+
"--font-family": this.styles.fontFamily || "system-ui, -apple-system, sans-serif",
|
|
636
|
+
"--font-size": this.styles.fontSize || "14px",
|
|
637
|
+
"--border-radius": this.styles.borderRadius || "8px",
|
|
519
638
|
};
|
|
520
639
|
}
|
|
521
640
|
};
|
|
@@ -547,6 +666,14 @@ __decorate([
|
|
|
547
666
|
Input(),
|
|
548
667
|
__metadata("design:type", Boolean)
|
|
549
668
|
], HijriDatePickerComponent.prototype, "isRequired", void 0);
|
|
669
|
+
__decorate([
|
|
670
|
+
Input(),
|
|
671
|
+
__metadata("design:type", Date)
|
|
672
|
+
], HijriDatePickerComponent.prototype, "minDate", void 0);
|
|
673
|
+
__decorate([
|
|
674
|
+
Input(),
|
|
675
|
+
__metadata("design:type", Date)
|
|
676
|
+
], HijriDatePickerComponent.prototype, "maxDate", void 0);
|
|
550
677
|
__decorate([
|
|
551
678
|
Input(),
|
|
552
679
|
__metadata("design:type", Boolean)
|
|
@@ -637,11 +764,11 @@ __decorate([
|
|
|
637
764
|
], HijriDatePickerComponent.prototype, "modeChanged", void 0);
|
|
638
765
|
HijriDatePickerComponent = __decorate([
|
|
639
766
|
Component({
|
|
640
|
-
selector:
|
|
767
|
+
selector: "hijri-date-picker",
|
|
641
768
|
standalone: true,
|
|
642
769
|
imports: [CommonModule],
|
|
643
|
-
templateUrl:
|
|
644
|
-
styleUrls: [
|
|
770
|
+
templateUrl: "./hijri-date-picker.component.html",
|
|
771
|
+
styleUrls: ["./hijri-date-picker.component.css"],
|
|
645
772
|
})
|
|
646
773
|
], HijriDatePickerComponent);
|
|
647
774
|
export { HijriDatePickerComponent };
|