datetime

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2025 License: BSD-3-Clause Imports: 8 Imported by: 0

README ¶

datetime

extending datetime

Static Badge

GoDoc GitHub stars Go Report Card codecov

Vesions

Stable Version GitHub Release GitHub Release

Installation

To use this package in your Go project, run:

go get -u github.com/gouef/datetime

Contributing

Read Contributing

Contributors

Join our Discord Community! 🎉

Discord

Click above to join our community on Discord!

Documentation ¶

Index ¶

Constants ¶

View Source
const (
	YearRegexp     = `(\d+)`
	MonthRegexp    = `(0[1-9]|1[0-2])`
	DayRegexp      = `(0[1-9]|[12][0-9]|3[01])`
	HourRegexp     = `(0[0-9]|1[0-9]|2[0-3])`
	MinuteRegexp   = `[0-5][0-9]`
	SecondRegexp   = `[0-5][0-9]`
	DateRegexp     = YearRegexp + `-` + MonthRegexp + `-` + DayRegexp
	TimeRegexp     = `(` + HourRegexp + `):(` + MinuteRegexp + `):(` + SecondRegexp + `)`
	DateTimeRegexp = `((` + DateRegexp + `) (` + TimeRegexp + `))`
	RangeRegexp    = `^([\[\(])` + DateTimeRegexp + `?\s*,\s*` + DateTimeRegexp + `?([\]\)])$`
)
View Source
const (
	Regexp = `^((\d+)-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01]))\s(0[0-9]|1[0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])$`
)

Variables ¶

View Source
var (
	// RangeStartStrict can not be equal
	RangeStartStrict RangeStart = "["
	// RangeStartOptional can be equal
	RangeStartOptional RangeStart = "("
	// RangeEndStrict can not be equal
	RangeEndStrict RangeEnd = "]"
	// RangeEndOptional can be equal
	RangeEndOptional RangeEnd = ")"
)

Functions ¶

func Calculate ¶ added in v0.10.0

func Calculate(year int) time.Time

func DaysInMonth ¶

func DaysInMonth(year int, month int) int

func DaysInMonthByDate ¶

func DaysInMonthByDate(t time.Time) int

func DaysInMonthList ¶ added in v0.10.0

func DaysInMonthList(year int, month int) []int

func GetDate ¶

func GetDate(year, month, day int) time.Time

func GetEaster ¶

func GetEaster(year int) time.Time

func GetGoodFriday ¶

func GetGoodFriday(year int) time.Time

func GetMonday ¶

func GetMonday(year int) time.Time

Types ¶

type DateTime ¶ added in v1.0.0

type DateTime struct {
	Year     int
	Month    int `validate:"min=1,max=12"`
	Day      int `validate:"min=1,max=31"`
	Hour     int `validate:"min=0,max=23"`
	Minute   int `validate:"min=0,max=59"`
	Second   int `validate:"min=0,max=59"`
	DateTime time.Time
}

func New ¶ added in v1.0.0

func New(year, month, day, hour, minute, second int) (*DateTime, error)

func Now ¶ added in v1.0.0

func Now() *DateTime

func (*DateTime) After ¶ added in v1.0.0

func (d *DateTime) After(u Interface) bool

func (*DateTime) Before ¶ added in v1.0.0

func (d *DateTime) Before(u Interface) bool

func (*DateTime) Between ¶ added in v1.0.0

func (d *DateTime) Between(start, end Interface) bool

func (*DateTime) Compare ¶ added in v1.0.0

func (d *DateTime) Compare(u Interface) int

Compare compares the date instant d with u. If d is before u, it returns -1; if d is after u, it returns +1; if they're the same, it returns 0.

func (*DateTime) Equal ¶ added in v1.0.0

func (d *DateTime) Equal(u Interface) bool

func (*DateTime) FromString ¶ added in v1.0.0

func (d *DateTime) FromString(value string) (Interface, error)

func (*DateTime) IsWeekend ¶ added in v1.0.0

func (d *DateTime) IsWeekend() bool

func (*DateTime) Time ¶ added in v1.0.0

func (d *DateTime) Time() time.Time

func (*DateTime) ToString ¶ added in v1.0.0

func (d *DateTime) ToString() string

type Historic ¶ added in v1.0.0

type Historic string
var (
	BeforeChrist Historic = "bc"
	AfterChrist  Historic = "ac"
)

type HistoricDate ¶ added in v1.0.0

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

type Interface ¶ added in v1.0.0

type Interface interface {
	ToString() string
	FromString(value string) (Interface, error)
	Time() time.Time
	Equal(u Interface) bool
	Between(start, end Interface) bool
	Before(u Interface) bool
	After(u Interface) bool
	Compare(u Interface) int
}

func FromString ¶ added in v1.0.0

func FromString(value string) (Interface, error)

type Range ¶ added in v1.0.0

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

func NewRange ¶ added in v1.0.0

func NewRange(from, to string, start RangeStart, end RangeEnd) (*Range, error)

func NewRangeOptional ¶ added in v1.0.0

func NewRangeOptional(from, to string) (*Range, error)

func NewRangeStartOptional ¶ added in v1.0.0

func NewRangeStartOptional(from, to string) (*Range, error)

func NewRangeStartStrict ¶ added in v1.0.0

func NewRangeStartStrict(from, to string) (*Range, error)

func NewRangeStrict ¶ added in v1.0.0

func NewRangeStrict(from, to string) (*Range, error)

func RangeFromString ¶ added in v1.0.0

func RangeFromString(value string) (*Range, error)

func (*Range) End ¶ added in v1.0.0

func (r *Range) End() RangeEnd

func (*Range) From ¶ added in v1.0.0

func (r *Range) From() ValueInterface

func (*Range) Is ¶ added in v1.0.0

func (r *Range) Is(value any) bool

func (*Range) Start ¶ added in v1.0.0

func (r *Range) Start() RangeStart

func (*Range) String ¶ added in v1.0.0

func (r *Range) String() string

func (*Range) To ¶ added in v1.0.0

func (r *Range) To() ValueInterface

type RangeEnd ¶ added in v0.10.0

type RangeEnd string

RangeEnd end bracket

type RangeInterface ¶ added in v1.0.0

type RangeInterface interface {
	Start() RangeStart
	End() RangeEnd
	From() ValueInterface
	To() ValueInterface
	String() string
	Is(value any) bool
}

type RangeStart ¶ added in v0.10.0

type RangeStart string

RangeStart start bracket

type Value ¶ added in v1.0.0

type Value string

func StringToValue ¶ added in v1.0.0

func StringToValue(value string) (Value, error)

func (Value) Date ¶ added in v1.0.0

func (d Value) Date() Interface

type ValueInterface ¶ added in v1.0.0

type ValueInterface interface {
	Date() Interface
}

Directories ¶

Path Synopsis

Jump to

Keyboard shortcuts

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