The Jalali calendar is a solar calendar that was used in Persia. Variants of this calendar are still used today in Iran, Afghanistan and some other countries. You can find more information on Wikipedia or check out the Calendar Converter.
go get github.com/erfanmomeniii/jalaliNext, include it in your application:
import "github.com/erfanmomeniii/jalali"The following example illustrates how to use this package:
package main
import (
"github.com/erfanmomeniii/jalali"
"time"
)
func main() {
// Return datetime of today
jalali.Now() //1402-04-29 14:12:00
// Return datetime of yesterday
jalali.Yesterday() // 1402-04-28 14:12:59
// Return datetime of tomorrow
jalali.Tomorrow() // 1402-04-30 14:13:47
// Convert gregorian datetime to jalali
jalali.ConvertGregorianToJalali(time.Date(
2023, 7, 20, 10, 45, 25, 0, time.UTC)) // 1402-04-29 14:15:25
// Convert jalali datetime to gregorian
jalali.ConvertJalaliToGregorian(jalali.New(
1402, 4, 29, 14, 15, 25)) // 2023-07-20 10:45:25 +0000 UTC
// Create instance of jalali datetime
j := jalali.New(1402, 4, 29, 14, 15, 25)
// Set locale for localizing the output
j.SetLocale(jalali.PersianLanguage)
j.String() // ۱۴۰۲-۰۴-۲۹ ۱۴:۱۵:۲۵
// Return the localized string representation of the day of the week and month of the year for j
j.MonthToString() // تیر
j.WeekToString() // پنجشنبه
// Return the day of the week, month and year for the j
j.DayOfWeek() // 6
j.DayOfMonth() // 29
j.DayOfYear() // 122
// Return yesterday and tomorrow of j
j.Yesterday() // ۱۴۰۲-۰۴-۲۸ ۱۴:۱۵:۲۵
j.Tomorrow() // ۱۴۰۲-۰۴-۳۰ ۱۴:۱۵:۲۵
j.SetLocale(jalali.EnglishLanguage)
// Return the datetime corresponding to adding the given number of years, months, and days to j
j.AddDate(0, 0, 1) // 1402-04-30 14:15:25
// Return year, month, day, hour, minute and second of j
j.Year() // 1402
j.Month() // 4
j.Day() // 29
j.Hour() // 14
j.Minute() // 15
j.Second() // 25
}You can find the complete documentation here.
jalaliDateTime is an instantiation of jalali Date and Time.
func New(year int, month int, day int, hour int, minute int, second int) *jalaliDateTimeNew creates a new instance of a jalaliDateTime.
func (j *jalaliDateTime) SetLocale(lang Lang)SetLocale sets the locale of the jalaliDateTime.
func Now() *jalaliDateTimeNow returns the current jalaliDateTime.
func ConvertGregorianToJalali(t time.Time) *jalaliDateTimeConvertGregorianToJalali returns converted date and time on t from gregorian to jalali.
func ConvertJalaliToGregorian(j *jalaliDateTime) time.TimeConvertJalaliToGregorian returns converted date and time on j from jalali to gregorian.
func ToGregorian(gregorianSeconds int64) time.TimeToGregorian returns time.Time obtained from given seconds.
func ToJalali(jalaliSeconds int64) *jalaliDateTimeToJalali returns jalaliDateTime obtained from given seconds.
func IsLeapYear(year int) intIsLeapYear determines the year is leap or not in jalali date.
func Yesterday() *jalaliDateTimeYesterday returns datetime of yesterday.
func Tomorrow() *jalaliDateTimeTomorrow returns datetime of tomorrow.
func (j *jalaliDateTime) Add(t jalaliDateTime) *jalaliDateTimeAdd returns the time j+t.
func (j *jalaliDateTime) AddDate(year int, month int, day int) *jalaliDateTimeAddDate returns the time corresponding to adding the given number of years, months, and days to j
func (j *jalaliDateTime) Yesterday() *jalaliDateTimeYesterday returns datetime of yesterday on a given day.
func (j *jalaliDateTime) Tomorrow() *jalaliDateTimeTomorrow returns datetime of tomorrow on a given day.
func (j *jalaliDateTime) Year() intYear returns the year in which j occurs.
func (j *jalaliDateTime) Month() intMonth returns the month of the year specified by j.
func (j *jalaliDateTime) Day() intDay returns the day of the month specified by j.
func (j *jalaliDateTime) Hour() intHour returns the hour within the day specified by j, in the range [0, 23].
func (j *jalaliDateTime) Minute() intMinute returns the minute offset within the hour specified by j, in the range [0, 59].
func (j *jalaliDateTime) Second() intSecond returns the second offset within the minute specified by j, in the range [0, 59].
func (j *jalaliDateTime) TimeStamp() int64TimeStamp returns the timestamp of the jalaliDateTime.
func (j *jalaliDateTime) DayOfYear() intDayOfYear returns the day of the year for the jalaliDateTime.
func (j *jalaliDateTime) DayOfMonth() intDayOfMonth returns the day the month for the jalaliDateTime.
func (j *jalaliDateTime) DayOfWeek() intDayOfWeek returns the day the week for the jalaliDateTime.
func (j *jalaliDateTime) WeekToString() stringWeekToString returns the localized string representation of the day of the week for the jalaliDateTime.
func (j *jalaliDateTime) MonthToString() stringMonthToString returns the localized string representation of the month for the jalaliDateTime.
func (j *jalaliDateTime) Time() time.TimeTime returns the time.Time equivalent of the jalaliDateTime.
func (j *jalaliDateTime) String() stringString returns the string representation of the jalaliDateTime.
Pull requests are welcome. For changes, please open an issue first to discuss what you would like to change. Please make sure to update tests as appropriate.