1
1
import dayjs from 'dayjs/esm'
2
- import advancedFormat from 'dayjs/plugin/advancedFormat'
3
2
import customParseFormat from 'dayjs/plugin/customParseFormat'
4
3
import localeData from 'dayjs/plugin/localeData'
5
4
import timezone from 'dayjs/plugin/timezone'
6
5
import utc from 'dayjs/plugin/utc'
7
- import jalaliday from 'jalaliday'
6
+ import calendarSystems from "@calidy/dayjs-calendarsystems" ;
7
+ import PersianCalendarSystem from "@calidy/dayjs-calendarsystems/calendarSystems/PersianCalendarSystem" ;
8
8
9
- dayjs . extend ( advancedFormat )
10
9
dayjs . extend ( customParseFormat )
11
10
dayjs . extend ( localeData )
12
11
dayjs . extend ( timezone )
13
12
dayjs . extend ( utc )
14
- dayjs . extend ( jalaliday )
15
- dayjs . calendar ( 'jalali' )
13
+ dayjs . extend ( calendarSystems )
14
+ dayjs . registerCalendarSystem ( "persian" , new PersianCalendarSystem ( ) ) ;
16
15
17
16
window . dayjs = dayjs
18
17
@@ -23,6 +22,9 @@ export default function filamentJalaliFormComponent({
23
22
locale,
24
23
shouldCloseOnDateSelection,
25
24
state,
25
+ months,
26
+ dayLabel,
27
+ dayShortLabel
26
28
} ) {
27
29
const timezone = dayjs . tz . guess ( )
28
30
@@ -53,14 +55,17 @@ export default function filamentJalaliFormComponent({
53
55
54
56
months : [ ] ,
55
57
56
- init : function ( ) {
57
- dayjs . locale ( locale ?? 'en' )
58
+ dayLabel,
59
+
60
+ dayShortLabel,
58
61
59
- this . focusedDate = dayjs ( ) . tz ( timezone )
62
+ init : function ( ) {
63
+ dayjs . locale ( locales [ locale ] ?? locales [ 'en' ] ) ;
64
+ this . focusedDate = dayjs ( ) . tz ( timezone ) . toCalendarSystem ( "persian" )
60
65
61
66
let date =
62
67
this . getSelectedDate ( ) ??
63
- dayjs ( ) . tz ( timezone ) . hour ( 0 ) . minute ( 0 ) . second ( 0 )
68
+ dayjs ( ) . tz ( timezone ) . toCalendarSystem ( "persian" ) . hour ( 0 ) . minute ( 0 ) . second ( 0 )
64
69
65
70
if ( this . getMaxDate ( ) !== null && date . isAfter ( this . getMaxDate ( ) ) ) {
66
71
date = null
@@ -107,7 +112,7 @@ export default function filamentJalaliFormComponent({
107
112
let year = + this . focusedYear
108
113
109
114
if ( ! Number . isInteger ( year ) ) {
110
- year = dayjs ( ) . tz ( timezone ) . year ( )
115
+ year = dayjs ( ) . tz ( timezone ) . toCalendarSystem ( "persian" ) . year ( )
111
116
112
117
this . focusedYear = year
113
118
}
@@ -268,25 +273,25 @@ export default function filamentJalaliFormComponent({
268
273
return false
269
274
}
270
275
271
- return disabledDate . isSame ( date , 'day' )
276
+ return disabledDate . isSame ( date . toCalendarSystem ( "gregory" ) , 'day' )
272
277
} ,
273
278
)
274
279
) {
275
280
return true
276
281
}
277
282
278
- if ( this . getMaxDate ( ) && date . isAfter ( this . getMaxDate ( ) , 'day' ) ) {
283
+ if ( this . getMaxDate ( ) && date . isAfter ( this . getMaxDate ( ) ) ) {
279
284
return true
280
285
}
281
- if ( this . getMinDate ( ) && date . isBefore ( this . getMinDate ( ) , 'day' ) ) {
286
+ if ( this . getMinDate ( ) && date . isBefore ( this . getMinDate ( ) ) ) {
282
287
return true
283
288
}
284
289
285
290
return false
286
291
} ,
287
292
288
293
dayIsDisabled : function ( day ) {
289
- this . focusedDate ??= dayjs ( ) . tz ( timezone )
294
+ this . focusedDate ??= dayjs ( ) . tz ( timezone ) . toCalendarSystem ( "persian" )
290
295
291
296
return this . dateIsDisabled ( this . focusedDate . date ( day ) )
292
297
} ,
@@ -298,7 +303,7 @@ export default function filamentJalaliFormComponent({
298
303
return false
299
304
}
300
305
301
- this . focusedDate ??= dayjs ( ) . tz ( timezone )
306
+ this . focusedDate ??= dayjs ( ) . tz ( timezone ) . toCalendarSystem ( "persian" )
302
307
303
308
return (
304
309
selectedDate . date ( ) === day &&
@@ -308,7 +313,7 @@ export default function filamentJalaliFormComponent({
308
313
} ,
309
314
310
315
dayIsToday : function ( day ) {
311
- let date = dayjs ( ) . tz ( timezone )
316
+ let date = dayjs ( ) . tz ( timezone ) . toCalendarSystem ( "persian" )
312
317
this . focusedDate ??= date
313
318
314
319
return (
@@ -319,31 +324,45 @@ export default function filamentJalaliFormComponent({
319
324
} ,
320
325
321
326
focusPreviousDay : function ( ) {
322
- this . focusedDate ??= dayjs ( ) . tz ( timezone )
327
+ this . focusedDate ??= dayjs ( ) . tz ( timezone ) . toCalendarSystem ( "persian" )
323
328
324
329
this . focusedDate = this . focusedDate . subtract ( 1 , 'day' )
325
330
} ,
326
331
327
332
focusPreviousWeek : function ( ) {
328
- this . focusedDate ??= dayjs ( ) . tz ( timezone )
333
+ this . focusedDate ??= dayjs ( ) . tz ( timezone ) . toCalendarSystem ( "persian" )
329
334
330
335
this . focusedDate = this . focusedDate . subtract ( 1 , 'week' )
331
336
} ,
332
337
333
338
focusNextDay : function ( ) {
334
- this . focusedDate ??= dayjs ( ) . tz ( timezone )
339
+ this . focusedDate ??= dayjs ( ) . tz ( timezone ) . toCalendarSystem ( "persian" )
335
340
336
341
this . focusedDate = this . focusedDate . add ( 1 , 'day' )
337
342
} ,
338
343
339
344
focusNextWeek : function ( ) {
340
- this . focusedDate ??= dayjs ( ) . tz ( timezone )
345
+ this . focusedDate ??= dayjs ( ) . tz ( timezone ) . toCalendarSystem ( "persian" )
341
346
342
347
this . focusedDate = this . focusedDate . add ( 1 , 'week' )
343
348
} ,
344
349
345
350
getDayLabels : function ( ) {
346
- const labels = dayjs . weekdaysShort ( )
351
+ let flag = this . $el . dataset . weekdaysShort ;
352
+ let labels = [ ] ;
353
+ if ( flag === 'short' ) {
354
+ if ( typeof this . dayShortLabel !== 'object' ) {
355
+ labels = dayjs . weekdaysShort ( )
356
+ } else {
357
+ labels = Object . values ( this . dayShortLabel ) ;
358
+ }
359
+ } else {
360
+ if ( typeof this . dayLabel !== 'object' ) {
361
+ labels = dayjs . weekdays ( )
362
+ } else {
363
+ labels = Object . values ( this . dayLabel ) ;
364
+ }
365
+ }
347
366
348
367
if ( firstDayOfWeek === 0 ) {
349
368
return labels
@@ -358,13 +377,13 @@ export default function filamentJalaliFormComponent({
358
377
getMaxDate : function ( ) {
359
378
let date = dayjs ( this . $refs . maxDate ?. value )
360
379
361
- return date . isValid ( ) ? date : null
380
+ return date . isValid ( ) ? date . toCalendarSystem ( "persian" ) : null
362
381
} ,
363
382
364
383
getMinDate : function ( ) {
365
384
let date = dayjs ( this . $refs . minDate ?. value )
366
385
367
- return date . isValid ( ) ? date : null
386
+ return date . isValid ( ) ? date . toCalendarSystem ( "persian" ) : null
368
387
} ,
369
388
370
389
getSelectedDate : function ( ) {
@@ -376,7 +395,7 @@ export default function filamentJalaliFormComponent({
376
395
return null
377
396
}
378
397
379
- let date = dayjs ( this . state )
398
+ let date = dayjs ( this . state ) . toCalendarSystem ( "persian" )
380
399
381
400
if ( ! date . isValid ( ) ) {
382
401
return null
@@ -390,7 +409,7 @@ export default function filamentJalaliFormComponent({
390
409
this . focusedDate =
391
410
this . getSelectedDate ( ) ??
392
411
this . getMinDate ( ) ??
393
- dayjs ( ) . tz ( timezone )
412
+ dayjs ( ) . tz ( timezone ) . toCalendarSystem ( "persian" )
394
413
395
414
this . setupDaysGrid ( )
396
415
}
@@ -403,7 +422,7 @@ export default function filamentJalaliFormComponent({
403
422
this . setFocusedDay ( day )
404
423
}
405
424
406
- this . focusedDate ??= dayjs ( ) . tz ( timezone )
425
+ this . focusedDate ??= dayjs ( ) . tz ( timezone ) . toCalendarSystem ( "persian" )
407
426
408
427
this . setState ( this . focusedDate )
409
428
@@ -419,17 +438,17 @@ export default function filamentJalaliFormComponent({
419
438
} ,
420
439
421
440
setMonths : function ( ) {
422
- this . months = dayjs . locale ( ) === 'en' ?
423
- dayjs . en . jmonths :
424
- 'فروردین_اردیبهشت_خرداد_تیر_مرداد_شهریور_مهر_آبان_آذر_دی_بهمن_اسفند' . split ( '_' )
441
+ if ( typeof this . months !== 'object' || ! Array . isArray ( this . months ) || this . months === null ) {
442
+ this . months = dayjs . months ( )
443
+ }
425
444
} ,
426
445
427
446
setDayLabels : function ( ) {
428
447
this . dayLabels = this . getDayLabels ( )
429
448
} ,
430
449
431
450
setupDaysGrid : function ( ) {
432
- this . focusedDate ??= dayjs ( ) . tz ( timezone )
451
+ this . focusedDate ??= dayjs ( ) . tz ( timezone ) . toCalendarSystem ( "persian" )
433
452
434
453
this . emptyDaysInFocusedMonth = Array . from (
435
454
{
@@ -447,9 +466,7 @@ export default function filamentJalaliFormComponent({
447
466
} ,
448
467
449
468
setFocusedDay : function ( day ) {
450
- this . focusedDate = ( this . focusedDate ?? dayjs ( ) . tz ( timezone ) ) . date (
451
- day ,
452
- )
469
+ this . focusedDate = dayjs ( ) . toCalendarSystem ( "persian" ) . year ( this . focusedDate . year ( ) ) . month ( this . focusedDate . month ( ) ) . date ( day ) ;
453
470
} ,
454
471
455
472
setState : function ( date ) {
@@ -465,10 +482,10 @@ export default function filamentJalaliFormComponent({
465
482
}
466
483
467
484
this . state = date
468
- . calendar ( 'gregory' )
469
485
. hour ( this . hour ?? 0 )
470
486
. minute ( this . minute ?? 0 )
471
487
. second ( this . second ?? 0 )
488
+ . toCalendarSystem ( 'gregory' )
472
489
. format ( 'YYYY-MM-DD HH:mm:ss' )
473
490
474
491
this . setDisplayText ( )
@@ -479,3 +496,41 @@ export default function filamentJalaliFormComponent({
479
496
} ,
480
497
}
481
498
}
499
+
500
+ const locales = {
501
+ ar : require ( 'dayjs/locale/ar' ) ,
502
+ bs : require ( 'dayjs/locale/bs' ) ,
503
+ ca : require ( 'dayjs/locale/ca' ) ,
504
+ cs : require ( 'dayjs/locale/cs' ) ,
505
+ cy : require ( 'dayjs/locale/cy' ) ,
506
+ da : require ( 'dayjs/locale/da' ) ,
507
+ de : require ( 'dayjs/locale/de' ) ,
508
+ en : require ( 'dayjs/locale/en' ) ,
509
+ es : require ( 'dayjs/locale/es' ) ,
510
+ fa : require ( 'dayjs/locale/fa' ) ,
511
+ fi : require ( 'dayjs/locale/fi' ) ,
512
+ fr : require ( 'dayjs/locale/fr' ) ,
513
+ hi : require ( 'dayjs/locale/hi' ) ,
514
+ hu : require ( 'dayjs/locale/hu' ) ,
515
+ hy : require ( 'dayjs/locale/hy-am' ) ,
516
+ id : require ( 'dayjs/locale/id' ) ,
517
+ it : require ( 'dayjs/locale/it' ) ,
518
+ ja : require ( 'dayjs/locale/ja' ) ,
519
+ ka : require ( 'dayjs/locale/ka' ) ,
520
+ km : require ( 'dayjs/locale/km' ) ,
521
+ ku : require ( 'dayjs/locale/ku' ) ,
522
+ ms : require ( 'dayjs/locale/ms' ) ,
523
+ my : require ( 'dayjs/locale/my' ) ,
524
+ nl : require ( 'dayjs/locale/nl' ) ,
525
+ pl : require ( 'dayjs/locale/pl' ) ,
526
+ pt_BR : require ( 'dayjs/locale/pt-br' ) ,
527
+ pt_PT : require ( 'dayjs/locale/pt' ) ,
528
+ ro : require ( 'dayjs/locale/ro' ) ,
529
+ ru : require ( 'dayjs/locale/ru' ) ,
530
+ sv : require ( 'dayjs/locale/sv' ) ,
531
+ tr : require ( 'dayjs/locale/tr' ) ,
532
+ uk : require ( 'dayjs/locale/uk' ) ,
533
+ vi : require ( 'dayjs/locale/vi' ) ,
534
+ zh_CN : require ( 'dayjs/locale/zh-cn' ) ,
535
+ zh_TW : require ( 'dayjs/locale/zh-tw' ) ,
536
+ }
0 commit comments