@@ -23,18 +23,7 @@ export function getExactDate(rawDate?: string, options = {}) {
2323 if ( rawDate ) {
2424 const isRelativeDate = rawDate . substring ( 0 , 3 ) === 'now' ;
2525 if ( isRelativeDate ) {
26- const isSubtractingDate = rawDate . indexOf ( '-' ) > 0 ;
27- const isRoundingDate = rawDate . indexOf ( '/' ) > 0 ;
28-
29- const rawDateWithouRounding =
30- // When relative time is subtracting a period and rounding the result (e.g. now-24h/h)
31- // removed the rounding part in order to get the exact time.
32- // This is needed because of of "Today"(now/d) and "This week"(now/w) options, it rounds the values up and down
33- // so the exact time is the rounded value.
34- isSubtractingDate && isRoundingDate
35- ? rawDate . substring ( 0 , rawDate . indexOf ( '/' ) )
36- : rawDate ;
37-
26+ const rawDateWithouRounding = rawDate . replace ( / \/ ( \w ) $ / , '' ) ;
3827 return getParsedDate ( rawDateWithouRounding , options ) ;
3928 }
4029 }
@@ -74,15 +63,15 @@ export function getDateRange({
7463
7564 // rounds down start to minute
7665 const roundedStart = moment ( start ) . startOf ( 'minute' ) ;
66+ // rounds down to minute
67+ const exactStart = getExactDate ( rangeFrom ) || roundedStart ;
68+ const exactEnd = getExactDate ( rangeTo , { roundUp : true } ) || end ;
7769
7870 return {
7971 start : roundedStart . toISOString ( ) ,
80- exactStart :
81- getExactDate ( rangeFrom ) ?. toISOString ( ) || roundedStart . toISOString ( ) ,
72+ exactStart : exactStart . toISOString ( ) ,
8273 end : end . toISOString ( ) ,
83- exactEnd :
84- getExactDate ( rangeTo , { roundUp : true } ) ?. toISOString ( ) ||
85- end . toISOString ( ) ,
74+ exactEnd : exactEnd . toISOString ( ) ,
8675 } ;
8776}
8877
0 commit comments