Announcement

Collapse
No announcement yet.

getDay()

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

  • getDay()

    Can I just confirm the following functionality:

    the getDay(0) function in eSignal returns a value from 1 to 31 representing the date numeral of the current bar.

    the getDay() function when used with a Date() object returns a value from 0 to 6 representing the day of the week.

    Is there a getDayOfWeek(0) function in eSignal that will return a value from 0 to 6 representing the day of the week for the current bar?
    Standing on the shoulders of giants.

  • #2
    Hello wildfiction,

    We do not currently have such a function. That would be a good suggestion for IDEAS.

    For now, you can get the day of week by creating a date object for each bar at bar state newbar using getValue("time").

    PHP Code:
    if (getBarState() == BARSTATE_NEWBAR) {
        var 
    barDate getValue("time");
        
    dayOfWeek barDate.getDay();  // global var
        
    debugPrintln(getCurrentBarIndex() + "  " dayOfWeek);

    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
      Can someone take a look at this and tell me what I'm doing wrong?

      PHP Code:
      var _currentDay 0;

      function 
      main() {
          if(
      _currentDay != getDay(0) ) // i.e. new day
          
      {
              var 
      _day getDay(0);
              var 
      _month getMonth(0);
              var 
      _year getYear(0);
              var 
      dateObj = new Date(_year_month_day);
              
      /*
                  0 = Sunday
                  1 = Monday
                  2 = Tuesday
                  3 = Wednesday
                  4 = Thursday
                  5 = Friday
                  6= Saturday
                  */
              
      var today dateObj.getDay();
              
      debugPrintln("bar's date=" _year "-" _month "-" _day " DayOfWeek=" today);
              
              
      _currentDay getDay(0);
          }

      My output currently lines up like this:
      2 = Sunday
      3 = Monday
      4 = Tuesday
      5 = Wednesday
      6 = Thursday
      0 = Friday
      1 = Saturday

      Is the documentation (help files) out of date?

      Or am I doing something wrong?
      Standing on the shoulders of giants.

      Comment


      • #4
        Hello wildfiction,

        I modified your efs to reflect what Jason had suggested for the day of the week and it seemed to work fine.

        PHP Code:
        var _currentDay 0;

        function 
        main() {
            if(
        _currentDay != getDay(0) ) // i.e. new day
            
        {
                var 
        _day getDay(0);
                var 
        _month getMonth(0);
                var 
        _year getYear(0);
                
        //var dateObj = new Date(_year, _month, _day);
                        
        var dateObj getValue("time");
                
        /*
                    0 = Sunday
                    1 = Monday
                    2 = Tuesday
                    3 = Wednesday
                    4 = Thursday
                    5 = Friday
                    6= Saturday
                    */
                
        var today dateObj.getDay();
                
        debugPrintln("bar's date=" _year "-" _month "-" _day " DayOfWeek=" today);
                
                
        _currentDay getDay(0);
            }

        here is a portion of the efs's output:

        PHP Code:
        bar's date=2005-11-14 DayOfWeek=1
        bar'
        s date=2005-11-15 DayOfWeek=2
        bar
        's date=2005-11-16 DayOfWeek=3
        bar'
        s date=2005-11-17 DayOfWeek=4
        bar
        's date=2005-11-18 DayOfWeek=5
        bar'
        s date=2005-11-21 DayOfWeek=1
        bar
        's date=2005-11-22 DayOfWeek=2
        bar'
        s date=2005-11-23 DayOfWeek=3
        bar
        's date=2005-11-24 DayOfWeek=4
        bar'
        s date=2005-11-25 DayOfWeek=5
        bar
        's date=2005-11-28 DayOfWeek=1
        bar'
        s date=2005-11-29 DayOfWeek=2
        bar
        's date=2005-11-30 DayOfWeek=3 
        Is this what you were trying to get to?

        Comment


        • #5
          Hi Steve,

          Yes that is what I was trying to get to.

          What concerns me is that I may have used the piece of code I posted a while back and I can't find it now and not sure who I gave it to.

          So that's why I'm trying to work out if there's something wrong with what I've done.

          I can also achieve the same result by using inspection and noticing which days return which numbers and do my own mapping. I'm worried about the documentation not tying up to my results. Did you get the same results as me when you ran my code? If so, can you see any bugs in my code?

          Many thanks for all your help.
          Standing on the shoulders of giants.

          Comment


          • #6
            Hello wildfiction,

            I read the documentation and found where you had slipped up.

            The Date Object in Javascript:

            Date Constructors

            var newDateObject = new Date();
            var newDateObject = new Date(dateValue);
            var newDateObject = new Date(year, month, day, [hours], [minutes], [seconds], [milliseconds]);
            var newDateObject = new Date(year, month, day);
            var newDateObject = new Date(year month, day, hour, minutes, seconds);

            If dateValue is a numeric value, it represents the number of milliseconds since January 1, 1970 00:00:00. The ranges of dates is approximately 285,616 years from either side of midnight. Negative numbers indicate dates prior to 1970.

            · Year: The full year (1980).
            · Month: 0-11 (January to December)
            · Day: 1-31
            · Hour: 0-23
            · Minutes: 0-59
            · Seconds: 0-59
            · Milliseconds: 0-999
            the required input for the Month is: 0-11 (January to December) and you were putting the the value returned by the efs method getMonth(0) which is in the 1-12 range.

            So, here is the code modified to reflect this:
            PHP Code:
            var _currentDay 0;

            function 
            main() {
                if(
            _currentDay != getDay(0) ) // i.e. new day
                
            {
                    var 
            _day getDay(0);
                    var 
            _month getMonth(0);
                    var 
            _year getYear(0);
                    var 
            dateObj = new Date(_year_month-1_day);
                            
            //var dateObj = getValue("time");
                    /*
                        0 = Sunday
                        1 = Monday
                        2 = Tuesday
                        3 = Wednesday
                        4 = Thursday
                        5 = Friday
                        6= Saturday
                        */
                    
            var today dateObj.getDay();
                    
            debugPrintln("bar's date=" _year "-" _month "-" _day " DayOfWeek=" today);
                    
                    
            _currentDay getDay(0);
                }

            The output is the same as I had previously.

            Comment


            • #7
              That's exactly what I did wrong - thanks for pointing that out Steve - much appreciated.
              Standing on the shoulders of giants.

              Comment


              • #8
                You are most welcome, FWIW I have had similar problems interfacing with the date object as well.

                Comment

                Working...
                X