Hi Bruno, On Sun, Nov 2, 2008 at 10:52 AM, Bruno Haible <[EMAIL PROTECTED]> wrote: > Hi, > > Bruce Korb wrote: >> I had need of a function to convert some variation of a time (duration) >> specification into a count of seconds. For your amusement and optional >> inclusion...(I *think* I've got papers on file for gnulib....) >> >> It accepts several formats: >> >> [DD d] [HH h] [MM m] [SS s] >> [DD d] [[HH:]MM:]SS >> [DD d] [HH h] [MM:]SS >> >> though it is unhappy if it finds nothing. > > Yes, I think if several programs can agree to parse durations in the same > way, this can only be beneficial.
My motivation was that I noticed that someone implemented what I implemented as ``timed-task'' as ``timeout'' and I used basically this code to parse the "how long should I wait" option. Though "timeout" only accepts it as an operand. > Looking at wikipedia [1], I would find it good if > 1) the function was called 'parse_duration', not 'parse_time' (since "time" > often denotes a time instant within a day), Sure. My coin landed "heads" instead of "tails" when I was deciding. > 2) the three duration formats described in [1] were also supported. 3? I only see one, though with lots of optional fields. That format also doesn't allow for visual space. Anyway, it's trivial enough to look for a string starting with 'P' or 'T' and handle the ISO-8601 duration. The little question remaining though is "how many seconds in a year" and, more importantly, "how many seconds in a month"? In other words, if some one in February were expecting P1M to represent a 28 day duration and a 31 day duration had it been March, um, well, I think maybe they should implement it. :) Dealing with "leap seconds" would get extremely over the top. Cheers - Bruce