* 50 seconds is 1 hour?
@ 2009-12-01 15:14 Lennart Borgman
2009-12-01 15:25 ` Andreas Schwab
0 siblings, 1 reply; 10+ messages in thread
From: Lennart Borgman @ 2009-12-01 15:14 UTC (permalink / raw)
To: Emacs-Devel devel
I use (current-time) and (time-substract) to get the elapsed time. I
get something like elapsed=(0 51 532000).
Then I try to use (format-time-string "%H" elapsed) and get "01". I am
a bit surprised. Is this a bug or am I doing something that surprises
Emacs?
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: 50 seconds is 1 hour?
2009-12-01 15:14 50 seconds is 1 hour? Lennart Borgman
@ 2009-12-01 15:25 ` Andreas Schwab
2009-12-01 15:28 ` Lennart Borgman
0 siblings, 1 reply; 10+ messages in thread
From: Andreas Schwab @ 2009-12-01 15:25 UTC (permalink / raw)
To: Lennart Borgman; +Cc: Emacs-Devel devel
Lennart Borgman <lennart.borgman@gmail.com> writes:
> I use (current-time) and (time-substract) to get the elapsed time. I
> get something like elapsed=(0 51 532000).
>
> Then I try to use (format-time-string "%H" elapsed) and get "01".
Try (format-time-string "%H" elapsed t). But format-time-string is not
designed to format time differences, only points in time.
Andreas.
--
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: 50 seconds is 1 hour?
2009-12-01 15:25 ` Andreas Schwab
@ 2009-12-01 15:28 ` Lennart Borgman
2009-12-01 15:42 ` Andreas Schwab
0 siblings, 1 reply; 10+ messages in thread
From: Lennart Borgman @ 2009-12-01 15:28 UTC (permalink / raw)
To: Andreas Schwab; +Cc: Emacs-Devel devel
On Tue, Dec 1, 2009 at 4:25 PM, Andreas Schwab <schwab@linux-m68k.org> wrote:
> Lennart Borgman <lennart.borgman@gmail.com> writes:
>
>> I use (current-time) and (time-substract) to get the elapsed time. I
>> get something like elapsed=(0 51 532000).
>>
>> Then I try to use (format-time-string "%H" elapsed) and get "01".
>
> Try (format-time-string "%H" elapsed t).
Thanks, it worked.
> But format-time-string is not
> designed to format time differences, only points in time.
I am just trying to stretch it a bit...
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: 50 seconds is 1 hour?
2009-12-01 15:28 ` Lennart Borgman
@ 2009-12-01 15:42 ` Andreas Schwab
2009-12-01 15:44 ` Lennart Borgman
0 siblings, 1 reply; 10+ messages in thread
From: Andreas Schwab @ 2009-12-01 15:42 UTC (permalink / raw)
To: Lennart Borgman; +Cc: Emacs-Devel devel
Lennart Borgman <lennart.borgman@gmail.com> writes:
> I am just trying to stretch it a bit...
Don't expect to get useful output, then.
Andreas.
--
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: 50 seconds is 1 hour?
2009-12-01 15:42 ` Andreas Schwab
@ 2009-12-01 15:44 ` Lennart Borgman
2009-12-01 17:24 ` Davis Herring
0 siblings, 1 reply; 10+ messages in thread
From: Lennart Borgman @ 2009-12-01 15:44 UTC (permalink / raw)
To: Andreas Schwab; +Cc: Emacs-Devel devel
On Tue, Dec 1, 2009 at 4:42 PM, Andreas Schwab <schwab@linux-m68k.org> wrote:
> Lennart Borgman <lennart.borgman@gmail.com> writes:
>
>> I am just trying to stretch it a bit...
>
> Don't expect to get useful output, then.
I meant "can't we use it for this too?".
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: 50 seconds is 1 hour?
2009-12-01 15:44 ` Lennart Borgman
@ 2009-12-01 17:24 ` Davis Herring
2009-12-01 17:34 ` Glenn Morris
2009-12-01 17:34 ` Lennart Borgman
0 siblings, 2 replies; 10+ messages in thread
From: Davis Herring @ 2009-12-01 17:24 UTC (permalink / raw)
To: Lennart Borgman; +Cc: Andreas Schwab, Emacs-Devel devel
> I meant "can't we use it for this too?".
Not really: it can't do anything useful for intervals longer than one day.
Sure, up to 31 days you can get (n+1)dHHhMMmSSs with the format string
"%dd%Hh%Mm%Ss", but obviously the n+1 is absurdly ugly (trying to fix it
by subtracting 86400 gives 31 rather than 0 for small intervals). And
after that it's entirely useless; a "month" is not a useful, fixed unit of
time in its reckoning.
The hack thus covers 0-86399 well (if you know you're in that range, so
you don't print the day), and 86400-2678399 in a very silly, broken way,
and it fails for the other 99.94% of time values, including all negative
intervals (which may or may not make sense depending on the application,
but "-3 seconds" or "3 seconds ago" is clearly much more correct than
"31d23h59m57s"). And it can't indicate partial seconds.
Clearly, extending it to handle all this would interfere terribly with its
correct usage. So, no. Perhaps you'd like to specify an interface for
the function you'd really like to have? I'd be willing to write it if I
knew what exactly you wanted it to return. (For instance, should it omit
fields that are 0? That is, without varying any formatting arguments that
it might have, should it be able to return "5:34" and "1:00:31" for 334
and 3631 seconds?)
Davis
--
This product is sold by volume, not by mass. If it appears too dense or
too sparse, it is because mass-energy conversion has occurred during
shipping.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: 50 seconds is 1 hour?
2009-12-01 17:24 ` Davis Herring
@ 2009-12-01 17:34 ` Glenn Morris
2009-12-01 17:37 ` Lennart Borgman
2009-12-01 17:38 ` Davis Herring
2009-12-01 17:34 ` Lennart Borgman
1 sibling, 2 replies; 10+ messages in thread
From: Glenn Morris @ 2009-12-01 17:34 UTC (permalink / raw)
To: herring; +Cc: Andreas Schwab, Lennart Borgman, Emacs-Devel devel
"Davis Herring" wrote:
> should it be able to return "5:34" and "1:00:31" for 334 and 3631
> seconds?)
(format-seconds "%h:%z%.2m:%s" 334)
(format-seconds "%h:%z%.2m:%s" 3631)
almost does this.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: 50 seconds is 1 hour?
2009-12-01 17:24 ` Davis Herring
2009-12-01 17:34 ` Glenn Morris
@ 2009-12-01 17:34 ` Lennart Borgman
1 sibling, 0 replies; 10+ messages in thread
From: Lennart Borgman @ 2009-12-01 17:34 UTC (permalink / raw)
To: herring; +Cc: Andreas Schwab, Emacs-Devel devel
On Tue, Dec 1, 2009 at 6:24 PM, Davis Herring <herring@lanl.gov> wrote:
>
> Clearly, extending it to handle all this would interfere terribly with its
> correct usage. So, no. Perhaps you'd like to specify an interface for
> the function you'd really like to have? I'd be willing to write it if I
> knew what exactly you wanted it to return. (For instance, should it omit
> fields that are 0? That is, without varying any formatting arguments that
> it might have, should it be able to return "5:34" and "1:00:31" for 334
> and 3631 seconds?)
I am just trying to get a human readable output of the result of
(time-subtract ...). I use it for elapsed time. Clearly for such usage
the output could in a strict sense contain only
days, hours, minutes, seconds
Making a good general function for that seems perhaps a bit tricky
since you may both want to leave out things from the beginning of this
list and specify a format for them. But maybe it can take four
optional format arguments in the reverse order of this list?
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: 50 seconds is 1 hour?
2009-12-01 17:34 ` Glenn Morris
@ 2009-12-01 17:37 ` Lennart Borgman
2009-12-01 17:38 ` Davis Herring
1 sibling, 0 replies; 10+ messages in thread
From: Lennart Borgman @ 2009-12-01 17:37 UTC (permalink / raw)
To: Glenn Morris; +Cc: Andreas Schwab, Emacs-Devel devel
On Tue, Dec 1, 2009 at 6:34 PM, Glenn Morris <rgm@gnu.org> wrote:
> "Davis Herring" wrote:
>
>> should it be able to return "5:34" and "1:00:31" for 334 and 3631
>> seconds?)
>
> (format-seconds "%h:%z%.2m:%s" 334)
> (format-seconds "%h:%z%.2m:%s" 3631)
>
> almost does this.
Thanks, I missed that one. Using that + float-time seems to do what I want.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: 50 seconds is 1 hour?
2009-12-01 17:34 ` Glenn Morris
2009-12-01 17:37 ` Lennart Borgman
@ 2009-12-01 17:38 ` Davis Herring
1 sibling, 0 replies; 10+ messages in thread
From: Davis Herring @ 2009-12-01 17:38 UTC (permalink / raw)
To: Glenn Morris; +Cc: Andreas Schwab, Lennart Borgman, Emacs-Devel devel
>> should it be able to return "5:34" and "1:00:31" for 334 and 3631
>> seconds?)
>
> (format-seconds "%h:%z%.2m:%s" 334)
> (format-seconds "%h:%z%.2m:%s" 3631)
>
> almost does this.
That's probably close enough (especially since one could strip leading 0s
afterwards if desired); I didn't know it existed. Thanks!
Davis
--
This product is sold by volume, not by mass. If it appears too dense or
too sparse, it is because mass-energy conversion has occurred during
shipping.
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2009-12-01 17:38 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-12-01 15:14 50 seconds is 1 hour? Lennart Borgman
2009-12-01 15:25 ` Andreas Schwab
2009-12-01 15:28 ` Lennart Borgman
2009-12-01 15:42 ` Andreas Schwab
2009-12-01 15:44 ` Lennart Borgman
2009-12-01 17:24 ` Davis Herring
2009-12-01 17:34 ` Glenn Morris
2009-12-01 17:37 ` Lennart Borgman
2009-12-01 17:38 ` Davis Herring
2009-12-01 17:34 ` Lennart Borgman
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).