jalaali

package module
v0.0.0-...-80525e8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 1, 2021 License: MIT Imports: 4 Imported by: 0

README

Jalaali

Golang implementation of Jalaali JS and Jalaali Python implementations of Jalaali (Jalali, Persian, Khayyami, Khorshidi, Shamsi) convertion to Gregorian calendar system and vice-versa.

This implementation is based on an algorithm by Kazimierz M. Borkowski. Borkowski claims that this algorithm works correctly for 3000 years!

Documentation on API is available here at Go official documentation site.

Installation

Use go get on this repository:

$ go get -u github.com/jalaali/go-jalaali

Usage

  • Wrapper around Golang time package:
    • Call Jalaali.Now() to get instance of current time. You can use all function from time package with this wrapper.
    • Call Jalaali.From(t) and pass a time instance to it. The you can work with it the same way you work with time package.
  • Jalaali Formatting:
    • Call JFormat method of a Jalaali instance and pass it the same formatting options that is used for Golang time package. The output will be in Jalaali date and use persian digits and words.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsLeapYear

func IsLeapYear(jy int) (bool, error)

IsLeapYear take a Jalaali year and return true if it is leap year. Error is not nil if Jalaali year passed to function is not valid.

func IsValidDate

func IsValidDate(jy, jm, jd int) bool

IsValidDate take Jalaali date and return true if it is valid, otherwise false.

func MonthLength

func MonthLength(jy, jm int) (int, error)

MonthLength take Jalaali date and return length of that specific month. Error is not nil if Jalaali year passed to function is not valid.

func ToGregorian

func ToGregorian(jalaaliYear int, jalaaliMonth Month, jalaaliDay int) (int, time.Month, int, error)

ToGregorian converts Jalaali to Gregorian date. Error is not nil if Jalaali year passed to function is not valid.

Types

type ErrorInvalidYear

type ErrorInvalidYear struct {
	// contains filtered or unexported fields
}

ErrorInvalidYear is happening when year passed is is in proper range.

func (*ErrorInvalidYear) Error

func (e *ErrorInvalidYear) Error() string

type ErrorNilReference

type ErrorNilReference struct{}

ErrorNilReference is happening when a pointer is nil.

func (*ErrorNilReference) Error

func (e *ErrorNilReference) Error() string

type Jalaali

type Jalaali struct {
	time.Time
}

A simple wrapper around Golang default time package. You have all the functionality of default time package and functionalities needed for Jalaali calender.

func From

func From(t time.Time) Jalaali

From initialize new instance of Jalaali from a time instance.

func Now

func Now() Jalaali

Now with return Jalaali instance of current time.

func (Jalaali) JFormat

func (j Jalaali) JFormat(layout string) (string, error)

JFormat gets default Golang layout string and parse put Jalaali calender information into the final string and return it.

type Month

type Month int

A Month specifies a month of the year (Farvardin = 1, ...).

const (
	Farvardin Month = 1 + iota
	Ordibehesht
	Khordad
	Tir
	Mordad
	Shahrivar
	Mehr
	Aban
	Azar
	Dey
	Bahman
	Esfand
)

func ToJalaali

func ToJalaali(gregorianYear int, gregorianMonth time.Month, gregorianDay int) (int, Month, int, error)

ToJalaali converts Gregorian to Jalaali date. Error is not nil if Jalaali year passed to function is not valid.

func (Month) String

func (m Month) String() string

type Weekday

type Weekday int

A Weekday specifies a day of the week (Shanbe = 0, ...).

const (
	Shanbe Weekday = iota
	IekShanbe
	DoShanbe
	SeShanbe
	ChaharShanbe
	PanjShanbe
	Jome
)

func (Weekday) String

func (d Weekday) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL