mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
rolling file appender: fix next rolling time for DST (#173811)
## Summary Fix https://github.com/elastic/kibana/issues/173808 ### Release Note Fix a bug that could cause the `rollingFile` log appender to not properly rotate files on DST switch days.
This commit is contained in:
parent
a636dcb11e
commit
1131932cd0
2 changed files with 27 additions and 2 deletions
|
@ -22,6 +22,29 @@ const formattedRollingTime = (date: string, duration: string, modulate: boolean)
|
|||
).format(format);
|
||||
|
||||
describe('getNextRollingTime', () => {
|
||||
describe('DST', () => {
|
||||
it('returns the correct date when entering DST', () => {
|
||||
expect(formattedRollingTime('2023-03-11 23:59:59:999', '24h', true)).toEqual(
|
||||
'2023-03-12 00:00:00:000'
|
||||
);
|
||||
});
|
||||
it('returns the correct date within DST', () => {
|
||||
expect(formattedRollingTime('2023-06-15 23:59:59:999', '24h', true)).toEqual(
|
||||
'2023-06-16 00:00:00:000'
|
||||
);
|
||||
});
|
||||
it('returns the correct date when exiting DST', () => {
|
||||
expect(formattedRollingTime('2023-11-05 23:59:59:999', '24h', true)).toEqual(
|
||||
'2023-11-06 00:00:00:000'
|
||||
);
|
||||
});
|
||||
it('returns the correct date outside of DST', () => {
|
||||
expect(formattedRollingTime('2023-01-07 23:59:59:999', '24h', true)).toEqual(
|
||||
'2023-01-08 00:00:00:000'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when `modulate` is false', () => {
|
||||
it('increments the current time by the interval', () => {
|
||||
expect(formattedRollingTime('2010-10-20 04:27:12:000', '15m', false)).toEqual(
|
||||
|
|
|
@ -23,8 +23,10 @@ export const getNextRollingTime = (
|
|||
const increment =
|
||||
interval.get(incrementedUnit) -
|
||||
(currentMoment.get(incrementedUnit) % interval.get(incrementedUnit));
|
||||
const incrementInMs = moment.duration(increment, incrementedUnit).asMilliseconds();
|
||||
return currentMoment.startOf(incrementedUnit).toDate().getTime() + incrementInMs;
|
||||
const nextRollingMoment = currentMoment
|
||||
.startOf(incrementedUnit)
|
||||
.add(increment, incrementedUnit);
|
||||
return nextRollingMoment.toDate().getTime();
|
||||
} else {
|
||||
return currentTime + interval.asMilliseconds();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue