Go Persian Calendar
![License](http://img.shields.io/:license-mit-blue.svg)
Go Persian Calendar v0.4.0 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
This assumes you're using go modules, and have set up your go.mod
file,
possibly using go mod init
.
import ptime github.com/yaa110/go-persian-calendar
- Building using
go build
will now automatically get go-persian-calendar
and
update your go.mod
Changelog
v0.4.0
- Change module import name
v0.3.1
v0.3
ptime.Iran
and ptime.Afghanistan
changed to ptime.Iran()
and ptime.Afghanistan()
, respectively.
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(ptime.Iran())
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, ptime.Iran())
pt.Format("yyyy/MM/dd E hh:mm:ss a")
Documentation
Use GoDoc documentation for more information about methods and functionality available for ptime.Time
, ptime.Month
, ptime.Weekday
and ptime.AmPm
.