You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
is there an easy way to floor a duration? 18m2.43245343s => 18m2s
There's some ways to achieve this in the language currently, but Excel's MROUND and related functions seem like a nice template of ideas of how we might improve on this.
Details
At the time this issue is being filed, super is at commit. 92e3052.
FWIW, the specific result the user was seeking can be obtained in a couple ways, such as using the bucket function as suggested by @mattnibs:
Before seeing that approach, I'd also come up with this hacky approach:
$ super -version
Version: v1.18.0-121-g92e30525
$ echo '18m2.43245343s' | super -z -c 'duration(regexp_replace(string(this), /\..*s$/, "s"))' -
18m2s
But for the general case, something more flexible is probably justified. Looking at what else is out there, Excel's MROUND has at least two improvements I could see adopting here.
Excel's MROUND accepts time-based values, not just pure numbers. Right now our functions like round and floor only take numeric arguments, so for a duration value like the user's, the functions currently just return the same value unmodified. While bucket does take time & duration values, it behaves only in a "floor"-like manner, so a user that wants something "round"-like or "ceil"-like would need another approach.
Excel's MROUND takes take an argument that can specify an arbitrary multiple by which to round/floor, whereas right now our round/floor/ceil functions only produce a result to the the appropriate nearest integer. bucket() can take an arbitrary duration value for its argument so it can produce a result like "the nearest 15-minute floor", but as previously mentioned, it can't produce a "round"-like or "ceil"-like result.
The text was updated successfully, but these errors were encountered:
tl;dr
A user asked in a recent community Slack thread:
There's some ways to achieve this in the language currently, but Excel's MROUND and related functions seem like a nice template of ideas of how we might improve on this.
Details
At the time this issue is being filed, super is at commit. 92e3052.
FWIW, the specific result the user was seeking can be obtained in a couple ways, such as using the
bucket
function as suggested by @mattnibs:Before seeing that approach, I'd also come up with this hacky approach:
But for the general case, something more flexible is probably justified. Looking at what else is out there, Excel's MROUND has at least two improvements I could see adopting here.
Excel's
MROUND
accepts time-based values, not just pure numbers. Right now our functions likeround
andfloor
only take numeric arguments, so for a duration value like the user's, the functions currently just return the same value unmodified. Whilebucket
does take time & duration values, it behaves only in a "floor"-like manner, so a user that wants something "round"-like or "ceil"-like would need another approach.Excel's
MROUND
takes take an argument that can specify an arbitrary multiple by which to round/floor, whereas right now our round/floor/ceil functions only produce a result to the the appropriate nearest integer.bucket()
can take an arbitrary duration value for its argument so it can produce a result like "the nearest 15-minute floor", but as previously mentioned, it can't produce a "round"-like or "ceil"-like result.The text was updated successfully, but these errors were encountered: