calendar
The Jalali, Hijri and Gregorian calendars: conversion, day arithmetic, month names and time zones.
import calendar
This package works with three calendars: Jalali (Solar Hijri, the official calendar of Iran and Afghanistan), Hijri (lunar) and Gregorian. A date is a plain struct of year, month and day, and each calendar has its own conversion, validation, day arithmetic and month name functions.
The Hijri calendar here is arithmetic: months alternate between 30 and 29 days and are not adjusted by sighting the moon, so a date can be one day off from the official calendar of a given country.
There are three ways to turn an instant into a date: EpochToJalali and its siblings use the machine local time, WallClockJalali takes a fixed time zone such as Tehran, and LoadZone covers zones that observe daylight saving.
Use it to show dates the way people in Iran, Afghanistan or the Arab world read them, to take a Jalali date from a form, and to turn a meeting time in one city into the time in another. Instants, durations and the clock itself are in time; store instants there and convert to a calendar only for display. For Persian digits in the output, see i18n.
The things people get wrong:
- Taking today's date on a server with
TodayJalaliorEpochToJalali. Those use the machine's zone, and a server set to UTC is still on yesterday until 03:30 in Tehran. UseWallClockJalali(time.Now(), TZTehran()). - Mixing the two weekday numberings.
JalaliWeekdaytakes a Julian day number and counts from Saturday as 0;Weekday,WeekdayJalaliand the otherWeekday...functions count from Sunday as 0. - Converting unchecked input. The conversions do not validate, so 31 Esfand or month 13 gives a wrong date instead of an error. Check with
IsValidJalaliDateand its siblings first. - Expecting the Hijri dates to match an official calendar to the day, or the fixed
TZLondonandTZNewYorkzones to follow daylight saving. They do not; useLoadZonefor that.
The Jalali conversion is the standard arithmetic one (as in the jalaali libraries), which works for the years -61 to 3177 and agrees with the official Iranian calendar for the years in use today.
Birthdays and anniversaries in Jalali
Dates are plain structs, so date logic is ordinary code: build the date in the current year, compare it with today using CompareJalali, and move to the next year if it has passed. DaysBetweenJalali counts the days in between, and JalaliToGregorian gives the same day in the other calendar.
import calendar
func next birthday(born: calendar.JalaliDate, today: calendar.JalaliDate): calendar.JalaliDate:
mut target year := today.year
mut target day := born.day
if born.month == 12 and target day == 30 and not calendar.IsLeapJalali(target year):
target day = 29
end
mut next := calendar.JalaliDate { year = target year, month = born.month, day = target day }
if calendar.CompareJalali(next, today) < 0:
target year++
target day = born.day
if born.month == 12 and target day == 30 and not calendar.IsLeapJalali(target year):
target day = 29
end
next = calendar.JalaliDate { year = target year, month = born.month, day = target day }
end
ret next
end
func main:
today := calendar.JalaliDate { year = 1405, month = 7, day = 25 }
born := calendar.JalaliDate { year = 1370, month = 9, day = 3 }
mut age := today.year - born.year
birthday now := calendar.JalaliDate { year = today.year, month = born.month, day = born.day }
if calendar.CompareJalali(birthday now, today) > 0:
age--
end
next := next birthday(born, today)
println "age:", age
println "next birthday:", calendar.FormatJalali(next), "(" + calendar.JalaliMonthNameEn(next.month) + ")"
println "days to go:", calendar.DaysBetweenJalali(today, next)
println "in the Gregorian calendar:", calendar.FormatGregorian(calendar.JalaliToGregorian(next))
leap := calendar.JalaliDate { year = 1403, month = 12, day = 30 }
println "born on 30 Esfand 1403, celebrates in 1405 on:", calendar.FormatJalali(next birthday(leap, today))
endOne case needs care: 30 Esfand exists only in leap years. Before building a date in another year, check it with IsLeapJalali or IsValidJalaliDate; the example moves such a birthday to 29 Esfand. AddYearsJalali and AddMonthsJalali do the same clamping for you when you only need to move a date.
Drawing a month
A month view needs two numbers: the weekday of the first day and the length of the month. JalaliWeekday numbers the days from Saturday as 0, which is how Persian calendars are laid out, and DaysInJalaliMonth gives the length.
import calendar
import str
func main:
shown year := 1405
shown month := 7
first := calendar.JalaliDate { year = shown year, month = shown month, day = 1 }
println calendar.JalaliMonthNameEn(shown month), shown year
println "Sa Su Mo Tu We Th Fr"
offset := calendar.JalaliWeekday(calendar.JalaliToJDN(first))
mut line := ""
repeat offset:
line += " "
end
days := calendar.DaysInJalaliMonth(shown year, shown month)
repeat 1 to days in d:
if d < 10:
line += " "
end
line += str.FromInt(d)
if (offset + d) % 7 == 0:
println line
line = ""
else:
line += " "
end
end
if line != "":
println line.Trim()
end
println "starts on", calendar.FormatGregorianLongEn(calendar.JalaliToGregorian(first))
endFor a week that starts on Sunday or Monday, use WeekdayJalali or WeekdayGregorian instead, which number from Sunday as 0, and shift by the day you want first.
A Hijri month in the other calendars
For Ramadan or Muharram you usually want the Hijri dates translated into Gregorian and Jalali ones. DaysInHijriMonth gives the length of the month and AddDaysHijri walks from its first day to its last.
import calendar
func main:
start := calendar.HijriDate { year = 1448, month = 9, day = 1 }
days := calendar.DaysInHijriMonth(start.year, start.month)
last := calendar.AddDaysHijri(start, days - 1)
eid := calendar.AddDaysHijri(last, 1)
println calendar.HijriMonthNameEn(start.month), start.year, "has", days, "days"
println "first day:", calendar.FormatGregorian(calendar.HijriToGregorian(start)), "=", calendar.FormatJalali(calendar.HijriToJalali(start))
println "last day: ", calendar.FormatGregorian(calendar.HijriToGregorian(last)), "=", calendar.FormatJalali(calendar.HijriToJalali(last))
println "Eid: ", calendar.FormatGregorian(calendar.HijriToGregorian(eid)), calendar.WeekdayNameEn(calendar.WeekdayHijri(eid))
println "in Arabic:", calendar.FormatHijriLongAr(eid)
endRemember that this is the arithmetic Hijri calendar. The official start of a month depends on sighting the moon and can be a day earlier or later, and differs between countries, so show these dates as an estimate.
One meeting, several cities
To schedule across time zones, turn the local date and time in one zone into an instant with ZonedToEpoch, then show that instant in each other zone. LoadZone reads the system's time zone database, so daylight saving is handled: London is on GMT on 25 March 2026 and on BST a week later, while New York had already moved to EDT.
import calendar
func show(label: str, epoch: i64, zone name: str):
mut z := calendar.LoadZone(zone name)
tz := calendar.TimeZoneAt(z, epoch)
d := calendar.WallClockGregorian(epoch, tz)
t := calendar.WallClockTime(epoch, tz)
println label, calendar.FormatGregorian(d), calendar.FormatClockTime(t), calendar.ZoneAbbrevAt(z, epoch)
calendar.FreeZone(z)
end
func main:
mut tehran := calendar.LoadZone("Asia/Tehran")
meeting day := calendar.GregorianDate { year = 2026, month = 3, day = 25 }
at := calendar.ClockTime { hour = 18, minute = 30 }
meeting := calendar.ZonedToEpoch(meeting day, at, tehran)
calendar.FreeZone(tehran)
show("Tehran: ", meeting, "Asia/Tehran")
show("London: ", meeting, "Europe/London")
show("New York:", meeting, "America/New_York")
show("Tokyo: ", meeting, "Asia/Tokyo")
show("one week later in London:", meeting + 7 * 86400, "Europe/London")
endLoadZone needs the zone files that Linux and macOS keep in /usr/share/zoneinfo; check ok on the result. For a zone with a fixed offset, such as Tehran since Iran stopped daylight saving, TZTehran() or FixedOffsetZone with WallClockJalali needs no files at all. Free a loaded zone with FreeZone when you are done with it.
Which function for which job
| Job | Use |
|---|---|
| Convert between calendars | GregorianToJalali, JalaliToGregorian, HijriToJalali and the rest |
| Today's date | TodayJalali, TodayGregorian, TodayHijri |
| A date from a stored instant | WallClockJalali(epoch, TZTehran()), or EpochToJalali for local time |
| Move a date | AddDaysJalali, AddMonthsJalali, AddYearsJalali |
| Compare or count days | CompareJalali, DaysBetweenJalali |
| Check user input | IsValidJalaliDate, IsValidGregorianDate, IsValidHijriDate |
| Show a date | FormatJalali, FormatJalaliLongFa, FormatHijriLongAr, FormatGregorianLongEn |
| Zones with daylight saving | LoadZone, ZonedToEpoch, TimeZoneAt |
Types
TimeZone
struct TimeZone| Name | Type | Description |
|---|---|---|
name | str = "UTC" | The zone name, such as Asia/Tehran. |
offset_minutes | int = 0 | The offset from UTC in minutes; 210 for Tehran. |
import calendar
func main:
t := 1710943509
tehran := calendar.TZTehran()
println tehran.name, tehran.offset_minutes
println calendar.FormatJalali(calendar.WallClockJalali(t, tehran)), calendar.FormatClockTime(calendar.WallClockTime(t, tehran))
println calendar.FormatGregorian(calendar.WallClockGregorian(t, calendar.TZTokyo())), calendar.FormatClockTime(calendar.WallClockTime(t, calendar.TZTokyo()))
println calendar.FormatHijri(calendar.WallClockHijri(t, calendar.TZMecca()))
each zone in [calendar.TZUTC(), calendar.TZKabul(), calendar.TZRiyadh(), calendar.TZDubai(), calendar.TZIstanbul(), calendar.TZLondon(), calendar.TZNewYork()]:
println zone.name, zone.offset_minutes, calendar.FormatClockTime(calendar.WallClockTime(t, zone))
end
g := calendar.GregorianDate { year = 2024, month = 3, day = 20 }
c := calendar.ClockTime { hour = 23, minute = 0, second = 0 }
println calendar.ZonedGregorianToEpoch(g, c, tehran)
println calendar.FormatGregorian(calendar.ConvertZonedGregorian(g, c, tehran, calendar.TZTokyo())), calendar.FormatClockTime(calendar.ConvertZonedTime(g, c, tehran, calendar.TZTokyo()))
fixed := calendar.FixedOffsetZone("UTC+05:30", 330)
println fixed.name, calendar.FormatClockTime(calendar.WallClockTime(t, fixed))
local := calendar.TZLocal(t)
println local.name, local.offset_minutes == calendar.LocalOffsetMinutes(t)
endGregorianDate
struct GregorianDate| Name | Type | Description |
|---|---|---|
year | int = 1970 | The year. |
month | int = 1 | The month, from 1. |
day | int = 1 | The day of the month, from 1. |
import calendar
func main:
g := calendar.GregorianDate { year = 2024, month = 3, day = 20 }
j := calendar.GregorianToJalali(g)
h := calendar.GregorianToHijri(g)
println calendar.FormatGregorian(g), calendar.FormatJalali(j), calendar.FormatHijri(h)
println calendar.FormatJalaliLongFa(j)
println calendar.FormatHijriLongFa(h)
println calendar.FormatHijriLongAr(h)
println calendar.FormatGregorianLongEn(g)
println calendar.FormatGregorian(calendar.JalaliToGregorian(calendar.JalaliDate { year = 1403, month = 1, day = 1 }))
println calendar.FormatGregorian(calendar.HijriToGregorian(calendar.HijriDate { year = 1445, month = 9, day = 1 }))
println calendar.FormatHijri(calendar.JalaliToHijri(j)), calendar.FormatJalali(calendar.HijriToJalali(h))
d := calendar.GregorianToJDN(g)
println d, calendar.JalaliToJDN(j), calendar.HijriToJDN(h)
println calendar.FormatGregorian(calendar.JDNToGregorian(d + 1)), calendar.FormatJalali(calendar.JDNToJalali(d + 1)), calendar.FormatHijri(calendar.JDNToHijri(d + 1))
endJalaliDate
struct JalaliDate| Name | Type | Description |
|---|---|---|
year | int = 1 | The year. |
month | int = 1 | The month, from 1 (Farvardin). |
day | int = 1 | The day of the month, from 1. |
The example for this item is shown with the ones above: calendar-Convert.salam
HijriDate
struct HijriDate| Name | Type | Description |
|---|---|---|
year | int = 1 | The year. |
month | int = 1 | The month, from 1 (Muharram). |
day | int = 1 | The day of the month, from 1. |
The example for this item is shown with the ones above: calendar-Convert.salam
ClockTime
struct ClockTime| Name | Type | Description |
|---|---|---|
hour | int = 0 | The hour, 0 to 23. |
minute | int = 0 | The minute. |
second | int = 0 | The second. |
import calendar
import time
func main:
t := 1710943509
zone := calendar.TZLocal(t)
g := calendar.EpochToGregorian(t)
println calendar.CompareGregorian(g, calendar.WallClockGregorian(t, zone)) == 0
println calendar.CompareJalali(calendar.EpochToJalali(t), calendar.WallClockJalali(t, zone)) == 0
println calendar.CompareHijri(calendar.EpochToHijri(t), calendar.WallClockHijri(t, zone)) == 0
println calendar.FormatClockTime(calendar.EpochToClockTime(t)) == calendar.FormatClockTime(calendar.WallClockTime(t, zone))
j := calendar.JalaliDate { year = 1403, month = 1, day = 1 }
println calendar.JalaliToUnixUTC(j, 14, 5, 9) == t
println calendar.GregorianToUnixUTC(calendar.GregorianDate { year = 2024, month = 3, day = 20 }, 14, 5, 9)
println calendar.HijriToUnixUTC(calendar.HijriDate { year = 1445, month = 9, day = 10 }, 0, 0, 0)
println calendar.CompareGregorian(calendar.TodayGregorian(), calendar.EpochToGregorian(time.Now())) >= 0, calendar.TodayGregorian().year >= 2024, calendar.TodayJalali().year >= 1403, calendar.TodayHijri().year >= 1445
c := calendar.NowClockTime()
println c.hour < 24, c.minute < 60, c.second < 61
endZone
struct Zone| Name | Type | Description |
|---|---|---|
name | str = "UTC" | The zone name. |
ok | bool = false | Whether the zone loaded. |
type_offset | Vector | The offset of each time type, in seconds. |
type_isdst | Vector | Whether each type is daylight saving. |
type_abbrev | Vector | The abbreviation of each type, such as EST. |
times | Vector | The instants at which the offset changes. |
type_at | Vector | The time type in force after each change. |
base_type | int = 0 | The type in force before the first change. |
rule | PosixTZ | The POSIX rule for the years after the last recorded change. |
import calendar
func main:
mut z := calendar.LoadZone("America/New_York")
println z.name, z.ok
winter := 1704067200
summer := 1719792000
println calendar.ZoneOffsetMinutes(z, winter), calendar.ZoneOffsetMinutes(z, summer), calendar.ZoneOffsetSeconds(z, summer)
println calendar.ZoneIsDST(z, winter), calendar.ZoneIsDST(z, summer)
println calendar.ZoneAbbrevAt(z, winter), calendar.ZoneAbbrevAt(z, summer)
tz := calendar.TimeZoneAt(z, summer)
println tz.name, tz.offset_minutes
println calendar.ZoneAt("Asia/Tehran", winter).offset_minutes
e := calendar.ZonedToEpoch(calendar.GregorianDate { year = 2024, month = 6, day = 30 }, calendar.ClockTime { hour = 20 }, z)
println e == summer
calendar.FreeZone(z)
println calendar.LoadZone("Mars/Olympus").ok
mut l := calendar.LocalZone()
println l.ok or not l.ok
calendar.FreeZone(l)
endFunctions
FixedOffsetZone
func FixedOffsetZone(name: str, offsetMinutes: int): TimeZoneThe example for this item is shown with the ones above: calendar-TimeZone.salam
TZUTC
func TZUTC(): TimeZoneThe example for this item is shown with the ones above: calendar-TimeZone.salam
TZTehran
func TZTehran(): TimeZoneThe example for this item is shown with the ones above: calendar-TimeZone.salam
TZKabul
func TZKabul(): TimeZoneThe example for this item is shown with the ones above: calendar-TimeZone.salam
TZRiyadh
func TZRiyadh(): TimeZoneThe example for this item is shown with the ones above: calendar-TimeZone.salam
TZMecca
func TZMecca(): TimeZoneThe example for this item is shown with the ones above: calendar-TimeZone.salam
TZDubai
func TZDubai(): TimeZoneThe example for this item is shown with the ones above: calendar-TimeZone.salam
TZIstanbul
func TZIstanbul(): TimeZoneThe example for this item is shown with the ones above: calendar-TimeZone.salam
TZLondon
func TZLondon(): TimeZoneLoadZone for that.The example for this item is shown with the ones above: calendar-TimeZone.salam
TZNewYork
func TZNewYork(): TimeZoneLoadZone for that.The example for this item is shown with the ones above: calendar-TimeZone.salam
TZTokyo
func TZTokyo(): TimeZoneThe example for this item is shown with the ones above: calendar-TimeZone.salam
LocalOffsetMinutes
func LocalOffsetMinutes(epoch: i64): intThe example for this item is shown with the ones above: calendar-TimeZone.salam
TZLocal
func TZLocal(epoch: i64): TimeZoneLocal carrying the local offset at that instant.The example for this item is shown with the ones above: calendar-TimeZone.salam
WallClockGregorian
func WallClockGregorian(epoch: i64, tz: TimeZone): GregorianDateThe example for this item is shown with the ones above: calendar-TimeZone.salam
WallClockJalali
func WallClockJalali(epoch: i64, tz: TimeZone): JalaliDateThe example for this item is shown with the ones above: calendar-TimeZone.salam
WallClockHijri
func WallClockHijri(epoch: i64, tz: TimeZone): HijriDateThe example for this item is shown with the ones above: calendar-TimeZone.salam
WallClockTime
func WallClockTime(epoch: i64, tz: TimeZone): ClockTimeThe example for this item is shown with the ones above: calendar-TimeZone.salam
ZonedGregorianToEpoch
func ZonedGregorianToEpoch(d: GregorianDate, t: ClockTime, tz: TimeZone): i64The example for this item is shown with the ones above: calendar-TimeZone.salam
ConvertZonedGregorian
func ConvertZonedGregorian(d: GregorianDate, t: ClockTime, from: TimeZone, toTz: TimeZone): GregorianDateThe example for this item is shown with the ones above: calendar-TimeZone.salam
ConvertZonedTime
func ConvertZonedTime(d: GregorianDate, t: ClockTime, from: TimeZone, toTz: TimeZone): ClockTimeThe example for this item is shown with the ones above: calendar-TimeZone.salam
GregorianToJalali
func GregorianToJalali(d: GregorianDate): JalaliDateThe example for this item is shown with the ones above: calendar-Convert.salam
JalaliToGregorian
func JalaliToGregorian(d: JalaliDate): GregorianDateThe example for this item is shown with the ones above: calendar-Convert.salam
GregorianToHijri
func GregorianToHijri(d: GregorianDate): HijriDateThe example for this item is shown with the ones above: calendar-Convert.salam
HijriToGregorian
func HijriToGregorian(d: HijriDate): GregorianDateThe example for this item is shown with the ones above: calendar-Convert.salam
JalaliToHijri
func JalaliToHijri(d: JalaliDate): HijriDateThe example for this item is shown with the ones above: calendar-Convert.salam
HijriToJalali
func HijriToJalali(d: HijriDate): JalaliDateThe example for this item is shown with the ones above: calendar-Convert.salam
EpochToGregorian
func EpochToGregorian(epoch: i64): GregorianDateThe example for this item is shown with the ones above: calendar-Epoch.salam
EpochToJalali
func EpochToJalali(epoch: i64): JalaliDateThe example for this item is shown with the ones above: calendar-Epoch.salam
EpochToHijri
func EpochToHijri(epoch: i64): HijriDateThe example for this item is shown with the ones above: calendar-Epoch.salam
EpochToClockTime
func EpochToClockTime(epoch: i64): ClockTimeThe example for this item is shown with the ones above: calendar-Epoch.salam
TodayGregorian
func TodayGregorian(): GregorianDateThe example for this item is shown with the ones above: calendar-Epoch.salam
TodayJalali
func TodayJalali(): JalaliDateThe example for this item is shown with the ones above: calendar-Epoch.salam
TodayHijri
func TodayHijri(): HijriDateThe example for this item is shown with the ones above: calendar-Epoch.salam
NowClockTime
func NowClockTime(): ClockTimeThe example for this item is shown with the ones above: calendar-Epoch.salam
GregorianToUnixUTC
func GregorianToUnixUTC(d: GregorianDate, hour: int, minute: int, second: int): i64The example for this item is shown with the ones above: calendar-Epoch.salam
JalaliToUnixUTC
func JalaliToUnixUTC(d: JalaliDate, hour: int, minute: int, second: int): i64The example for this item is shown with the ones above: calendar-Epoch.salam
HijriToUnixUTC
func HijriToUnixUTC(d: HijriDate, hour: int, minute: int, second: int): i64The example for this item is shown with the ones above: calendar-Epoch.salam
FormatGregorian
func FormatGregorian(d: GregorianDate): str2024-03-20.The example for this item is shown with the ones above: calendar-Convert.salam
FormatJalali
func FormatJalali(d: JalaliDate): str1403-01-01.The example for this item is shown with the ones above: calendar-Convert.salam
FormatHijri
func FormatHijri(d: HijriDate): str1445-09-10.The example for this item is shown with the ones above: calendar-Convert.salam
FormatClockTime
func FormatClockTime(t: ClockTime): str14:05:09.The example for this item is shown with the ones above: calendar-Epoch.salam
FormatJalaliLongFa
func FormatJalaliLongFa(d: JalaliDate): str1 فروردین 1403.The example for this item is shown with the ones above: calendar-Convert.salam
FormatHijriLongAr
func FormatHijriLongAr(d: HijriDate): strThe example for this item is shown with the ones above: calendar-Convert.salam
FormatHijriLongFa
func FormatHijriLongFa(d: HijriDate): str10 رمضان 1445.The example for this item is shown with the ones above: calendar-Convert.salam
FormatGregorianLongEn
func FormatGregorianLongEn(d: GregorianDate): strMarch 20, 2024.The example for this item is shown with the ones above: calendar-Convert.salam
JalaliToJDN
func JalaliToJDN(d: JalaliDate): i64The example for this item is shown with the ones above: calendar-Convert.salam
JDNToJalali
func JDNToJalali(jdn: i64): JalaliDateThe example for this item is shown with the ones above: calendar-Convert.salam
IsLeapJalali
func IsLeapJalali(year: int): boolimport calendar
func main:
println calendar.IsLeapJalali(1403), calendar.IsLeapJalali(1404), calendar.DaysInJalaliYear(1403)
println calendar.DaysInJalaliMonth(1403, 1), calendar.DaysInJalaliMonth(1403, 7), calendar.DaysInJalaliMonth(1403, 12), calendar.DaysInJalaliMonth(1404, 12)
println calendar.IsValidJalaliDate(1404, 12, 30), calendar.IsValidJalaliDate(1403, 12, 30)
println calendar.JalaliMonthNameFa(1), calendar.JalaliMonthNameEn(1), calendar.JalaliMonthNameFa(12)
j := calendar.JalaliDate { year = 1403, month = 6, day = 31 }
d := calendar.JalaliToJDN(j)
println calendar.JalaliWeekday(d), calendar.JalaliWeekdayNameFa(calendar.JalaliWeekday(d))
println calendar.WeekdayJalali(j), calendar.WeekdayNameFa(calendar.WeekdayJalali(j))
println calendar.FormatJalali(calendar.AddDaysJalali(j, 1)), calendar.FormatJalali(calendar.AddWeeksJalali(j, 2))
println calendar.FormatJalali(calendar.AddMonthsJalali(j, 1)), calendar.FormatJalali(calendar.AddYearsJalali(j, -1))
println calendar.FormatJalali(calendar.StartOfMonthJalali(j)), calendar.FormatJalali(calendar.EndOfMonthJalali(calendar.AddMonthsJalali(j, 6)))
nowruz := calendar.JalaliDate { year = 1404, month = 1, day = 1 }
println calendar.DaysBetweenJalali(j, nowruz), calendar.CompareJalali(j, nowruz), calendar.CompareJalali(nowruz, nowruz)
endDaysInJalaliMonth
func DaysInJalaliMonth(year: int, month: int): intThe example for this item is shown with the ones above: calendar-Jalali.salam
IsValidJalaliDate
func IsValidJalaliDate(year: int, month: int, day: int): boolThe example for this item is shown with the ones above: calendar-Jalali.salam
JalaliMonthNameFa
func JalaliMonthNameFa(month: int): strThe example for this item is shown with the ones above: calendar-Jalali.salam
JalaliMonthNameEn
func JalaliMonthNameEn(month: int): strThe example for this item is shown with the ones above: calendar-Jalali.salam
JalaliWeekday
func JalaliWeekday(jdn: i64): intThe example for this item is shown with the ones above: calendar-Jalali.salam
JalaliWeekdayNameFa
func JalaliWeekdayNameFa(weekday: int): strJalaliWeekday number, where zero is Saturday.The example for this item is shown with the ones above: calendar-Jalali.salam
CompareJalali
func CompareJalali(a: JalaliDate, b: JalaliDate): intThe example for this item is shown with the ones above: calendar-Jalali.salam
GregorianToJDN
func GregorianToJDN(d: GregorianDate): i64The example for this item is shown with the ones above: calendar-Convert.salam
JDNToGregorian
func JDNToGregorian(jdn: i64): GregorianDateThe example for this item is shown with the ones above: calendar-Convert.salam
IsLeapGregorian
func IsLeapGregorian(year: int): boolimport calendar
func main:
println calendar.IsLeapGregorian(2024), calendar.IsLeapGregorian(1900), calendar.DaysInGregorianYear(2024)
println calendar.DaysInGregorianMonth(2024, 2), calendar.DaysInGregorianMonth(2023, 2), calendar.IsValidGregorianDate(2023, 2, 29)
g := calendar.GregorianDate { year = 2024, month = 1, day = 31 }
w := calendar.WeekdayGregorian(g)
println w, calendar.WeekdayNameEn(w), calendar.WeekdayNameFa(w), calendar.WeekdayNameAr(w)
println calendar.Weekday(calendar.GregorianToJDN(g)), calendar.GregorianMonthNameEn(1)
println calendar.FormatGregorian(calendar.AddMonthsGregorian(g, 1)), calendar.FormatGregorian(calendar.AddYearsGregorian(calendar.GregorianDate { year = 2024, month = 2, day = 29 }, 1))
println calendar.FormatGregorian(calendar.AddDaysGregorian(g, 30)), calendar.FormatGregorian(calendar.AddWeeksGregorian(g, -1))
println calendar.FormatGregorian(calendar.StartOfMonthGregorian(g)), calendar.FormatGregorian(calendar.EndOfMonthGregorian(calendar.AddMonthsGregorian(g, 1)))
println calendar.FormatGregorian(calendar.NextWeekdayOnOrAfter(g, 5))
year_end := calendar.GregorianDate { year = 2024, month = 12, day = 31 }
println calendar.DaysBetweenGregorian(g, year_end), calendar.CompareGregorian(year_end, g)
endDaysInGregorianMonth
func DaysInGregorianMonth(year: int, month: int): intThe example for this item is shown with the ones above: calendar-Gregorian.salam
IsValidGregorianDate
func IsValidGregorianDate(year: int, month: int, day: int): boolThe example for this item is shown with the ones above: calendar-Gregorian.salam
Weekday
func Weekday(jdn: i64): intThe example for this item is shown with the ones above: calendar-Gregorian.salam
WeekdayNameEn
func WeekdayNameEn(weekday: int): strWeekday number.The example for this item is shown with the ones above: calendar-Gregorian.salam
WeekdayNameFa
func WeekdayNameFa(weekday: int): strWeekday number, where zero is Sunday.The example for this item is shown with the ones above: calendar-Gregorian.salam
WeekdayNameAr
func WeekdayNameAr(weekday: int): strWeekday number.The example for this item is shown with the ones above: calendar-Gregorian.salam
GregorianMonthNameEn
func GregorianMonthNameEn(month: int): strThe example for this item is shown with the ones above: calendar-Gregorian.salam
CompareGregorian
func CompareGregorian(a: GregorianDate, b: GregorianDate): intThe example for this item is shown with the ones above: calendar-Gregorian.salam
AddDaysGregorian
func AddDaysGregorian(d: GregorianDate, n: int): GregorianDaten days to a Gregorian date; a negative n goes back.The example for this item is shown with the ones above: calendar-Gregorian.salam
AddWeeksGregorian
func AddWeeksGregorian(d: GregorianDate, n: int): GregorianDaten weeks to a Gregorian date.The example for this item is shown with the ones above: calendar-Gregorian.salam
AddMonthsGregorian
func AddMonthsGregorian(d: GregorianDate, n: int): GregorianDaten months to a Gregorian date; when the day does not exist in the target month, the last day of that month is used.The example for this item is shown with the ones above: calendar-Gregorian.salam
AddYearsGregorian
func AddYearsGregorian(d: GregorianDate, n: int): GregorianDaten years to a Gregorian date; a leap day missing from the target year moves to the end of the month.The example for this item is shown with the ones above: calendar-Gregorian.salam
DaysBetweenGregorian
func DaysBetweenGregorian(from: GregorianDate, toDate: GregorianDate): i64from to toDate; negative when the second is earlier.The example for this item is shown with the ones above: calendar-Gregorian.salam
StartOfMonthGregorian
func StartOfMonthGregorian(d: GregorianDate): GregorianDateThe example for this item is shown with the ones above: calendar-Gregorian.salam
EndOfMonthGregorian
func EndOfMonthGregorian(d: GregorianDate): GregorianDateThe example for this item is shown with the ones above: calendar-Gregorian.salam
DaysInGregorianYear
func DaysInGregorianYear(year: int): intThe example for this item is shown with the ones above: calendar-Gregorian.salam
AddDaysJalali
func AddDaysJalali(d: JalaliDate, n: int): JalaliDaten days to a Jalali date; a negative n goes back.The example for this item is shown with the ones above: calendar-Jalali.salam
AddWeeksJalali
func AddWeeksJalali(d: JalaliDate, n: int): JalaliDaten weeks to a Jalali date.The example for this item is shown with the ones above: calendar-Jalali.salam
AddMonthsJalali
func AddMonthsJalali(d: JalaliDate, n: int): JalaliDaten months to a Jalali date; when the day does not exist in the target month, the last day of that month is used.The example for this item is shown with the ones above: calendar-Jalali.salam
AddYearsJalali
func AddYearsJalali(d: JalaliDate, n: int): JalaliDaten years to a Jalali date; a leap day missing from the target year moves to the end of the month.The example for this item is shown with the ones above: calendar-Jalali.salam
DaysBetweenJalali
func DaysBetweenJalali(from: JalaliDate, toDate: JalaliDate): i64from to toDate; negative when the second is earlier.The example for this item is shown with the ones above: calendar-Jalali.salam
StartOfMonthJalali
func StartOfMonthJalali(d: JalaliDate): JalaliDateThe example for this item is shown with the ones above: calendar-Jalali.salam
EndOfMonthJalali
func EndOfMonthJalali(d: JalaliDate): JalaliDateThe example for this item is shown with the ones above: calendar-Jalali.salam
DaysInJalaliYear
func DaysInJalaliYear(year: int): intThe example for this item is shown with the ones above: calendar-Jalali.salam
AddDaysHijri
func AddDaysHijri(d: HijriDate, n: int): HijriDaten days to a Hijri date; a negative n goes back.import calendar
func main:
h := calendar.HijriDate { year = 1445, month = 9, day = 29 }
println calendar.IsLeapHijri(1445), calendar.IsLeapHijri(1446)
println calendar.DaysInHijriMonth(1445, 9), calendar.DaysInHijriMonth(1445, 12), calendar.DaysInHijriMonth(1446, 12)
println calendar.IsValidHijriDate(1445, 9, 30), calendar.IsValidHijriDate(1445, 10, 30)
println calendar.HijriMonthNameFa(9), calendar.HijriMonthNameAr(9), calendar.HijriMonthNameEn(9)
println calendar.FormatHijri(calendar.AddDaysHijri(h, 1)), calendar.FormatHijri(calendar.AddWeeksHijri(h, 1))
println calendar.FormatHijri(calendar.AddMonthsHijri(h, 3)), calendar.FormatHijri(calendar.AddYearsHijri(h, 1))
println calendar.FormatHijri(calendar.StartOfMonthHijri(h)), calendar.FormatHijri(calendar.EndOfMonthHijri(h))
muharram := calendar.HijriDate { year = 1446, month = 1, day = 1 }
println calendar.DaysBetweenHijri(h, muharram), calendar.CompareHijri(h, muharram)
println calendar.WeekdayNameFa(calendar.WeekdayHijri(h))
endAddWeeksHijri
func AddWeeksHijri(d: HijriDate, n: int): HijriDaten weeks to a Hijri date.The example for this item is shown with the ones above: calendar-Hijri.salam
AddMonthsHijri
func AddMonthsHijri(d: HijriDate, n: int): HijriDaten months to a Hijri date; when the day does not exist in the target month, the last day of that month is used.The example for this item is shown with the ones above: calendar-Hijri.salam
AddYearsHijri
func AddYearsHijri(d: HijriDate, n: int): HijriDaten years to a Hijri date; a leap day missing from the target year moves to the end of the month.The example for this item is shown with the ones above: calendar-Hijri.salam
DaysBetweenHijri
func DaysBetweenHijri(from: HijriDate, toDate: HijriDate): i64from to toDate; negative when the second is earlier.The example for this item is shown with the ones above: calendar-Hijri.salam
StartOfMonthHijri
func StartOfMonthHijri(d: HijriDate): HijriDateThe example for this item is shown with the ones above: calendar-Hijri.salam
EndOfMonthHijri
func EndOfMonthHijri(d: HijriDate): HijriDateThe example for this item is shown with the ones above: calendar-Hijri.salam
WeekdayGregorian
func WeekdayGregorian(d: GregorianDate): intWeekday does, with zero Sunday.The example for this item is shown with the ones above: calendar-Gregorian.salam
WeekdayJalali
func WeekdayJalali(d: JalaliDate): intWeekday does, with zero Sunday.The example for this item is shown with the ones above: calendar-Jalali.salam
WeekdayHijri
func WeekdayHijri(d: HijriDate): intWeekday does, with zero Sunday.The example for this item is shown with the ones above: calendar-Hijri.salam
NextWeekdayOnOrAfter
func NextWeekdayOnOrAfter(d: GregorianDate, weekday: int): GregorianDateweekday; the date itself counts.The example for this item is shown with the ones above: calendar-Gregorian.salam
HijriToJDN
func HijriToJDN(d: HijriDate): i64The example for this item is shown with the ones above: calendar-Convert.salam
JDNToHijri
func JDNToHijri(jdn: i64): HijriDateThe example for this item is shown with the ones above: calendar-Convert.salam
IsLeapHijri
func IsLeapHijri(year: int): boolThe example for this item is shown with the ones above: calendar-Hijri.salam
DaysInHijriMonth
func DaysInHijriMonth(year: int, month: int): intThe example for this item is shown with the ones above: calendar-Hijri.salam
IsValidHijriDate
func IsValidHijriDate(year: int, month: int, day: int): boolThe example for this item is shown with the ones above: calendar-Hijri.salam
HijriMonthNameAr
func HijriMonthNameAr(month: int): strThe example for this item is shown with the ones above: calendar-Hijri.salam
HijriMonthNameFa
func HijriMonthNameFa(month: int): strThe example for this item is shown with the ones above: calendar-Hijri.salam
HijriMonthNameEn
func HijriMonthNameEn(month: int): strThe example for this item is shown with the ones above: calendar-Hijri.salam
CompareHijri
func CompareHijri(a: HijriDate, b: HijriDate): intThe example for this item is shown with the ones above: calendar-Hijri.salam
LoadZone
func LoadZone(name: str): ZoneAmerica/New_York, from the system tzdata files. On Windows those files are usually absent and ok stays false.The example for this item is shown with the ones above: calendar-Zone.salam
LocalZone
func LocalZone(): ZoneTZ variable or /etc/localtime.The example for this item is shown with the ones above: calendar-Zone.salam
FreeZone
func FreeZone(z &: Zone)The example for this item is shown with the ones above: calendar-Zone.salam
ZoneOffsetSeconds
func ZoneOffsetSeconds(z: Zone, epoch: i64): intThe example for this item is shown with the ones above: calendar-Zone.salam
ZoneOffsetMinutes
func ZoneOffsetMinutes(z: Zone, epoch: i64): intThe example for this item is shown with the ones above: calendar-Zone.salam
ZoneIsDST
func ZoneIsDST(z: Zone, epoch: i64): boolThe example for this item is shown with the ones above: calendar-Zone.salam
ZoneAbbrevAt
func ZoneAbbrevAt(z: Zone, epoch: i64): strThe example for this item is shown with the ones above: calendar-Zone.salam
TimeZoneAt
func TimeZoneAt(z: Zone, epoch: i64): TimeZoneTimeZone.The example for this item is shown with the ones above: calendar-Zone.salam
ZoneAt
func ZoneAt(name: str, epoch: i64): TimeZoneTimeZone at that instant.The example for this item is shown with the ones above: calendar-Zone.salam
ZonedToEpoch
func ZonedToEpoch(d: GregorianDate, t: ClockTime, z: Zone): i64The example for this item is shown with the ones above: calendar-Zone.salam