Skip to content

Dates

arapy.dates.ardate

ArDate: a date with Arabic formatting and parsing.

ArDate

Bases: date

A date that formats and parses Arabic text.

Arithmetic, replace() and the classmethods (today, fromisoformat, …) already return the subclass in the standard library, so the result stays an ArDate; date - date is still a timedelta. strftime() and format()-protocol output are standard.

from arapy import ArDate

d = ArDate(2026, 1, 5)

print(d.format("%O من %B %Y", digits="arabic"))  # الخامس من كانون الثاني ٢٠٢٦

weekday_name property

weekday_name: str

«الاثنين» … «الأحد».

from_date classmethod

from_date(d: date) -> Self

Convert a plain date (or the date part of a datetime).

month_name

month_name(style: MonthNames = MonthNames.LEVANT) -> str

The month's name in style: «كانون الثاني», «يناير», …

format

format(
    fmt: str,
    *,
    months: MonthNames = MonthNames.LEVANT,
    digits: DigitSet = "latin",
) -> str

Format with Arabic names: strftime date directives plus %O for the ordinal day.

strptime classmethod

strptime(
    text: str, fmt: str, *, months: MonthNames | None = None
) -> Self

Strictly parse text written with fmt, in any digit set.

months=None accepts the month names of every style. Missing fields default to 1900-01-01, as in datetime.strptime. A weekday or day of year that does not match the date raises ParseError.

to_hijri

to_hijri() -> HijriDate

The same day in the Hijri (Umm al-Qura) calendar. Needs arapy[hijri].

parse_gregorian

parse_gregorian(
    text: str,
    fmt: str,
    *,
    months: MonthNames | None,
    directives: str,
) -> tuple[date, dict[str, int]]

Parse the date part of text; also return the parsed fields (for the time part).

arapy.dates.ardatetime

ArDateTime: a datetime with Arabic formatting and parsing.

ArDateTime

Bases: datetime

A datetime that formats and parses Arabic text.

Like ArDate, arithmetic, replace() and the classmethods (now, combine, …) return the subclass, and strftime() and format()-protocol output are standard. .format() adds the time directives %H %I %M %S and %p (صباحًا / مساءً).

from arapy import ArDateTime

dt = ArDateTime(2026, 1, 5, 14, 30)

print(dt.format("%I:%M %p", digits="arabic"))  # ٠٢:٣٠ مساءً

weekday_name property

weekday_name: str

«الاثنين» … «الأحد».

from_datetime classmethod

from_datetime(dt: datetime) -> Self

Convert a plain datetime, keeping its time zone and fold.

month_name

month_name(style: MonthNames = MonthNames.LEVANT) -> str

The month's name in style: «كانون الثاني», «يناير», …

format

format(
    fmt: str,
    *,
    months: MonthNames = MonthNames.LEVANT,
    digits: DigitSet = "latin",
) -> str

Format with Arabic names: date directives, %O, and %H %I %M %S %p.

strptime classmethod

strptime(
    text: str, fmt: str, *, months: MonthNames | None = None
) -> Self

Strictly parse text written with fmt, in any digit set.

The rules are those of ArDate.strptime; missing time fields default to midnight.

to_hijri

to_hijri() -> HijriDate

The date part in the Hijri (Umm al-Qura) calendar. Needs arapy[hijri].

arapy.dates.hijri

HijriDate: an Umm al-Qura Hijri date with a date-like API. Needs arapy[hijri].

HijriDate dataclass

A Hijri date (Umm al-Qura, 1343–1500 AH). Compares and subtracts with date by day.

from arapy import HijriDate

ramadan = HijriDate(1447, 9, 1)

print(ramadan.format("%O من %B %Y هـ", digits="arabic"))  # الأول من رمضان ١٤٤٧ هـ
print(ramadan.to_gregorian())  # 2026-02-18

weekday_name property

weekday_name: str

«الاثنين» … «الأحد».

from_date classmethod

from_date(d: date) -> Self

The Hijri date of a date (or the date part of a datetime).

weekday

weekday() -> int

Monday = 0 … Sunday = 6, as in date.weekday().

month_name

month_name() -> str

«محرم» … «ذو الحجة».

format

format(fmt: str, *, digits: DigitSet = 'latin') -> str

Format with Arabic names: %a %A %b %B %d %m %Y %j %O %%.

strptime classmethod

strptime(text: str, fmt: str) -> Self

Strictly parse text written with fmt, in any digit set.

Accepts ربيع الثاني and جمادى الثانية as well. Missing fields default to the first day of the year 1400, and a weekday or day of year that does not match raises ParseError.

arapy.dates.humanize

Relative times and durations in Arabic words: «منذ ثلاثة أيام», «سنة وثلاثة أشهر».

RelativeDeltaLike

Bases: Protocol

Anything with calendar fields, such as dateutil.relativedelta.relativedelta.

ar_since

ar_since(dt: datetime, now: datetime | None = None) -> str

How long ago (or how far ahead) dt is, in its largest whole unit.

«منذ ثلاثة أيام», «بعد شهرين», «منذ ثلاث ثوانٍ»; «الآن» when under one second. now defaults to the current time in dt's time zone.

ar_duration

ar_duration(value: timedelta | RelativeDeltaLike) -> str

A duration in words, largest unit first: «سنة وثلاثة أشهر», «أسبوعان ويومان».

A timedelta has no months or years, so its days are split into weeks and days only. Zero is «صفر ثانية». Sub-second parts are ignored; negative parts raise.

arapy.dates.months

Month and weekday names: Gregorian month styles, weekdays and Hijri months.

MONTHS module-attribute

MONTHS: Final[Mapping[MonthNames, tuple[str, ...]]] = (
    MappingProxyType(
        {
            MonthNames.LEVANT: _LEVANT,
            MonthNames.EGYPTIAN: _EGYPTIAN,
            MonthNames.MAGHREB: _MAGHREB,
            MonthNames.LEVANT_WITH_EGYPTIAN: tuple(
                f"{levant} ({egyptian})"
                for levant, egyptian in zip(
                    _LEVANT, _EGYPTIAN, strict=True
                )
            ),
        }
    )
)

Twelve month names per style, January first.

WEEKDAYS module-attribute

WEEKDAYS: Final = (
    "الاثنين",
    "الثلاثاء",
    "الأربعاء",
    "الخميس",
    "الجمعة",
    "السبت",
    "الأحد",
)

Weekday names, Monday first, matching date.weekday().

HIJRI_MONTHS module-attribute

HIJRI_MONTHS: Final = (
    "محرم",
    "صفر",
    "ربيع الأول",
    "ربيع الآخر",
    "جمادى الأولى",
    "جمادى الآخرة",
    "رجب",
    "شعبان",
    "رمضان",
    "شوال",
    "ذو القعدة",
    "ذو الحجة",
)

Hijri month names, محرم first.

MonthNames

Bases: StrEnum

Gregorian month-name styles.

month_numbers

month_numbers(
    style: MonthNames | None = None,
) -> dict[str, int]

Map month names to 1–12 for one style, or for every style when style is None.