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