I am just starting to try and learn more about Nim having installed it a while ago. My idea was to go through the exercises from the (free) online book 'How to think like a Computer Scientist with Julia' which I had worked through a while ago - using Julia of course. For the exercises, my intention was to read online the Nim features needed for the exercise and implement the solution in Nim. One of the first exercises - which was done in the Julia REPL but required coding in Nim - boiled down to taking a time of day and adding a duration in minutes and seconds to get a new time. Specifically starting with 6:15 and adding 38 minutes and 6 seconds. Instead of doing lots of arithmetic, I decided to look at using the Nim std/times documentation. I actually found it a little confusing but this was my first time looking at the documentation so it could be just unfamiliarity on my part.
The, no doubt not very well written, code seems to run fine:
import times
let f = initTimeFormat("HH:mm:ss") var startTime = "06:52:00".parse(f) let secs = 6 let mins = 38 var d: Duration = initDuration(seconds=secs,minutes=mins) echo (startTime + d).format(f)
However if I change the first line to: let f = initTimeFormat("H:mm:ss") the parse() fails but it says in the manual that for a format patern of HH: ' The hours in two digits always. 0 is prepended if the hour is one digit.'
Can one of you gurus clear up my misunderstanding please? Perhaps you would be king enough to suggest a better way to code it. Apologies for the verbose question.
Many Thanks Ron
You mention that you installed Nim a while ago, which version of Nim are you using? If you're using an older version but reading the latest docs this might be the reason for the contradiction, especially since @void09 seems to not be able to replicate your issue.
By the way, I took the liberty to add a triple-backtick code block around your code so that it is formatted correctly which makes it quite a bit easier to read.