Nodejs Day of Year dayOfYear()

Here you can find the source of dayOfYear()

Method Source Code

// http://www.webdeveloper.com/forum/showthread.php?125428
Date.prototype.dayOfYear = function() {
  var d = new Date(); // gets today's date
  var yn = d.getFullYear();
  var mn = d.getMonth();
  var dn = d.getDate();
  var d1 = new Date(yn,0,1,12,0,0); // noon on Jan. 1
  var d2 = new Date(yn,mn,dn,12,0,0); // noon on input date
  var ddiff = Math.round((d2-d1)/864e5);
  return ddiff+1; 
}

Date.prototype.stdTimezoneOffset = function() {
  var jan = new Date(this.getFullYear(), 0, 1);
  var jul = new Date(this.getFullYear(), 6, 1);
  return Math.max(jan.getTimezoneOffset(), jul.getTimezoneOffset());
}

Date.prototype.dst = function() {
  return this.getTimezoneOffset() < this.stdTimezoneOffset();
}

Related

  1. dayOfYear()
    Date.prototype.dayOfYear = function() {
       var startdayofyear = new Date(this.getFullYear(),0,1);
      return Math.ceil((this - startdayofyear) / 86400000);
    
  2. getDOY()
    Date.prototype.getDOY = function() {
      var onejan = new Date(this.getFullYear(),0,1);
      return Math.ceil((this - onejan) / 86400000);
    
  3. getDOY()
    Date.prototype.getDOY = function(){
      var firstOfJan = new Date(this.getFullYear(),0,1);
      return Math.ceil((this - firstOfJan) / 86400000);
    
  4. getDOY()
    Date.prototype.getDOY = function() {
        var dayCount = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334];
        var mn = this.getMonth();
        var dn = this.getDate();
        var dayOfYear = dayCount[mn] + dn;
        if (mn > 1 && this.isLeapYear()) dayOfYear++;
        return dayOfYear;
    };
    
  5. getDOY()
    ---
    ---
    Date.prototype.getDOY = function() {
      var onejan = new Date(this.getFullYear(),0,1);
      return Math.ceil((this - onejan) / 86400000);