mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
# 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) <!--- Backport version: 8.9.7 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Pierre Gayvallet","email":"pierre.gayvallet@elastic.co"},"sourceCommit":{"committedDate":"2023-12-22T09:40:20Z","message":"rolling file appender: fix next rolling time for DST (#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 (#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 (#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 <pierre.gayvallet@elastic.co>
This commit is contained in:
parent
8794c84361
commit
84f9679fb8
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