jalali

package module
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2022 License: MIT Imports: 7 Imported by: 2

README

Jalali

Structural time package for jalali calendar. This package support parse from string, json and time.

Structures

There are three data structures for jalali:

  • Jalali jalali date with current system time zone.
  • JalaliTehran jalali date with Asia/Tehran time zone.
  • JalaliKabul jalali date with Asia/Kabul time zone.
Methods

All structures has following methods for work with date.

IsNil

Check if date object is empty.

jDate.IsNil()
SetTime

Set date from standard time object.

jDate.SetTime(time.Now())
Parse

Parse date from jalali date string.

Note: if date is invalid date object will be nil.

jDate.Parse("1400-01-02")
Time

Get current date as standard time. This function return nil if date is empty.

t := jDate.Time()
JTime

Get current date as jalali date object. This function return nil if date is empty.

j := jDate.JTime()
UTC

Get current date as standard time object with utc timezone. This function return nil if date is empty.

utcT :=jDate.UTC()
Format

Format jalali date. This function support standard go time formatting parameters.

f := jDate.Format("2006-01-02")

Helper Functions

TehranTz

Get timezone for Asia/Tehran.

KabulTz

Get timezone for Asia/Kabul.

Parse

Parse jalali date string as time. This function use system timezone.

ParseForLocale

Parse jalali date string as time for timezone.

New

Create new Jalali structure from time object. This function use system timezone.

NewTehran

Create new JalaliTehran structure from time object. This function use Asia/Tehran timezone.

NewKabul

Create new JalaliKabul structure from time object. This function use Asia/Kabul timezone.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func KabulTz

func KabulTz() *time.Location

KabulTz get kabul time zone

func Parse

func Parse(str string) *time.Time

Parse parse jalali date from string

this function return nil if invalid date passed

func ParseForLocale

func ParseForLocale(str string, loc *time.Location) *time.Time

ParseForLocale parse jalali date from string for locale

this function return nil if invalid date passed

func TehranTz

func TehranTz() *time.Location

TehranTz get tehran time zone

Types

type Jalali

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

Jalali data structure

func New

func New(t time.Time) Jalali

New create new jalali date from time

this function use current time zone

func (Jalali) Format

func (this Jalali) Format(format string) string

Format format jalali date using standard go time format

func (Jalali) IsNil

func (this Jalali) IsNil() bool

IsNil check if date is nil

func (Jalali) JTime added in v1.1.0

func (this Jalali) JTime() *ptime.Time

JTime get jalali time

func (Jalali) MarshalJSON

func (this Jalali) MarshalJSON() ([]byte, error)

MarshalJSON get value for json

func (*Jalali) Parse

func (this *Jalali) Parse(str string)

Parse parse from jalali string date

func (*Jalali) SetTime

func (this *Jalali) SetTime(t time.Time)

SetTime set jalali date from time

func (Jalali) String

func (this Jalali) String() string

func (Jalali) Time

func (this Jalali) Time() *time.Time

Time get normal time

func (Jalali) UTC

func (this Jalali) UTC() *time.Time

UTC get normal time in UTC

func (*Jalali) UnmarshalJSON

func (this *Jalali) UnmarshalJSON(data []byte) error

UnmarshalJSON parse jalali from bytes

type JalaliKabul

type JalaliKabul struct {
	Jalali
}

JalaliKabul jalali date with kabul locale

func NewKabul

func NewKabul(t time.Time) JalaliKabul

New create new jalali date from time

this function use kabul time zone

func (*JalaliKabul) Parse

func (this *JalaliKabul) Parse(str string)

Parse parse from jalali string date

func (*JalaliKabul) SetTime added in v1.0.2

func (this *JalaliKabul) SetTime(t time.Time)

SetTime set jalali date from time

func (*JalaliKabul) UnmarshalJSON

func (this *JalaliKabul) UnmarshalJSON(data []byte) error

UnmarshalJSON parse jalali from bytes

type JalaliTehran

type JalaliTehran struct {
	Jalali
}

JalaliTehran jalali date with tehran locale

func NewTehran

func NewTehran(t time.Time) JalaliTehran

New create new jalali date from time

this function use tehran time zone

func (*JalaliTehran) Parse

func (this *JalaliTehran) Parse(str string)

Parse parse from jalali string date

func (*JalaliTehran) SetTime added in v1.0.2

func (this *JalaliTehran) SetTime(t time.Time)

SetTime set jalali date from time

func (*JalaliTehran) UnmarshalJSON

func (this *JalaliTehran) UnmarshalJSON(data []byte) error

UnmarshalJSON parse jalali from bytes

Jump to

Keyboard shortcuts

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