|
Joined: Dec 2002
Posts: 341
Pan-dimensional mouse
|
OP
Pan-dimensional mouse
Joined: Dec 2002
Posts: 341 |
I still would like to suggest that $duration to be modified.
Currently $duration(seconds,N) returns week/day/hour/minute/second format N=2 does not include seconds N=3 returns it in hh:nn:ss format
Suggestion N=4 returns day/hour/minute/second format N=5 returns day/hour/minute format without seconds N=6 returns it in dd:hh:nn:ss format, with dd referring to the number of days
Examples $duration(9999999) = 16wks 3days 17hrs 46mins 39secs $duration(9999999,2) = 16wks 3days 17hrs 46mins $duration(9999999,3) = 2777:46:39 $duration(9999999,4) = 115days 17hrs 46mins 39secs $duration(9999999,5) = 115days 17hrs 46mins $duration(9999999,6) = 115:17:46:39
|
|
|
|
Joined: Apr 2010
Posts: 30
Ameglian cow
|
Ameglian cow
Joined: Apr 2010
Posts: 30 |
Uh, why so random?
My suggestion:
Allow a format parameter $duration(seconds,format)
that works just like the one of $asctime
example: $duration(9999999,dd:hh:nn:ss) = 115:17:46:39
imho this would be a lot better way than providing a bunch of random presets
|
|
|
|
Joined: Oct 2004
Posts: 8,061
Hoopy frood
|
Hoopy frood
Joined: Oct 2004
Posts: 8,061 |
Agreed. Using a format parameter makes more sense. I used that method when setting up my $DateXpander() identifier that takes $duration() and expands it to output months and years accurately based on # of days per month including leap years. It works well and is easy to remember.
|
|
|
|
Joined: Jan 2003
Posts: 2,125
Hoopy frood
|
Hoopy frood
Joined: Jan 2003
Posts: 2,125 |
A problem with a format parameter is that duration cannot be broken down to months/years without specifying the start date, eg 60 days may not be exactly two months if the start date is 1st of January (since 31 + 28 = 59). One approach would be to assume months are 30 days on average (and years are 365 days). If that approach were taken, I'm sure somebody would come here complaining about this  A related problem is the absence of a 'weeks' sequence from the available formats. In general, the format parameter is meant to represent points in time, not durations. I'm not arguing against the feature, just pointing out that there are issues (which I'm guessing are the reason $duration has not supported a format parameter so far).
|
|
|
|
Joined: Oct 2003
Posts: 3,641
Hoopy frood
|
Hoopy frood
Joined: Oct 2003
Posts: 3,641 |
Why bake this into $duration when you have $asctime($duration(...), FORMAT)
|
|
|
|
Joined: Oct 2004
Posts: 8,061
Hoopy frood
|
Hoopy frood
Joined: Oct 2004
Posts: 8,061 |
A problem with a format parameter is that duration cannot be broken down to months/years without specifying the start date You don't have to include months/years in the format parameter. I just used that as an example with how mine worked when I included a format parameter. @argv0, yes, $asctime($duration(),format) would also work. Even so, for such a commonly used identifier, I don't see why a format parameter can't be included in the identifier.
|
|
|
|
Joined: Apr 2010
Posts: 30
Ameglian cow
|
Ameglian cow
Joined: Apr 2010
Posts: 30 |
$asctime($duration(...), FORMAT) does not work as expected:
example: //echo -a $asctime($duration(3600),s) i expect "3600" i get "1" (wtf?) //echo -a $asctime($duration(3600),n) i expect "60" i get "00"
the format parameter to calculate a duration has to be a lot more intelligent than the parameter of asctime. It has to look out if a larger time interval format parameters is present and if not it has to re-calculate the value using a smaller time interval: n:s -> 60:0 s -> 3600
I see how this is a problem and why there are presets for $duration.
I guess it's best to use your own scripts to format a duration the way you want it.
Last edited by m0viefreak; 26/05/10 12:21 AM.
|
|
|
|
Joined: Oct 2003
Posts: 3,641
Hoopy frood
|
Hoopy frood
Joined: Oct 2003
Posts: 3,641 |
Actually $asctime($duration(N),format) is unusable, I'm not sure why I suggested it. On a related note, your examples don't work because $duration(3600) returns "1hr" which $asctime can't interpret. And unfortunately $asctime does not start at 0:00, so it's unreliable to be used in this way.
|
|
|
|
|