Announcement

Collapse
No announcement yet.

DayLight Savings

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

  • DayLight Savings

    Hi,

    I wrote a script to give me some pivots after the first 30 minutes. It works OK for the moment. However, I could not program it to incorporate the DayLight Savings issue. I am sure it will not work when the hours change.

    What I simply do is to run a function if the current hour is greater or equal to 10.

    I think that it can be coded but I dont know how. Can anybody help?

    thanks in advance,
    Izak

  • #2
    Hello Izak,

    You're correct about the day light savings problem. JavaScript does not account for this automatically. The code example below will show you how to handle this. Basicly it checks to see if the current date is between the first Sunday of April and the last Sunday of October. If that condition is found to be true then we add 1 to the time zone offset. Hope this helps.

    DayLightSavings.efs

    PHP Code:
    /*****************************************************************
    Provided By : eSignal. (c) Copyright 2004
    *****************************************************************/

    function preMain() {
        
    setPriceStudy(true);
        
    setStudyTitle("Day Light Savings ");
        
    setShowCursorLabel(false);
    }


    //var vTime = null;
    var zoneOffset null;
    var 
    NYzoneOffset 5;
    var 
    NYfirstHr 1030;
    var 
    firstHr null;
    var 
    vDay null;
    var 
    nDayLightSavings 0;


    function 
    main() {
        var 
    nState getBarState();
        
        
    // set up target hour equal to 10:30am EST
        
    if (firstHr == null) {
            var 
    = new Date();
            
    vDay x.getDate();
            
    nDayLightSavings DayLightSavings(x);
            
    zoneOffset = (x.getTimezoneOffset()/60) + nDayLightSavings;
            
    firstHr NYfirstHr - (zoneOffset NYzoneOffset)*100;
            
    debugPrintln("10:30am EST is: " firstHr " my time.");
        }
        
        return;
    }



    function 
    DayLightSavings(vDate) {
        
    /*** Daylight Saving Time (DST) begins at 2:00 a.m. on the first Sunday of April
             and reverts to Standard Time at 2:00 a.m. on the last Sunday of October. ***/

        
    var 0;
        var 
    nDST 0;
        var 
    DSTstartDSTend
        
        
    for (1<= 31; ++i) {
            var 
    tempDate = new Date("4/" "/" vDate.getFullYear());
            if (
    tempDate.getDay() == 0) {  // First Sunday of April
                
    DSTstart tempDate;
                
    debugPrintln("First Sunday of April: " DSTstart);
                
    32;
            }
        }
        
        
    31;
        for (
    310; --i) {
            var 
    tempDate = new Date("10/" "/" vDate.getFullYear());
            if (
    tempDate.getDay() == 0) {  // Last Sunday of October
                
    DSTend tempDate;
                
    debugPrintln("Last Sunday of October:  " DSTend);
                
    0;
            }
        }
        
        if (
    vDate >= DSTstart && vDate DSTendnDST 1;

        return 
    nDST;

    Jason K.
    Project Manager
    eSignal - an Interactive Data company

    EFS KnowledgeBase
    JavaScript for EFS Video Series
    EFS Beginner Tutorial Series
    EFS Glossary
    Custom EFS Development Policy

    New User Orientation

    Comment


    • #3
      thank you so much Jason. The code has been very helpful.

      I have another general question, if I may. In your code there is

      for (i = 1; i <= 31; ++i) {
      var tempDate = new Date(.....


      When I don't use the "var" keyword there I get the same result. Actually, I seldomly use the var. Instead I just write the variable name make an assignment.

      Does it cause any problems that I am not aware of? or do you use it for readability reasons?

      Thank you so much again

      Izak

      Comment


      • #4
        Hello Izak,

        JavaScript is soft-typed language, which means variables do not have to be explicitly defined with the var keyword. I use it anyway just out of habit, but it does help me quickly locate my variables when reading through larger formulas.
        Jason K.
        Project Manager
        eSignal - an Interactive Data company

        EFS KnowledgeBase
        JavaScript for EFS Video Series
        EFS Beginner Tutorial Series
        EFS Glossary
        Custom EFS Development Policy

        New User Orientation

        Comment


        • #5
          what is the point to use daylight savings? When the market's time change your computers' time change also.

          Can anyone explain or am I missing something?

          Comment


          • #6
            rookie2004
            Arizona Hawaii and most of Indiana and many countries in Asia and in the southern hemisphere don't observe Daylight Saving Time.
            Alex

            Comment


            • #7
              In case someone is using the DayLightSavings.efs posted earlier in this thread here is a revised version of the script that takes into account the new Daylight Saving Time requirements
              Alex


              PHP Code:
              /*****************************************************************
              Provided By : eSignal. (c) Copyright 2004
              Modified by : Alexis C. Montenegro March 11 2007
              *****************************************************************/

              function preMain() {
                  
              setPriceStudy(true);
                  
              setStudyTitle("Daylight Saving ");
                  
              setShowCursorLabel(false);
              }

              var 
              zoneOffset null;
              var 
              NYzoneOffset 5;
              var 
              NYfirstHr 1030;
              var 
              firstHr null;
              var 
              vDay null;
              var 
              nDayLightSavings 0;

              function 
              main() {
                  var 
              nState getBarState();
                  
                  
              // set up target hour equal to 10:30am EST
                  
              if (firstHr == null) {
                      var 
              = new Date();
                      
              vDay x.getDate();
                      
              nDayLightSavings DayLightSavings(x);
                      
              zoneOffset = (x.getTimezoneOffset()/60) + nDayLightSavings;
                      
              firstHr NYfirstHr - (zoneOffset NYzoneOffset)*100;
                      
              debugPrintln("10:30am EST is: " firstHr " my time.");
                  }
                  
                  return;
              }


              function 
              DayLightSavings(vDate) {
                  
              /*** Daylight Saving Time (DST) begins at 2:00 a.m. on the second Sunday of March
                       and reverts to Standard Time at 2:00 a.m. on the first Sunday of November. ***/

                  
              var 0;
                  var 
              nDST 0;
                  var 
              DSTstartDSTend;
                  var 
              Counter 0;//added by ACM
                  
                  //begin section modified by ACM
                  
              for (1<= 31; ++i) {
                      var 
              tempDate = new Date("3/" "/" vDate.getFullYear());
                      if (
              tempDate.getDay() == 0) { //if the day is a Sunday 
                          
              Counter++;//increase the variable Counter by 1
                          
              if(Counter==2){//Second Sunday of March
                              
              DSTstart tempDate;
                              
              debugPrintln("Second Sunday of March: " DSTstart);
                              
              i=32
                          
              }
                      }
                  }
                  
                  for (
              1<= 31; ++i) {
                      var 
              tempDate = new Date("11/" "/" vDate.getFullYear());
                      if (
              tempDate.getDay() == 0) {  //First Sunday in November
                          
              DSTend tempDate;
                          
              debugPrintln("First Sunday of November: " DSTend);
                          
              32;
                      }
                  }
                  
              //end section modified by ACM
                  
                  
              if (vDate >= DSTstart && vDate DSTendnDST 1;

                  return 
              nDST;

              Comment

              Working...
              X