@@ -79,13 +79,16 @@ describe('Billing Core Functions', () => {
7979 vi . setSystemTime ( new Date ( '2024-07-15T10:00:00Z' ) )
8080 const result = calculateBillingPeriod ( )
8181
82- // Should return current calendar month
82+ // Should return current calendar month (1st to last day of current month)
8383 expect ( result . start . getUTCFullYear ( ) ) . toBe ( 2024 )
8484 expect ( result . start . getUTCMonth ( ) ) . toBe ( 6 ) // July (0-indexed)
8585 expect ( result . start . getUTCDate ( ) ) . toBe ( 1 ) // Should start on 1st of month
8686 expect ( result . end . getUTCFullYear ( ) ) . toBe ( 2024 )
87- expect ( result . end . getUTCMonth ( ) ) . toBe ( 7 ) // August (0-indexed)
88- expect ( result . end . getUTCDate ( ) ) . toBe ( 1 ) // Should end on 1st of next month
87+ expect ( result . end . getUTCMonth ( ) ) . toBe ( 6 ) // July (0-indexed) - ends on last day of current month
88+ expect ( result . end . getUTCDate ( ) ) . toBe ( 31 ) // Should end on last day of July
89+ expect ( result . end . getUTCHours ( ) ) . toBe ( 23 ) // Should end at 23:59:59.999
90+ expect ( result . end . getUTCMinutes ( ) ) . toBe ( 59 )
91+ expect ( result . end . getUTCSeconds ( ) ) . toBe ( 59 )
8992 } )
9093
9194 it . concurrent ( 'handles subscription anniversary date correctly' , ( ) => {
@@ -110,18 +113,18 @@ describe('Billing Core Functions', () => {
110113 const currentPeriodEnd = new Date ( '2024-07-15T23:59:59Z' )
111114 const result = calculateNextBillingPeriod ( currentPeriodEnd )
112115
113- expect ( result . start . getDate ( ) ) . toBe ( 15 )
114- expect ( result . start . getMonth ( ) ) . toBe ( 6 ) // July (0-indexed)
115- expect ( result . end . getDate ( ) ) . toBe ( 15 )
116- expect ( result . end . getMonth ( ) ) . toBe ( 7 ) // August (0-indexed)
116+ expect ( result . start . getUTCDate ( ) ) . toBe ( 15 )
117+ expect ( result . start . getUTCMonth ( ) ) . toBe ( 6 ) // July (0-indexed)
118+ expect ( result . end . getUTCDate ( ) ) . toBe ( 15 )
119+ expect ( result . end . getUTCMonth ( ) ) . toBe ( 7 ) // August (0-indexed)
117120 } )
118121
119122 it . concurrent ( 'handles month boundary correctly' , ( ) => {
120123 const currentPeriodEnd = new Date ( '2024-01-31T23:59:59Z' )
121124 const result = calculateNextBillingPeriod ( currentPeriodEnd )
122125
123- expect ( result . start . getMonth ( ) ) . toBe ( 0 ) // January
124- expect ( result . end . getMonth ( ) ) . toBeGreaterThanOrEqual ( 1 ) // February or later due to month overflow
126+ expect ( result . start . getUTCMonth ( ) ) . toBe ( 0 ) // January
127+ expect ( result . end . getUTCMonth ( ) ) . toBeGreaterThanOrEqual ( 1 ) // February or later due to month overflow
125128 } )
126129 } )
127130
@@ -227,8 +230,8 @@ describe('Billing Core Functions', () => {
227230 const janEnd = new Date ( '2024-01-31T00:00:00Z' )
228231 const result = calculateNextBillingPeriod ( janEnd )
229232
230- expect ( result . start . getMonth ( ) ) . toBe ( 0 ) // January
231- expect ( result . end . getMonth ( ) ) . toBeGreaterThanOrEqual ( 1 ) // February or later due to month overflow
233+ expect ( result . start . getUTCMonth ( ) ) . toBe ( 0 ) // January
234+ expect ( result . end . getUTCMonth ( ) ) . toBeGreaterThanOrEqual ( 1 ) // February or later due to month overflow
232235 } )
233236
234237 it . concurrent ( 'handles leap year correctly' , ( ) => {
@@ -247,10 +250,10 @@ describe('Billing Core Functions', () => {
247250 const decEnd = new Date ( '2024-12-15T00:00:00Z' )
248251 const result = calculateNextBillingPeriod ( decEnd )
249252
250- expect ( result . start . getFullYear ( ) ) . toBe ( 2024 )
251- expect ( result . start . getMonth ( ) ) . toBe ( 11 ) // December
252- expect ( result . end . getFullYear ( ) ) . toBe ( 2025 )
253- expect ( result . end . getMonth ( ) ) . toBe ( 0 ) // January
253+ expect ( result . start . getUTCFullYear ( ) ) . toBe ( 2024 )
254+ expect ( result . start . getUTCMonth ( ) ) . toBe ( 11 ) // December
255+ expect ( result . end . getUTCFullYear ( ) ) . toBe ( 2025 )
256+ expect ( result . end . getUTCMonth ( ) ) . toBe ( 0 ) // January
254257 } )
255258
256259 it . concurrent ( 'basic date calculations work' , ( ) => {
0 commit comments