Skip to content

Commit

Permalink
flux-cron: coerce values to integer when using %d
Browse files Browse the repository at this point in the history
Problem: On centos8 some of the tests in t0016-cron-faketime.t
fail with the following error:

 lua: /usr/src/src/cmd/flux-cron:102:
   bad argument #2 to 'fmt' (number has no integer representation)

Coerce values to integer using math.floor when %d is used in string.format
to avoid this error.
  • Loading branch information
grondo committed Dec 21, 2021
1 parent 37229a0 commit caaf39a
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/cmd/flux-cron
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ local function reladate (t)
return fmt ("a minute ago")
end
if (diff < 90) then
return fmt ("%d minutes ago", diff)
return fmt ("%d minutes ago", math.floor (diff + 0.5))
end

-- Convert to hours:
Expand All @@ -96,10 +96,10 @@ local function reladate (t)
-- weeks for past 10 weeks or so, reduce precision in output:
local d = math.floor (diff)
if (d < 70) then
return fmt ("%d weeks ago", (d + 3) / 7)
return fmt ("%d weeks ago", math.floor ((d + 3) / 7))
end
if (d < 365) then
return fmt ("%d months ago", (d + 15) / 30)
return fmt ("%d months ago", math.floor ((d + 15) / 30))
end

return fmt ("%.1f years ago", diff / 365)
Expand Down

0 comments on commit caaf39a

Please sign in to comment.