Truly independent web browser
/*
* Copyright (c) 2026, Tim Flynn <[email protected]>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Optional.h>
#include <AK/String.h>
#include <AK/StringView.h>
#include <AK/Types.h>
#include <AK/Utf16String.h>
#include <AK/Utf16View.h>
namespace Unicode {
// 3.5.1 ISO Date Records, https://tc39.es/proposal-temporal/#sec-temporal-iso-date-records
struct ISODate {
i32 year { 0 };
u8 month { 0 };
u8 day { 0 };
};
// 12.2 Month Codes, https://tc39.es/proposal-temporal/#sec-temporal-month-codes
struct MonthCode {
u8 month_number { 0 };
bool is_leap_month { false };
};
// 14.3 The Year-Week Record Specification Type, https://tc39.es/proposal-temporal/#sec-year-week-record-specification-type
struct YearWeek {
Optional<u8> week;
Optional<i32> year;
};
// 12.3.1 Calendar Date Records, https://tc39.es/proposal-temporal/#sec-temporal-calendar-date-records
struct CalendarDate {
Optional<Utf16String> era;
Optional<i32> era_year;
i32 year { 0 };
u8 month { 0 };
Utf16String month_code;
u8 day { 0 };
u8 day_of_week { 0 };
u16 day_of_year { 0 };
YearWeek week_of_year;
u8 days_in_week { 0 };
u8 days_in_month { 0 };
u16 days_in_year { 0 };
u8 months_in_year { 0 };
bool in_leap_year { false };
};
Optional<MonthCode> parse_month_code(Utf16View month_code);
Utf16String create_month_code(u8 month_number, bool is_leap_month);
CalendarDate iso_date_to_calendar_date(StringView calendar, ISODate);
Optional<ISODate> calendar_date_to_iso_date(StringView calendar, i32 year, u8 month, u8 day);
Optional<ISODate> iso_year_and_month_code_to_iso_date(StringView calendar, i32 year, Utf16View month_code, u8 day);
Optional<ISODate> calendar_year_and_month_code_to_iso_date(StringView calendar, i32 arithmetic_year, Utf16View month_code, u8 day);
u8 calendar_months_in_year(StringView calendar, i32 arithmetic_year);
u8 calendar_days_in_month(StringView calendar, i32 arithmetic_year, u8 ordinal_month);
u8 calendar_max_days_in_month_code(StringView calendar, Utf16View month_code);
bool calendar_year_contains_month_code(StringView calendar, i32 arithmetic_year, Utf16View month_code);
}