mirror of
https://github.com/crazy-max/diun.git
synced 2026-01-03 19:45:05 +01:00
Bumps [github.com/dromara/carbon/v2](https://github.com/dromara/carbon) from 2.5.2 to 2.6.8. - [Release notes](https://github.com/dromara/carbon/releases) - [Commits](https://github.com/dromara/carbon/compare/v2.5.2...v2.6.8) --- updated-dependencies: - dependency-name: github.com/dromara/carbon/v2 dependency-version: 2.6.8 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com>
64 lines
1.5 KiB
Go
64 lines
1.5 KiB
Go
// @Package carbon
|
|
// @Description a simple, semantic and developer-friendly time package for golang
|
|
// @Page github.com/dromara/carbon
|
|
// @Developer gouguoyin
|
|
// @Blog www.gouguoyin.com
|
|
// @Email 245629560@qq.com
|
|
|
|
// Package carbon is a simple, semantic and developer-friendly time package for golang.
|
|
package carbon
|
|
|
|
import (
|
|
"time"
|
|
)
|
|
|
|
type StdTime = time.Time
|
|
type Weekday = time.Weekday
|
|
type Location = time.Location
|
|
type Duration = time.Duration
|
|
|
|
// Carbon defines a Carbon struct.
|
|
type Carbon struct {
|
|
time StdTime
|
|
weekStartsAt Weekday
|
|
weekendDays []Weekday
|
|
loc *Location
|
|
lang *Language
|
|
currentLayout string
|
|
isEmpty bool
|
|
Error error
|
|
}
|
|
|
|
// NewCarbon returns a new Carbon instance.
|
|
func NewCarbon(stdTime ...StdTime) *Carbon {
|
|
c := new(Carbon)
|
|
c.lang = NewLanguage().SetLocale(DefaultLocale)
|
|
c.weekStartsAt = DefaultWeekStartsAt
|
|
c.weekendDays = DefaultWeekendDays
|
|
c.currentLayout = DefaultLayout
|
|
if len(stdTime) > 0 {
|
|
c.time = stdTime[0]
|
|
c.loc = c.time.Location()
|
|
return c
|
|
}
|
|
c.loc, c.Error = parseTimezone(DefaultTimezone)
|
|
return c
|
|
}
|
|
|
|
// Copy returns a copy of the Carbon instance.
|
|
func (c *Carbon) Copy() *Carbon {
|
|
if c.IsNil() {
|
|
return nil
|
|
}
|
|
return &Carbon{
|
|
time: time.Date(c.Year(), time.Month(c.Month()), c.Day(), c.Hour(), c.Minute(), c.Second(), c.Nanosecond(), c.loc),
|
|
weekStartsAt: c.weekStartsAt,
|
|
weekendDays: c.weekendDays,
|
|
loc: c.loc,
|
|
lang: c.lang.Copy(),
|
|
currentLayout: c.currentLayout,
|
|
isEmpty: c.isEmpty,
|
|
Error: c.Error,
|
|
}
|
|
}
|