Go Persian Calendar
Go Persian Calendar provides functionality for conversion among Persian (Solar Hijri) and Gregorian calendars. A Julian calendar is used as an interface for all conversions. The package name is ptime
and it is compatible with the package time. All months are available with both Iranian and Dari Persian names. This source code is licensed under MIT license that can be found in the LICENSE file.
Installation
go get github.com/yaa110/go-persian-calendar
Getting started
1- Import the package ptime
. Most of the time you need to import time
and fmt
packages, too.
import (
ptime "github.com/yaa110/go-persian-calendar"
"time"
"fmt"
)
2- Convert Gregorian calendar to Persian calendar.
var t time.Time = time.Date(2016, time.January, 1, 12, 1, 1, 0, ptime.Iran())
pt := ptime.New(t)
fmt.Println(pt.Date())
3- Convert Persian calendar to Gregorian calendar.
var pt ptime.Time = ptime.Date(1394, ptime.Mehr, 2, 12, 59, 59, 0, ptime.Iran())
t := pt.Time()
fmt.Println(t.Date())
4- Get the current time.
pt := ptime.Now()
fmt.Println(pt.Date())
fmt.Println(pt.Year(), pt.Month(), pt.Day())
fmt.Println(pt.Clock())
fmt.Println(pt.Hour(), pt.Minute(), pt.Second())
fmt.Println(pt.Unix())
fmt.Println(pt.Yesterday().Weekday())
fmt.Println(pt.Weekday())
fmt.Println(pt.Tomorrow().Weekday())
fmt.Println(pt.FirstWeekDay().Date())
fmt.Println(pt.LastWeekday().Date())
fmt.Println(pt.FirstMonthDay().Weekday())
fmt.Println(pt.LastMonthDay().Weekday())
fmt.Println(pt.FirstYearDay().Weekday())
fmt.Println(pt.LastYearDay().Weekday())
fmt.Println(pt.MonthWeek())
fmt.Println(pt.YearWeek())
fmt.Println(pt.RYearWeek())
5- Format the time.
pt := ptime.Unix(1454277270, 0)
fmt.Println(pt.Format("yyyy/MM/dd E hh:mm:ss a"))
6- Format the time using standard format.
pt := ptime.Date(1394, 7, 2, 14, 7, 8, 0, Iran())
fmt.Println(pt.TimeFormat("2 Jan 2006"))
Limitations
- The minimum value of Gregorian year is 1097, otherwise a zero instance of
ptime.Time
is returned.
Documentation
Please read the documentation for more information about methods and functionality available for ptime.Time
, ptime.Month
, ptime.Weekday
and ptime.AmPm
.