Skip to content

Instantly share code, notes, and snippets.

@oleksis
Last active March 1, 2024 04:43
Show Gist options
  • Save oleksis/f0742d283ff81eeaf10a502652a95a29 to your computer and use it in GitHub Desktop.
Save oleksis/f0742d283ff81eeaf10a502652a95a29 to your computer and use it in GitHub Desktop.
The year 2024 is a leap year

Gregorian calendar

The year 2024 is a leap year, or bisiesto in Spanish. According to the Gregorian calendar, a year is considered a leap year if it is divisible by 4, except for end-of-century years which must be divisible by 400. This means that the year 2024, which is divisible by 4, has 366 days including the extra day, February 29.

This system keeps our calendar year synchronized with the solar year.

JavaScript application

class Calendar {
    constructor(year, month) {
        this.year = year;
        this.month = month;
    }

    getDaysInMonth() {
        return new Date(this.year, this.month, 0).getDate();
    }

    getFirstDay() {
        return new Date(this.year, this.month - 1, 1).getDay();
    }

    printCalendar() {
        let firstDay = this.getFirstDay();
        let daysInMonth = this.getDaysInMonth();

        let str = 'Sun Mon Tue Wed Thu Fri Sat\n';
        for (let i = 0; i < firstDay; i++) {
            str += '    ';
        }

        for (let i = 1; i <= daysInMonth; i++) {
            if (i < 10) {
                str += ' ' + i + '  ';
            } else {
                str += i + '  ';
            }

            if ((i + firstDay) % 7 === 0) {
                str += '\n';
            }
        }

        return str;
    }
}

let calendar = new Calendar(2024, 2); // February 2024
console.log(calendar.printCalendar());

calendar js-2024-02-29 101251

Python Calendar

  • py -m calendar 2024 2
  • py .\my_calendar.py

Python-Calendar-Module-2024-02-29 152903

import calendar
from datetime import datetime
# Get the current year and month
year = datetime.now().year
month = datetime.now().month
# Print the calendar for the current month
print(calendar.month(year, month))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment