Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder ArcticFox's Avatar
    Join Date
    Jan 2004
    Vostok Station, AQ
    Thanked 3 Times in 3 Posts

    UTC Sunday; not Sun or 0

    I don't know why I'm having so much trouble with this code. I just cannot figure out how to get it to display the full day name instead of just the first three letters. I'm almost sure it can be done, but I've been staring at this code for so long that I'm really burnt out on it.

    Can anyone take a look and show me where to make adjustments?

     <title>Hanke-Henry Date and Time</title> 
     <body onLoad="bszTime();"><center>
    <script language="JavaScript" type="text/javascript">
    var dayNames = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
    var monthCodes = Array(5,1,1,4,6,2,4,0,3,5,1,3);
    var monNames = new Array("January","February","March","April","May","June","July","August","September","October","November","December","Xtr");
    function pad(number, length) {var padded = '' + number;
    while (padded.length < length) {padded = '0' + padded; }return padded;}
    function addCommas(nStr)
    {nStr += '';
    x = nStr.split('.');
    x1 = x[0];
    x2 = x.length > 1 ? '.' + x[1] : '';
    var rgx = /(\d+)(\d{3})/;
    while (rgx.test(x1)) {
    x1 = x1.replace(rgx, '$1' + ',' + '$2');
    }return x1 + x2;}
    function dayOfWeek(year,m,d){                             // Gregorian (naturally)
    c = Math.floor(year/100);
    if((year%4==0) && (year%100!=0 || year%400==0) && (m==1 || m==2)) isLeapJanFeb=1;
    else isLeapJanFeb=0;
    weekday = (1*d + 1*monthCodes[m-1] + 1*y + 1*Math.floor(y/4) - 2*(c%4) - 1*isLeapJanFeb) % 7;
    return weekday;}
    function extraWeekYear(start,end) {extra=0
    if(start==3)extra=1;                                      // 3 = Thursday; if a Gregorian Year begins, or ends, on a Thursday,
    if(end==3)extra=1;                                        // 3 = Thursday; then the reform year has an extra week after December.
    return extra;}
    function bszTime() {                                      // 2010 May 2 reform 11:45
    today = new Date();                                       // today
    Date.prototype.getJulianFull = function() {
    return (this / 86400000) + 2440587.5;}
    julianDayFull = today.getJulianFull();                    // julianDayFull  (includes decimal)
    julianDayGMT=Math.floor(julianDayFull);                   // julianDayGMT   ( 2453736 <- begins at noon GMT on 2005 Dec 31)
    UTCstring = today.toUTCString();                          // 2453736.5 = midnight on 2005 Dec 31)
    dayOfTheWeek=UTCstring.substr(0,3)                        // dayOfTheWeek
    ESTstring = today.toString();
    elapsed=Math.floor(julianDayFull-2453735.5)               // number the days at Greenwich, with day 1 = 2006 Jan 1
    years=2006; // these are reform years
    extraWeekYear(first,last);                                // "dayOfWeek" & "extraWeekYear" assume Gregorian (that's OK!)
    if(elapsed<subtractor)break;                              // break
    years=years+1;}                                           // years
    if(elapsed<=29)reformmonth=0;                             // Jan
    if(elapsed>29 && elapsed<=59)newdate=elapsed-30;
    if(elapsed>29 && elapsed<=59)reformmonth=1;               // Feb
    if(elapsed>59 && elapsed<=91)newdate=elapsed-60;
    if(elapsed>59 && elapsed<=91)reformmonth=2;               // Mar
    if(elapsed>91 && elapsed<=121)newdate=elapsed-91;
    if(elapsed>91 && elapsed<=121)reformmonth=3;              // Apr
    if(elapsed>121 && elapsed<=151)newdate=elapsed-121;
    if(elapsed>121 && elapsed<=151)reformmonth=4;             // May
    if(elapsed>151 && elapsed<=182)newdate=elapsed-151;
    if(elapsed>151 && elapsed<=182)reformmonth=5;             // Jun
    if(elapsed>182 && elapsed<=212)newdate=elapsed-182;
    if(elapsed>182 && elapsed<=212)reformmonth=6;             // Jul
    if(elapsed>212 && elapsed<=242)newdate=elapsed-212;       
    if(elapsed>212 && elapsed<=242)reformmonth=7;             // Aug
    if(elapsed>242 && elapsed<=273)newdate=elapsed-242;
    if(elapsed>242 && elapsed<=273)reformmonth=8;             // Sep
    if(elapsed>273 && elapsed<=303)newdate=elapsed-273;
    if(elapsed>273 && elapsed<=303)reformmonth=9;             // Oct
    if(elapsed>303 && elapsed<=333)newdate=elapsed-303;
    if(elapsed>303 && elapsed<=333)reformmonth=10;            // Nov
    if(elapsed>333 && elapsed<=364)newdate=elapsed-333;
    if(elapsed>333 && elapsed<=364)reformmonth=11;            // Dec
    if(elapsed>364)reformmonth=12;                            // Xtr
    document.getElementById("clock").innerHTML=(dayOfTheWeek+", "+pad(newdate,2)+" "+monNames[reformmonth]+" "+years+" - "+UTCstring.substr(17,5));
    setTimeout("bszTime()", 60000);}                          // end of function bszTime()
    <span id="clock" size="32" style="text-align:center; font-family:verdana; color:black; font-size:12px; background-color:transparent; border:none" ></span>
    Thank you.
    <div> - putting your mind in a box since 1997

  2. #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Sydney, Australia
    Thanked 932 Times in 919 Posts
    Why don't you use the Date object as your starting point - then half the code you have there would be unnecessary. Alternatively use my extended date object from http://javascriptexample.net/dollarD.php and you can reduce your code to about three lines.
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  3. #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Thanked 4,947 Times in 4,908 Posts
    Ummm...Felgall, to some degree he does use the Data object.

    But he's trying to create some kind of "Reformed" calendar, if you look closely.

    He has an "Xtr" (extra) month for days 365 and 366 of the year, among other things.

    The code is incredibly clumsy, though.

    And it's not surprising that he isn't displaying the full day name, because although he creates the array dayNames, he never ever uses it. I can't even find where in the code that he attempts to do anything relating to dayNames in his "Reformed" calendar. The only place related to day names is dayOfTheWeek=UTCstring.substr(0,3) which is clearly (a) only 3 characters and (b) likely not at all relevant to "Reformed" day names.
    Be yourself. No one else is as qualified.

  4. #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    London, England
    Thanked 2,700 Times in 2,676 Posts

    Hanke-Henry Permanent Calendar is a proposed new calendar which aims to reform the current Gregorian Calendar by making every year identical. With the Hanke-Henry Permanent Calendar, every calendar date always falls on the same day of the week.

    We learn something new every day!

    Sounds like something barmy proposed by the EU! Like the permitted degree of curvature in bananas.
    Last edited by Philip M; 04-01-2013 at 09:03 AM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  5. #5
    Regular Coder
    Join Date
    May 2012
    Thanked 32 Times in 30 Posts
    Some remarks...

    The function addCommas is useless...

    The variable weekday is not a global variable (It's define only in the function dayofWeek). Then it is undefined later.
    // Replace this code
    // with
    var first=dayOfWeek(years,1,1);
    var last=dayOfWeek(years,12,31);
    This function dayOfWeek can be better write with the Date object
    // Return 0 for sunday, 1 for monday....
    function dayOfWeek(year,m,d){// Gregorian (naturally)
    	return newDate(year,m-1,d,12).getDay();// a -1 for a javascript month from 0 to 11 
    This suite of if is not programming ! It could be better to subtract something like [30,30,31] [index%3] with an index to increment on each while loop;

    Without guidance, it is very difficult to make the connection (date and time) between this calendar and our Gregorian or Julian Day Number and to propose a better script...

    This is not a good idea to reduce the vacation days with a new calendar!
    And alternatively how to calculate, like here, the dates of the seasons with this new calendar ?
    Last edited by 007julien; 04-01-2013 at 05:31 PM.

  6. #6
    Regular Coder
    Join Date
    Sep 2010
    Far far away
    Thanked 16 Times in 16 Posts
    Can anyone take a look and show me where to make adjustments?
    Completely rewrite! It is weird, misunderstandable and has some coding errors. For example Date.prototype.getJulianFull is redefined each times as bszTime is called. UTCstring.substr(17,5) depends on system settings -- changing locale settings, you will change the resulting string. With this code I saw weird resulting string. And your code without good formatting is really a hell for reading. Etc...

    I just cannot figure out how to get it to display the full day name instead of just the first three letters.
    As an example use this code:
    // padding a 2-digit's number with leading zero: '00', ..., '09', '10', ...
    function pad(number)
        return ('00' + number).slice(-2);
    var weekNames = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
    var monthNames = [
        'January', 'February', 'March', 'April', 'May', 'June', 
        'July', 'August', 'September', 'October', 'November', 'December'
    function bszTime()
        var now = new Date();
        var week = weekNames[now.getUTCDay()];
        var month = monthNames[now.getUTCMonth()];
        var result = week + ', ' 
        	+ pad(now.getUTCDate()) + ' ' + month + ' ' + now.getUTCFullYear() + ' ' 
        	+ pad(now.getUTCHours()) + ':' + pad(now.getUTCMinutes()) + ':' + pad(now.getUTCSeconds());
        document.getElementById("clock").innerHTML = result;
        // DON'T USE a string, a function only!!!
        setTimeout(bszTime, 60000);


Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts