<story><title>Jiff: Datetime library for Rust</title><url>https://github.com/BurntSushi/jiff</url></story><parent_chain><item><author>TacticalCoder</author><text>I love burntsushi&amp;#x27;s ripgrep and certainly use it all the time, calling it directly from my beloved Emacs (and I do invoke it all the time). If was using ripgrep already years before Debian shipped &lt;i&gt;rg&lt;/i&gt; natively.&lt;p&gt;I was also using JodaTime back when some people still though Eclipse was better than IntelliJ IDEA.&lt;p&gt;But there&amp;#x27;s nothing in that document that contradicts: &lt;i&gt;&amp;quot;just represent duration as nanoseconds&amp;quot;&lt;/i&gt;.&lt;p&gt;Users needs to see timezones and correct hour depending on DST, sure. Programs typically do not. Unless you&amp;#x27;re working on stuff specifically dealing with different timezones, it&amp;#x27;s usually a very safe bet to: &lt;i&gt;&amp;quot;represent duration as milliseconds&amp;#x2F;nanoseconds&amp;quot;&lt;/i&gt;.&lt;p&gt;That humans have invented timezones and DST won&amp;#x27;t change the physics of a CPU&amp;#x27;s internal clock ticking x billion times per second.&lt;p&gt;Just look at, say, the kernel of an OS that didn&amp;#x27;t crash on half the planet a few days ago: there are plenty of timeouts in code expressed as milliseconds.&lt;p&gt;Reading your comment could be misinterpreted as: &lt;i&gt;&amp;quot;We&amp;#x27;ll allow a 30 seconds cooldown, so let&amp;#x27;s take the current timezone, add 30 seconds to that, save that time as a string with the time 30 seconds from now, complete with its timezone, DST, 12&amp;#x2F;24 hours representation and while we&amp;#x27;re at it maybe add exta code logic to check if there&amp;#x27;s going to be a leap second or not to make sure we don&amp;#x27;t wait 29 or 31 seconds, then let the cooldown happen at the &amp;#x27;correct&amp;#x27; time&amp;quot;&lt;/i&gt;. Or you could, you know, just use a freakin&amp;#x27; 30 seconds timeout&amp;#x2F;cooldown expressed in milliseconds (without caring about whether a leap second happened or not btw because we don&amp;#x27;t care if it actually happens after 29 seconds &lt;i&gt;as seen by the user&lt;/i&gt;).</text></item><item><author>magnio</author><text>I have seen many people downplaying the complexity of a datetime library. &amp;quot;Just use UTC&amp;#x2F;Unix time as an internal representation&amp;quot;, &amp;quot;just represent duration as nanoseconds&amp;quot;, &amp;quot;just use offset instead of timezones&amp;quot;, and on and on&lt;p&gt;For anyone having that thought, try reading through the design document of Jiff (&lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;github.com&amp;#x2F;BurntSushi&amp;#x2F;jiff&amp;#x2F;blob&amp;#x2F;master&amp;#x2F;DESIGN.md&quot;&gt;https:&amp;#x2F;&amp;#x2F;github.com&amp;#x2F;BurntSushi&amp;#x2F;jiff&amp;#x2F;blob&amp;#x2F;master&amp;#x2F;DESIGN.md&lt;/a&gt;), which, as all things burntsushi do, is excellent and extensive. Another good read is the comparison with (mainly) chrono, the de facto standard datetime library in Rust: &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;docs.rs&amp;#x2F;jiff&amp;#x2F;latest&amp;#x2F;jiff&amp;#x2F;_documentation&amp;#x2F;comparison&amp;#x2F;index.html&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;docs.rs&amp;#x2F;jiff&amp;#x2F;latest&amp;#x2F;jiff&amp;#x2F;_documentation&amp;#x2F;comparison&amp;#x2F;i...&lt;/a&gt;&lt;p&gt;Stuffs like DST arithmetic (that works across ser&amp;#x2F;de!), roundable duration, timezone aware calendar arithmetic, retrospective timezone conflict detection (!), etc. all contribute to a making the library correct, capable, and pleasant to use. In my experience, chrono is a very comprehensive and &amp;quot;correct&amp;quot; library, but it is also rigid and not very easy to use.</text></item></parent_chain><comment><author>burntsushi</author><text>I&amp;#x27;m not sure what the issue is here exactly, but there are surely use cases where a `std::time::SystemTime` (which you can think of as a Unix timestamp) is plenty sufficient. ripgrep, for example, uses `SystemTime`. But it has never used a datetime library. Just because Jiff exists doesn&amp;#x27;t all of a sudden mean you can&amp;#x27;t use `SystemTime`.&lt;p&gt;But there&amp;#x27;s a whole world above and beyond timestamps.</text></comment>
<story><title>Jiff: Datetime library for Rust</title><url>https://github.com/BurntSushi/jiff</url></story><parent_chain><item><author>TacticalCoder</author><text>I love burntsushi&amp;#x27;s ripgrep and certainly use it all the time, calling it directly from my beloved Emacs (and I do invoke it all the time). If was using ripgrep already years before Debian shipped &lt;i&gt;rg&lt;/i&gt; natively.&lt;p&gt;I was also using JodaTime back when some people still though Eclipse was better than IntelliJ IDEA.&lt;p&gt;But there&amp;#x27;s nothing in that document that contradicts: &lt;i&gt;&amp;quot;just represent duration as nanoseconds&amp;quot;&lt;/i&gt;.&lt;p&gt;Users needs to see timezones and correct hour depending on DST, sure. Programs typically do not. Unless you&amp;#x27;re working on stuff specifically dealing with different timezones, it&amp;#x27;s usually a very safe bet to: &lt;i&gt;&amp;quot;represent duration as milliseconds&amp;#x2F;nanoseconds&amp;quot;&lt;/i&gt;.&lt;p&gt;That humans have invented timezones and DST won&amp;#x27;t change the physics of a CPU&amp;#x27;s internal clock ticking x billion times per second.&lt;p&gt;Just look at, say, the kernel of an OS that didn&amp;#x27;t crash on half the planet a few days ago: there are plenty of timeouts in code expressed as milliseconds.&lt;p&gt;Reading your comment could be misinterpreted as: &lt;i&gt;&amp;quot;We&amp;#x27;ll allow a 30 seconds cooldown, so let&amp;#x27;s take the current timezone, add 30 seconds to that, save that time as a string with the time 30 seconds from now, complete with its timezone, DST, 12&amp;#x2F;24 hours representation and while we&amp;#x27;re at it maybe add exta code logic to check if there&amp;#x27;s going to be a leap second or not to make sure we don&amp;#x27;t wait 29 or 31 seconds, then let the cooldown happen at the &amp;#x27;correct&amp;#x27; time&amp;quot;&lt;/i&gt;. Or you could, you know, just use a freakin&amp;#x27; 30 seconds timeout&amp;#x2F;cooldown expressed in milliseconds (without caring about whether a leap second happened or not btw because we don&amp;#x27;t care if it actually happens after 29 seconds &lt;i&gt;as seen by the user&lt;/i&gt;).</text></item><item><author>magnio</author><text>I have seen many people downplaying the complexity of a datetime library. &amp;quot;Just use UTC&amp;#x2F;Unix time as an internal representation&amp;quot;, &amp;quot;just represent duration as nanoseconds&amp;quot;, &amp;quot;just use offset instead of timezones&amp;quot;, and on and on&lt;p&gt;For anyone having that thought, try reading through the design document of Jiff (&lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;github.com&amp;#x2F;BurntSushi&amp;#x2F;jiff&amp;#x2F;blob&amp;#x2F;master&amp;#x2F;DESIGN.md&quot;&gt;https:&amp;#x2F;&amp;#x2F;github.com&amp;#x2F;BurntSushi&amp;#x2F;jiff&amp;#x2F;blob&amp;#x2F;master&amp;#x2F;DESIGN.md&lt;/a&gt;), which, as all things burntsushi do, is excellent and extensive. Another good read is the comparison with (mainly) chrono, the de facto standard datetime library in Rust: &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;docs.rs&amp;#x2F;jiff&amp;#x2F;latest&amp;#x2F;jiff&amp;#x2F;_documentation&amp;#x2F;comparison&amp;#x2F;index.html&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;docs.rs&amp;#x2F;jiff&amp;#x2F;latest&amp;#x2F;jiff&amp;#x2F;_documentation&amp;#x2F;comparison&amp;#x2F;i...&lt;/a&gt;&lt;p&gt;Stuffs like DST arithmetic (that works across ser&amp;#x2F;de!), roundable duration, timezone aware calendar arithmetic, retrospective timezone conflict detection (!), etc. all contribute to a making the library correct, capable, and pleasant to use. In my experience, chrono is a very comprehensive and &amp;quot;correct&amp;quot; library, but it is also rigid and not very easy to use.</text></item></parent_chain><comment><author>tijsvd</author><text>Of course you don&amp;#x27;t need a calendar library to measure 30 seconds. That&amp;#x27;s not the use case.&lt;p&gt;Try adding one year to a timestamp because you&amp;#x27;re tracking someone&amp;#x27;s birthday. Or add one week because of running a backup schedule.</text></comment>