{"id":6592,"date":"2025-06-17T22:15:37","date_gmt":"2025-06-18T05:15:37","guid":{"rendered":"https:\/\/blackcap.name\/blog\/new\/?p=6592"},"modified":"2025-06-17T22:15:37","modified_gmt":"2025-06-18T05:15:37","slug":"time-and-date-done-right","status":"publish","type":"post","link":"https:\/\/blackcap.name\/blog\/new\/?p=6592","title":{"rendered":"Time and Date Done Right"},"content":{"rendered":"<p>To avoid being simply negative and cutting others&#8217; efforts down, I will contrast the shambolic time and date situation in Java with the superior one in Python.<\/p>\n<p>The latter has two time and date packages. This is largely as a result of history. One, <kbd>time<\/kbd>, came early on, and basically is a way to call the Posix time and date functions from Python. The other, <kbd>datetime<\/kbd>, came later, and is geared to more advanced use cases.<\/p>\n<p>I almost always just use <kbd>time<\/kbd>, because as I said earlier, by far the most common uses for a time datatype are to create an instance of one and to print it. For that, the traditional <kbd>time<\/kbd> library is more than sufficient.<\/p>\n<p>But even <kbd>datetime<\/kbd> is so much better designed than its Java counterpart. Instead of nine absolute time types, there are three (a calendar date, a time of day, and a date with a time). Instead of two relative types, there is just one (which, really, is all one needs). Instead of an elaborate set of classes devoted to formatting and outputting a time, there is just a <kbd>strftime<\/kbd> method for each time object (and all the <kbd>strftime<\/kbd>&#8216;s use exactly the same format-specifying mini-language, which is mostly compatible with the one used in the Posix\/C world. The cognitive load of understanding it all is so much more reasonable.<\/p>\n<p>As for the legacy class, its base time type is a Python floating point number. This is a value type, and as such avoids all the headaches associated with a mutable reference type. Its alternate time type is a Python tuple. Since tuples are immutable in Python, this also neatly avoids mutability headaches. And since standard, pre-existing data types are used, there is once more less cognitive load imposed on the programmer.<\/p>\n<p>Since there is nothing fundamentally wrong with the older <kbd>time<\/kbd> class, it is considered just fine to use it in new programs. Because of course it is: it is the simpler of the two, and simplicity has long been a <a href=\"https:\/\/peps.python.org\/pep-0020\/\">core value<\/a> in the Python world.<\/p>\n<p>It&#8217;s one of the reasons I can be so harsh on Java. They knew better, or rather <em>should have<\/em> known better. Python predates Java, and Python did not come up with this simplicity-as-a-virtue business. UNIX embodied it over two decades before Python popped onto the scene. By the time the 1990&#8217;s rolled around, UNIX had a longstanding reputation for being an exceptionally productive programming environment.<\/p>\n<p>The principles were known. The Java world chose to ignore them, and has suffered as a result ever since.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>To avoid being simply negative and cutting others&#8217; efforts down, I will contrast the shambolic time and date situation in Java with the superior one in Python. The latter has two time and date packages. This is largely as a result of history. One, time, came early on, and basically is a way to call [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-6592","post","type-post","status-publish","format-standard","hentry","category-computers"],"_links":{"self":[{"href":"https:\/\/blackcap.name\/blog\/new\/index.php?rest_route=\/wp\/v2\/posts\/6592","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blackcap.name\/blog\/new\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blackcap.name\/blog\/new\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blackcap.name\/blog\/new\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blackcap.name\/blog\/new\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6592"}],"version-history":[{"count":1,"href":"https:\/\/blackcap.name\/blog\/new\/index.php?rest_route=\/wp\/v2\/posts\/6592\/revisions"}],"predecessor-version":[{"id":6593,"href":"https:\/\/blackcap.name\/blog\/new\/index.php?rest_route=\/wp\/v2\/posts\/6592\/revisions\/6593"}],"wp:attachment":[{"href":"https:\/\/blackcap.name\/blog\/new\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6592"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blackcap.name\/blog\/new\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6592"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blackcap.name\/blog\/new\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6592"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}