Skip to content

Commit 15fab0f

Browse files
Merge pull request #236 from ExtremeFiretop/ExtremeFiretop-patch-Cron-Estimates
Fix/Patch Cron Estimates
2 parents 2eba66a + 42c735b commit 15fab0f

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

MerlinAU.sh

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
#
55
# Original Creation Date: 2023-Oct-01 by @ExtremeFiretop.
66
# Official Co-Author: @Martinski W. - Date: 2023-Nov-01
7-
# Last Modified: 2024-Jun-05
7+
# Last Modified: 2024-Jun-10
88
###################################################################
99
set -u
1010

11-
readonly SCRIPT_VERSION=1.2.1
11+
readonly SCRIPT_VERSION=1.2.2
1212
readonly SCRIPT_NAME="MerlinAU"
1313

1414
##-------------------------------------##
@@ -3106,9 +3106,9 @@ expand_cron_field()
31063106
fi
31073107
}
31083108

3109-
##----------------------------------------##
3110-
## Modified by Martinski W. [2024-May-18] ##
3111-
##----------------------------------------##
3109+
##------------------------------------------##
3110+
## Modified by ExtremeFiretop [2024-Jun-10] ##
3111+
##------------------------------------------##
31123112
_EstimateNextCronTimeAfterDate_()
31133113
{
31143114
local post_date_secs="$1"
@@ -3139,17 +3139,18 @@ _EstimateNextCronTimeAfterDate_()
31393139
while [ "$found" = "false" ]
31403140
do
31413141
loopCount="$((loopCount + 1))"
3142+
31423143
if matches_month "$current_month" "$month_field" && \
31433144
matches_day_of_month "$current_day" "$dom_field" && \
31443145
matches_day_of_week "$current_dow" "$dow_field"
31453146
then
31463147
for this_hour in $(expand_cron_field "$hour_field" 0 23)
31473148
do
3148-
if [ "$this_hour" -gt "$current_hour" ]
3149+
if [ "$this_hour" -gt "$current_hour" ] || [ "$loopCount" -gt 1 ]
31493150
then
31503151
for this_min in $(expand_cron_field "$minute_field" 0 59)
31513152
do
3152-
echo "$(date '+%s' -d "$current_year-$current_month-$current_day $this_hour:$this_min")"
3153+
echo "$(date -d "@$(date '+%s' -d "$current_year-$current_month-$current_day $this_hour:$this_min")" '+%Y-%m-%d %H:%M:%S')"
31533154
found=true
31543155
return 0
31553156
done
@@ -3159,7 +3160,7 @@ _EstimateNextCronTimeAfterDate_()
31593160
do
31603161
if [ "$this_min" -gt "$current_minute" ]
31613162
then
3162-
echo "$(date '+%s' -d "$current_year-$current_month-$current_day $this_hour:$this_min")"
3163+
echo "$(date -d "@$(date '+%s' -d "$current_year-$current_month-$current_day $this_hour:$this_min")" '+%Y-%m-%d %H:%M:%S')"
31633164
found=true
31643165
return 0
31653166
fi
@@ -3209,9 +3210,9 @@ _Calculate_DST_()
32093210
echo "$((notifyTimeSecs + postponeTimeSecs))"
32103211
}
32113212

3212-
##----------------------------------------##
3213-
## Modified by Martinski W. [2024-May-18] ##
3214-
##----------------------------------------##
3213+
##------------------------------------------##
3214+
## Modified by ExtremeFiretop [2024-Jun-10] ##
3215+
##------------------------------------------##
32153216
_Calculate_NextRunTime_()
32163217
{
32173218
local fwNewUpdateVersion fwNewUpdateNotificationDate
@@ -3240,18 +3241,16 @@ _Calculate_NextRunTime_()
32403241
fwNewUpdateNotificationDate="$(date +%Y-%m-%d_%H:%M:%S)"
32413242
fi
32423243
upfwDateTimeSecs="$(_Calculate_DST_ "$(echo "$fwNewUpdateNotificationDate" | sed 's/_/ /g')")"
3243-
nextCronTimeSecs="$(_EstimateNextCronTimeAfterDate_ "$upfwDateTimeSecs" "$FW_UpdateCronJobSchedule")"
3244-
if [ "$nextCronTimeSecs" = "$CRON_UNKNOWN_DATE" ]
3244+
ExpectedFWUpdateRuntime="$(_EstimateNextCronTimeAfterDate_ "$upfwDateTimeSecs" "$FW_UpdateCronJobSchedule")"
3245+
if [ "$ExpectedFWUpdateRuntime" = "$CRON_UNKNOWN_DATE" ]
32453246
then
32463247
Update_Custom_Settings FW_New_Update_Expected_Run_Date "TBD"
32473248
ExpectedFWUpdateRuntime="${REDct}UNKNOWN${NOct}"
32483249
else
3249-
Update_Custom_Settings FW_New_Update_Expected_Run_Date "$nextCronTimeSecs"
3250-
ExpectedFWUpdateRuntime="$(date -d @$nextCronTimeSecs +"%Y-%b-%d %I:%M %p")"
3250+
Update_Custom_Settings FW_New_Update_Expected_Run_Date "$ExpectedFWUpdateRuntime"
32513251
ExpectedFWUpdateRuntime="${GRNct}$ExpectedFWUpdateRuntime${NOct}"
32523252
fi
32533253
else
3254-
ExpectedFWUpdateRuntime="$(date -d @$ExpectedFWUpdateRuntime +"%Y-%b-%d %I:%M %p")"
32553254
ExpectedFWUpdateRuntime="${GRNct}$ExpectedFWUpdateRuntime${NOct}"
32563255
fi
32573256
}
@@ -3938,8 +3937,7 @@ _CheckTimeToUpdateFirmware_()
39383937
return 1
39393938
fi
39403939

3941-
upfwDateTimeStrn="$(date -d @$nextCronTimeSecs +"%A, %Y-%b-%d %I:%M %p")"
3942-
Say "The firmware update is expected to occur on ${GRNct}${upfwDateTimeStrn}${NOct}."
3940+
Say "The firmware update is expected to occur on ${GRNct}${nextCronTimeSecs}${NOct}."
39433941
echo ""
39443942

39453943
# Check if running in a menu environment

0 commit comments

Comments
 (0)