import moment from 'moment' ; import { Coordinate } from '../../typings/timeseries' ; export function offsetPreviousPeriodCoordinates ( { currentPeriodTimeseries , previousPeriodTimeseries , } ) { if ( ! previousPeriodTimeseries ?. length ) { return [ ] ; } const currentPeriodStart = currentPeriodTimeseries ?. [ 0 ] . x ?? 0 ; const dateDiff = currentPeriodStart - previousPeriodTimeseries [ 0 ] . x ; return previousPeriodTimeseries . map ( ( { x , y } ) => { const offsetX = moment ( x ) . add ( dateDiff ) . valueOf ( ) ; return { x : offsetX , y , } ; } ) ; }