Skip to content
Amir Iranmanesh edited this page Aug 11, 2026 · 3 revisions

Go Persian Calendar

ptime is a complete, dependency-free Persian (Solar Hijri / Jalali) calendar for Go, shaped like the standard time package.

go get github.com/amiranmanesh/go-persian-calendar
import ptime "github.com/amiranmanesh/go-persian-calendar"

pt := ptime.Now()
fmt.Println(pt.Format("yyyy/MM/dd E"))

Where to go next

Page What it covers
Getting Started Installing, converting in both directions, the shape of Time
Formatting Both layout languages, every pattern letter, the predefined layouts
Parsing Parse, locations, two digit years, error handling
Encoding JSON, text, and SQL Value/Scan
Calendar Helpers Leap years, weeks, first and last days, day parts
Public Holidays The holiday package, why lunar dates are estimates, keeping data current
Migration Moving from yaa110/go-persian-calendar
FAQ Time zones, leap year rules, thread safety, performance

The generated API reference for every exported identifier lives on pkg.go.dev. This wiki is for the parts that need more than a doc comment.

How the conversion works

Every conversion passes through the Julian Day Number, a continuous count of days that belongs to no calendar:

Persian date  ⟷  JDN  ⟷  Gregorian date

Going through a neutral representation costs one extra step and buys exactness across the 1582 Gregorian reform: dates before it are interpreted in the Julian calendar, dates on or after it in the Gregorian calendar, and the package picks the right formula for you.

Design notes

  • Time is a value. Methods with a value receiver return a new Time; nothing is mutated behind your back. Copy it freely.
  • Names track the standard library. If time has a method for the idea, ptime uses the same name, signature and semantics — Add, AddDate, Sub, Before, After, Equal, Compare, Truncate, Round, Unix, In.
  • No dependencies. Only the standard library, and no I/O beyond loading time zone data.

Clone this wiki locally