Programming Search⌘K

Taskintro

Find the day of the week

Also called day of the week, weekday, weekday of a date, ISO weekday, ISO week number, week of the year, week-based year, Zeller's congruence, getDay, DayOfWeek, isoweekday.

Find the weekday of a calendar date and its ISO 8601 week. Libraries number the days from 0 or from 1, and from Sunday or from Monday, and the week-based year is not always the calendar year.

Task

Find the day of the week of a calendar date. A date here has no time of day and no time zone, such as 2024-03-10, which was a Sunday.

The contract day_of_week(year, month, day) returns the number of ISO 8601: 1 for Monday, 2 for Tuesday and so on to 7 for Sunday. The dates use the proleptic Gregorian calendar for the years 1 to 9999.

Libraries use different numbers for the same day:

API Monday Sunday
ISO 8601, Python isoweekday(), Java DayOfWeek.getValue(), C++ iso_encoding(), date +%u 1 7
Python weekday() 0 6
JavaScript getDay(), C tm_wday, C# DayOfWeek, Go Weekday, C++ c_encoding(), date +%w 1 0

ISO 8601 also numbers the weeks. A week starts on Monday, and week 1 of a year is the week with the first Thursday of the year. So the days at the start and end of a calendar year can be in a week of the year before or the year after. 2024-12-30 is a Monday in week 1 of the week-based year 2025, and 2027-01-01 is a Friday in week 53 of 2026. Each solution also has an iso_week(year, month, day) function that returns the week-based year and the week number.

Solutions

Each solution reads the date with no time zone, or as midnight UTC. A date read in local time can be the day before (see the pitfalls).

  • Python. date(year, month, day).isoweekday() gives 1 to 7. date.isocalendar() gives the week-based year, the week and the weekday.
  • JavaScript. The solution sets the date with setUTCFullYear and calls getUTCDay(), which returns 0 for Sunday. getUTCDay() || 7 changes 0 to 7. There is no function for the ISO week, so the solution moves to the Thursday of the same week. The year of that Thursday is the week-based year, and its day of the year gives the week.
  • TypeScript. The same code as JavaScript, with the type number.
  • Java. LocalDate.getDayOfWeek() returns a DayOfWeek, and its documentation says that "The int value follows the ISO-8601 standard, from 1 (Monday) to 7 (Sunday)." date.get(IsoFields.WEEK_BASED_YEAR) and date.get(IsoFields.WEEK_OF_WEEK_BASED_YEAR) give the ISO week.
  • C#. DateOnly.DayOfWeek is a DayOfWeek with Sunday = 0, so the solution changes 0 to 7. ISOWeek.GetYear and ISOWeek.GetWeekOfYear give the ISO week.
  • Go. time.Date(..., time.UTC).Weekday() returns a time.Weekday with Sunday = 0. t.ISOWeek() returns the week-based year and the week.
  • Rust. The standard library has no calendar date. The solution computes a day number with days_from_civil of Howard Hinnant. 1970-01-01, day 0, was a Thursday, so the weekday is (days + 3).rem_euclid(7) + 1.
  • C. The same day arithmetic as Rust. The % operator of C keeps the sign of the left operand, so the solution adds 7 to a negative remainder. mktime also sets tm_wday, but it reads the fields as local time.
  • C++. std::chrono::weekday{sys_days{ymd}} gives the weekday. iso_encoding() returns 1 to 7, and c_encoding() returns 0 to 6.
  • Bash. GNU date -u -d 2024-03-10 +%u prints the ISO number. +%G %V prints the week-based year and the week.

The library functions give the same answer for each date:

from datetime import date

for d in [date(2024, 3, 10), date(1970, 1, 1), date(2024, 12, 30), date(2027, 1, 1)]:
    iso = d.isocalendar()
    print(d, d.strftime("%A"), d.isoweekday(), f"{iso.year}-W{iso.week:02d}-{iso.weekday}")
Output
2024-03-10 Sunday 7 2024-W10-7
1970-01-01 Thursday 4 1970-W01-4
2024-12-30 Monday 1 2025-W01-1
2027-01-01 Friday 5 2026-W53-5

Without a library, Zeller's congruence computes the weekday from the year, the month and the day. January and February count as the months 13 and 14 of the year before. The result h is 0 for Saturday, 1 for Sunday and so on to 6 for Friday. The usual formula has - 2J, which can make a negative number. The version below uses + 5J, which gives the same remainder modulo 7:

from datetime import date


def zeller(year, month, day):
    """Return 0 for Saturday, 1 for Sunday, ..., 6 for Friday."""
    if month < 3:
        month += 12
        year -= 1
    k, j = year % 100, year // 100
    return (day + 13 * (month + 1) // 5 + k + k // 4 + j // 4 + 5 * j) % 7


for d in [date(2024, 3, 10), date(1970, 1, 1), date(2000, 2, 29), date(1, 1, 1)]:
    h = zeller(d.year, d.month, d.day)
    iso = (h + 5) % 7 + 1
    print(d, h, iso, d.isoweekday())
Output
2024-03-10 1 7 7
1970-01-01 5 4 4
2000-02-29 3 2 2
0001-01-01 2 1 1

Edge cases

The cases are in cases/basic.jsonl and cases/edge.jsonl.

  • a-sunday, a-monday and a-saturday: Sunday is 7 and not 0.
  • the-epoch and before-the-epoch: 1970-01-01 was a Thursday and 1969-12-31 a Wednesday. A day number before 1970 is negative.
  • leap-day, after-leap-day-2000, year-1900-is-not-leap and year-2100-is-not-leap: a wrong leap year rule moves every later date by one day.
  • gregorian-reform and day-before-the-reform: 1582-10-15 was a Friday. 1582-10-04 is a Monday in the proleptic Gregorian calendar. In the Julian calendar it was a Thursday, the day before 1582-10-15.
  • first-day and last-day: 0001-01-01 is a Monday and 9999-12-31 a Friday.
  • year-99: 0099-12-31 was a Thursday. An API that reads the year 99 as 1999 gives a Friday.
  • iso-week-of-next-year and iso-week-of-last-year: 2024-12-30 and 2027-01-01, where the week-based year is not the calendar year.
  • month-end: 2024-04-30 was a Tuesday.

Pitfalls

  • Sunday is 0 in many APIs. JavaScript, C, C#, Go and date +%w number the days from 0 for Sunday. Python weekday() numbers them from 0 for Monday. A table of day names indexed with the wrong number shows the wrong day:

This code runs but gives a wrong answer on purpose.

from datetime import date

sunday = date(2024, 3, 10)
print(sunday.weekday(), sunday.isoweekday())
print(sunday.strftime("%w %u %A"))
Output
6 7
0 7 Sunday
  • A date read in local time can be the day before. new Date("2024-03-10") reads a date with no time as midnight UTC. getDay() returns the weekday in local time, and in New York midnight UTC is 19:00 of the day before:

This code runs but gives a wrong answer on purpose.

process.env.TZ = "America/New_York";
const date = new Date("2024-03-10");
console.log(date.getDay());
console.log(date.getUTCDay());
console.log(date.toString());
Output
6
0
Sat Mar 09 2024 19:00:00 GMT-0500 (Eastern Standard Time)
  • The week-based year is not the calendar year. In a Java pattern, Y is the week-based year and y is the year. The week rules of Y come from the locale. With Locale.US, a week starts on Sunday, and 2024-12-30 is in the first week of 2025:

This code runs but gives a wrong answer on purpose.

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Locale;

public class Main {
    public static void main(String[] args) {
        LocalDate date = LocalDate.of(2024, 12, 30);
        System.out.println(date.format(DateTimeFormatter.ofPattern("YYYY-MM-dd", Locale.US)));
        System.out.println(date.format(DateTimeFormatter.ofPattern("yyyy-MM-dd", Locale.US)));
    }
}
Output
2025-12-30
2024-12-30

In strftime and date, %Y is the calendar year and %G is the week-based year of %V. A week number with the wrong year is a week a year away:

This code runs but gives a wrong answer on purpose.

date -u -d 2024-12-30 '+%Y-W%V'
date -u -d 2024-12-30 '+%G-W%V'
Output
2024-W01
2025-W01
  • A week rule that is close to ISO 8601 is not ISO 8601. The .NET documentation says that Calendar.GetWeekOfYear "does not map exactly to ISO 8601", even with CalendarWeekRule.FirstFourDayWeek and Monday. For 2007-12-31, a Monday in ISO week 1 of 2008, it returns 53:

This code runs but gives a wrong answer on purpose.

using System.Globalization;

var date = new DateTime(2007, 12, 31);
var calendar = CultureInfo.InvariantCulture.Calendar;
Console.WriteLine(calendar.GetWeekOfYear(date, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday));
Console.WriteLine(ISOWeek.GetWeekOfYear(date));
Console.WriteLine(ISOWeek.GetYear(date));
Output
53
1
2008
  • The remainder of a negative number is negative in C. A weekday from a day number before 1970 needs a remainder from 0 to 6. In C, Java, C#, Go, JavaScript and Rust % keeps the sign of the left operand. Python % and Rust rem_euclid do not:

This code runs but gives a wrong answer on purpose.

#include <stdio.h>

int main(void) {
    long long days = -4;  // 1969-12-28, a Sunday
    printf("%lld\n", (days + 3) % 7 + 1);
    long long r = (days + 3) % 7;
    printf("%lld\n", (r < 0 ? r + 7 : r) + 1);
}
Output
0
7

See Calendar arithmetic and ISO 8601 for the calendar and the week dates.

Code

The build runs the native tests of each language in a pinned toolchain.

weekday.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://programming.tamnd.com/find-the-day-of-the-week/.

from datetime import date


def day_of_week(year: int, month: int, day: int) -> int:
    """Return the ISO 8601 day of the week: 1 for Monday to 7 for Sunday."""
    return date(year, month, day).isoweekday()


def iso_week(year: int, month: int, day: int) -> tuple[int, int]:
    """Return the ISO 8601 week-based year and week number of a date."""
    iso = date(year, month, day).isocalendar()
    return iso.year, iso.week
test_weekday.py 54 lines
# SPDX-License-Identifier: MIT
# Part of https://programming.tamnd.com/find-the-day-of-the-week/.

from datetime import date

import pytest

from weekday import day_of_week, iso_week

CASES = [
    ("a-sunday", (2024, 3, 10), 7),
    ("a-monday", (2024, 3, 11), 1),
    ("the-epoch", (1970, 1, 1), 4),
    ("year-2000", (2000, 1, 1), 6),
    ("a-saturday", (2024, 3, 16), 6),
    ("leap-day", (2024, 2, 29), 4),
    ("after-leap-day-2000", (2000, 3, 1), 3),
    ("year-1900-is-not-leap", (1900, 3, 1), 4),
    ("year-2100-is-not-leap", (2100, 3, 1), 1),
    ("before-the-epoch", (1969, 12, 31), 3),
    ("gregorian-reform", (1582, 10, 15), 5),
    ("day-before-the-reform", (1582, 10, 4), 1),
    ("first-day", (1, 1, 1), 1),
    ("last-day", (9999, 12, 31), 5),
    ("year-99", (99, 12, 31), 4),
    ("iso-week-of-next-year", (2024, 12, 30), 1),
    ("iso-week-of-last-year", (2027, 1, 1), 5),
    ("month-end", (2024, 4, 30), 2),
]

WEEKS = [
    ((2024, 3, 10), (2024, 10)),
    ((2024, 12, 30), (2025, 1)),
    ((2027, 1, 1), (2026, 53)),
    ((2000, 1, 1), (1999, 52)),
    ((1969, 12, 31), (1970, 1)),
    ((99, 12, 31), (99, 53)),
]


@pytest.mark.parametrize(("name", "fields", "want"), CASES, ids=[c[0] for c in CASES])
def test_day_of_week(name, fields, want):
    assert day_of_week(*fields) == want


@pytest.mark.parametrize(("fields", "want"), WEEKS)
def test_iso_week(fields, want):
    assert iso_week(*fields) == want


def test_weekday_counts_from_zero():
    sunday = date(2024, 3, 10)
    assert sunday.weekday() == 6
    assert sunday.isoweekday() == 7
weekday.hppI0RawGitHub
// SPDX-License-Identifier: MIT
// Part of https://programming.tamnd.com/find-the-day-of-the-week/.

#ifndef DAY_OF_WEEK_HPP
#define DAY_OF_WEEK_HPP

#include <chrono>
#include <utility>

// Returns the ISO 8601 day of the week: 1 for Monday to 7 for Sunday.
// weekday::c_encoding() has Sunday = 0, and iso_encoding() has Sunday = 7.
inline int day_of_week(int y, int m, int d) {
    using namespace std::chrono;
    const sys_days date{year{y} / month{static_cast<unsigned>(m)} / day{static_cast<unsigned>(d)}};
    return static_cast<int>(weekday{date}.iso_encoding());
}

// Returns the ISO 8601 week-based year and week number of a date. The
// Thursday of the same week is always in the week-based year.
inline std::pair<int, int> iso_week(int y, int m, int d) {
    using namespace std::chrono;
    const sys_days date{year{y} / month{static_cast<unsigned>(m)} / day{static_cast<unsigned>(d)}};
    const sys_days thursday = date + days{4 - static_cast<int>(weekday{date}.iso_encoding())};
    const year week_year = year_month_day{thursday}.year();
    const auto week = (thursday - sys_days{week_year / January / 1}).count() / 7 + 1;
    return {static_cast<int>(week_year), static_cast<int>(week)};
}

#endif
test_weekday.cpp 75 lines
// SPDX-License-Identifier: MIT
// Part of https://programming.tamnd.com/find-the-day-of-the-week/.

#include <cstdio>
#include <utility>

#include "weekday.hpp"

namespace {

struct test_case {
    const char* name;
    int year, month, day;
    int want;
};

const test_case cases[] = {
    {"a-sunday", 2024, 3, 10, 7},
    {"a-monday", 2024, 3, 11, 1},
    {"the-epoch", 1970, 1, 1, 4},
    {"year-2000", 2000, 1, 1, 6},
    {"a-saturday", 2024, 3, 16, 6},
    {"leap-day", 2024, 2, 29, 4},
    {"after-leap-day-2000", 2000, 3, 1, 3},
    {"year-1900-is-not-leap", 1900, 3, 1, 4},
    {"year-2100-is-not-leap", 2100, 3, 1, 1},
    {"before-the-epoch", 1969, 12, 31, 3},
    {"gregorian-reform", 1582, 10, 15, 5},
    {"day-before-the-reform", 1582, 10, 4, 1},
    {"first-day", 1, 1, 1, 1},
    {"last-day", 9999, 12, 31, 5},
    {"year-99", 99, 12, 31, 4},
    {"iso-week-of-next-year", 2024, 12, 30, 1},
    {"iso-week-of-last-year", 2027, 1, 1, 5},
    {"month-end", 2024, 4, 30, 2},
};

struct week_case {
    int year, month, day;
    int week_year, week;
};

const week_case weeks[] = {
    {2024, 3, 10, 2024, 10},
    {2024, 12, 30, 2025, 1},
    {2027, 1, 1, 2026, 53},
    {2000, 1, 1, 1999, 52},
    {1969, 12, 31, 1970, 1},
    {99, 12, 31, 99, 53},
};

}  // namespace

int main() {
    int failures = 0;
    for (const auto& c : cases) {
        const int got = day_of_week(c.year, c.month, c.day);
        if (got != c.want) {
            std::printf("FAIL %s: got %d, want %d\n", c.name, got, c.want);
            ++failures;
        }
    }
    for (const auto& c : weeks) {
        const auto got = iso_week(c.year, c.month, c.day);
        if (got != std::pair{c.week_year, c.week}) {
            std::printf("FAIL iso week of %04d-%02d-%02d: got %d-W%02d\n", c.year, c.month, c.day, got.first, got.second);
            ++failures;
        }
    }
    if (failures != 0) {
        return 1;
    }
    std::printf("ok\n");
    return 0;
}
Weekday.javaI0RawGitHub
// SPDX-License-Identifier: MIT
// Part of https://programming.tamnd.com/find-the-day-of-the-week/.

import java.time.LocalDate;
import java.time.temporal.IsoFields;

/** Finds the day of the week and the ISO week of a date. */
public final class Weekday {
    private Weekday() {}

    /** Returns the ISO 8601 day of the week: 1 for Monday to 7 for Sunday. */
    public static int dayOfWeek(int year, int month, int day) {
        return LocalDate.of(year, month, day).getDayOfWeek().getValue();
    }

    /** Returns the ISO 8601 week-based year and week number of a date. */
    public static int[] isoWeek(int year, int month, int day) {
        LocalDate date = LocalDate.of(year, month, day);
        return new int[] {date.get(IsoFields.WEEK_BASED_YEAR), date.get(IsoFields.WEEK_OF_WEEK_BASED_YEAR)};
    }
}
WeekdayTest.java 67 lines
// SPDX-License-Identifier: MIT
// Part of https://programming.tamnd.com/find-the-day-of-the-week/.

import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.util.stream.Stream;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

class WeekdayTest {
    static Stream<Arguments> cases() {
        return Stream.of(
                Arguments.of("a-sunday", 2024, 3, 10, 7),
                Arguments.of("a-monday", 2024, 3, 11, 1),
                Arguments.of("the-epoch", 1970, 1, 1, 4),
                Arguments.of("year-2000", 2000, 1, 1, 6),
                Arguments.of("a-saturday", 2024, 3, 16, 6),
                Arguments.of("leap-day", 2024, 2, 29, 4),
                Arguments.of("after-leap-day-2000", 2000, 3, 1, 3),
                Arguments.of("year-1900-is-not-leap", 1900, 3, 1, 4),
                Arguments.of("year-2100-is-not-leap", 2100, 3, 1, 1),
                Arguments.of("before-the-epoch", 1969, 12, 31, 3),
                Arguments.of("gregorian-reform", 1582, 10, 15, 5),
                Arguments.of("day-before-the-reform", 1582, 10, 4, 1),
                Arguments.of("first-day", 1, 1, 1, 1),
                Arguments.of("last-day", 9999, 12, 31, 5),
                Arguments.of("year-99", 99, 12, 31, 4),
                Arguments.of("iso-week-of-next-year", 2024, 12, 30, 1),
                Arguments.of("iso-week-of-last-year", 2027, 1, 1, 5),
                Arguments.of("month-end", 2024, 4, 30, 2)
        );
    }

    static Stream<Arguments> weeks() {
        return Stream.of(
                Arguments.of(2024, 3, 10, 2024, 10),
                Arguments.of(2024, 12, 30, 2025, 1),
                Arguments.of(2027, 1, 1, 2026, 53),
                Arguments.of(2000, 1, 1, 1999, 52),
                Arguments.of(1969, 12, 31, 1970, 1),
                Arguments.of(99, 12, 31, 99, 53)
        );
    }

    @ParameterizedTest(name = "{0}")
    @MethodSource("cases")
    void dayOfWeek(String name, int year, int month, int day, int want) {
        assertEquals(want, Weekday.dayOfWeek(year, month, day));
    }

    @ParameterizedTest
    @MethodSource("weeks")
    void isoWeek(int year, int month, int day, int weekYear, int week) {
        assertArrayEquals(new int[] {weekYear, week}, Weekday.isoWeek(year, month, day));
    }

    @Test
    void sundayIsSeven() {
        assertEquals(DayOfWeek.SUNDAY, LocalDate.of(2024, 3, 10).getDayOfWeek());
        assertEquals(7, DayOfWeek.SUNDAY.getValue());
    }
}
weekday.cI0RawGitHub
// SPDX-License-Identifier: MIT
// Part of https://programming.tamnd.com/find-the-day-of-the-week/.

#include "weekday.h"

// The day arithmetic is from Howard Hinnant, "chrono-Compatible Low-Level
// Date Algorithms". It needs no time zone and no time_t, so it also works
// for years before 1970 and before 1900.
static long long days_from_civil(long long year, int month, int day) {
    long long y = month <= 2 ? year - 1 : year;
    long long era = (y >= 0 ? y : y - 399) / 400;
    long long yoe = y - era * 400;
    long long mp = (month + 9) % 12;
    long long doy = (153 * mp + 2) / 5 + day - 1;
    long long doe = yoe * 365 + yoe / 4 - yoe / 100 + doy;
    return era * 146097 + doe - 719468;
}

static long long year_from_days(long long days) {
    long long z = days + 719468;
    long long era = (z >= 0 ? z : z - 146096) / 146097;
    long long doe = z - era * 146097;
    long long yoe = (doe - doe / 1460 + doe / 36524 - doe / 146096) / 365;
    long long doy = doe - (365 * yoe + yoe / 4 - yoe / 100);
    long long mp = (5 * doy + 2) / 153;
    return yoe + era * 400 + (mp >= 10 ? 1 : 0);
}

// 1970-01-01 was a Thursday, which is day 4. The % operator of C keeps the
// sign of the left operand, so a negative remainder needs 7 added.
static int weekday_from_days(long long days) {
    int r = (int)((days + 3) % 7);
    return (r < 0 ? r + 7 : r) + 1;
}

int day_of_week(int year, int month, int day) {
    return weekday_from_days(days_from_civil(year, month, day));
}

void iso_week(int year, int month, int day, int *week_year, int *week) {
    long long days = days_from_civil(year, month, day);
    long long thursday = days + 4 - weekday_from_days(days);
    long long y = year_from_days(thursday);
    *week_year = (int)y;
    *week = (int)((thursday - days_from_civil(y, 1, 1)) / 7 + 1);
}
weekday.h 13 lines
// SPDX-License-Identifier: MIT
// Part of https://programming.tamnd.com/find-the-day-of-the-week/.

#ifndef DAY_OF_WEEK_H
#define DAY_OF_WEEK_H

// Returns the ISO 8601 day of the week: 1 for Monday to 7 for Sunday.
int day_of_week(int year, int month, int day);

// Writes the ISO 8601 week-based year and week number of a date.
void iso_week(int year, int month, int day, int *week_year, int *week);

#endif
test_weekday.c 74 lines
// SPDX-License-Identifier: MIT
// Part of https://programming.tamnd.com/find-the-day-of-the-week/.

#include "weekday.h"

#include <stdio.h>
#include <stdlib.h>

struct test_case {
    const char *name;
    int year, month, day;
    int want;
};

static const struct test_case cases[] = {
    {"a-sunday", 2024, 3, 10, 7},
    {"a-monday", 2024, 3, 11, 1},
    {"the-epoch", 1970, 1, 1, 4},
    {"year-2000", 2000, 1, 1, 6},
    {"a-saturday", 2024, 3, 16, 6},
    {"leap-day", 2024, 2, 29, 4},
    {"after-leap-day-2000", 2000, 3, 1, 3},
    {"year-1900-is-not-leap", 1900, 3, 1, 4},
    {"year-2100-is-not-leap", 2100, 3, 1, 1},
    {"before-the-epoch", 1969, 12, 31, 3},
    {"gregorian-reform", 1582, 10, 15, 5},
    {"day-before-the-reform", 1582, 10, 4, 1},
    {"first-day", 1, 1, 1, 1},
    {"last-day", 9999, 12, 31, 5},
    {"year-99", 99, 12, 31, 4},
    {"iso-week-of-next-year", 2024, 12, 30, 1},
    {"iso-week-of-last-year", 2027, 1, 1, 5},
    {"month-end", 2024, 4, 30, 2},
};

struct week_case {
    int year, month, day;
    int week_year, week;
};

static const struct week_case weeks[] = {
    {2024, 3, 10, 2024, 10},
    {2024, 12, 30, 2025, 1},
    {2027, 1, 1, 2026, 53},
    {2000, 1, 1, 1999, 52},
    {1969, 12, 31, 1970, 1},
    {99, 12, 31, 99, 53},
};

int main(void) {
    int failures = 0;
    for (size_t i = 0; i < sizeof cases / sizeof cases[0]; i++) {
        const struct test_case *c = &cases[i];
        int got = day_of_week(c->year, c->month, c->day);
        if (got != c->want) {
            printf("FAIL %s: got %d, want %d\n", c->name, got, c->want);
            failures++;
        }
    }
    for (size_t i = 0; i < sizeof weeks / sizeof weeks[0]; i++) {
        const struct week_case *c = &weeks[i];
        int week_year = 0, week = 0;
        iso_week(c->year, c->month, c->day, &week_year, &week);
        if (week_year != c->week_year || week != c->week) {
            printf("FAIL iso week of %04d-%02d-%02d: got %d-W%02d\n", c->year, c->month, c->day, week_year, week);
            failures++;
        }
    }
    if (failures != 0) {
        return EXIT_FAILURE;
    }
    printf("ok\n");
    return EXIT_SUCCESS;
}
Weekday.csI0RawGitHub
// SPDX-License-Identifier: MIT
// Part of https://programming.tamnd.com/find-the-day-of-the-week/.

using System;
using System.Globalization;

/// <summary>Finds the day of the week and the ISO week of a date.</summary>
public static class Weekday
{
    /// <summary>Returns the ISO 8601 day of the week: 1 for Monday to 7 for Sunday.</summary>
    public static int DayOfWeekIso(int year, int month, int day)
    {
        // The DayOfWeek enumeration has Sunday = 0, so 0 becomes 7.
        var weekday = (int)new DateOnly(year, month, day).DayOfWeek;
        return weekday == 0 ? 7 : weekday;
    }

    /// <summary>Returns the ISO 8601 week-based year and week number of a date.</summary>
    public static (int WeekYear, int Week) IsoWeek(int year, int month, int day)
    {
        var date = new DateTime(year, month, day);
        return (ISOWeek.GetYear(date), ISOWeek.GetWeekOfYear(date));
    }
}
WeekdayTests.cs 61 lines
// SPDX-License-Identifier: MIT
// Part of https://programming.tamnd.com/find-the-day-of-the-week/.

using System;
using Xunit;

public sealed class WeekdayTests
{
    public static TheoryData<string, int, int, int, int> Cases => new()
    {
        { "a-sunday", 2024, 3, 10, 7 },
        { "a-monday", 2024, 3, 11, 1 },
        { "the-epoch", 1970, 1, 1, 4 },
        { "year-2000", 2000, 1, 1, 6 },
        { "a-saturday", 2024, 3, 16, 6 },
        { "leap-day", 2024, 2, 29, 4 },
        { "after-leap-day-2000", 2000, 3, 1, 3 },
        { "year-1900-is-not-leap", 1900, 3, 1, 4 },
        { "year-2100-is-not-leap", 2100, 3, 1, 1 },
        { "before-the-epoch", 1969, 12, 31, 3 },
        { "gregorian-reform", 1582, 10, 15, 5 },
        { "day-before-the-reform", 1582, 10, 4, 1 },
        { "first-day", 1, 1, 1, 1 },
        { "last-day", 9999, 12, 31, 5 },
        { "year-99", 99, 12, 31, 4 },
        { "iso-week-of-next-year", 2024, 12, 30, 1 },
        { "iso-week-of-last-year", 2027, 1, 1, 5 },
        { "month-end", 2024, 4, 30, 2 },
    };

    public static TheoryData<int, int, int, int, int> Weeks => new()
    {
        { 2024, 3, 10, 2024, 10 },
        { 2024, 12, 30, 2025, 1 },
        { 2027, 1, 1, 2026, 53 },
        { 2000, 1, 1, 1999, 52 },
        { 1969, 12, 31, 1970, 1 },
        { 99, 12, 31, 99, 53 },
    };

    [Theory]
    [MemberData(nameof(Cases))]
    public void DayOfWeekIso(string name, int year, int month, int day, int want)
    {
        Assert.NotNull(name);
        Assert.Equal(want, Weekday.DayOfWeekIso(year, month, day));
    }

    [Theory]
    [MemberData(nameof(Weeks))]
    public void IsoWeek(int year, int month, int day, int weekYear, int week)
    {
        Assert.Equal((weekYear, week), Weekday.IsoWeek(year, month, day));
    }

    [Fact]
    public void SundayIsZero()
    {
        Assert.Equal(0, (int)new DateOnly(2024, 3, 10).DayOfWeek);
    }
}
weekday.jsI0RawGitHub
// SPDX-License-Identifier: MIT
// Part of https://programming.tamnd.com/find-the-day-of-the-week/.

const MS_PER_DAY = 24 * 60 * 60 * 1000;

/**
 * Returns a Date at midnight UTC of a date.
 * setUTCFullYear takes the year as it is. Date.UTC reads the years 0 to 99 as 1900 to 1999.
 */
function utcDate(year, month, day) {
  const date = new Date(0);
  date.setUTCFullYear(year, month - 1, day);
  return date;
}

/**
 * Returns the ISO 8601 day of the week: 1 for Monday to 7 for Sunday.
 * getUTCDay returns 0 for Sunday, so 0 becomes 7.
 */
export function dayOfWeek(year, month, day) {
  return utcDate(year, month, day).getUTCDay() || 7;
}

/**
 * Returns the ISO 8601 week-based year and week number of a date.
 * The Thursday of the same week is always in the week-based year.
 */
export function isoWeek(year, month, day) {
  const date = utcDate(year, month, day);
  const thursday = new Date(date.getTime() + (4 - (date.getUTCDay() || 7)) * MS_PER_DAY);
  const weekYear = thursday.getUTCFullYear();
  const january1 = utcDate(weekYear, 1, 1);
  const week = Math.floor((thursday.getTime() - january1.getTime()) / MS_PER_DAY / 7) + 1;
  return [weekYear, week];
}
weekday.test.js 53 lines
// SPDX-License-Identifier: MIT
// Part of https://programming.tamnd.com/find-the-day-of-the-week/.

import assert from "node:assert/strict";
import { test } from "node:test";

import { dayOfWeek, isoWeek } from "./weekday.js";

const cases = [
  ["a-sunday", [2024, 3, 10], 7],
  ["a-monday", [2024, 3, 11], 1],
  ["the-epoch", [1970, 1, 1], 4],
  ["year-2000", [2000, 1, 1], 6],
  ["a-saturday", [2024, 3, 16], 6],
  ["leap-day", [2024, 2, 29], 4],
  ["after-leap-day-2000", [2000, 3, 1], 3],
  ["year-1900-is-not-leap", [1900, 3, 1], 4],
  ["year-2100-is-not-leap", [2100, 3, 1], 1],
  ["before-the-epoch", [1969, 12, 31], 3],
  ["gregorian-reform", [1582, 10, 15], 5],
  ["day-before-the-reform", [1582, 10, 4], 1],
  ["first-day", [1, 1, 1], 1],
  ["last-day", [9999, 12, 31], 5],
  ["year-99", [99, 12, 31], 4],
  ["iso-week-of-next-year", [2024, 12, 30], 1],
  ["iso-week-of-last-year", [2027, 1, 1], 5],
  ["month-end", [2024, 4, 30], 2],
];

const weeks = [
  [[2024, 3, 10], [2024, 10]],
  [[2024, 12, 30], [2025, 1]],
  [[2027, 1, 1], [2026, 53]],
  [[2000, 1, 1], [1999, 52]],
  [[1969, 12, 31], [1970, 1]],
  [[99, 12, 31], [99, 53]],
];

for (const [name, [year, month, day], want] of cases) {
  test(name, () => {
    assert.equal(dayOfWeek(year, month, day), want);
  });
}

for (const [[year, month, day], want] of weeks) {
  test(`ISO week of ${year}-${month}-${day}`, () => {
    assert.deepEqual(isoWeek(year, month, day), want);
  });
}

test("getUTCDay counts from Sunday", () => {
  assert.equal(new Date(Date.UTC(2024, 2, 10)).getUTCDay(), 0);
});
weekday.tsI0RawGitHub
// SPDX-License-Identifier: MIT
// Part of https://programming.tamnd.com/find-the-day-of-the-week/.

const MS_PER_DAY = 24 * 60 * 60 * 1000;

/**
 * Returns a Date at midnight UTC of a date.
 * setUTCFullYear takes the year as it is. Date.UTC reads the years 0 to 99 as 1900 to 1999.
 */
function utcDate(year: number, month: number, day: number): Date {
  const date = new Date(0);
  date.setUTCFullYear(year, month - 1, day);
  return date;
}

/**
 * Returns the ISO 8601 day of the week: 1 for Monday to 7 for Sunday.
 * getUTCDay returns 0 for Sunday, so 0 becomes 7.
 */
export function dayOfWeek(year: number, month: number, day: number): number {
  return utcDate(year, month, day).getUTCDay() || 7;
}

/**
 * Returns the ISO 8601 week-based year and week number of a date.
 * The Thursday of the same week is always in the week-based year.
 */
export function isoWeek(year: number, month: number, day: number): [number, number] {
  const date = utcDate(year, month, day);
  const thursday = new Date(date.getTime() + (4 - (date.getUTCDay() || 7)) * MS_PER_DAY);
  const weekYear = thursday.getUTCFullYear();
  const january1 = utcDate(weekYear, 1, 1);
  const week = Math.floor((thursday.getTime() - january1.getTime()) / MS_PER_DAY / 7) + 1;
  return [weekYear, week];
}
weekday.test.ts 53 lines
// SPDX-License-Identifier: MIT
// Part of https://programming.tamnd.com/find-the-day-of-the-week/.

import assert from "node:assert/strict";
import { test } from "node:test";

import { dayOfWeek, isoWeek } from "./weekday.ts";

const cases: [string, [number, number, number], number][] = [
  ["a-sunday", [2024, 3, 10], 7],
  ["a-monday", [2024, 3, 11], 1],
  ["the-epoch", [1970, 1, 1], 4],
  ["year-2000", [2000, 1, 1], 6],
  ["a-saturday", [2024, 3, 16], 6],
  ["leap-day", [2024, 2, 29], 4],
  ["after-leap-day-2000", [2000, 3, 1], 3],
  ["year-1900-is-not-leap", [1900, 3, 1], 4],
  ["year-2100-is-not-leap", [2100, 3, 1], 1],
  ["before-the-epoch", [1969, 12, 31], 3],
  ["gregorian-reform", [1582, 10, 15], 5],
  ["day-before-the-reform", [1582, 10, 4], 1],
  ["first-day", [1, 1, 1], 1],
  ["last-day", [9999, 12, 31], 5],
  ["year-99", [99, 12, 31], 4],
  ["iso-week-of-next-year", [2024, 12, 30], 1],
  ["iso-week-of-last-year", [2027, 1, 1], 5],
  ["month-end", [2024, 4, 30], 2],
];

const weeks: [[number, number, number], [number, number]][] = [
  [[2024, 3, 10], [2024, 10]],
  [[2024, 12, 30], [2025, 1]],
  [[2027, 1, 1], [2026, 53]],
  [[2000, 1, 1], [1999, 52]],
  [[1969, 12, 31], [1970, 1]],
  [[99, 12, 31], [99, 53]],
];

for (const [name, [year, month, day], want] of cases) {
  test(name, () => {
    assert.equal(dayOfWeek(year, month, day), want);
  });
}

for (const [[year, month, day], want] of weeks) {
  test(`ISO week of ${year}-${month}-${day}`, () => {
    assert.deepEqual(isoWeek(year, month, day), want);
  });
}

test("getUTCDay counts from Sunday", () => {
  assert.equal(new Date(Date.UTC(2024, 2, 10)).getUTCDay(), 0);
});
weekday.goI0RawGitHub
// SPDX-License-Identifier: MIT
// Part of https://programming.tamnd.com/find-the-day-of-the-week/.

// Package weekday finds the day of the week and the ISO week of a date.
package weekday

import "time"

// DayOfWeek returns the ISO 8601 day of the week: 1 for Monday to 7 for
// Sunday. time.Weekday has Sunday = 0, so 0 becomes 7.
func DayOfWeek(year, month, day int) int {
	weekday := int(time.Date(year, time.Month(month), day, 0, 0, 0, 0, time.UTC).Weekday())
	if weekday == 0 {
		return 7
	}
	return weekday
}

// ISOWeek returns the ISO 8601 week-based year and week number of a date.
func ISOWeek(year, month, day int) (int, int) {
	return time.Date(year, time.Month(month), day, 0, 0, 0, 0, time.UTC).ISOWeek()
}
weekday_test.go 71 lines
// SPDX-License-Identifier: MIT
// Part of https://programming.tamnd.com/find-the-day-of-the-week/.

package weekday

import (
	"testing"
	"time"
)

var cases = []struct {
	name             string
	year, month, day int
	want             int
}{
	{"a-sunday", 2024, 3, 10, 7},
	{"a-monday", 2024, 3, 11, 1},
	{"the-epoch", 1970, 1, 1, 4},
	{"year-2000", 2000, 1, 1, 6},
	{"a-saturday", 2024, 3, 16, 6},
	{"leap-day", 2024, 2, 29, 4},
	{"after-leap-day-2000", 2000, 3, 1, 3},
	{"year-1900-is-not-leap", 1900, 3, 1, 4},
	{"year-2100-is-not-leap", 2100, 3, 1, 1},
	{"before-the-epoch", 1969, 12, 31, 3},
	{"gregorian-reform", 1582, 10, 15, 5},
	{"day-before-the-reform", 1582, 10, 4, 1},
	{"first-day", 1, 1, 1, 1},
	{"last-day", 9999, 12, 31, 5},
	{"year-99", 99, 12, 31, 4},
	{"iso-week-of-next-year", 2024, 12, 30, 1},
	{"iso-week-of-last-year", 2027, 1, 1, 5},
	{"month-end", 2024, 4, 30, 2},
}

var weeks = []struct {
	year, month, day int
	weekYear, week   int
}{
	{2024, 3, 10, 2024, 10},
	{2024, 12, 30, 2025, 1},
	{2027, 1, 1, 2026, 53},
	{2000, 1, 1, 1999, 52},
	{1969, 12, 31, 1970, 1},
	{99, 12, 31, 99, 53},
}

func TestDayOfWeek(t *testing.T) {
	for _, c := range cases {
		t.Run(c.name, func(t *testing.T) {
			if got := DayOfWeek(c.year, c.month, c.day); got != c.want {
				t.Fatalf("got %d, want %d", got, c.want)
			}
		})
	}
}

func TestISOWeek(t *testing.T) {
	for _, c := range weeks {
		weekYear, week := ISOWeek(c.year, c.month, c.day)
		if weekYear != c.weekYear || week != c.week {
			t.Fatalf("%04d-%02d-%02d: got %d-W%02d, want %d-W%02d", c.year, c.month, c.day, weekYear, week, c.weekYear, c.week)
		}
	}
}

func TestSundayIsZero(t *testing.T) {
	if got := time.Date(2024, time.March, 10, 0, 0, 0, 0, time.UTC).Weekday(); got != time.Sunday || int(got) != 0 {
		t.Fatalf("got %v", got)
	}
}
weekday.rsI0RawGitHub
// SPDX-License-Identifier: MIT
// Part of https://programming.tamnd.com/find-the-day-of-the-week/.

/// Returns the number of days from 1970-01-01 to a date of the proleptic
/// Gregorian calendar. The formula is from Howard Hinnant, "chrono-Compatible
/// Low-Level Date Algorithms".
pub fn days_from_civil(year: i64, month: i64, day: i64) -> i64 {
    let y = if month <= 2 { year - 1 } else { year };
    let era = y.div_euclid(400);
    let yoe = y - era * 400;
    let mp = (month + 9) % 12;
    let doy = (153 * mp + 2) / 5 + day - 1;
    let doe = yoe * 365 + yoe / 4 - yoe / 100 + doy;
    era * 146_097 + doe - 719_468
}

/// Returns the year of a day number. This is the year part of the
/// civil_from_days algorithm of Howard Hinnant.
fn year_from_days(days: i64) -> i64 {
    let z = days + 719_468;
    let era = z.div_euclid(146_097);
    let doe = z - era * 146_097;
    let yoe = (doe - doe / 1460 + doe / 36_524 - doe / 146_096) / 365;
    let doy = doe - (365 * yoe + yoe / 4 - yoe / 100);
    let mp = (5 * doy + 2) / 153;
    let month = if mp < 10 { mp + 3 } else { mp - 9 };
    yoe + era * 400 + if month <= 2 { 1 } else { 0 }
}

/// Returns the ISO 8601 day of the week of a day number. 1970-01-01 was a
/// Thursday, which is day 4.
fn weekday_from_days(days: i64) -> i64 {
    (days + 3).rem_euclid(7) + 1
}

/// Returns the ISO 8601 day of the week: 1 for Monday to 7 for Sunday.
pub fn day_of_week(year: i64, month: i64, day: i64) -> i64 {
    weekday_from_days(days_from_civil(year, month, day))
}

/// Returns the ISO 8601 week-based year and week number of a date. The
/// Thursday of the same week is always in the week-based year.
pub fn iso_week(year: i64, month: i64, day: i64) -> (i64, i64) {
    let days = days_from_civil(year, month, day);
    let thursday = days + 4 - weekday_from_days(days);
    let week_year = year_from_days(thursday);
    (week_year, (thursday - days_from_civil(week_year, 1, 1)) / 7 + 1)
}
tests/weekday_test.rs 48 lines
// SPDX-License-Identifier: MIT
// Part of https://programming.tamnd.com/find-the-day-of-the-week/.

use algo_find_the_day_of_the_week::{day_of_week, iso_week};

const CASES: &[(&str, i64, i64, i64, i64)] = &[
    ("a-sunday", 2024, 3, 10, 7),
    ("a-monday", 2024, 3, 11, 1),
    ("the-epoch", 1970, 1, 1, 4),
    ("year-2000", 2000, 1, 1, 6),
    ("a-saturday", 2024, 3, 16, 6),
    ("leap-day", 2024, 2, 29, 4),
    ("after-leap-day-2000", 2000, 3, 1, 3),
    ("year-1900-is-not-leap", 1900, 3, 1, 4),
    ("year-2100-is-not-leap", 2100, 3, 1, 1),
    ("before-the-epoch", 1969, 12, 31, 3),
    ("gregorian-reform", 1582, 10, 15, 5),
    ("day-before-the-reform", 1582, 10, 4, 1),
    ("first-day", 1, 1, 1, 1),
    ("last-day", 9999, 12, 31, 5),
    ("year-99", 99, 12, 31, 4),
    ("iso-week-of-next-year", 2024, 12, 30, 1),
    ("iso-week-of-last-year", 2027, 1, 1, 5),
    ("month-end", 2024, 4, 30, 2),
];

const WEEKS: &[(i64, i64, i64, i64, i64)] = &[
    (2024, 3, 10, 2024, 10),
    (2024, 12, 30, 2025, 1),
    (2027, 1, 1, 2026, 53),
    (2000, 1, 1, 1999, 52),
    (1969, 12, 31, 1970, 1),
    (99, 12, 31, 99, 53),
];

#[test]
fn cases() {
    for &(name, year, month, day, want) in CASES {
        assert_eq!(day_of_week(year, month, day), want, "{name}");
    }
}

#[test]
fn iso_weeks() {
    for &(year, month, day, week_year, week) in WEEKS {
        assert_eq!(iso_week(year, month, day), (week_year, week), "{year}-{month}-{day}");
    }
}
weekday.shI0RawGitHub
#!/usr/bin/env bash
# SPDX-License-Identifier: MIT
# Part of https://programming.tamnd.com/find-the-day-of-the-week/.

# day_of_week YEAR MONTH DAY
# Prints the ISO 8601 day of the week: 1 for Monday to 7 for Sunday. It needs
# GNU date. %u is the ISO number, and %w counts from 0 for Sunday. The -u
# option reads the date as midnight UTC.
day_of_week() {
  date -u -d "$(printf '%04d-%02d-%02d' "$1" "$2" "$3")" +%u
}

# iso_week YEAR MONTH DAY
# Prints the ISO 8601 week-based year and week number, such as "2025 1".
# %G is the week-based year and %V is the week number. %Y is the calendar
# year, and it is different for some days at the start and end of a year.
iso_week() {
  local out
  out=$(date -u -d "$(printf '%04d-%02d-%02d' "$1" "$2" "$3")" '+%G %V') || return 1
  local week_year=${out% *} week=${out#* }
  echo "$(( 10#$week_year )) $(( 10#$week ))"
}
test_weekday.bats 32 lines
#!/usr/bin/env bats
# SPDX-License-Identifier: MIT
# Part of https://programming.tamnd.com/find-the-day-of-the-week/.

setup() {
  source "$BATS_TEST_DIRNAME/weekday.sh"
}

@test "a-sunday" { run day_of_week 2024 3 10; [ "$status" -eq 0 ]; [ "$output" = 7 ]; }
@test "a-monday" { run day_of_week 2024 3 11; [ "$status" -eq 0 ]; [ "$output" = 1 ]; }
@test "the-epoch" { run day_of_week 1970 1 1; [ "$status" -eq 0 ]; [ "$output" = 4 ]; }
@test "year-2000" { run day_of_week 2000 1 1; [ "$status" -eq 0 ]; [ "$output" = 6 ]; }
@test "a-saturday" { run day_of_week 2024 3 16; [ "$status" -eq 0 ]; [ "$output" = 6 ]; }
@test "leap-day" { run day_of_week 2024 2 29; [ "$status" -eq 0 ]; [ "$output" = 4 ]; }
@test "after-leap-day-2000" { run day_of_week 2000 3 1; [ "$status" -eq 0 ]; [ "$output" = 3 ]; }
@test "year-1900-is-not-leap" { run day_of_week 1900 3 1; [ "$status" -eq 0 ]; [ "$output" = 4 ]; }
@test "year-2100-is-not-leap" { run day_of_week 2100 3 1; [ "$status" -eq 0 ]; [ "$output" = 1 ]; }
@test "before-the-epoch" { run day_of_week 1969 12 31; [ "$status" -eq 0 ]; [ "$output" = 3 ]; }
@test "gregorian-reform" { run day_of_week 1582 10 15; [ "$status" -eq 0 ]; [ "$output" = 5 ]; }
@test "day-before-the-reform" { run day_of_week 1582 10 4; [ "$status" -eq 0 ]; [ "$output" = 1 ]; }
@test "first-day" { run day_of_week 1 1 1; [ "$status" -eq 0 ]; [ "$output" = 1 ]; }
@test "last-day" { run day_of_week 9999 12 31; [ "$status" -eq 0 ]; [ "$output" = 5 ]; }
@test "year-99" { run day_of_week 99 12 31; [ "$status" -eq 0 ]; [ "$output" = 4 ]; }
@test "iso-week-of-next-year" { run day_of_week 2024 12 30; [ "$status" -eq 0 ]; [ "$output" = 1 ]; }
@test "iso-week-of-last-year" { run day_of_week 2027 1 1; [ "$status" -eq 0 ]; [ "$output" = 5 ]; }
@test "month-end" { run day_of_week 2024 4 30; [ "$status" -eq 0 ]; [ "$output" = 2 ]; }
@test "iso week of 2024-03-10" { run iso_week 2024 3 10; [ "$status" -eq 0 ]; [ "$output" = "2024 10" ]; }
@test "iso week of 2024-12-30" { run iso_week 2024 12 30; [ "$status" -eq 0 ]; [ "$output" = "2025 1" ]; }
@test "iso week of 2027-01-01" { run iso_week 2027 1 1; [ "$status" -eq 0 ]; [ "$output" = "2026 53" ]; }
@test "iso week of 2000-01-01" { run iso_week 2000 1 1; [ "$status" -eq 0 ]; [ "$output" = "1999 52" ]; }
@test "iso week of 1969-12-31" { run iso_week 1969 12 31; [ "$status" -eq 0 ]; [ "$output" = "1970 1" ]; }
@test "iso week of 0099-12-31" { run iso_week 99 12 31; [ "$status" -eq 0 ]; [ "$output" = "99 53" ]; }

References

  1. The Python Standard Library, datetime, date.weekday(); date.isoweekday(); date.isocalendar()
  2. MDN Web Docs, Date.prototype.getDay(), Return value
  3. MDN Web Docs, Date.prototype.getUTCDay(), Return value
  4. MDN Web Docs, Date.parse(), Examples
  5. Java SE 25 API, java.time.DayOfWeek, the description of the enum
  6. Java SE 25 API, java.time.temporal.IsoFields, WEEK_BASED_YEAR; WEEK_OF_WEEK_BASED_YEAR
  7. Java SE 25 API, java.time.format.DateTimeFormatter, Patterns for Formatting and Parsing
  8. .NET API reference, DayOfWeek Enum, Fields
  9. .NET API reference, ISOWeek Class, Methods
  10. .NET API reference, Calendar.GetWeekOfYear, Remarks
  11. Go standard library, time, type Weekday; func (Time) Weekday; func (Time) ISOWeek
  12. cppreference.com, std::chrono::weekday::c_encoding, std::chrono::weekday::iso_encoding, Return value
  13. Howard Hinnant, chrono-Compatible Low-Level Date Algorithms, days_from_civil; weekday_from_days
  14. The Open Group Base Specifications Issue 8, strftime, DESCRIPTION: %u, %w, %G, %V
  15. Linux manual page, date(1), FORMAT: %u, %G, %V
  16. Wikipedia, ISO week date, First week
  17. Wikipedia, Zeller's congruence, Formula; Implementations in software

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH0 no proof
  • add a proof in proofs/ (06.5)
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (bash)I0 not checked yet
  • the tests did not run in this build
Code (c)I0 not checked yet
  • the tests did not run in this build
Code (cpp)I0 not checked yet
  • the tests did not run in this build
Code (csharp)I0 not checked yet
  • the tests did not run in this build
Code (go)I0 not checked yet
  • the tests did not run in this build
Code (java)I0 not checked yet
  • the tests did not run in this build
Code (javascript)I0 not checked yet
  • the tests did not run in this build
Code (python)I0 not checked yet
  • the tests did not run in this build
Code (rust)I0 not checked yet
  • the tests did not run in this build
Code (typescript)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW3 standard
  • a history with a source