Announcement

Collapse
No announcement yet.

Date.getDay() not returning 0 for Sunday???

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Date.getDay() not returning 0 for Sunday???

    The docs say that Date.getDay() returns the day of the week where 0 == Sunday. I am getting a 0 for Thursday and Friday, intermittently with this efs script;

    // Day of week

    function preMain() {
    setStudyTitle("Day of week");
    setComputeOnClose();
    return;
    }
    function main( ) {

    var yr = getYear(0);
    var mon = getMonth(0);
    var dom = getDay(0);
    var hour = getHour(0);
    var min = getMinute(0);
    var sec = getSecond(0);
    var bdate = new Date(yr, mon, dom, hour, min, sec);
    var dow = bdate.getDay();
    var msg = yr + "/" + mon + "/" + dom + " " + hour + ":" + min + ":" + sec + " " + dow;
    log(msg);

    return 0;
    }
    function preMain() {
    setStudyTitle("Day of week");
    setComputeOnClose();
    return;
    }

    function log(msg) {
    var logfile = new File("dow.log"); //the file will be created in: eSignal/FormulaOutput/
    logfile.open("at+"); // Opens and appends the file
    if(!logfile.isOpen()) {
    debugPrintln("Could not open file!");
    } else {
    logfile.writeln(msg);
    debugPrintln(msg);
    }
    logfile.close();
    }

    And here's the output;

    2007/3/1 0:0:0 0
    2007/3/2 0:0:0 1
    2007/3/5 0:0:0 4
    2007/3/6 0:0:0 5
    2007/3/7 0:0:0 6
    2007/3/8 0:0:0 0
    2007/3/9 0:0:0 1
    2007/3/12 0:0:0 4
    2007/3/13 0:0:0 5
    2007/3/14 0:0:0 6
    2007/3/15 0:0:0 0
    2007/3/16 0:0:0 1
    2007/3/19 0:0:0 4
    2007/3/20 0:0:0 5
    2007/3/21 0:0:0 6
    2007/3/22 0:0:0 0
    2007/3/23 0:0:0 1
    2007/3/26 0:0:0 4
    2007/3/27 0:0:0 5
    2007/3/28 0:0:0 6
    2007/3/29 0:0:0 0
    2007/3/30 0:0:0 1
    2007/4/2 0:0:0 3
    2007/4/3 0:0:0 4
    2007/4/4 0:0:0 5
    2007/4/5 0:0:0 6
    2007/4/9 0:0:0 3
    2007/4/10 0:0:0 4
    2007/4/11 0:0:0 5
    2007/4/12 0:0:0 6
    2007/4/13 0:0:0 0
    2007/4/16 0:0:0 3
    2007/4/17 0:0:0 4
    2007/4/18 0:0:0 5
    2007/4/19 0:0:0 6
    2007/4/20 0:0:0 0
    2007/4/23 0:0:0 3
    2007/4/24 0:0:0 4
    2007/4/25 0:0:0 5
    2007/4/26 0:0:0 6
    2007/4/27 0:0:0 0
    2007/4/30 0:0:0 3
    2007/5/1 0:0:0 5
    2007/5/2 0:0:0 6
    2007/5/3 0:0:0 0
    2007/5/4 0:0:0 1

    Am I missing something here or is the Date.getDay() not working correctly?

    Thanks,
    Mike

  • #2
    Got it

    The JS Date uses months 0-11 where as efs uses months 1-12.

    Good grief.

    Comment

    Working...
    X