Fix end date for last periods (https://github.com/woocommerce/woocommerce-admin/pull/6584)
* Fix end date for last periods * Test February end date for leap year * Add changelog and testing instructions * Handle feedback * Fix merge conflict * Add changelog
This commit is contained in:
parent
35d58de151
commit
78e49ab09e
|
@ -11,6 +11,18 @@
|
|||
5. Click the Download button.
|
||||
6. Open the downloaded file and confirm the status values match the table.
|
||||
|
||||
### Fix end date for last periods #6584
|
||||
1. Update your system clock to March 2021
|
||||
2. Create a completed order on 29th February 2020
|
||||
3. Go to Analytics > Revenue
|
||||
4. In the date range filter, select "Last Month" preset and compare to "Previous Year"
|
||||
5. Observe that 29th February sales are included
|
||||
6. In the date range filter, select "Last Week" preset and compare to "Previous Year"
|
||||
7. Observe that the end date is the same as the current year's end date
|
||||
8. In the date range filter, select "Last Quarter" preset and compare to "Previous Year"
|
||||
9. Observe that the end date is the same as the selected quarter and subtract 1 year
|
||||
10. In the date range filter, select "Last Year" preset and compare to "Previous Year"
|
||||
11. Observe that the end date is the same as the selected year and subtract 1 year
|
||||
## 2.5.0
|
||||
|
||||
### Fix WC Home crash when the Analytics is disabled #7339
|
||||
|
@ -84,7 +96,6 @@ Please make sure to test it on Safari as well.
|
|||
5. Click on "Set up Tax" option on Task list.
|
||||
6. TOS should not blink.
|
||||
|
||||
|
||||
### Use saved values if available when switching tabs #7226
|
||||
|
||||
1. Start onboarding wizard and continue to step 4.
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
Significance: patch
|
||||
Type: Fix
|
||||
|
||||
Fix end date for last periods
|
|
@ -173,9 +173,12 @@ export function getLastPeriod( period, compare ) {
|
|||
secondaryEnd = primaryStart.clone().subtract( 1, 'days' );
|
||||
secondaryStart = secondaryEnd.clone().subtract( daysDiff, 'days' );
|
||||
}
|
||||
} else {
|
||||
} else if ( period === 'week' ) {
|
||||
secondaryStart = primaryStart.clone().subtract( 1, 'years' );
|
||||
secondaryEnd = primaryEnd.clone().subtract( 1, 'years' );
|
||||
} else {
|
||||
secondaryStart = primaryStart.clone().subtract( 1, 'years' );
|
||||
secondaryEnd = secondaryStart.clone().endOf( period );
|
||||
}
|
||||
|
||||
// When the period is month, be sure to force end of month to take into account leap year
|
||||
|
|
|
@ -579,6 +579,19 @@ describe( 'getLastPeriod', () => {
|
|||
lastMonthkLastYearEnd.isSame( dateValue.secondaryEnd, 'day' )
|
||||
).toBe( true );
|
||||
} );
|
||||
|
||||
it( 'should return correct values on a leap year', () => {
|
||||
// Mock the current time as a year and month after a leap year month, March 2021.
|
||||
const dateNowSpy = jest
|
||||
.spyOn( Date, 'now' )
|
||||
.mockImplementation( () => 1615587095000 );
|
||||
|
||||
const dateValue = getLastPeriod( 'month', 'previous_year' );
|
||||
|
||||
expect( dateValue.secondaryEnd.date() ).toBe( 29 );
|
||||
|
||||
dateNowSpy.mockRestore();
|
||||
} );
|
||||
} );
|
||||
|
||||
describe( 'quarter', () => {
|
||||
|
|
Loading…
Reference in New Issue