1 Star 0 Fork 70

golang-package/carbon

forked from dromara/carbon 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
carbon.go 1.68 KB
一键复制 编辑 原始数据 按行查看 历史
// @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.
// 定义 Carbon 结构体
type Carbon struct {
layout string
time StdTime
weekStartsAt Weekday
weekendDays []Weekday
loc *Location
lang *Language
Error error
}
// NewCarbon returns a new Carbon instance.
// 返回 Carbon 实例
func NewCarbon(time ...StdTime) *Carbon {
c := new(Carbon)
c.lang = NewLanguage().SetLocale(DefaultLocale)
c.layout = DefaultLayout
c.weekStartsAt = DefaultWeekStartsAt
c.weekendDays = DefaultWeekendDays
if len(time) > 0 {
c.time = time[0]
c.loc = c.time.Location()
return c
}
c.loc, c.Error = parseTimezone(DefaultTimezone)
return c
}
// Copy returns a new copy of the current Carbon instance
// 复制 Carbon 实例
func (c *Carbon) Copy() *Carbon {
newCarbon := NewCarbon()
newCarbon.time = time.Date(c.Year(), time.Month(c.Month()), c.Day(), c.Hour(), c.Minute(), c.Second(), c.Nanosecond(), c.loc)
newCarbon.layout = c.layout
newCarbon.weekStartsAt = c.weekStartsAt
newCarbon.weekendDays = c.weekendDays
newCarbon.loc = c.loc
newCarbon.Error = c.Error
newCarbon.lang.dir = c.lang.dir
newCarbon.lang.locale = c.lang.locale
newCarbon.lang.resources = c.lang.resources
newCarbon.lang.Error = c.lang.Error
return newCarbon
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/golang-package/carbon.git
git@gitee.com:golang-package/carbon.git
golang-package
carbon
carbon
v2.6.5

搜索帮助