toml-lang / toml

Tom's Obvious, Minimal Language
https://toml.io
MIT License
19.45k stars 847 forks source link

Does time need to be < 24h? (use case: elapsed time) #952

Closed silverhook closed 1 year ago

silverhook commented 1 year ago

I have a use-case where I want to log how much time something took.

In that case should I use the (local?) time type? Which may be against the (local) time type intention.

time = 342:12:29

or do I need to declare it as a string? Which is just very confusing since there is also a time type (and it is OK if you use it within the range of 24h).

time = "342:12:29"
marzer commented 1 year ago

Yes, the Time type in TOML is a time point, as in, a specific time of day (optionally at a specific date using the full Date-Time formats).

What you're asking for is a Duration type; there's a proposal to add one to the language here: https://github.com/toml-lang/toml/issues/514

silverhook commented 1 year ago

Ah, thanks. I searched before and at a very lazy look that issue did not seem the same, but you’re right.

I’m closing this issue in favour of #514 then.

marzer commented 1 year ago

If you're not too interested in down-to-the-nanosecond precision, a user-friendly workaround for this is to simply use a float, e.g.

timeout_minutes = 2.5 # 2 min 30 sec
silverhook commented 1 year ago

@marzer That’s a good option, thanks. But my use case is at the same time kinda niche and silly, and not really that important – I use TOML to keep my highscores and a few games record also how much time something took.

I decided to just save it as a string for now.

marzer commented 1 year ago

Ah yup, in that case you'd definitely want precision, lest you incur the wrath of angry players :D