fix gaps in sample flight data (#19912)

This commit is contained in:
Nathan Reese 2018-06-15 16:15:41 -06:00 committed by GitHub
parent 5691dcff69
commit bdebff91fb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 2 deletions

View file

@ -112,7 +112,7 @@ export function flightsSpecProvider() {
}
},
timeFields: ['timestamp'],
currentTimeMarker: '2018-01-02T00:00:00Z',
currentTimeMarker: '2018-01-02T00:00:00',
preserveDayOfWeekTimeOfDay: true,
savedObjects: savedObjects,
};

View file

@ -40,7 +40,7 @@ export function adjustTimestamp(timestamp, currentTimeMarker, now, preserveDayOf
// Move timestamp to current week, preserving day of week and time of day
const weekDelta = Math.round((timestampDate.getTime() - currentTimeMarker.getTime()) / (MILLISECONDS_IN_DAY * 7));
const dayOfWeekDelta = timestampDate.getUTCDay() - now.getUTCDay();
const dayOfWeekDelta = timestampDate.getDay() - now.getDay();
const daysDelta = dayOfWeekDelta * MILLISECONDS_IN_DAY + (weekDelta * MILLISECONDS_IN_DAY * 7);
const yearMonthDay = (new Date(now.getTime() + daysDelta)).toISOString().substring(0, 10);
return `${yearMonthDay}T${timestamp.substring(11)}`;

View file

@ -61,5 +61,13 @@ describe('preserve day of week and time of day', () => {
const timestamp = adjustTimestamp(originalTimestamp, currentTimeMarker, now, true);
expect(timestamp).toBe('2018-05-04T23:50:00Z');
});
test('adjusts timestamp to correct day of week even when UTC day is on different day.', () => {
const currentTimeMarker = new Date(Date.parse('2018-01-02T00:00:00')); // Tuesday
const now = new Date(Date.parse('2018-06-14T10:38')); // Thurs
const originalTimestamp = '2018-01-01T17:57:25'; // Monday
const timestamp = adjustTimestamp(originalTimestamp, currentTimeMarker, now, true);
expect(timestamp).toBe('2018-06-11T17:57:25'); // Monday
});
});