1
+ import dayjs from "dayjs" ;
2
+ import calendarSystems from "../src/index" ;
3
+ import GregoryCalendarSystem from "../src/calendarSystems/GregoryCalendarSystem" ;
4
+ import PersianCalendarSystem from "../src/calendarSystems/PersianCalendarSystem" ;
5
+ import HijriCalendarSystem from "../src/calendarSystems/HijriCalendarSystem" ;
6
+
7
+ describe ( 'Calendar Systems Conversion' , ( ) => {
8
+ const targetDate = "2023-05-24" ;
9
+ const targetPersianDate = "1402-03-03" ;
10
+ const targetIslamicDate = "1444-11-04" ;
11
+
12
+ beforeAll ( ( ) => {
13
+ dayjs . extend ( calendarSystems ) ;
14
+ dayjs . registerCalendarSystem ( "gregory" , new GregoryCalendarSystem ( ) ) ;
15
+ dayjs . registerCalendarSystem ( "persian" , new PersianCalendarSystem ( ) ) ;
16
+ dayjs . registerCalendarSystem ( "islamic" , new HijriCalendarSystem ( ) ) ;
17
+ } ) ;
18
+
19
+ test ( 'Convert to Persian' , ( ) => {
20
+ const persianDate = dayjs ( targetDate ) . toCalendarSystem ( "persian" ) . format ( "YYYY-MM-DD" ) ;
21
+ expect ( persianDate ) . toEqual ( targetPersianDate ) ;
22
+ } ) ;
23
+
24
+ test ( 'Convert to Gregorian' , ( ) => {
25
+ const gregorianDate = dayjs ( targetDate ) . toCalendarSystem ( "gregory" ) . format ( "YYYY-MM-DD" ) ;
26
+ expect ( gregorianDate ) . toEqual ( targetDate ) ; // Gregorian date should be the same as targetDate
27
+ } ) ;
28
+
29
+ test ( 'Convert to Islamic' , ( ) => {
30
+ const hijriDate = dayjs ( targetDate ) . toCalendarSystem ( "islamic" ) . format ( "YYYY-MM-DD" ) ;
31
+ expect ( hijriDate ) . toEqual ( targetIslamicDate ) ;
32
+ } ) ;
33
+
34
+ test ( 'Convert Persian to Gregorian' , ( ) => {
35
+ const persianToGregorian = dayjs ( targetDate ) . toCalendarSystem ( "persian" ) . toCalendarSystem ( "gregory" ) . format ( "YYYY-MM-DD" ) ;
36
+ expect ( persianToGregorian ) . toEqual ( targetDate ) ;
37
+ } ) ;
38
+
39
+ test ( 'Convert Persian to Islamic' , ( ) => {
40
+ const persianToIslamic = dayjs ( targetDate ) . toCalendarSystem ( "persian" ) . toCalendarSystem ( "islamic" ) . format ( "YYYY-MM-DD" ) ;
41
+ expect ( persianToIslamic ) . toEqual ( targetIslamicDate ) ;
42
+ } ) ;
43
+
44
+ test ( 'Convert Gregorian to Persian' , ( ) => {
45
+ const gregorianToPersian = dayjs ( targetDate ) . toCalendarSystem ( "gregory" ) . toCalendarSystem ( "persian" ) . format ( "YYYY-MM-DD" ) ;
46
+ expect ( gregorianToPersian ) . toEqual ( targetPersianDate ) ;
47
+ } ) ;
48
+
49
+ test ( 'Convert Gregorian to Islamic' , ( ) => {
50
+ const gregorianToIslamic = dayjs ( targetDate ) . toCalendarSystem ( "gregory" ) . toCalendarSystem ( "islamic" ) . format ( "YYYY-MM-DD" ) ;
51
+ expect ( gregorianToIslamic ) . toEqual ( targetIslamicDate ) ;
52
+ } ) ;
53
+
54
+ test ( 'Convert Islamic to Persian' , ( ) => {
55
+ const islamicToPersian = dayjs ( targetDate ) . toCalendarSystem ( "islamic" ) . toCalendarSystem ( "persian" ) . format ( "YYYY-MM-DD" ) ;
56
+ expect ( islamicToPersian ) . toEqual ( targetPersianDate ) ;
57
+ } ) ;
58
+
59
+ test ( 'Convert Islamic to Gregorian' , ( ) => {
60
+ const islamicToGregorian = dayjs ( targetDate ) . toCalendarSystem ( "islamic" ) . toCalendarSystem ( "gregory" ) . format ( "YYYY-MM-DD" ) ;
61
+ expect ( islamicToGregorian ) . toEqual ( targetDate ) ;
62
+ } ) ;
63
+
64
+ } ) ;
0 commit comments