Skip to content

Commit

Permalink
[8.12] rolling file appender: fix next rolling time for DST (elastic#…
Browse files Browse the repository at this point in the history
…173811) (elastic#173901)

# Backport

This will backport the following commits from `main` to `8.12`:
- [rolling file appender: fix next rolling time for DST
(elastic#173811)](elastic#173811)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Pierre
Gayvallet","email":"[email protected]"},"sourceCommit":{"committedDate":"2023-12-22T09:40:20Z","message":"rolling
file appender: fix next rolling time for DST (elastic#173811)\n\n##
Summary\r\n\r\nFix
https://github.com/elastic/kibana/issues/173808\r\n\r\n### Release
Note\r\n\r\nFix a bug that could cause the `rollingFile` log appender to
not\r\nproperly rotate files on DST switch
days.","sha":"1131932cd0ec24283a8c62973e09ee3ab20edfb4","branchLabelMapping":{"^v8.13.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Team:Core","release_note:fix","Feature:Logging","backport:prev-minor","v8.13.0"],"number":173811,"url":"https://github.com/elastic/kibana/pull/173811","mergeCommit":{"message":"rolling
file appender: fix next rolling time for DST (elastic#173811)\n\n##
Summary\r\n\r\nFix
https://github.com/elastic/kibana/issues/173808\r\n\r\n### Release
Note\r\n\r\nFix a bug that could cause the `rollingFile` log appender to
not\r\nproperly rotate files on DST switch
days.","sha":"1131932cd0ec24283a8c62973e09ee3ab20edfb4"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v8.13.0","labelRegex":"^v8.13.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/173811","number":173811,"mergeCommit":{"message":"rolling
file appender: fix next rolling time for DST (elastic#173811)\n\n##
Summary\r\n\r\nFix
https://github.com/elastic/kibana/issues/173808\r\n\r\n### Release
Note\r\n\r\nFix a bug that could cause the `rollingFile` log appender to
not\r\nproperly rotate files on DST switch
days.","sha":"1131932cd0ec24283a8c62973e09ee3ab20edfb4"}}]}] BACKPORT-->

Co-authored-by: Pierre Gayvallet <[email protected]>
  • Loading branch information
kibanamachine and pgayvallet authored Dec 22, 2023
1 parent 8794c84 commit 84f9679
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit 84f9679

Please sign in to comment.