Forum Discussion

levi_bryant's avatar
levi_bryant
Contributor
10 years ago
Solved

aqDateTime.GetDay may have a bug

I'm using TestComplete with JScript. If I get the TimeInterval between two date/Time objects that are on the same day, aqDateTime.GetDay returns 30 instead of 0. If I get the interval between t...
  • HKosova's avatar
    10 years ago
    Short answer: It's by design. Use aqConvert.TimeIntervalToStr to get the day count for time intervals:



    var strDiff = aqConvert.TimeIntervalToStr(difference); // "0:03:02:01"

    Log.Message(strDiff.split(":")[0]); // Prints 0



    Long answer: Date-time values are stored as the time passed since December 30, 1899. Time intervals are date-time values too. So, intervals with 0-day difference map to the "zero day", December 30, 1899; with 1-day difference - to December 31, 1899; with 4-day difference - to January 3, 1900, and so on. GetDay treats values as dates, that's why it returns 30 and 3 in your example. The proper way to work with the days component of time internals is by using TimeIntervalToStr - it treats its parameter as a time span rather than a date.





    You may find the .NET DateTime more convenient to use for such things:



    function Test()

    {

      var time1 = dotNET.System.DateTime.Now();

      Delay(1000);

      var time2 = dotNET.System.DateTime.Now().AddHours(3).AddMinutes(2);



      var difference = time2.Subtract(time1);

      Log.Message(difference.Days); // 0



      time2 = time2.AddDays(4);

      difference = time2.Subtract(time1);



      Log.Message(difference.Days); // 4

    }