@@ -18,10 +18,10 @@ export function getPreviousQuarter(now = new Date()): Range {
1818 const previousQuarterYear = now . getFullYear ( ) - ( currentQuarter === 0 ? 1 : 0 ) ;
1919
2020 const previousQuarterStart = quarters [ previousQuarter ] [ 0 ] ;
21- const start = safeDate ( previousQuarterYear , previousQuarterStart ) ;
21+ const start = safeDate ( previousQuarterYear , previousQuarterStart , 1 ) ;
2222
2323 const previousQuarterEnd = quarters [ previousQuarter ] [ 2 ] ;
24- const end = new Date ( new Date ( previousQuarterYear , previousQuarterEnd + 1 ) . getTime ( ) - 1 ) ;
24+ const end = new Date ( safeDate ( previousQuarterYear , previousQuarterEnd + 1 , 1 ) . getTime ( ) - 1 ) ;
2525
2626 return { start, end } ;
2727}
@@ -31,38 +31,38 @@ export function getCurrentQuarter(now = new Date()): Range {
3131 const currentQuarter = quarters . findIndex ( months => months . includes ( currentMonth ) ) ;
3232
3333 const currentQuarterStart = quarters [ currentQuarter ] [ 0 ] ;
34- const start = safeDate ( now . getFullYear ( ) , currentQuarterStart ) ;
34+ const start = safeDate ( now . getFullYear ( ) , currentQuarterStart , 1 ) ;
3535
3636 const currentQuarterEnd = quarters [ currentQuarter ] [ 2 ] ;
37- const end = new Date ( safeDate ( now . getFullYear ( ) , currentQuarterEnd + 1 ) . getTime ( ) - 1 ) ;
37+ const end = new Date ( safeDate ( now . getFullYear ( ) , currentQuarterEnd + 1 , 1 ) . getTime ( ) - 1 ) ;
3838
3939 return { start, end } ;
4040}
4141
4242export function getPreviousMonth ( now = new Date ( ) ) : Range {
43- const start = safeDate ( now . getFullYear ( ) , now . getMonth ( ) - 1 ) ;
44- const end = new Date ( safeDate ( now . getFullYear ( ) , now . getMonth ( ) ) . getTime ( ) - 1 ) ;
43+ const start = safeDate ( now . getFullYear ( ) , now . getMonth ( ) - 1 , 1 ) ;
44+ const end = new Date ( safeDate ( now . getFullYear ( ) , now . getMonth ( ) , 1 ) . getTime ( ) - 1 ) ;
4545
4646 return { start, end } ;
4747}
4848
4949export function getCurrentMonth ( now = new Date ( ) ) : Range {
50- const start = safeDate ( now . getFullYear ( ) , now . getMonth ( ) ) ;
51- const end = new Date ( safeDate ( now . getFullYear ( ) , now . getMonth ( ) + 1 ) . getTime ( ) - 1 ) ;
50+ const start = safeDate ( now . getFullYear ( ) , now . getMonth ( ) , 1 ) ;
51+ const end = new Date ( safeDate ( now . getFullYear ( ) , now . getMonth ( ) + 1 , 1 ) . getTime ( ) - 1 ) ;
5252
5353 return { start, end } ;
5454}
5555
5656export function getPreviousYear ( now = new Date ( ) ) : Range {
57- const start = safeDate ( now . getFullYear ( ) - 1 , 0 ) ;
58- const end = new Date ( safeDate ( now . getFullYear ( ) , 0 ) . getTime ( ) - 1 ) ;
57+ const start = safeDate ( now . getFullYear ( ) - 1 , 0 , 1 ) ;
58+ const end = new Date ( safeDate ( now . getFullYear ( ) , 0 , 1 ) . getTime ( ) - 1 ) ;
5959
6060 return { start, end } ;
6161}
6262
6363export function getCurrentYear ( now = new Date ( ) ) : Range {
64- const start = safeDate ( now . getFullYear ( ) , 0 ) ;
65- const end = new Date ( safeDate ( now . getFullYear ( ) + 1 , 0 ) . getTime ( ) - 1 ) ;
64+ const start = safeDate ( now . getFullYear ( ) , 0 , 1 ) ;
65+ const end = new Date ( safeDate ( now . getFullYear ( ) + 1 , 0 , 1 ) . getTime ( ) - 1 ) ;
6666
6767 return { start, end } ;
6868}
0 commit comments