persian

package
v2.3.11 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: MIT Imports: 5 Imported by: 0

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").Lunar().Minute() // 14
// Get persian second
carbon.Parse("2020-08-05 13:14:15").Lunar().Second() // 15

// Get persian date and time string
carbon.Parse("2020-08-05 13:14:15").Lunar().String() // 1399-05-15 13:14:15
fmt.Printf("%s", carbon.Parse("2020-08-05 13:14:15").Lunar()) // 1399-05-15 13:14:15
// // Get persian month as string
carbon.Parse("2020-08-05 13:14:15").Persian().ToMonthString() // مرداد
// // Get persian week as string
carbon.Parse("2020-08-05 13:14:15").Persian().ToWeekString() // چهارشنبه

// Whether is a persian zero time
carbon.Parse("0000-00-00 00:00:00").Persian().IsZero() // true
carbon.Parse("2020-08-05 13:14:15").Persian().IsZero() // false

// Whether is a persian leap year
carbon.Parse("2016-03-20 00:00:00").Persian().IsLeapYear() // true
carbon.Parse("2020-08-05 13:14:15").Persian().IsLeapYear() // false
Convert Persian calendar to Gregorian calendar
carbon.CreateFromPersian(1395, 1, 1, 0, 0, 0).ToDateTimeString() // 2016-03-20 00:00:00
carbon.CreateFromPersian(1399, 5, 15, 13, 14, 15).ToDateTimeString() // 2020-08-05 13:14:15

Documentation

Overview

Package persian is part of the carbon package.

Index

Constants

This section is empty.

Variables

This section is empty.

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 (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 leap year. 是否是闰年

func (Persian) IsZero

func (p Persian) IsZero() bool

IsZero reports whether is zero time. 是否是零值时间

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() (month string)

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

func (Persian) ToWeekString

func (p Persian) ToWeekString() (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