www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Can we add metric prefix to dur function?

reply Andrea Fontana <nospam example.org> writes:
Every time I use dur, I can't remember if it is "seconds" 
"second" "sec" "millisecond" "milliseconds" "msec" "msecs" etc..

Can't we add the metric prefix as alternative?

For example:

1.dur!"s"
10.dur!"ms"
20.dur!"µs"  <-- (altgr+m on my linux keyboard)
12.dur!"ns"

We should add also non-SI abbrevetion for other common accepted 
units like:

1.dur!"m"
1.dur!"h"
1.dur!"w"

Andrea
Jun 21 2021
next sibling parent Nicholas Wilson <iamthewilsonator hotmail.com> writes:
On Monday, 21 June 2021 at 10:34:51 UTC, Andrea Fontana wrote:
 Every time I use dur, I can't remember if it is "seconds" 
 "second" "sec" "millisecond" "milliseconds" "msec" "msecs" etc..

 Can't we add the metric prefix as alternative?
Sure, open a PR against https://github.com/dlang/druntime/blob/master/src/core/time.d#L1880 and https://github.com/dlang/druntime/blob/master/src/core/time.d#L3416
Jun 22 2021
prev sibling parent reply Dennis <dkorpel gmail.com> writes:
On Monday, 21 June 2021 at 10:34:51 UTC, Andrea Fontana wrote:
 Can't we add the metric prefix as alternative?
Please no. I agree that the current list is not the most consistent or easiest to remember, but the current error message is actually really informative: ``` Error: template instance core.time.dur!"millis" does not match template declaration dur(string units)(long length) with units = "millis" whose parameters have the following constraints: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > units == "weeks" or: > units == "days" or: > units == "hours" or: > units == "minutes" or: > units == "seconds" or: > units == "msecs" or: > units == "usecs" or: > units == "hnsecs" or: > units == "nsecs" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ``` Adding a bunch of synonyms makes things more complex. Whenever there are multiple alternatives for something, it spawns questions like "are there differences" and "which is the preferred one" which you simply don't have with one name per unit.
 20.dur!"µs"  <-- (altgr+m on my linux keyboard)
Next thing someone wants "us" to be consistent with "usecs". Also let's add "secs" and "useconds" and "µseconds". Once there's precedent for synonyms, it can easily get out of hand.
 We should add also non-SI abbrevetion for other common accepted 
 units like:

 1.dur!"m"
 1.dur!"h"
 1.dur!"w"
m = months and w = weeks? I'm familiar with m = meter or milli, but m = month is not obvious to me.
Jun 22 2021
parent Andrea Fontana <nospam example.org> writes:
On Tuesday, 22 June 2021 at 11:08:19 UTC, Dennis wrote:
 On Monday, 21 June 2021 at 10:34:51 UTC, Andrea Fontana wrote:
 m = months and w = weeks? I'm familiar with m = meter or milli, 
 but m = month is not obvious to me.
That's why I added them in another list :) They are non-SI.
Jun 22 2021