Skip to content

Commit 5205470

Browse files
abrilgzzdanielluo-msft
authored andcommitted
Adjust the next run time until it is in the future
1 parent 7ad061f commit 5205470

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

UI/web-app/src/utils/dateUtils.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,19 @@ export function formatLastRunTime(lastSuccessfulRunTime: string, period: number)
2727

2828
export function formatNextRunTime(lastSuccessfulRunTime: string, period: number, enabled: boolean): [string, number] {
2929
const currentTime = moment.utc();
30-
const lastRunMoment = moment.utc(lastSuccessfulRunTime);
30+
let lastRunMoment = moment.utc(lastSuccessfulRunTime);
31+
let estimatedNextRunTime = lastRunMoment.add(period, 'hours');
32+
33+
// Adjust the next run time until it is in the future
34+
while (estimatedNextRunTime.isBefore(currentTime) && enabled) {
35+
lastRunMoment = estimatedNextRunTime; // Set new base for calculation
36+
estimatedNextRunTime = lastRunMoment.add(period, 'hours');
37+
}
3138

32-
const estimatedNextRunTime = lastRunMoment.add(period, 'hours');
33-
const formattedDate = estimatedNextRunTime.local().format('MM/DD/YYYY');
34-
const isNextRunInThePast = estimatedNextRunTime.isBefore(currentTime);
35-
const hoursLeft = isNextRunInThePast ? 0 : Math.abs(currentTime.diff(estimatedNextRunTime, 'hours'));
39+
const formattedDate: string = estimatedNextRunTime.local().format('MM/DD/YYYY');
40+
const hoursLeft = Math.abs(currentTime.diff(estimatedNextRunTime, 'hours'));
3641

37-
if (isNextRunInThePast || !enabled) {
42+
if (!enabled) {
3843
return ['', 0];
3944
} else {
4045
return [formattedDate, hoursLeft];

0 commit comments

Comments
 (0)