mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
fix gaps in sample flight data (#19912)
This commit is contained in:
parent
5691dcff69
commit
bdebff91fb
3 changed files with 10 additions and 2 deletions
|
@ -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,
|
||||
};
|
||||
|
|
|
@ -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)}`;
|
||||
|
|
|
@ -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
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue