taskwarrior icon indicating copy to clipboard operation
taskwarrior copied to clipboard

"task calc 12h + 25m + 30s" gives 750+ days

Open smemsh opened this issue 3 years ago • 15 comments

with taskwarrior v2.6.2:

$ src/task calc 12h + 25m + 30s
P750DT12H30S

discrepant with https://taskwarrior.org/docs/commands/calc/ section "Durations" where it claims the output should be:

$ task calc 12h + 25m +30s
PT12H25mPT30S

(I tried with and without the space after second +, present on web site but makes no difference) (not sure if libshared is the right place for this issue?)

smemsh avatar Aug 03 '22 18:08 smemsh

Looks like m gets interpreted as month, so that's where 750 (=25x30 days) comes from. Using min instead of m yields the expected result:

task calc 12h + 25min + 30s
PT12H25M30S

Perhaps we should try to be case-sensitive in the parsing of the intervals, where M would mean month and m a minute.

tbabej avatar Aug 04 '22 15:08 tbabej

Ah so that's where it came from. Actually I noticed even the supposed output on that page was not being parsed correctly even when it was written, it says:

$ task calc 12h + 25m +30s
PT12H25mPT30S

Note the m in the middle, probably unchanged from the input m. It's giving two separate time durations, as denoted by two PT. looks like it was seeing three expressions: (1) the interval 12h + 25, (2) the letter m, and then (3) 30s. So probably this was never correct even in prior versions.

Perhaps we should try to be case-sensitive in the parsing of the intervals, where M would mean month and m a minute.

I do think most people would assume a single m was a minute rather than a month. Also note that mo, mos, month and months already are availble to mean 30 days (but mon or mons does not work).

Actually, timew-durations(7) shows:

minutes, minute, mins, min
monthly, months, month, mnths, mths, mth, mos, mo, m

Also we should consider that ISO8601 durations use capital M for minute, ie the format being:

P<date>T<days>D<hours>H<minutes>M<seconds>S

I would vote for m changed to mean minutes, rather than months, because that's what the obvious meaning is, but it would be a breaking change. I like it better, but admittedly it's subjective.

Perhaps just the docs at that url should be changed to use correct syntax. Or we should wait to see if there's any other comments...

smemsh avatar Aug 05 '22 01:08 smemsh

I don't think this should be changed. Task dates are far more likely to be measured in days, weeks, months vs seconds, minutes, or even hours. I can't remember ever needing to add a task with a due date in X minutes time.

ar1428 avatar Oct 14 '22 08:10 ar1428

this is not just for setting for due dates, it's for any operation where durations are used in any context (both task and time -warrior), they are all being parsed by this libshared code. I frequently use minutes and seconds and do "task calc ... " in subshells to make start/end times for example. it seems really strange to me that hms stands for hour, month, second rather than hour, minute, second, I think would be the normal expectation (carried over from other contexts too, unrelated to task warrior, where it would be the typical expectation).

That said you're the only one that voted besides me and it's against the change so hopefully we'll get some other votes!

smemsh avatar Oct 14 '22 13:10 smemsh

pressed wrong button didn't mean to close

smemsh avatar Oct 14 '22 13:10 smemsh

@smemsh I've not needed to use timewarrior, so wasn't particularly aware of that context.

Some other ideas:

  • Allow it to be re-configured by the user (i.e. I could leave it as month, you could remap it to minute)
  • Attempt to detect and warn the user of likely incorrect usage, e.g. hours and months together

ar1428 avatar Oct 15 '22 10:10 ar1428