persian

package
v2.5.2 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2024 License: MIT Imports: 5 Imported by: 1

README

Persian(Jalaali) Calendar

English | 简体中文 | 日本語

Usage and example
Convert Gregorian calendar to Persian calendar
// Get persian year
carbon.Parse("2020-08-05 13:14:15").Persian().Year() // 1399
// Get persian month
carbon.Parse("2020-08-05 13:14:15").Persian().Month() // 5
// Get persian day
carbon.Parse("2020-08-05 13:14:15").Persian().Day() // 15
// Get persian hour
carbon.Parse("2020-08-05 13:14:15").Persian().Hour() // 13
// Get persian minute
carbon.Parse("2020-08-05 13:14:15").Persian().Minute() // 14
// Get persian second
carbon.Parse("2020-08-05 13:14:15").Persian().Second() // 15

// Get persian date and time string
carbon.Parse("2020-08-05 13:14:15").Persian().String() // 1399-05-15 13:14:15
fmt.Printf("%s", carbon.Parse("2020-08-05 13:14:15").Persian()) // 1399-05-15 13:14:15

// Get persian month as string
carbon.Parse("2020-08-05 13:14:15").Persian().ToMonthString() // Mordad
carbon.Parse("2020-08-05 13:14:15").Persian().ToMonthString("en") // Mordad
carbon.Parse("2020-08-05 13:14:15").Persian().ToMonthString("fa") // مرداد

// Get persian short month as string
carbon.Parse("2020-08-05 13:14:15").Persian().ToShortMonthString() // Mor
carbon.Parse("2020-08-05 13:14:15").Persian().ToShortMonthString("en") // Mor
carbon.Parse("2020-08-05 13:14:15").Persian().ToShortMonthString("fa") // مرد

// Get persian week as string
carbon.Parse("2020-08-05 13:14:15").Persian().ToWeekString() // Chaharshanbeh
carbon.Parse("2020-08-05 13:14:15").Persian().ToWeekString("en") // Chaharshanbeh
carbon.Parse("2020-08-05 13:14:15").Persian().ToWeekString("fa") // چهارشنبه

// Get persian short week as string
carbon.Parse("2020-08-05 13:14:15").Persian().ToShortWeekString() // Cha
carbon.Parse("2020-08-05 13:14:15").Persian().ToShortWeekString("en") // Cha
carbon.Parse("2020-08-05 13:14:15").Persian().ToShortWeekString("fa") // د

Convert Persian calendar to Gregorian calendar
carbon.CreateFromPersian(1, 1, 1, 0, 0, 0).ToDateTimeString() // 2016-03-20 00:00:00
carbon.CreateFromPersian(622, 1, 1, 0, 0, 0).ToDateTimeString() // 1243-03-21 00:00:00
carbon.CreateFromPersian(1395, 1, 1, 0, 0, 0).ToDateTimeString() // 2016-03-20 00:00:00
carbon.CreateFromPersian(9377, 1, 1, 0, 0, 0).ToDateTimeString() // 9998-03-19 00:00:00
Comparison
// Whether is a valid persian date
carbon.CreateFromPersian(1, 1, 1, 0, 0, 0).IsValid() // true
carbon.CreateFromPersian(622, 1, 1, 0, 0, 0).IsValid() // true
carbon.CreateFromPersian(9377, 1, 1, 0, 0, 0).IsValid() // true
carbon.CreateFromPersian(0, 0, 0, 0, 0, 0).IsValid() // false
carbon.CreateFromPersian(2024, 0, 1, 0, 0, 0).IsValid() // false
carbon.CreateFromPersian(2024, 1, 0, 0, 0, 0).IsValid() // false

// Whether is a persian leap year
carbon.CreateFromPersian(1395, 1, 1, 0, 0, 0).IsLeapYear() // true
carbon.CreateFromPersian(9377, 1, 1, 0, 0, 0).IsLeapYear() // true
carbon.CreateFromPersian(622, 1, 1, 0, 0, 0).IsLeapYear() // false
carbon.CreateFromPersian(9999, 1, 1, 0, 0, 0).IsLeapYear() // false

Documentation

Overview

Package persian is part of the carbon package.

Index

Constants

This section is empty.

Variables

View Source
var (
	EnMonths      = []string{"Farvardin", "Ordibehesht", "Khordad", "Tir", "Mordad", "Shahrivar", "Mehr", "Aban", "Azar", "Dey", "Bahman", "Esfand"}
	ShortEnMonths = []string{"Far", "Ord", "Kho", "Tir", "Mor", "Sha", "Meh", "Aba", "Aza", "Dey", "Bah", "Esf"}

	FaMonths      = []string{"فروردین", "اردیبهشت", "خرداد", "تیر", "مرداد", "شهریور", "مهر", "آبان", "آذر", "دی", "بهمن", "اسفند"}
	ShortFaMonths = []string{"فرو", "ارد", "خرد", "تیر", "مرد", "شهر", "مهر", "آبا", "آذر", "دی", "بهم", "اسف"}

	EnWeeks      = []string{"Yekshanbeh", "Doshanbeh", "Seshanbeh", "Chaharshanbeh", "Panjshanbeh", "Jomeh", "Shanbeh"}
	ShortEnWeeks = []string{"Yek", "Dos", "Ses", "Cha", "Pan", "Jom", "Sha"}

	FaWeeks      = []string{"نجشنبه", "دوشنبه", "سه شنبه", "چهارشنبه", "پنجشنبه", "جمعه", "شنبه"}
	ShortFaWeeks = []string{"پ", "چ", "س", "د", "ی", "ش", "ج"}

	InvalidDateError = func() error {
		return fmt.Errorf("invalid persian date, please make sure the date is valid")
	}
)

Functions

This section is empty.

Types

type Gregorian

type Gregorian struct {
	calendar.Gregorian
}

Gregorian defines a Gregorian struct. 定义 Gregorian 结构体

func FromGregorian

func FromGregorian(t time.Time) (g Gregorian)

FromGregorian creates a Gregorian instance from time.Time. 从标准 time.Time 创建 Gregorian 实例

func (Gregorian) ToPersian

func (g Gregorian) ToPersian() (p Persian)

ToPersian converts Gregorian instance to Persian instance. 将 Gregorian 实例转化为 Persian 实例

type Month

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

type Persian

type Persian struct {
	Error error
	// contains filtered or unexported fields
}

Persian defines a Persian struct. 定义 Persian 结构体

func FromPersian

func FromPersian(year, month, day, hour, minute, second int) (p Persian)

FromPersian creates a Persian instance from persian datetime. 从 波斯日期 创建 Persian 实例

func MaxValue added in v2.5.2

func MaxValue() Persian

MaxValue returns a Persian instance for the greatest supported date. 返回 Persian 的最大值

func MinValue added in v2.5.2

func MinValue() Persian

MinValue returns a Persian instance for the lowest supported date. 返回 Persian 的最小值

func (Persian) Day

func (p Persian) Day() int

Day gets lunar day like 5. 获取日,如 5

func (Persian) Hour

func (p Persian) Hour() int

Hour gets current hour like 13. 获取小时,如 13

func (Persian) IsLeapYear

func (p Persian) IsLeapYear() bool

IsLeapYear reports whether is a persian leap year. 是否是闰年

func (Persian) IsValid added in v2.5.2

func (p Persian) IsValid() bool

IsValid reports whether is a valid persian date. 是否是有效的日期

func (Persian) Minute

func (p Persian) Minute() int

Minute gets current minute like 14. 获取分钟数,如 14

func (Persian) Month

func (p Persian) Month() int

Month gets lunar month like 8. 获取月份,如 8

func (Persian) Second

func (p Persian) Second() int

Second gets current second like 15. 获取秒数,如 15

func (Persian) String

func (p Persian) String() string

String implements Stringer interface and outputs a string in YYYY-MM-DD HH::ii::ss format like "1402-11-11 00:00:00". 实现 Stringer 接口, 输出 YYYY-MM-DD HH::ii::ss 格式字符串,如 "1402-11-11 00:00:00"

func (Persian) ToGregorian

func (p Persian) ToGregorian() (g Gregorian)

ToGregorian converts Persian instance to Gregorian instance. 将 Persian 实例转化为 Gregorian 实例

func (Persian) ToMonthString

func (p Persian) ToMonthString(locale ...string) (month string)

ToMonthString outputs a string in persian month format like "فروردین". 获取完整月份字符串,如 "فروردین"

func (Persian) ToShortMonthString added in v2.5.2

func (p Persian) ToShortMonthString(locale ...string) (month string)

ToShortMonthString outputs a short string in persian month format like "فروردین". 获取缩写月份字符串,如 "فروردین"

func (Persian) ToShortWeekString added in v2.5.2

func (p Persian) ToShortWeekString(locale ...string) (month string)

ToShortWeekString outputs a short string in week layout like "چهارشنبه". 输出缩写星期字符串,如 "چهارشنبه"

func (Persian) ToWeekString

func (p Persian) ToWeekString(locale ...string) (month string)

ToWeekString outputs a string in week layout like "چهارشنبه". 输出完整星期字符串,如 "چهارشنبه"

func (Persian) Year

func (p Persian) Year() int

Year gets lunar year like 2020. 获取年份,如 2020

Jump to

Keyboard shortcuts

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