Merge pull request woocommerce/woocommerce-admin#1778 from woocommerce/fix/1651-rest-api-datetime-offset

Remove timezone from appendTimestamp() output.
This commit is contained in:
Jeff Stieler 2019-03-12 07:35:13 -06:00 committed by GitHub
commit ec9ea43c9b
3 changed files with 10 additions and 6 deletions

View File

@ -1,3 +1,7 @@
# 1.0.6
- Removed timezone from `appendTimestamp()` output.
# 1.0.5
- Fixed bug in getAllowedIntervalsForQuery() to not return `hour` for default intervals

View File

@ -63,15 +63,15 @@ export const periods = [
export const appendTimestamp = ( date, timeOfDay ) => {
date = date.format( isoDateFormat );
if ( timeOfDay === 'start' ) {
return date + 'T00:00:00+00:00';
return date + 'T00:00:00';
}
if ( timeOfDay === 'now' ) {
// Set seconds to 00 to avoid consecutives calls happening before the previous
// one finished.
return date + 'T' + moment().format( 'HH:mm:00' ) + '+00:00';
return date + 'T' + moment().format( 'HH:mm:00' );
}
if ( timeOfDay === 'end' ) {
return date + 'T23:59:59+00:00';
return date + 'T23:59:59';
}
throw new Error( 'appendTimestamp requires second parameter to be either `start`, `now` or `end`' );
};

View File

@ -26,16 +26,16 @@ import {
describe( 'appendTimestamp', () => {
it( 'should append `start` timestamp', () => {
expect( appendTimestamp( moment( '2018-01-01' ), 'start' ) ).toEqual( '2018-01-01T00:00:00+00:00' );
expect( appendTimestamp( moment( '2018-01-01' ), 'start' ) ).toEqual( '2018-01-01T00:00:00' );
} );
it( 'should append `now` timestamp', () => {
const nowTimestamp = moment().format( 'HH:mm:00' );
expect( appendTimestamp( moment( '2018-01-01' ), 'now' ) ).toEqual( '2018-01-01T' + nowTimestamp + '+00:00' );
expect( appendTimestamp( moment( '2018-01-01' ), 'now' ) ).toEqual( '2018-01-01T' + nowTimestamp );
} );
it( 'should append `end` timestamp', () => {
expect( appendTimestamp( moment( '2018-01-01' ), 'end' ) ).toEqual( '2018-01-01T23:59:59+00:00' );
expect( appendTimestamp( moment( '2018-01-01' ), 'end' ) ).toEqual( '2018-01-01T23:59:59' );
} );
it( 'should throw and error if `timeOfDay` is not valid', () => {