From 84f9679fb8cca0bc30cc4d385222aecbce4fc39d Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Fri, 22 Dec 2023 05:48:31 -0500 Subject: [PATCH] [8.12] rolling file appender: fix next rolling time for DST (#173811) (#173901) # Backport This will backport the following commits from `main` to `8.12`: - [rolling file appender: fix next rolling time for DST (#173811)](https://github.com/elastic/kibana/pull/173811) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) Co-authored-by: Pierre Gayvallet --- .../get_next_rolling_time.test.ts | 23 +++++++++++++++++++ .../time_interval/get_next_rolling_time.ts | 6 +++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/packages/core/logging/core-logging-server-internal/src/appenders/rolling_file/policies/time_interval/get_next_rolling_time.test.ts b/packages/core/logging/core-logging-server-internal/src/appenders/rolling_file/policies/time_interval/get_next_rolling_time.test.ts index 197d3757f1386..4d61172b7d156 100644 --- a/packages/core/logging/core-logging-server-internal/src/appenders/rolling_file/policies/time_interval/get_next_rolling_time.test.ts +++ b/packages/core/logging/core-logging-server-internal/src/appenders/rolling_file/policies/time_interval/get_next_rolling_time.test.ts @@ -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( diff --git a/packages/core/logging/core-logging-server-internal/src/appenders/rolling_file/policies/time_interval/get_next_rolling_time.ts b/packages/core/logging/core-logging-server-internal/src/appenders/rolling_file/policies/time_interval/get_next_rolling_time.ts index 343bd97cb8dff..a31a01e881188 100644 --- a/packages/core/logging/core-logging-server-internal/src/appenders/rolling_file/policies/time_interval/get_next_rolling_time.ts +++ b/packages/core/logging/core-logging-server-internal/src/appenders/rolling_file/policies/time_interval/get_next_rolling_time.ts @@ -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(); }