Nodejs Year Leap Check isLeapYear()

Here you can find the source of isLeapYear()

Method Source Code

Date.isLeapYear = function(year) {
    return (((year % 4 === 0) && (year % 100 !== 0)) || (year % 400 === 0)); 
};

Date.getDaysInMonth = function(year, month) {
    return [31, (Date.isLeapYear(year) ? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month];
};

Date.prototype.isLeapYear = function() {
    return Date.isLeapYear(this.getFullYear()); 
};

Date.prototype.getDaysInMonth = function() {
    return Date.getDaysInMonth(this.getFullYear(), this.getMonth());
};

Date.prototype.addMonths = function(value) {
    const n = this.getDate();/*  w  ww. java2 s.  c o m*/

    this.setDate(1);
    this.setMonth(this.getMonth() + value);
    this.setDate(Math.min(n, this.getDaysInMonth()));

    return this;
};

Date.prototype.formatted = function() {
   const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];

   return months[this.getMonth()] + ', ' + this.getFullYear();
};

export default Date;

Related

  1. isLeapYear()
    Date.prototype.isLeapYear = function() {
      var year = this.getFullYear();
      return !(year % 4) && (year % 100) || !(year % 400);
    
  2. isLeapYear()
    Date.prototype.isLeapYear = function() {
        var year = this.getFullYear();
        if ((year & 3) != 0) return false;
        return ((year % 100) != 0 || (year % 400) == 0);
    };
    
  3. isLeapYear()
    Date.prototype.isLeapYear = function () {
       return this.getFullYear()%4?0:this.getFullYear()%100?1:this.getFullYear%400?0:1
    
  4. isLeapYear()
    Date.prototype.isLeapYear = function() {
        var year = this.getFullYear();
        if((year & 3) != 0) return false;
        return ((year % 100) != 0 || (year % 400) == 0);
    };
    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();
    ...
    
  5. isLeapYear()
    Date.prototype.isLeapYear = function(){
      return (0==this.getYear()%4 && ((this.getYear()%100 != 0) || (this.getYear()%400 == 0))); 
    
  6. isLeapYear()
    Date.prototype.isLeapYear = function () {
        var year = this.getFullYear();
        return ((year & 3) == 0 && (year % 100 || (year % 400 == 0 && year)));
    
  7. isLeapYear()
    Date.prototype.isLeapYear = function () {
      return new Date(this.getFullYear(), 1, 29).getDate() == 29;
    };
    
  8. isLeapYear()
    Date.prototype.isLeapYear = function() {
      return Date.isLeapYear(this.getFullYear());
    };