Today's date, the long way



  • Over at a certain website, down at the bottom, they have a "Last Updated" timestamp. It says "Friday, 5th April, 2013." Their site appears to be built in PHP, so that's a quick one-liner, right?

    date('l, jS F, Y');

    Or maybe not. They decided to build the date string using 126 lines of JavaScript. At least they've anticipated the edge case where it's the "0th" day of the month.

     

     

    <!--
    	function ISO8601Local30(date) {
    	// handles years from 0000 to 9999 only
    		var offset30 = date.getTimezoneOffset();
    		var offsetSign30 = "-";
    		if (offset30 <= 0) {
    			offsetSign30 = "+";
    			offset30 = -offset30;
    		}
    		var offsetHours30 = Math.floor(offset30 / 60);
    		var offsetMinutes30 = offset30 - offsetHours30 * 60;
    		return ("000" + date.getFullYear()).slice(-4) +
    		"-" + ("0" + (date.getMonth() + 1)).slice(-2) +
    		"-" + ("0" + date.getDate()).slice(-2) +
    		"T" + ("0" + date.getHours()).slice(-2) +
    		":" + ("0" + date.getMinutes()).slice(-2) +
    		":" + ("0" + date.getSeconds()).slice(-2) +
    		"," + ("00" + date.getMilliseconds()).slice(-3) +
    		offsetSign30 + ("0" + offsetHours30).slice(-2) +
    		":" + ("0" + offsetMinutes30).slice(-2);
    	}
    
    	var ISO860130 = "0";
    
    	function clock30() {
    		var newdate30 = new Date();
    
    		if(ISO860130 == "1") {
    
    			var time30 = ISO8601Local30(newdate30);
    
    		} else {
    
    			var day30="";
    			var month30="";
    			var myweekday30="";
    			var year30="";
    			var mydate30 = new Date();
    			var dston30  =  new  Date('March 14, 1999 2:59:59');
    			var dstoff30 = new Date('November 7, 1999 2:59:59');
    			dston30.setFullYear(newdate30.getFullYear());
    			dstoff30.setFullYear(newdate30.getFullYear());
    
    			var dst30 = "0";
    			var myzone30 = newdate30.getTimezoneOffset();
    
    			var zone30 = -5;
    			
    			// zone is negative so convert to positive to do calculations
    			if (zone30 <= 0) {
    				zoneb30 = -zone30;
    			} else {
    				zoneb30 = zone30;
    			}
    			
    			if (mydate30 > dston30 && mydate30 < dstoff30 && dst30 == "1") {
    			//date is between dst dates and dst adjust is on.
    				zonea30 = zoneb30 - 1;
    				var houradjust30 = 0;
    			} else {
    				zonea30 = zoneb30;
    				var houradjust30 = -1;
    			};
    
    			newtime30=newdate30.getTime();
    
    			var newzone30 =  (zonea30*60*60*1000);
    
    			// convert zone back to negative if it was negative originally
    			if (zone30 <= 0) {
    				newzone30 = -newzone30;
    			}
    			newtimea30 = newtime30+(myzone30*60*1000)+newzone30;
    
    			mydate30.setTime(newtimea30);
    			myday30 = mydate30.getDay();
    			mymonth30 = mydate30.getMonth();
    			myweekday30= mydate30.getDate();
    			myyear30= mydate30.getYear();
    			year30 = myyear30;
    
    			if (year30 < 2000) year30 = year30 + 1900;
    			myhours30 = mydate30.getHours();
    
    			
    			var mm30 = "am";
    			if (myhours30 > 11 + houradjust30)
    				mm30 = "pm";
    			if (myhours30 > 12 + houradjust30)
    				myhours30 -= 12;
    			if (myhours30 == 0) myhours30 = 12;
    
    			
    			myminutes30 = mydate30.getMinutes();
    
    			if (myminutes30 < 10){
    				mytime30 = "0" + myminutes30;
    			}
    			else {
    				mytime30 = "" + myminutes30;
    			};
    
    			myseconds30 = mydate30.getSeconds();
    
    			if (myseconds30 < 10) {
    				myseconds30 = "0" + myseconds30;
    			} else {
    				myseconds30 = "" + myseconds30;
    			};
    
    			arday30 = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
    			armonth30 = new Array("January","February","March","April","May","June","July","August","September", "October","November","December")
    			ardate30 = new Array("0th","1st","2nd","3rd","4th","5th","6th","7th","8th","9th","10th","11th","12th","13th","14th","15th","16th","17th","18th","19th","20th","21st","22nd","23rd","24th","25th","26th","27th","28th","29th","30th","31st");
    
    			
    				var time30 = (""+arday30[myday30]+","+"&#65533;"+ardate30[myweekday30]+"&#65533;"+armonth30[mymonth30]+"&#65533;"+year30+"");
    
    					}
    
    	document.getElementById('ty2udate30').innerHTML  = time30;
    
    	setTimeout("clock30()", 1000)
    
    	}
    	listen("load", window, clock30);
    	//-->

     



  • Of course, TRWTF is that "last updated" is not "today's date".


  • Considered Harmful

    @Frigax said:

    // handles years from 0000 to 9999 only

    This is simply unacceptable.



  •  @spamcourt said:

    Of course, TRWTF is that "last updated" is not "today's date".

    TRWTF is

    setTimeout("clock30()", 1000)
    OMG is it tomorrow yet? 
    OMG is it tomorrow yet?
    
    OMG is it tomorrow yet?
    
    OMG is it tomorrow yet?
    
    OMG is it tomorrow yet?
    
    OMG is it tomorrow yet?
    ... 

     



  •  I do not understand how it is possible to write code while being functionally retarded.



  • Why do I get the feeling they have 29 other versions of it, each one broken in new and hilariously stupid ways?



  • @joe.edwards said:

    @Frigax said:
    // handles years from 0000 to 9999 only

    This is simply unacceptable.

    I know, it's like they never even heard of the Y10k problem.  Co-incidentally, we just had the 14th anniversary of RFC2550.




  •  I get that people feel compelled to elaborately NIH their own time & date code. I've seen it again and again. But why, why ever would you explicitly insert &#65533;'s?

     



  • @superjer said:

     I get that people feel compelled to elaborately NIH their own time & date code. I've seen it again and again. But why, why ever would you explicitly insert &#65533;'s?

     



  • @Frigax said:

    Over at a certain website, down at the bottom, they have a "Last Updated" timestamp. It says "Friday, 5th April, 2013."
     

    Not any more. They've updated it:  Saturday,?6th?April?2013



  • Everything you need to know is contained in this paragraph from their About Us page:

    "Our partners Altosys' back offices in Chennai are amongst the most well equipped world wide. They are well laid out, equipped with hundreds of work stations, a secure network with fast servers, state of the art communication facilities, and most important, a team of committed, energetic and skilled people. Click here to view photographs of our back office in Chennai."

    As a bonus, contains the ironic statement "Quality is our No:1 objective at all times." on a page with multiple obvious errors in the content.



  • @dhromed said:

     I do not understand how it is possible to write code while being functionally retarded.

    Sheer numbers. A thousand functionally retarded people writing code on a thousand teletypes will eventually produce Android.


Log in to reply