1
1
import dayjs from "dayjs" ;
2
+ import timeZone from "dayjs/plugin/timezone" ;
3
+ //import toArray from "dayjs/plugin/toArray";
4
+ import utc from "dayjs/plugin/utc" ;
2
5
import calendarSystems from "../src/index" ;
3
6
import GregoryCalendarSystem from "../src/calendarSystems/GregoryCalendarSystem" ;
4
7
import PersianCalendarSystem from "../src/calendarSystems/PersianCalendarSystem" ;
@@ -8,6 +11,8 @@ describe("daysInMonth method with different calendar systems", () => {
8
11
dayjs . extend ( calendarSystems ) ;
9
12
dayjs . registerCalendarSystem ( "gregory" , new GregoryCalendarSystem ( ) ) ;
10
13
dayjs . registerCalendarSystem ( "persian" , new PersianCalendarSystem ( ) ) ;
14
+ dayjs . extend ( utc ) ;
15
+ dayjs . extend ( timeZone ) ;
11
16
} ) ;
12
17
13
18
test ( "should return the correct number of days in a month for Gregorian calendar" , ( ) => {
@@ -19,10 +24,55 @@ describe("daysInMonth method with different calendar systems", () => {
19
24
} ) ;
20
25
21
26
test ( "should return the correct number of days in a month for Persian calendar" , ( ) => {
22
- const dateInFarvardin = dayjs ( "2023-03-21" ) . toCalendarSystem ( "persian" ) ;
27
+ // console.log("TEST_DAYS_IN_MONTH",
28
+ // dayjs("2023-03-21").toDate().toLocaleString('en-US', { timeZone: "Europe/Paris" }),
29
+ // dayjs("2023-03-21").toCalendarSystem("persian").toDate().toLocaleString('en-US', { timeZone: "Europe/Paris" }),
30
+ // dayjs("2023-03-21").tz("Europe/Paris").toCalendarSystem("persian").toDate().toLocaleString('en-US', { timeZone: "Europe/Paris" })
31
+ // );
32
+ const dateInFarvardin = dayjs ( "2023-03-21" ) . tz ( "Europe/Paris" ) . toCalendarSystem ( "persian" ) ;
23
33
const daysInFarvardin = dateInFarvardin . daysInMonth ( ) ;
24
34
expect ( daysInFarvardin ) . toBe ( 31 ) ;
25
35
36
+ const dateInOrdibehesht = dayjs ( "2023-04-21" ) . toCalendarSystem ( "persian" ) ;
37
+ const daysInOrdibehesht = dateInOrdibehesht . daysInMonth ( ) ;
38
+ expect ( daysInOrdibehesht ) . toBe ( 31 ) ;
39
+
40
+ const dateInKhordad = dayjs ( "2023-05-21" ) . toCalendarSystem ( "persian" ) ;
41
+ const daysInKhordad = dateInKhordad . daysInMonth ( ) ;
42
+ expect ( daysInKhordad ) . toBe ( 31 ) ;
43
+
44
+ const dateInTir = dayjs ( "2023-06-21" ) . toCalendarSystem ( "persian" ) ;
45
+ const daysInTir = dateInTir . daysInMonth ( ) ;
46
+ expect ( daysInTir ) . toBe ( 31 ) ;
47
+
48
+ const dateInMordad = dayjs ( "2023-07-21" ) . toCalendarSystem ( "persian" ) ;
49
+ const daysInMordad = dateInMordad . daysInMonth ( ) ;
50
+ expect ( daysInMordad ) . toBe ( 31 ) ;
51
+
52
+ const dateInShahrivar = dayjs ( "2023-08-21" ) . toCalendarSystem ( "persian" ) ;
53
+ const daysInShahrivar = dateInShahrivar . daysInMonth ( ) ;
54
+ expect ( daysInShahrivar ) . toBe ( 31 ) ;
55
+
56
+ const dateInMehr = dayjs ( "2023-09-23" ) . toCalendarSystem ( "persian" ) ;
57
+ const daysInMehr = dateInMehr . daysInMonth ( ) ;
58
+ expect ( daysInMehr ) . toBe ( 30 ) ;
59
+
60
+ const dateInAban = dayjs ( "2023-10-21" ) . toCalendarSystem ( "persian" ) ;
61
+ const daysInAban = dateInAban . daysInMonth ( ) ;
62
+ expect ( daysInAban ) . toBe ( 30 ) ;
63
+
64
+ const dateInAzar = dayjs ( "2023-11-21" ) . toCalendarSystem ( "persian" ) ;
65
+ const daysInAzar = dateInAzar . daysInMonth ( ) ;
66
+ expect ( daysInAzar ) . toBe ( 30 ) ;
67
+
68
+ const dateInDey = dayjs ( "2023-12-21" ) . tz ( "Europe/Paris" ) . toCalendarSystem ( "persian" ) ;
69
+ const daysInDey = dateInDey . daysInMonth ( ) ;
70
+ expect ( daysInDey ) . toBe ( 30 ) ;
71
+
72
+ const dateInBahman = dayjs ( "2023-01-21" ) . tz ( "Europe/Paris" ) . toCalendarSystem ( "persian" ) ;
73
+ const daysInBahman = dateInBahman . daysInMonth ( ) ;
74
+ expect ( daysInBahman ) . toBe ( 30 ) ;
75
+
26
76
const dateInEsfand = dayjs ( "2024-02-20" ) . toCalendarSystem ( "persian" ) ;
27
77
const daysInEsfand = dateInEsfand . daysInMonth ( ) ;
28
78
expect ( daysInEsfand ) . toBe ( 29 ) ; // Esfand in a leap year has 29 days
0 commit comments