@@ -78,31 +78,17 @@ export function subtractInterval(date: moment.Moment, interval: ParsedInterval):
7878 */
7979export const alignToOrigin = ( startDate : moment . Moment , interval : ParsedInterval , origin : moment . Moment ) : moment . Moment => {
8080 let alignedDate = startDate . clone ( ) ;
81- let intervalOp ;
82- let isIntervalNegative = false ;
83-
84- let offsetDate = addInterval ( origin , interval ) ;
85-
86- // The easiest way to check the interval sign
87- if ( offsetDate . isBefore ( origin ) ) {
88- isIntervalNegative = true ;
89- }
90-
91- offsetDate = origin . clone ( ) ;
81+ let offsetDate = origin . clone ( ) ;
9282
9383 if ( startDate . isBefore ( origin ) ) {
94- intervalOp = isIntervalNegative ? addInterval : subtractInterval ;
95-
9684 while ( offsetDate . isAfter ( startDate ) ) {
97- offsetDate = intervalOp ( offsetDate , interval ) ;
85+ offsetDate = subtractInterval ( offsetDate , interval ) ;
9886 }
9987 alignedDate = offsetDate ;
10088 } else {
101- intervalOp = isIntervalNegative ? subtractInterval : addInterval ;
102-
10389 while ( offsetDate . isBefore ( startDate ) ) {
10490 alignedDate = offsetDate . clone ( ) ;
105- offsetDate = intervalOp ( offsetDate , interval ) ;
91+ offsetDate = addInterval ( offsetDate , interval ) ;
10692 }
10793
10894 if ( offsetDate . isSame ( startDate ) ) {
0 commit comments