Announcement

Collapse
No announcement yet.

Date(rawtime) != Bar date

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

  • Date(rawtime) != Bar date

    function preMain() {

    setStudyTitle("datetest");
    setComputeOnClose(true);
    }

    function main() {

    if (!isDaily()) { return null };

    var dt = null;
    var raw = 0;

    // SECONDS since 1/1/1970
    raw = getValue("rawtime",0);

    // ctor needs MILLISECSONDS since 1/1/1970
    dt = new Date((raw * 1000));

    debugPrint(" Bar Rawtime == " + raw );
    debugPrintln("Bar Date == " + (getMonth(0)) + "/" + getDay(0) + "/" + getYear(0) +",");

    debugPrint(" Obj MSecs == " + dt.getTime());
    debugPrintln("Obj Date == " + (dt.getMonth()+1) + "/" + dt.getDate() + "/" + dt.getFullYear() + ",");
    debugPrintln("");


    return null;

    }

    Here is the output (file) I got while testing...

    Bar Date == 10/13/2005, Bar Rawtime == 1129158060
    Obj Date == 10/12/2005, Obj MSecs == 1129158060000

    Bar Date == 10/14/2005, Bar Rawtime == 1129244460
    Obj Date == 10/13/2005, Obj MSecs == 1129244460000

    Bar Date == 10/17/2005, Bar Rawtime == 1129503660
    Obj Date == 10/16/2005, Obj MSecs == 1129503660000

    Bar Date == 10/18/2005, Bar Rawtime == 1129590060
    Obj Date == 10/17/2005, Obj MSecs == 1129590060000

    Bar Date == 10/19/2005, Bar Rawtime == 1129676460
    Obj Date == 10/18/2005, Obj MSecs == 1129676460000

    Bar Date == 10/20/2005, Bar Rawtime == 1129762860
    Obj Date == 10/19/2005, Obj MSecs == 1129762860000

    Bar Date == 10/21/2005, Bar Rawtime == 1129849260
    Obj Date == 10/20/2005, Obj MSecs == 1129849260000

  • #2
    druck3r,

    try setting the date in this manner

    PHP Code:
    dt = new Date();
    dt.setTime(raw 1000); 
    dt.setDate(getDay(0));
    dt.setMonth(getMonth(0)-1); 
    You will see that the difference in seconds equates to one day, or 86400 seconds (86400000 miliseconds).

    try either

    dt.setTime((raw+86400) * 1000);

    or

    dt = new Date(((raw+86400) * 1000));

    This works well on this end.

    Comment


    • #3
      Different Solution

      druck3r,

      After I worked on this a while, I came up with with a better solution I think. In my last post, I came up with a delta of one day, erroniously I might add. This was due to me calculating the difference on a daily basis.

      I modified efs to run on any interval, and to calculate the difference by itself. I also have it outputting the hours minutes and seconds as well, confirming the difference that was calculated remains the same. btw, I am not sure why there is a difference here, but this work around works ....

      I hope this helps you out, as it helped me out. I had been looking for a good method to convert date and time to coincide with the "second" values returned from rawtime(0), and this did the trick, thanks.

      PHP Code:
      // druck3r code modified by S.Hare 10/22/2005
      function preMain() {

      setStudyTitle("datetest");
      setComputeOnClose(true);
      }
      var 
      binit false;
      var 
      difference 0;
      function 
      main() {
          if(
      binit == false){
              
      binit true;
              
      difference =  new Date(getYear(0), (getMonth(0)-1), getDay(0), (getHour(0)), getMinute(0), getSecond(0),0).getTime()-(rawtime(0) * 1000) ; 
              
      debugPrintln("difference = "+difference+"\n");
          }
      //if (!isDaily()) { return null };

      // SECONDS since 1/1/1970
      var raw rawtime(0); 

      // ctor needs MILLISECSONDS since 1/1/1970
      var dt = new Date((raw 1000)+difference); 

      debugPrint(" Bar Rawtime == " raw );
      debugPrintln("Bar Date == " + (getMonth(0)) + "/" getDay(0) + "/" getYear(0) +","+getHour(0)+","+getMinute(0)+","+getSecond(0)+",");

      debugPrint(" Obj MSecs == " dt.getTime());
      debugPrintln("Obj Date == " + (dt.getMonth()+1) + "/" dt.getDate() + "/" dt.getFullYear() +","+dt.getHours()+","+dt.getMinutes()+","+dt.getSeconds()+",");
      debugPrintln("delta = "+(dt.getTime()-rawtime(0)*1000));
      debugPrintln("");

      difference = 17940000

      Bar Rawtime == 1129244460Bar Date == 10/14/2005,0,0,0,
      Obj MSecs == 1129262400000Obj Date == 10/14/2005,0,0,0,
      delta = 17940000

      Bar Rawtime == 1129244760Bar Date == 10/14/2005,0,5,0,
      Obj MSecs == 1129262700000Obj Date == 10/14/2005,0,5,0,
      delta = 17940000

      Bar Rawtime == 1129245360Bar Date == 10/14/2005,0,15,0,
      Obj MSecs == 1129263300000Obj Date == 10/14/2005,0,15,0,
      delta = 17940000

      Bar Rawtime == 1129245660Bar Date == 10/14/2005,0,20,0,
      Obj MSecs == 1129263600000Obj Date == 10/14/2005,0,20,0,
      delta = 17940000

      Comment


      • #4
        Nice...
        Using the "difference" is the better way. And easier to "unfix" if this item is ever squashed.

        Thanks

        Comment


        • #5
          Hi druck3r,

          You are most welcome, this worked out nicely for me as well.
          Last edited by ; 10-24-2005, 03:51 AM.

          Comment

          Working...
          X