Skip to content

Feature-rich Go library for Jalali date conversion, formatting, and arithmetic.

License

amireshoon/gojalali

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gojalali

A rich Go library for converting and interacting with Jalali (Persian) calendar dates.
This package provides easy-to-use functions to convert between Gregorian and Jalali calendars, format Jalali dates, and perform date arithmetic in the Jalali calendar system.


Features

  • Convert Gregorian time.Time to Jalali year/month/day and vice versa
  • Create Jalali dates and convert them to time.Time
  • Format Jalali dates using customizable formats
  • Date arithmetic functions (add/remove days, weeks, months, years) in Jalali calendar
  • Retrieve Jalali weekday names and month names
  • Simple and idiomatic Go API

Installation

Use Go Modules to install the package:

go get github.com/amireshoon/gojalali/jalali

Quick Start

Basic Conversion (Gregorian to Jalali)

t := time.Date(2025, 5, 20, 0, 0, 0, 0, time.UTC)
y, m, d := jalali.ToJalali(t)
fmt.Printf("Jalali date: %d/%02d/%02d\n", y, m, d)

Or you can create date from Jalali calendar

jt := jalali.NewJalaliTime(1404, 2, 30)
fmt.Printf("Jalali Date: %d/%02d/%02d\n", jt.Year, jt.Month, jt.Day)

Then you can even convert it to Gregorian calendar

fmt.Println("Gregorian date:", jt.ToGregorian())

Also you can add days,weeks,months and years to your JalaliTime

jt.AddDays(1)
jt.AddWeeks(1)
jt.AddMonths(1)
jt.AddYears(1)

And you can format it however you want it

jalali.ToJalaliFormat(time.Now(), "yyyy/mm/dd")

Examples

See Examples directory for runnable example programs demonstrating various use cases.

Documentaion

Full API documentation is available at pkg.go.dev

License

This project is licensed under the MIT License

About

Feature-rich Go library for Jalali date conversion, formatting, and arithmetic.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages