{"id":456,"date":"2012-04-08T21:48:14","date_gmt":"2012-04-09T04:48:14","guid":{"rendered":"http:\/\/10kdev.ivystreetinc.com\/?p=456"},"modified":"2012-04-08T21:48:14","modified_gmt":"2012-04-09T04:48:14","slug":"y2k-dates-out-of-control","status":"publish","type":"post","link":"http:\/\/10kdev.net\/?p=456","title":{"rendered":"Y2K Dates Out Of Control!"},"content":{"rendered":"<p>Wow check this out I was digging in a java code base and ran into this date conversion code (added the dateString initialization to illustrate):<\/p>\n<pre style=\"padding-left: 30px;\"><span style=\"color: #0000ff;\">String dateString = \"04\/29\/05\" ; \u00a0 \/\/ two digit year<\/span>\r\n<span style=\"color: #0000ff;\"> String newDateString = dateString.substring(0, length - 2);<\/span>\r\n<span style=\"color: #0000ff;\"> if (Integer.parseInt(year.substring(2)) &gt; 25) {<\/span>\r\n<span style=\"color: #0000ff;\">\u00a0 \u00a0 \u00a0 newDateString += \"19\";<\/span>\r\n<span style=\"color: #0000ff;\"> } else {<\/span>\r\n<span style=\"color: #0000ff;\">\u00a0 \u00a0 \u00a0newDateString += \"20\";<\/span>\r\n<span style=\"color: #0000ff;\"> }<\/span><\/pre>\n<pre style=\"padding-left: 30px;\"><span style=\"color: #0000ff;\">newDateString += dateString.substring(length - 2);<\/span><\/pre>\n<pre style=\"padding-left: 30px;\"><span style=\"color: #0000ff;\"> dateString = newDateString;<\/span><\/pre>\n<p>LOL. \u00a0So if the year is greater than 25, it&#8217;s the 1900&#8217;s, else its the 2000&#8217;s. \u00a0:-\/<\/p>\n<p>I know that dates suck big time in Java, but this code was result of just bad design. \u00a0Across it is all types of date input formats, and no centralized date code and this garbage all over. \u00a0Death by 1000 cuts.<\/p>\n<p>There are tons of utilities like Joda Time all over to handle this stuff. \u00a0But if they knew the six digit date, they were safe just doing the conversion and formatting it with SimpleDateFormat into a date and then extracting the string! \u00a0Even this would have been easier<\/p>\n<pre><span style=\"color: #0000ff;\">    DateFormat formatter = new SimpleDateFormat(\"MM\/dd\/yy\");\r\n    Date date = (Date)formatter.parse(dateString);<\/span><\/pre>\n<p>Or something to that effect. \u00a0I&#8217;m pretty sure there are no 1924 records in the database.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Wow check this out I was digging in a java code base and ran into this date conversion code (added the dateString initialization to illustrate): String dateString = &#8220;04\/29\/05&#8221; ; \u00a0 \/\/ two digit year String newDateString = dateString.substring(0, length &#8211; 2); if (Integer.parseInt(year.substring(2)) &gt; 25) { \u00a0 \u00a0 \u00a0 newDateString += &#8220;19&#8221;; } else [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"http:\/\/10kdev.net\/index.php?rest_route=\/wp\/v2\/posts\/456"}],"collection":[{"href":"http:\/\/10kdev.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/10kdev.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/10kdev.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/10kdev.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=456"}],"version-history":[{"count":1,"href":"http:\/\/10kdev.net\/index.php?rest_route=\/wp\/v2\/posts\/456\/revisions"}],"predecessor-version":[{"id":457,"href":"http:\/\/10kdev.net\/index.php?rest_route=\/wp\/v2\/posts\/456\/revisions\/457"}],"wp:attachment":[{"href":"http:\/\/10kdev.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=456"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/10kdev.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=456"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/10kdev.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=456"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}