Start a new topic

get_DayOfYear incorrect

The day of year is incorrect calculated, it uses the current date.


possible fix:

 

    $p.get_DayOfYear = function DateTime_get_DayOfYear() {
        var date = this.get_JsDate();
        var start = new Date(date.getFullYear(), 0);
        var diff = date - start;
        var oneDay = 86400000;
        var day = Math.ceil(diff / oneDay);
        return day;
    };

 


Thanks for reporting, we reproduced it and fixed it already in the coming version 1.2.

Thanks.

Hi, there is a bug in fixed version of the get_DayOfYear function. 

new System.DateTime.ctor$2(2015, 3,29 ).get_DayOfYear()

  returns 88

  

new System.DateTime.ctor$2(2015, 3, 30).get_DayOfYear()

  returns 88


And the 2015-3-31 will go further with 89.. 4-1: 90.. 4-2: 91 and so on.

That's strange.. on the end 2015-12-31 is 365 so somewhere a day will be skipped?


So please reopen this issue.

My solution in the first post is not correct but the following seems to solve the issue for us:

 

$p.get_DayOfYear = function DateTime_get_DayOfYear() {
    var date = this.get_JsDate();
    var start = new Date(date.getFullYear(), 0);
    var diff = date - start;
    var oneDay = 86400000;
    var day = Math.ceil(diff / oneDay);
    return day+1;
};

 Note the day+1 on the end

Thanks for reporting and fix :-), we will fix that in the coming version 1.3.

I will also ask to add more tests on that.

Thanks

We investigated it and it was much complex, and it's because Daylight Savings Time starting in March.

See: http://stackoverflow.com/questions/8619879/javascript-calculate-the-day-of-the-year-1-366


We fixed this, again thanks.

 

public int DayOfYear
{
    get
    {
        var start = new JsDate(value.getFullYear(), 0);
        var diff = value - start + (start.getTimezoneOffset() - value.getTimezoneOffset()) * 60 * 1000;
        var oneDay = 1000 * 60 * 60 * 24;
        var day = JsMath.ceil((diff + 0.5) / oneDay);
        return day;
    }
}

 


1 person likes this
Login or Signup to post a comment