Remove Previous Year week alignment (https://github.com/woocommerce/woocommerce-admin/pull/3271)
* remove previous year week alignment, include full day at end of previous period * update script testing of weeks in last year
This commit is contained in:
parent
53e3009c4b
commit
c5f0fa90b2
|
@ -152,15 +152,8 @@ export function getLastPeriod( period, compare ) {
|
|||
secondaryStart = secondaryEnd.clone().subtract( daysDiff, 'days' );
|
||||
}
|
||||
} else {
|
||||
secondaryStart =
|
||||
'week' === period
|
||||
? primaryStart
|
||||
.clone()
|
||||
.subtract( 1, 'years' )
|
||||
.week( primaryStart.week() )
|
||||
.startOf( 'week' )
|
||||
: primaryStart.clone().subtract( 1, 'years' );
|
||||
secondaryEnd = secondaryStart.clone().endOf( period );
|
||||
secondaryStart = primaryStart.clone().subtract( 1, 'years' );
|
||||
secondaryEnd = primaryEnd.clone().subtract( 1, 'years' );
|
||||
}
|
||||
return {
|
||||
primaryStart,
|
||||
|
@ -189,15 +182,9 @@ export function getCurrentPeriod( period, compare ) {
|
|||
secondaryStart = primaryStart.clone().subtract( 1, period );
|
||||
secondaryEnd = primaryEnd.clone().subtract( 1, period );
|
||||
} else {
|
||||
secondaryStart =
|
||||
'week' === period
|
||||
? primaryStart
|
||||
.clone()
|
||||
.subtract( 1, 'years' )
|
||||
.week( primaryStart.week() )
|
||||
.startOf( 'week' )
|
||||
: primaryStart.clone().subtract( 1, 'years' );
|
||||
secondaryEnd = secondaryStart.clone().add( daysSoFar, 'days' );
|
||||
secondaryStart = primaryStart.clone().subtract( 1, 'years' );
|
||||
// Set the end time to 23:59:59.
|
||||
secondaryEnd = secondaryStart.clone().add( daysSoFar + 1, 'days' ).subtract( 1, 'seconds' );
|
||||
}
|
||||
return {
|
||||
primaryStart,
|
||||
|
|
|
@ -213,11 +213,8 @@ describe( 'getCurrentPeriod', () => {
|
|||
it( 'should return correct values for previous_year', () => {
|
||||
const dateValue = getCurrentPeriod( 'week', 'previous_year' );
|
||||
const daysSoFar = today.diff( thisWeekStart, 'days' );
|
||||
const thisWeekLastYearStart = thisWeekStart
|
||||
.clone()
|
||||
.subtract( 1, 'years' )
|
||||
.week( thisWeekStart.week() )
|
||||
.startOf( 'week' );
|
||||
// Last year weeks are aligned by calendar date not day of week.
|
||||
const thisWeekLastYearStart = thisWeekStart.clone().subtract( 1, 'years' );
|
||||
const todayThisWeekLastYear = thisWeekLastYearStart.clone().add( daysSoFar, 'days' );
|
||||
|
||||
expect( thisWeekLastYearStart.isSame( dateValue.secondaryStart, 'day' ) ).toBe( true );
|
||||
|
@ -394,12 +391,9 @@ describe( 'getLastPeriod', () => {
|
|||
it( 'should return correct values for previous_year', () => {
|
||||
const dateValue = getLastPeriod( 'week', 'previous_year' );
|
||||
|
||||
const lastWeekLastYearStart = lastWeekStart
|
||||
.clone()
|
||||
.subtract( 1, 'year' )
|
||||
.week( lastWeekStart.week() )
|
||||
.startOf( 'week' );
|
||||
const lastWeekLastYearEnd = lastWeekLastYearStart.clone().endOf( 'week' );
|
||||
// Last year weeks are aligned by calendar date not day of week.
|
||||
const lastWeekLastYearStart = lastWeekStart.clone().subtract( 1, 'year' );
|
||||
const lastWeekLastYearEnd = lastWeekEnd.clone().subtract( 1, 'year' );
|
||||
|
||||
expect( lastWeekLastYearStart.isSame( dateValue.secondaryStart, 'day' ) ).toBe( true );
|
||||
expect( lastWeekLastYearEnd.isSame( dateValue.secondaryEnd, 'day' ) ).toBe( true );
|
||||
|
|
Loading…
Reference in New Issue