proc `$`*(moment: Moment): string = result &= "[" if moment.minutes != 0: result &= fmt"{moment.minutes}m " if moment.seconds != 0: result &= fmt"{moment.seconds}s " if moment.milliSeconds != 0: result &= fmt"{moment.milliSeconds}ms " if moment.microSeconds != 0: result &= fmt"{moment.microSeconds}μs " result &= fmt"{moment.nanoSeconds:.2f}ns" result &= "]"
proc toTime(time: int64): Moment = var moment = new Moment let nanoTime = TimeInt(time) moment.nanoSeconds = float(nanoTime mod1_000) moment.microSeconds = (nanoTime div1_000) mod1_000 moment.milliSeconds = (nanoTime div1_000_000) mod1_000 moment.seconds = (nanoTime div1_000_000_000) mod1_000 moment.minutes = (nanoTime div1_000_000_000div60) mod1_000 moment