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 flux-framework#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 Oct 14, 2021
1 parent 1530471 commit 628a2cd
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 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 @@ -99,7 +99,7 @@ local function reladate (t)
return fmt ("%d weeks ago", (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 628a2cd

Please sign in to comment.