<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Standards on Much Ado About IT</title><link>https://it.knightnet.org.uk/tags/standards/</link><description>
Recent content about Standards from Much Ado About IT |
Ramblings and rantings from IT Architect &amp; Designer, Julian Knight</description><generator>Hugo | gohugo.io | Theme twenty-sixteen</generator><language>en-gb</language><copyright>This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.</copyright><lastBuildDate>Mon, 24 Apr 2023 21:27:28 +0000</lastBuildDate><atom:link href="https://it.knightnet.org.uk/tags/standards/feed.xml" rel="self" type="application/rss+xml"/><item><title>Rules for working with dates and times</title><link>https://it.knightnet.org.uk/blog/rules-for-working-with-dates-and-times/</link><guid isPermaLink="true">https://it.knightnet.org.uk/blog/rules-for-working-with-dates-and-times/</guid><pubDate>Sat, 07 Mar 2020 15:35:49 +0000</pubDate><guid>https://it.knightnet.org.uk/blog/rules-for-working-with-dates-and-times/</guid><description><div>Dates and times are incredibly complex. They can be different in different countries, languages. They are often inconsistent and have weird edge-cases. These are some basic rules I apply when working with dates and times.</div><div>&lt;p>when handling dates and timestamps, here are the foundation rules that I work to:&lt;/p>
&lt;ul>
&lt;li>
&lt;p>&lt;strong>Always use ISO date format where possible&lt;/strong> (YYYY-MM-DD)&lt;/p>
&lt;p>So that there can be no ambiguity and so that date strings will naturally sort&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Always work in UTC&lt;/strong> (Aka Zulu time or GMT) except when displaying to the user&lt;/p>
&lt;p>To avoid weird errors, especially with timezone and daylight savings transitions. It also makes date/time calculations a LOT easier.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>When needing a string format for timestamps, always use ISO format&lt;/strong>&lt;/p>
&lt;p>e.g. &lt;code>2020-03-07T15:27:46.123Z&lt;/code>&lt;/p>
&lt;p>These are always unambiguous and easily machine parsed.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>When specifying decimal seconds in a timestamp, avoid more than 3 decimal places&lt;/strong>&lt;/p>
&lt;p>The &lt;a href="https://github.com/gr2m/moment-parseformat">parsing tool&lt;/a> used in &lt;a href="">node-red-contrib-moment&lt;/a> to parse input dates in different formats cannot cope with more than 3dp and may return strange dates, a problem that I reported in May 2019 but hasn&amp;rsquo;t been resolved.&lt;/p>
&lt;p>It should also be noted that I&amp;rsquo;m not sure that MomentJS can cope with more than 9dp.&lt;/p>
&lt;p>Also worth noting that JavaScript&amp;rsquo;s &lt;code>Date&lt;/code> native object only supports up to 3dp anyway and will turn anything beyond that into zero&amp;rsquo;s.&lt;/p>
&lt;/li>
&lt;/ul>
&lt;h2 id="references">References&lt;/h2>
&lt;ul>
&lt;li>
&lt;p>&lt;a href="https://github.com/gr2m/moment-parseformat/issues/96">parseFormat function issue for &amp;gt;3dp seconds resolution&lt;/a>&lt;/p>
&lt;p>The worst thing about this issue is that it can result in an incorrect date being returned but does not give a warning.&lt;/p>
&lt;/li>
&lt;/ul></div></description><author>Julian Knight</author><category domain="https://it.knightnet.org.uk/categories/information-management">Information Management</category><category domain="https://it.knightnet.org.uk/categories/data">Data</category><category domain="https://it.knightnet.org.uk/categories/development">Development</category><category domain="https://it.knightnet.org.uk/categories/software">Software</category><category domain="https://it.knightnet.org.uk/tags/databases">Databases</category><category domain="https://it.knightnet.org.uk/tags/dates">Dates</category><category domain="https://it.knightnet.org.uk/tags/dba">DBA</category><category domain="https://it.knightnet.org.uk/tags/debugging">Debugging</category><category domain="https://it.knightnet.org.uk/tags/development">Development</category><category domain="https://it.knightnet.org.uk/tags/software">Software</category><category domain="https://it.knightnet.org.uk/tags/solutions-architecture">Solutions Architecture</category><category domain="https://it.knightnet.org.uk/tags/standards">Standards</category><category domain="https://it.knightnet.org.uk/tags/timestamps">Timestamps</category></item></channel></rss>