From ce62dfd722638cf86f893b0749fb4e5f081e255c Mon Sep 17 00:00:00 2001 From: CrazyMax <1951866+crazy-max@users.noreply.github.com> Date: Sat, 21 Dec 2024 00:26:14 +0100 Subject: [PATCH] switch from durafmt to github.com/dromara/carbon --- go.mod | 2 +- go.sum | 4 +- internal/app/diun.go | 7 +- .../dromara/carbon/v2/.editorconfig | 14 + .../durafmt => dromara/carbon/v2}/LICENSE | 4 +- .../github.com/dromara/carbon/v2/README.cn.md | 1580 +++++++++++++++++ .../github.com/dromara/carbon/v2/README.jp.md | 1562 ++++++++++++++++ vendor/github.com/dromara/carbon/v2/README.md | 1561 ++++++++++++++++ .../github.com/dromara/carbon/v2/boundary.go | 201 +++ .../github.com/dromara/carbon/v2/calendar.go | 61 + .../dromara/carbon/v2/calendar/gregorian.go | 280 +++ .../carbon/v2/calendar/julian/README.cn.md | 61 + .../carbon/v2/calendar/julian/README.jp.md | 60 + .../carbon/v2/calendar/julian/README.md | 60 + .../carbon/v2/calendar/julian/julian.go | 161 ++ .../carbon/v2/calendar/lunar/README.cn.md | 98 + .../carbon/v2/calendar/lunar/README.jp.md | 97 + .../carbon/v2/calendar/lunar/README.md | 97 + .../dromara/carbon/v2/calendar/lunar/lunar.go | 590 ++++++ .../carbon/v2/calendar/persian/README.cn.md | 74 + .../carbon/v2/calendar/persian/README.jp.md | 73 + .../carbon/v2/calendar/persian/README.md | 74 + .../carbon/v2/calendar/persian/persian.go | 321 ++++ vendor/github.com/dromara/carbon/v2/carbon.go | 483 +++++ .../github.com/dromara/carbon/v2/comparer.go | 517 ++++++ .../dromara/carbon/v2/constellation.go | 246 +++ .../github.com/dromara/carbon/v2/creator.go | 254 +++ .../github.com/dromara/carbon/v2/database.go | 890 ++++++++++ .../github.com/dromara/carbon/v2/default.go | 45 + .../dromara/carbon/v2/difference.go | 292 +++ vendor/github.com/dromara/carbon/v2/errors.go | 41 + .../github.com/dromara/carbon/v2/extremum.go | 67 + vendor/github.com/dromara/carbon/v2/getter.go | 433 +++++ vendor/github.com/dromara/carbon/v2/helper.go | 127 ++ .../github.com/dromara/carbon/v2/lang/ar.json | 21 + .../github.com/dromara/carbon/v2/lang/bg.json | 21 + .../github.com/dromara/carbon/v2/lang/de.json | 21 + .../github.com/dromara/carbon/v2/lang/dk.json | 21 + .../github.com/dromara/carbon/v2/lang/en.json | 21 + .../github.com/dromara/carbon/v2/lang/es.json | 21 + .../github.com/dromara/carbon/v2/lang/fa.json | 21 + .../github.com/dromara/carbon/v2/lang/fr.json | 21 + .../github.com/dromara/carbon/v2/lang/hi.json | 21 + .../github.com/dromara/carbon/v2/lang/hu.json | 21 + .../github.com/dromara/carbon/v2/lang/id.json | 21 + .../github.com/dromara/carbon/v2/lang/it.json | 20 + .../github.com/dromara/carbon/v2/lang/jp.json | 21 + .../github.com/dromara/carbon/v2/lang/kr.json | 21 + .../dromara/carbon/v2/lang/ms-MY.json | 21 + .../github.com/dromara/carbon/v2/lang/nl.json | 21 + .../github.com/dromara/carbon/v2/lang/pl.json | 21 + .../github.com/dromara/carbon/v2/lang/pt.json | 21 + .../github.com/dromara/carbon/v2/lang/ro.json | 21 + .../github.com/dromara/carbon/v2/lang/ru.json | 21 + .../github.com/dromara/carbon/v2/lang/se.json | 21 + .../github.com/dromara/carbon/v2/lang/th.json | 21 + .../github.com/dromara/carbon/v2/lang/tr.json | 21 + .../github.com/dromara/carbon/v2/lang/uk.json | 21 + .../github.com/dromara/carbon/v2/lang/vi.json | 21 + .../dromara/carbon/v2/lang/zh-CN.json | 21 + .../dromara/carbon/v2/lang/zh-TW.json | 21 + .../github.com/dromara/carbon/v2/language.go | 109 ++ .../github.com/dromara/carbon/v2/outputer.go | 892 ++++++++++ vendor/github.com/dromara/carbon/v2/parser.go | 104 ++ vendor/github.com/dromara/carbon/v2/season.go | 131 ++ vendor/github.com/dromara/carbon/v2/setter.go | 302 ++++ vendor/github.com/dromara/carbon/v2/test.go | 19 + .../github.com/dromara/carbon/v2/traveler.go | 585 ++++++ vendor/github.com/hako/durafmt/.gitignore | 24 - vendor/github.com/hako/durafmt/.travis.yml | 21 - .../hako/durafmt/CODE_OF_CONDUCT.md | 46 - .../github.com/hako/durafmt/CONTRIBUTING.md | 9 - vendor/github.com/hako/durafmt/README.md | 154 -- vendor/github.com/hako/durafmt/durafmt.go | 330 ---- vendor/github.com/hako/durafmt/unit.go | 108 -- vendor/modules.txt | 10 +- 76 files changed, 13143 insertions(+), 704 deletions(-) create mode 100644 vendor/github.com/dromara/carbon/v2/.editorconfig rename vendor/github.com/{hako/durafmt => dromara/carbon/v2}/LICENSE (95%) create mode 100644 vendor/github.com/dromara/carbon/v2/README.cn.md create mode 100644 vendor/github.com/dromara/carbon/v2/README.jp.md create mode 100644 vendor/github.com/dromara/carbon/v2/README.md create mode 100644 vendor/github.com/dromara/carbon/v2/boundary.go create mode 100644 vendor/github.com/dromara/carbon/v2/calendar.go create mode 100644 vendor/github.com/dromara/carbon/v2/calendar/gregorian.go create mode 100644 vendor/github.com/dromara/carbon/v2/calendar/julian/README.cn.md create mode 100644 vendor/github.com/dromara/carbon/v2/calendar/julian/README.jp.md create mode 100644 vendor/github.com/dromara/carbon/v2/calendar/julian/README.md create mode 100644 vendor/github.com/dromara/carbon/v2/calendar/julian/julian.go create mode 100644 vendor/github.com/dromara/carbon/v2/calendar/lunar/README.cn.md create mode 100644 vendor/github.com/dromara/carbon/v2/calendar/lunar/README.jp.md create mode 100644 vendor/github.com/dromara/carbon/v2/calendar/lunar/README.md create mode 100644 vendor/github.com/dromara/carbon/v2/calendar/lunar/lunar.go create mode 100644 vendor/github.com/dromara/carbon/v2/calendar/persian/README.cn.md create mode 100644 vendor/github.com/dromara/carbon/v2/calendar/persian/README.jp.md create mode 100644 vendor/github.com/dromara/carbon/v2/calendar/persian/README.md create mode 100644 vendor/github.com/dromara/carbon/v2/calendar/persian/persian.go create mode 100644 vendor/github.com/dromara/carbon/v2/carbon.go create mode 100644 vendor/github.com/dromara/carbon/v2/comparer.go create mode 100644 vendor/github.com/dromara/carbon/v2/constellation.go create mode 100644 vendor/github.com/dromara/carbon/v2/creator.go create mode 100644 vendor/github.com/dromara/carbon/v2/database.go create mode 100644 vendor/github.com/dromara/carbon/v2/default.go create mode 100644 vendor/github.com/dromara/carbon/v2/difference.go create mode 100644 vendor/github.com/dromara/carbon/v2/errors.go create mode 100644 vendor/github.com/dromara/carbon/v2/extremum.go create mode 100644 vendor/github.com/dromara/carbon/v2/getter.go create mode 100644 vendor/github.com/dromara/carbon/v2/helper.go create mode 100644 vendor/github.com/dromara/carbon/v2/lang/ar.json create mode 100644 vendor/github.com/dromara/carbon/v2/lang/bg.json create mode 100644 vendor/github.com/dromara/carbon/v2/lang/de.json create mode 100644 vendor/github.com/dromara/carbon/v2/lang/dk.json create mode 100644 vendor/github.com/dromara/carbon/v2/lang/en.json create mode 100644 vendor/github.com/dromara/carbon/v2/lang/es.json create mode 100644 vendor/github.com/dromara/carbon/v2/lang/fa.json create mode 100644 vendor/github.com/dromara/carbon/v2/lang/fr.json create mode 100644 vendor/github.com/dromara/carbon/v2/lang/hi.json create mode 100644 vendor/github.com/dromara/carbon/v2/lang/hu.json create mode 100644 vendor/github.com/dromara/carbon/v2/lang/id.json create mode 100644 vendor/github.com/dromara/carbon/v2/lang/it.json create mode 100644 vendor/github.com/dromara/carbon/v2/lang/jp.json create mode 100644 vendor/github.com/dromara/carbon/v2/lang/kr.json create mode 100644 vendor/github.com/dromara/carbon/v2/lang/ms-MY.json create mode 100644 vendor/github.com/dromara/carbon/v2/lang/nl.json create mode 100644 vendor/github.com/dromara/carbon/v2/lang/pl.json create mode 100644 vendor/github.com/dromara/carbon/v2/lang/pt.json create mode 100644 vendor/github.com/dromara/carbon/v2/lang/ro.json create mode 100644 vendor/github.com/dromara/carbon/v2/lang/ru.json create mode 100644 vendor/github.com/dromara/carbon/v2/lang/se.json create mode 100644 vendor/github.com/dromara/carbon/v2/lang/th.json create mode 100644 vendor/github.com/dromara/carbon/v2/lang/tr.json create mode 100644 vendor/github.com/dromara/carbon/v2/lang/uk.json create mode 100644 vendor/github.com/dromara/carbon/v2/lang/vi.json create mode 100644 vendor/github.com/dromara/carbon/v2/lang/zh-CN.json create mode 100644 vendor/github.com/dromara/carbon/v2/lang/zh-TW.json create mode 100644 vendor/github.com/dromara/carbon/v2/language.go create mode 100644 vendor/github.com/dromara/carbon/v2/outputer.go create mode 100644 vendor/github.com/dromara/carbon/v2/parser.go create mode 100644 vendor/github.com/dromara/carbon/v2/season.go create mode 100644 vendor/github.com/dromara/carbon/v2/setter.go create mode 100644 vendor/github.com/dromara/carbon/v2/test.go create mode 100644 vendor/github.com/dromara/carbon/v2/traveler.go delete mode 100644 vendor/github.com/hako/durafmt/.gitignore delete mode 100644 vendor/github.com/hako/durafmt/.travis.yml delete mode 100644 vendor/github.com/hako/durafmt/CODE_OF_CONDUCT.md delete mode 100644 vendor/github.com/hako/durafmt/CONTRIBUTING.md delete mode 100644 vendor/github.com/hako/durafmt/README.md delete mode 100644 vendor/github.com/hako/durafmt/durafmt.go delete mode 100644 vendor/github.com/hako/durafmt/unit.go diff --git a/go.mod b/go.mod index f81b4fba3..0513f8c7e 100644 --- a/go.mod +++ b/go.mod @@ -17,11 +17,11 @@ require ( github.com/docker/docker v27.3.1+incompatible github.com/docker/go-connections v0.5.0 github.com/docker/go-units v0.5.0 + github.com/dromara/carbon/v2 v2.5.2 github.com/eclipse/paho.mqtt.golang v1.5.0 github.com/go-gomail/gomail v0.0.0-20160411212932-81ebce5c23df github.com/go-playground/validator/v10 v10.23.0 github.com/gregdel/pushover v1.3.1 - github.com/hako/durafmt v0.0.0-20210608085754-5c1018a4e16b github.com/hashicorp/nomad/api v0.0.0-20231213195942-64e3dca9274b // v1.7.2 github.com/jedib0t/go-pretty/v6 v6.6.5 github.com/matcornic/hermes/v2 v2.1.0 diff --git a/go.sum b/go.sum index 29d35a992..1bd6f8863 100644 --- a/go.sum +++ b/go.sum @@ -90,6 +90,8 @@ github.com/docker/go-metrics v0.0.1 h1:AgB/0SvBxihN0X8OR4SjsblXkbMvalQ8cjmtKQ2rQ github.com/docker/go-metrics v0.0.1/go.mod h1:cG1hvH2utMXtqgqqYE9plW6lDxS3/5ayHzueweSI3Vw= github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4= github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= +github.com/dromara/carbon/v2 v2.5.2 h1:GquNyA9Imda+LwS9FIzHhKg+foU2QPstH+S3idBRjKg= +github.com/dromara/carbon/v2 v2.5.2/go.mod h1:zyPlND2o27sKKkRmdgLbk/qYxkmmH6Z4eE8OoM0w3DM= github.com/eclipse/paho.mqtt.golang v1.5.0 h1:EH+bUVJNgttidWFkLLVKaQPGmkTUfQQqjOsyvMGvD6o= github.com/eclipse/paho.mqtt.golang v1.5.0/go.mod h1:du/2qNQVqJf/Sqs4MEL77kR8QTqANF7XU7Fk0aOTAgk= github.com/emicklei/go-restful/v3 v3.11.0 h1:rAQeMHw1c7zTmncogyy8VvRZwtkmkZ4FxERmMY4rD+g= @@ -156,8 +158,6 @@ github.com/gregdel/pushover v1.3.1 h1:4bMLITOZ15+Zpi6qqoGqOPuVHCwSUvMCgVnN5Xhilf github.com/gregdel/pushover v1.3.1/go.mod h1:EcaO66Nn1StkpEm1iKtBTV3d2A16SoMsVER1PthX7to= github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 h1:YBftPWNWd4WwGqtY2yeZL2ef8rHAxPBD8KFhJpmcqms= github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0/go.mod h1:YN5jB8ie0yfIUg6VvR9Kz84aCaG7AsGZnLjhHbUqwPg= -github.com/hako/durafmt v0.0.0-20210608085754-5c1018a4e16b h1:wDUNC2eKiL35DbLvsDhiblTUXHxcOPwQSCzi7xpQUN4= -github.com/hako/durafmt v0.0.0-20210608085754-5c1018a4e16b/go.mod h1:VzxiSdG6j1pi7rwGm/xYI5RbtpBgM8sARDXlvEvxlu0= github.com/hashicorp/cronexpr v1.1.2 h1:wG/ZYIKT+RT3QkOdgYc+xsKWVRgnxJ1OJtjjy84fJ9A= github.com/hashicorp/cronexpr v1.1.2/go.mod h1:P4wA0KBl9C5q2hABiMO7cp6jcIg96CDh1Efb3g1PWA4= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= diff --git a/internal/app/diun.go b/internal/app/diun.go index e68830035..47a6b41f7 100644 --- a/internal/app/diun.go +++ b/internal/app/diun.go @@ -4,7 +4,6 @@ import ( "net/url" "sync" "sync/atomic" - "time" "github.com/crazy-max/cron/v3" "github.com/crazy-max/diun/v4/internal/config" @@ -20,7 +19,7 @@ import ( nomadPrd "github.com/crazy-max/diun/v4/internal/provider/nomad" swarmPrd "github.com/crazy-max/diun/v4/internal/provider/swarm" "github.com/crazy-max/gohealthchecks" - "github.com/hako/durafmt" + "github.com/dromara/carbon/v2" "github.com/panjf2000/ants/v2" "github.com/pkg/errors" "github.com/rs/zerolog/log" @@ -120,7 +119,7 @@ func (di *Diun) Start() error { // Start scheduler di.cron.Start() log.Info().Msgf("Next run in %s (%s)", - durafmt.Parse(time.Until(di.cron.Entry(di.jobID).Next)).LimitFirstN(2).String(), + carbon.CreateFromStdTime(di.cron.Entry(di.jobID).Next).DiffAbsInString(), di.cron.Entry(di.jobID).Next) select {} @@ -135,7 +134,7 @@ func (di *Diun) Run() { defer atomic.StoreUint32(&di.locker, 0) if di.jobID > 0 { defer log.Info().Msgf("Next run in %s (%s)", - durafmt.Parse(time.Until(di.cron.Entry(di.jobID).Next)).LimitFirstN(2).String(), + carbon.CreateFromStdTime(di.cron.Entry(di.jobID).Next).DiffAbsInString(), di.cron.Entry(di.jobID).Next) } diff --git a/vendor/github.com/dromara/carbon/v2/.editorconfig b/vendor/github.com/dromara/carbon/v2/.editorconfig new file mode 100644 index 000000000..355fcba24 --- /dev/null +++ b/vendor/github.com/dromara/carbon/v2/.editorconfig @@ -0,0 +1,14 @@ +# http://editorconfig.org +root = true + +[*] +indent_style = tab +charset = utf-8 +trim_trailing_whitespace = true + +[*.md] +indent_size = 4 +trim_trailing_whitespace = false + +[lang/*.json] +indent_size = 4 diff --git a/vendor/github.com/hako/durafmt/LICENSE b/vendor/github.com/dromara/carbon/v2/LICENSE similarity index 95% rename from vendor/github.com/hako/durafmt/LICENSE rename to vendor/github.com/dromara/carbon/v2/LICENSE index ccb595049..c5d13d6a1 100644 --- a/vendor/github.com/hako/durafmt/LICENSE +++ b/vendor/github.com/dromara/carbon/v2/LICENSE @@ -1,6 +1,6 @@ -The MIT License (MIT) +MIT License -Copyright (c) 2016 Wesley Hill +Copyright (c) 2022 gouguoyin Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/vendor/github.com/dromara/carbon/v2/README.cn.md b/vendor/github.com/dromara/carbon/v2/README.cn.md new file mode 100644 index 000000000..501720173 --- /dev/null +++ b/vendor/github.com/dromara/carbon/v2/README.cn.md @@ -0,0 +1,1580 @@ +# Carbon # + +[![Carbon Release](https://img.shields.io/github/release/dromara/carbon.svg)](https://github.com/dromara/carbon/releases) +[![Go Test](https://github.com/dromara/carbon/actions/workflows/test.yml/badge.svg)](https://github.com/dromara/carbon/actions) +[![Go Report Card](https://goreportcard.com/badge/github.com/dromara/carbon/v2)](https://goreportcard.com/report/github.com/dromara/carbon/v2) +[![Go Coverage](https://codecov.io/gh/dromara/carbon/branch/master/graph/badge.svg)](https://codecov.io/gh/dromara/carbon) +[![Carbon Doc](https://img.shields.io/badge/go.dev-reference-brightgreen?logo=go&logoColor=white&style=flat)](https://pkg.go.dev/github.com/dromara/carbon/v2) +[![License](https://img.shields.io/github/license/dromara/carbon)](https://github.com/dromara/carbon/blob/master/LICENSE) + +简体中文 | [English](README.md) | [日本語](README.jp.md) + +#### 项目简介 + +一个轻量级、语义化、对开发者友好的 golang 时间处理库,支持链式调用,已被 [awesome-go](https://github.com/yinggaozhen/awesome-go-cn#日期和时间 "awesome-go-cn") 收录,并获得 `gitee` 2024 年最有价值项目(`GVP`)和 `gitcode` 2024 年度开源摘星计划 (`G-Star`) 项目 + +#### 仓库地址 + +[github.com/dromara/carbon](https://github.com/dromara/carbon "github.com/dromara/carbon") + +[gitee.com/dromara/carbon](https://gitee.com/dromara/carbon "gitee.com/dromara/carbon") + +[gitcode.com/dromara/carbon](https://gitcode.com/dromara/carbon "gitcode.com/dromara/carbon") + +#### 安装使用 + +##### go version >= 1.17 + +```go +// 使用 github 库 +go get -u github.com/dromara/carbon/v2 +import "github.com/dromara/carbon/v2" + +// 使用 gitee 库 +go get -u gitee.com/dromara/carbon/v2 +import "gitee.com/dromara/carbon/v2" + +// 使用 gitcode 库 +go get -u gitcode.com/dromara/carbon/v2 +import "gitcode.com/dromara/carbon/v2" +``` + +`Carbon` 已经捐赠给了 [dromara](https://dromara.org/ "dromara") 组织,仓库地址发生了改变,如果之前用的路径是 `golang-module/carbon`,请在 `go.mod` 里将原地址更换为新路径,或执行如下命令 + +```go +go mod edit -replace github.com/golang-module/carbon/v2=github.com/dromara/carbon/v2 +``` + +#### 用法示例 + +> 假设当前时间为 2020-08-05 13:14:15.999999999 +0800 CST + +##### 设置全局默认值 + +```go +carbon.SetDefault(carbon.Default{ + Layout: carbon.DateTimeLayout, + Timezone: carbon.PRC, + WeekStartsAt: carbon.Sunday, + Locale: "zh-CN", // 取值范围:lang 目录下翻译文件名,不包含文件后缀 +}) +``` +> 建议在入口文件如 `main.go` 中设置 + +##### `Carbon` 和 `time.Time` 互转 + +```go +// 将标准 time.Time 转换成 Carbon +carbon.CreateFromStdTime(time.Now()) +// 将 Carbon 转换成标准 time.Time +carbon.Now().StdTime() +``` + +##### 昨天、今天、明天 + +```go +// 今天此刻 +fmt.Printf("%s", carbon.Now()) // 2020-08-05 13:14:15 +carbon.Now().String() // 2020-08-05 13:14:15 +carbon.Now().ToString() // 2020-08-05 13:14:15 +0800 CST +carbon.Now().ToDateTimeString() // 2020-08-05 13:14:15 +// 今天日期 +carbon.Now().ToDateString() // 2020-08-05 +// 今天时间 +carbon.Now().ToTimeString() // 13:14:15 +// 指定时区的今天此刻 +carbon.Now(Carbon.NewYork).ToDateTimeString() // 2020-08-05 14:14:15 +// 今天秒级时间戳 +carbon.Now().Timestamp() // 1596604455 +// 今天毫秒级时间戳 +carbon.Now().TimestampMilli() // 1596604455999 +// 今天微秒级时间戳 +carbon.Now().TimestampMicro() // 1596604455999999 +// 今天纳秒级时间戳 +carbon.Now().TimestampNano() // 1596604455999999999 + +// 昨天此刻 +fmt.Printf("%s", carbon.Yesterday()) // 2020-08-04 13:14:15 +carbon.Yesterday().String() // 2020-08-04 13:14:15 +carbon.Yesterday().ToString() // 2020-08-04 13:14:15 +0800 CST +carbon.Yesterday().ToDateTimeString() // 2020-08-04 13:14:15 +// 昨天日期 +carbon.Yesterday().ToDateString() // 2020-08-04 +// 昨天时间 +carbon.Yesterday().ToTimeString() // 13:14:15 +// 指定日期的昨天此刻 +carbon.Parse("2021-01-28 13:14:15").Yesterday().ToDateTimeString() // 2021-01-27 13:14:15 +// 指定时区的昨天此刻 +carbon.Yesterday(Carbon.NewYork).ToDateTimeString() // 2020-08-04 14:14:15 +// 昨天秒级时间戳 +carbon.Yesterday().Timestamp() // 1596518055 +// 昨天毫秒级时间戳 +carbon.Yesterday().TimestampMilli() // 1596518055999 +// 昨天微秒级时间戳 +carbon.Yesterday().TimestampMicro() // 1596518055999999 +// 昨天纳秒级时间戳 +carbon.Yesterday().TimestampNano() // 1596518055999999999 + +// 明天此刻 +fmt.Printf("%s", carbon.Tomorrow()) // 2020-08-06 13:14:15 +carbon.Tomorrow().String() // 2020-08-06 13:14:15 +carbon.Tomorrow().ToString() // 2020-08-06 13:14:15 +0800 CST +carbon.Tomorrow().ToDateTimeString() // 2020-08-06 13:14:15 +// 明天日期 +carbon.Tomorrow().ToDateString() // 2020-08-06 +// 明天时间 +carbon.Tomorrow().ToTimeString() // 13:14:15 +// 指定日期的明天此刻 +carbon.Parse("2021-01-28 13:14:15").Tomorrow().ToDateTimeString() // 2021-01-29 13:14:15 +// 指定时区的明天此刻 +carbon.Tomorrow(Carbon.NewYork).ToDateTimeString() // 2020-08-06 14:14:15 +// 明天秒级时间戳 +carbon.Tomorrow().Timestamp() // 1596690855 +// 明天毫秒级时间戳 +carbon.Tomorrow().TimestampMilli() // 1596690855999 +// 明天微秒级时间戳 +carbon.Tomorrow().TimestampMicro() // 1596690855999999 +// 明天纳秒级时间戳 +carbon.Tomorrow().TimestampNano() // 1596690855999999999 +``` + +##### 创建 `Carbon` 实例 + +```go +// 从秒级时间戳创建 Carbon 实例 +carbon.CreateFromTimestamp(-1).ToString() // 1970-01-01 07:59:59 +0800 CST +carbon.CreateFromTimestamp(0).ToString() // 1970-01-01 08:00:00 +0800 CST +carbon.CreateFromTimestamp(1).ToString() // 1970-01-01 08:00:01 +0800 CST +carbon.CreateFromTimestamp(1649735755).ToString() // 2022-04-12 11:55:55 +0800 CST +// 从毫秒级时间戳创建 Carbon 实例 +carbon.CreateFromTimestampMilli(1649735755981).ToString() // 2022-04-12 11:55:55.981 +0800 CST +// 从微秒级时间戳创建 Carbon 实例 +carbon.CreateFromTimestampMicro(1649735755981566).ToString() // 2022-04-12 11:55:55.981566 +0800 CST +// 从纳秒级时间戳创建 Carbon 实例 +carbon.CreateFromTimestampNano(1649735755981566000).ToString() // 2022-04-12 11:55:55.981566 +0800 CST + +// 从年月日时分秒创建 Carbon 实例 +carbon.CreateFromDateTime(2020, 8, 5, 13, 14, 15).ToString() // 2020-08-05 13:14:15 +0800 CST +// 从年月日时分秒创建 Carbon 实例,包含毫秒 +carbon.CreateFromDateTimeMilli(2020, 8, 5, 13, 14, 15, 999).ToString() // 2020-08-05 13:14:15.999 +0800 CST +// 从年月日时分秒创建 Carbon 实例,包含微秒 +carbon.CreateFromDateTimeMicro(2020, 8, 5, 13, 14, 15, 999999).ToString() // 2020-08-05 13:14:15.999999 +0800 CST +// 从年月日时分秒创建 Carbon 实例,包含纳秒 +carbon.CreateFromDateTimeNano(2020, 8, 5, 13, 14, 15, 999999999).ToString() // 2020-08-05 13:14:15.999999999 +0800 CST + +// 从年月日创建 Carbon 实例 +carbon.CreateFromDate(2020, 8, 5).ToString() // 2020-08-05 00:00:00 +0800 CST +// 从年月日创建 Carbon 实例,包含毫秒 +carbon.CreateFromDateMilli(2020, 8, 5, 999).ToString() // 2020-08-05 00:00:00.999 +0800 CST +// 从年月日创建 Carbon 实例,包含微秒 +carbon.CreateFromDateMicro(2020, 8, 5, 999999).ToString() // 2020-08-05 00:00:00.999999 +0800 CST +// 从年月日创建 Carbon 实例,包含纳秒 +carbon.CreateFromDateNano(2020, 8, 5, 999999999).ToString() // 2020-08-05 00:00:00.999999999 +0800 CST + +// 从时分秒创建 Carbon 实例(年月日默认为当前年月日) +carbon.CreateFromTime(13, 14, 15).ToString() // 2020-08-05 13:14:15 +0800 CST +// 从时分秒创建 Carbon 实例(年月日默认为当前年月日),包含毫秒 +carbon.CreateFromTimeMilli(13, 14, 15, 999).ToString() // 2020-08-05 13:14:15.999 +0800 CST +// 从时分秒创建 Carbon 实例(年月日默认为当前年月日),包含微秒 +carbon.CreateFromTimeMicro(13, 14, 15, 999999).ToString() // 2020-08-05 13:14:15.999999 +0800 CST +// 从时分秒创建 Carbon 实例(年月日默认为当前年月日),包含纳秒 +carbon.CreateFromTimeNano(13, 14, 15, 999999999).ToString() // 2020-08-05 13:14:15.999999999 +0800 CST +``` + +##### 将 `时间字符串` 解析成 `Carbon` 实例 + +```go +carbon.Parse("").ToDateTimeString() // 空字符串 +carbon.Parse("0").ToDateTimeString() // 空字符串 +carbon.Parse("00:00:00").ToDateTimeString() // 空字符串 +carbon.Parse("0000-00-00").ToDateTimeString() // 空字符串 +carbon.Parse("0000-00-00 00:00:00").ToDateTimeString() // 空字符串 + +carbon.Parse("now").ToString() // 2020-08-05 13:14:15 +0800 CST +carbon.Parse("yesterday").ToString() // 2020-08-04 13:14:15 +0800 CST +carbon.Parse("tomorrow").ToString() // 2020-08-06 13:14:15 +0800 CST + +carbon.Parse("2020").ToString() // 2020-01-01 00:00:00 +0800 CST +carbon.Parse("2020-8").ToString() // 2020-08-01 00:00:00 +0800 CST +carbon.Parse("2020-08").ToString() // 2020-08-01 00:00:00 +0800 CST +carbon.Parse("2020-8-5").ToString() // 2020-08-05 00:00:00 +0800 CST +carbon.Parse("2020-8-05").ToString() // 2020-08-05 00:00:00 +0800 CST +carbon.Parse("2020-08-05").ToString() // 2020-08-05 00:00:00 +0800 CST +carbon.Parse("2020-08-05.999").ToString() // 2020-08-05 00:00:00.999 +0800 CST +carbon.Parse("2020-08-05.999999").ToString() // 2020-08-05 00:00:00.999999 +0800 CST +carbon.Parse("2020-08-05.999999999").ToString() // 2020-08-05 00:00:00.999999999 +0800 CST + +carbon.Parse("2020-8-5 13:14:15").ToString() // 2020-08-05 13:14:15 +0800 CST +carbon.Parse("2020-8-05 13:14:15").ToString() // 2020-08-05 13:14:15 +0800 CST +carbon.Parse("2020-08-5 13:14:15").ToString() // 2020-08-05 13:14:15 +0800 CST +carbon.Parse("2020-08-05 13:14:15").ToString() // 2020-08-05 13:14:15 +0800 CST +carbon.Parse("2020-08-05 13:14:15.999").ToString() // 2020-08-05 13:14:15.999 +0800 CST +carbon.Parse("2020-08-05 13:14:15.999999").ToString() // 2020-08-05 13:14:15.999999 +0800 CST +carbon.Parse("2020-08-05 13:14:15.999999999").ToString() // 2020-08-05 13:14:15.999999999 +0800 CST + +carbon.Parse("2020-8-5T13:14:15+08:00").ToString() // 2020-08-05 13:14:15 +0800 CST +carbon.Parse("2020-8-05T13:14:15+08:00").ToString() // 2020-08-05 13:14:15 +0800 CST +carbon.Parse("2020-08-05T13:14:15+08:00").ToString() // 2020-08-05 13:14:15 +0800 CST +carbon.Parse("2020-08-05T13:14:15.999+08:00").ToString() // 2020-08-05 13:14:15.999 +0800 CST +carbon.Parse("2020-08-05T13:14:15.999999+08:00").ToString() // 2020-08-05 13:14:15.999999 +0800 CST +carbon.Parse("2020-08-05T13:14:15.999999999+08:00").ToString() // 2020-08-05 13:14:15.999999999 +0800 CST + +carbon.Parse("20200805").ToString() // 2020-08-05 00:00:00 +0800 CST +carbon.Parse("20200805131415").ToString() // 2020-08-05 13:14:15 +0800 CST +carbon.Parse("20200805131415.999").ToString() // 2020-08-05 13:14:15.999 +0800 CST +carbon.Parse("20200805131415.999999").ToString() // 2020-08-05 13:14:15.999999 +0800 CST +carbon.Parse("20200805131415.999999999").ToString() // 2020-08-05 13:14:15.999999999 +0800 CST +carbon.Parse("20200805131415.999+08:00").ToString() // 2020-08-05 13:14:15.999 +0800 CST +carbon.Parse("20200805131415.999999+08:00").ToString() // 2020-08-05 13:14:15.999999 +0800 CST +carbon.Parse("20200805131415.999999999+08:00").ToString() // 2020-08-05 13:14:15.999999999 +0800 CST + +``` + +##### 通过 `格式模板` 将时间字符串解析成 `Carbon` 实例 + +> 如果使用的字母与格式模板冲突时,请使用转义符转义该字母 + +```go +carbon.ParseByFormat("2020|08|05 13|14|15", "Y|m|d H|i|s").ToDateTimeString() // 2020-08-05 13:14:15 +carbon.ParseByFormat("It is 2020-08-05 13:14:15", "\\I\\t \\i\\s Y-m-d H:i:s").ToDateTimeString() // 2020-08-05 13:14:15 +carbon.ParseByFormat("今天是 2020年08月05日13时14分15秒", "今天是 Y年m月d日H时i分s秒").ToDateTimeString() // 2020-08-05 13:14:15 +carbon.ParseByFormat("2020-08-05 13:14:15", "Y-m-d H:i:s", carbon.Tokyo).ToDateTimeString() // 2020-08-05 14:14:15 +``` + +##### 通过 `布局模板` 将时间字符串解析成 `Carbon` 实例 + +```go +carbon.ParseByLayout("2020|08|05 13|14|15", "2006|01|02 15|04|05").ToDateTimeString() // 2020-08-05 13:14:15 +carbon.ParseByLayout("It is 2020-08-05 13:14:15", "It is 2006-01-02 15:04:05").ToDateTimeString() // 2020-08-05 13:14:15 +carbon.ParseByLayout("今天是 2020年08月05日13时14分15秒", "今天是 2006年01月02日15时04分05秒").ToDateTimeString() // 2020-08-05 13:14:15 +carbon.ParseByLayout("2020-08-05 13:14:15", "2006-01-02 15:04:05", carbon.Tokyo).ToDateTimeString() // 2020-08-05 14:14:15 +``` + +##### 时间边界 + +```go +// 本世纪开始时间 +carbon.Parse("2020-08-05 13:14:15").StartOfCentury().ToDateTimeString() // 2000-01-01 00:00:00 +// 本世纪结束时间 +carbon.Parse("2020-08-05 13:14:15").EndOfCentury().ToDateTimeString() // 2999-12-31 23:59:59 + +// 本年代开始时间 +carbon.Parse("2020-08-05 13:14:15").StartOfDecade().ToDateTimeString() // 2020-01-01 00:00:00 +carbon.Parse("2021-08-05 13:14:15").StartOfDecade().ToDateTimeString() // 2020-01-01 00:00:00 +carbon.Parse("2029-08-05 13:14:15").StartOfDecade().ToDateTimeString() // 2020-01-01 00:00:00 +// 本年代结束时间 +carbon.Parse("2020-08-05 13:14:15").EndOfDecade().ToDateTimeString() // 2029-12-31 23:59:59 +carbon.Parse("2021-08-05 13:14:15").EndOfDecade().ToDateTimeString() // 2029-12-31 23:59:59 +carbon.Parse("2029-08-05 13:14:15").EndOfDecade().ToDateTimeString() // 2029-12-31 23:59:59 + +// 本年开始时间 +carbon.Parse("2020-08-05 13:14:15").StartOfYear().ToDateTimeString() // 2020-01-01 00:00:00 +// 本年结束时间 +carbon.Parse("2020-08-05 13:14:15").EndOfYear().ToDateTimeString() // 2020-12-31 23:59:59 + +// 本季度开始时间 +carbon.Parse("2020-08-05 13:14:15").StartOfQuarter().ToDateTimeString() // 2020-07-01 00:00:00 +// 本季度结束时间 +carbon.Parse("2020-08-05 13:14:15").EndOfQuarter().ToDateTimeString() // 2020-09-30 23:59:59 + +// 本月开始时间 +carbon.Parse("2020-08-05 13:14:15").StartOfMonth().ToDateTimeString() // 2020-08-01 00:00:00 +// 本月结束时间 +carbon.Parse("2020-08-05 13:14:15").EndOfMonth().ToDateTimeString() // 2020-08-31 23:59:59 + +// 本周开始时间 +carbon.Parse("2020-08-05 13:14:15").StartOfWeek().ToDateTimeString() // 2020-08-02 00:00:00 +carbon.Parse("2020-08-05 13:14:15").SetWeekStartsAt(carbon.Sunday).StartOfWeek().ToDateTimeString() // 2020-08-02 00:00:00 +carbon.Parse("2020-08-05 13:14:15").SetWeekStartsAt(carbon.Monday).StartOfWeek().ToDateTimeString() // 2020-08-03 00:00:00 +// 本周结束时间 +carbon.Parse("2020-08-05 13:14:15").EndOfWeek().ToDateTimeString() // 2020-08-08 23:59:59 +carbon.Parse("2020-08-05 13:14:15").SetWeekStartsAt(carbon.Sunday).EndOfWeek().ToDateTimeString() // 2020-08-08 23:59:59 +carbon.Parse("2020-08-05 13:14:15").SetWeekStartsAt(carbon.Monday).EndOfWeek().ToDateTimeString() // 2020-08-09 23:59:59 + +// 本日开始时间 +carbon.Parse("2020-08-05 13:14:15").StartOfDay().ToDateTimeString() // 2020-08-05 00:00:00 +// 本日结束时间 +carbon.Parse("2020-08-05 13:14:15").EndOfDay().ToDateTimeString() // 2020-08-05 23:59:59 + +// 本小时开始时间 +carbon.Parse("2020-08-05 13:14:15").StartOfHour().ToDateTimeString() // 2020-08-05 13:00:00 +// 本小时结束时间 +carbon.Parse("2020-08-05 13:14:15").EndOfHour().ToDateTimeString() // 2020-08-05 13:59:59 + +// 本分钟开始时间 +carbon.Parse("2020-08-05 13:14:15").StartOfMinute().ToDateTimeString() // 2020-08-05 13:14:00 +// 本分钟结束时间 +carbon.Parse("2020-08-05 13:14:15").EndOfMinute().ToDateTimeString() // 2020-08-05 13:14:59 + +// 本秒开始时间 +carbon.Parse("2020-08-05 13:14:15").StartOfSecond().ToString() // 2020-08-05 13:14:15 +0800 CST +// 本秒结束时间 +carbon.Parse("2020-08-05 13:14:15").EndOfSecond().ToString() // 2020-08-05 13:14:15.999999999 +0800 CST +``` + +##### 时间旅行 + +```go +// 三个世纪后 +carbon.Parse("2020-02-29 13:14:15").AddCenturies(3).ToDateTimeString() // 2320-02-29 13:14:15 +// 三个世纪后(月份不溢出) +carbon.Parse("2020-02-29 13:14:15").AddCenturiesNoOverflow(3).ToDateTimeString() // 2320-02-29 13:14:15 +// 一个世纪后 +carbon.Parse("2020-02-29 13:14:15").AddCentury().ToDateTimeString() // 2120-02-29 13:14:15 +// 一个世纪后(月份不溢出) +carbon.Parse("2020-02-29 13:14:15").AddCenturyNoOverflow().ToDateTimeString() // 2120-02-29 13:14:15 +// 三个世纪前 +carbon.Parse("2020-02-29 13:14:15").SubCenturies(3).ToDateTimeString() // 1720-02-29 13:14:15 +// 三个世纪前(月份不溢出) +carbon.Parse("2020-02-29 13:14:15").SubCenturiesNoOverflow(3).ToDateTimeString() // 1720-02-29 13:14:15 +// 一个世纪前 +carbon.Parse("2020-02-29 13:14:15").SubCentury().ToDateTimeString() // 1920-02-29 13:14:15 +// 一世纪前(月份不溢出) +carbon.Parse("2020-02-29 13:14:15").SubCenturyNoOverflow().ToDateTimeString() // 1920-02-29 13:14:15 + +// 三个年代后 +carbon.Parse("2020-02-29 13:14:15").AddDecades(3).ToDateTimeString() // 2050-03-01 13:14:15 +// 三个年代后(月份不溢出) +carbon.Parse("2020-02-29 13:14:15").AddDecadesNoOverflow(3).ToDateTimeString() // 2050-02-28 13:14:15 +// 一个年代后 +carbon.Parse("2020-02-29 13:14:15").AddDecade().ToDateTimeString() // 2030-03-01 13:14:15 +// 一个年代后(月份不溢出) +carbon.Parse("2020-02-29 13:14:15").AddDecadeNoOverflow().ToDateTimeString() // 2030-02-28 13:14:15 +// 三个年代前 +carbon.Parse("2020-02-29 13:14:15").SubDecades(3).ToDateTimeString() // 1990-03-01 13:14:15 +// 三个年代前(月份不溢出) +carbon.Parse("2020-02-29 13:14:15").SubDecadesNoOverflow(3).ToDateTimeString() // 1990-02-28 13:14:15 +// 一个年代前 +carbon.Parse("2020-02-29 13:14:15").SubDecade().ToDateTimeString() // 2010-03-01 13:14:15 +// 一个年代前(月份不溢出) +carbon.Parse("2020-02-29 13:14:15").SubDecadeNoOverflow().ToDateTimeString() // 2010-02-28 13:14:15 + +// 三年后 +carbon.Parse("2020-02-29 13:14:15").AddYears(3).ToDateTimeString() // 2023-03-01 13:14:15 +// 三年后(月份不溢出) +carbon.Parse("2020-02-29 13:14:15").AddYearsNoOverflow(3).ToDateTimeString() // 2023-02-28 13:14:15 +// 一年后 +carbon.Parse("2020-02-29 13:14:15").AddYear().ToDateTimeString() // 2021-03-01 13:14:15 +// 一年后(月份不溢出) +carbon.Parse("2020-02-29 13:14:15").AddYearNoOverflow().ToDateTimeString() // 2021-02-28 13:14:15 +// 三年前 +carbon.Parse("2020-02-29 13:14:15").SubYears(3).ToDateTimeString() // 2017-03-01 13:14:15 +// 三年前(月份不溢出) +carbon.Parse("2020-02-29 13:14:15").SubYearsNoOverflow(3).ToDateTimeString() // 2017-02-28 13:14:15 +// 一年前 +carbon.Parse("2020-02-29 13:14:15").SubYear().ToDateTimeString() // 2019-03-01 13:14:15 +// 一年前(月份不溢出) +carbon.Parse("2020-02-29 13:14:15").SubYearNoOverflow().ToDateTimeString() // 2019-02-28 13:14:15 + +// 三个季度后 +carbon.Parse("2019-05-31 13:14:15").AddQuarters(3).ToDateTimeString() // 2020-03-02 13:14:15 +// 三个季度后(月份不溢出) +carbon.Parse("2019-05-31 13:14:15").AddQuartersNoOverflow(3).ToDateTimeString() // 2020-02-29 13:14:15 +// 一个季度后 +carbon.Parse("2019-11-30 13:14:15").AddQuarter().ToDateTimeString() // 2020-03-01 13:14:15 +// 一个季度后(月份不溢出) +carbon.Parse("2019-11-30 13:14:15").AddQuarterNoOverflow().ToDateTimeString() // 2020-02-29 13:14:15 +// 三个季度前 +carbon.Parse("2019-08-31 13:14:15").SubQuarters(3).ToDateTimeString() // 2019-03-03 13:14:15 +// 三个季度前(月份不溢出) +carbon.Parse("2019-08-31 13:14:15").SubQuartersNoOverflow(3).ToDateTimeString() // 2019-02-28 13:14:15 +// 一个季度前 +carbon.Parse("2020-05-31 13:14:15").SubQuarter().ToDateTimeString() // 2020-03-02 13:14:15 +// 一个季度前(月份不溢出) +carbon.Parse("2020-05-31 13:14:15").SubQuarterNoOverflow().ToDateTimeString() // 2020-02-29 13:14:15 + +// 三个月后 +carbon.Parse("2020-02-29 13:14:15").AddMonths(3).ToDateTimeString() // 2020-05-29 13:14:15 +// 三个月后(月份不溢出) +carbon.Parse("2020-02-29 13:14:15").AddMonthsNoOverflow(3).ToDateTimeString() // 2020-05-29 13:14:15 +// 一个月后 +carbon.Parse("2020-01-31 13:14:15").AddMonth().ToDateTimeString() // 2020-03-02 13:14:15 +// 一个月后(月份不溢出) +carbon.Parse("2020-01-31 13:14:15").AddMonthNoOverflow().ToDateTimeString() // 2020-02-29 13:14:15 +// 三个月前 +carbon.Parse("2020-02-29 13:14:15").SubMonths(3).ToDateTimeString() // 2019-11-29 13:14:15 +// 三个月前(月份不溢出) +carbon.Parse("2020-02-29 13:14:15").SubMonthsNoOverflow(3).ToDateTimeString() // 2019-11-29 13:14:15 +// 一个月前 +carbon.Parse("2020-03-31 13:14:15").SubMonth().ToDateTimeString() // 2020-03-02 13:14:15 +// 一个月前(月份不溢出) +carbon.Parse("2020-03-31 13:14:15").SubMonthNoOverflow().ToDateTimeString() // 2020-02-29 13:14:15 + +// 三周后 +carbon.Parse("2020-02-29 13:14:15").AddWeeks(3).ToDateTimeString() // 2020-03-21 13:14:15 +// 一周后 +carbon.Parse("2020-02-29 13:14:15").AddWeek().ToDateTimeString() // 2020-03-07 13:14:15 +// 三周前 +carbon.Parse("2020-02-29 13:14:15").SubWeeks(3).ToDateTimeString() // 2020-02-08 13:14:15 +// 一周前 +carbon.Parse("2020-02-29 13:14:15").SubWeek().ToDateTimeString() // 2020-02-22 13:14:15 + +// 三天后 +carbon.Parse("2020-08-05 13:14:15").AddDays(3).ToDateTimeString() // 2020-08-08 13:14:15 +// 一天后 +carbon.Parse("2020-08-05 13:14:15").AddDay().ToDateTimeString() // 2020-08-05 13:14:15 +// 三天前 +carbon.Parse("2020-08-05 13:14:15").SubDays(3).ToDateTimeString() // 2020-08-02 13:14:15 +// 一天前 +carbon.Parse("2020-08-05 13:14:15").SubDay().ToDateTimeString() // 2020-08-04 13:14:15 + +// 三小时后 +carbon.Parse("2020-08-05 13:14:15").AddHours(3).ToDateTimeString() // 2020-08-05 16:14:15 +// 二小时半后 +carbon.Parse("2020-08-05 13:14:15").AddDuration("2.5h").ToDateTimeString() // 2020-08-05 15:44:15 +carbon.Parse("2020-08-05 13:14:15").AddDuration("2h30m").ToDateTimeString() // 2020-08-05 15:44:15 +// 一小时后 +carbon.Parse("2020-08-05 13:14:15").AddHour().ToDateTimeString() // 2020-08-05 14:14:15 +// 三小时前 +carbon.Parse("2020-08-05 13:14:15").SubHours(3).ToDateTimeString() // 2020-08-05 10:14:15 +// 二小时半前 +carbon.Parse("2020-08-05 13:14:15").SubDuration("2.5h").ToDateTimeString() // 2020-08-05 10:44:15 +carbon.Parse("2020-08-05 13:14:15").SubDuration("2h30m").ToDateTimeString() // 2020-08-05 10:44:15 +// 一小时前 +carbon.Parse("2020-08-05 13:14:15").SubHour().ToDateTimeString() // 2020-08-05 12:14:15 + +// 三分钟后 +carbon.Parse("2020-08-05 13:14:15").AddMinutes(3).ToDateTimeString() // 2020-08-05 13:17:15 +// 二分钟半后 +carbon.Parse("2020-08-05 13:14:15").AddDuration("2.5m").ToDateTimeString() // 2020-08-05 13:16:45 +carbon.Parse("2020-08-05 13:14:15").AddDuration("2m30s").ToDateTimeString() // 2020-08-05 13:16:45 +// 一分钟后 +carbon.Parse("2020-08-05 13:14:15").AddMinute().ToDateTimeString() // 2020-08-05 13:15:15 +// 三分钟前 +carbon.Parse("2020-08-05 13:14:15").SubMinutes(3).ToDateTimeString() // 2020-08-05 13:11:15 +// 二分钟半前 +carbon.Parse("2020-08-05 13:14:15").SubDuration("2.5m").ToDateTimeString() // 2020-08-05 13:11:45 +carbon.Parse("2020-08-05 13:14:15").SubDuration("2m30s").ToDateTimeString() // 2020-08-05 13:11:45 +// 一分钟前 +carbon.Parse("2020-08-05 13:14:15").SubMinute().ToDateTimeString() // 2020-08-05 13:13:15 + +// 三秒钟后 +carbon.Parse("2020-08-05 13:14:15").AddSeconds(3).ToDateTimeString() // 2020-08-05 13:14:18 +// 二秒钟半后 +carbon.Parse("2020-08-05 13:14:15").AddDuration("2.5s").ToDateTimeString() // 2020-08-05 13:14:17 +// 一秒钟后 +carbon.Parse("2020-08-05 13:14:15").AddSecond().ToDateTimeString() // 2020-08-05 13:14:16 +// 三秒钟前 +carbon.Parse("2020-08-05 13:14:15").SubSeconds(3).ToDateTimeString() // 2020-08-05 13:14:12 +// 二秒钟半前 +carbon.Parse("2020-08-05 13:14:15").SubDuration("2.5s").ToDateTimeString() // 2020-08-05 13:14:12 +// 一秒钟前 +carbon.Parse("2020-08-05 13:14:15").SubSecond().ToDateTimeString() // 2020-08-05 13:14:14 + +// 三毫秒后 +carbon.Parse("2020-08-05 13:14:15.222222222").AddMilliseconds(3).ToString() // 2020-08-05 13:14:15.225222222 +0800 CST +// 一毫秒后 +carbon.Parse("2020-08-05 13:14:15.222222222").AddMillisecond().ToString() // 2020-08-05 13:14:15.223222222 +0800 CST +// 三毫秒前 +carbon.Parse("2020-08-05 13:14:15.222222222").SubMilliseconds(3).ToString() // 2020-08-05 13:14:15.219222222 +0800 CST +// 一毫秒前 +carbon.Parse("2020-08-05 13:14:15.222222222").SubMillisecond().ToString() // 2020-08-05 13:14:15.221222222 +0800 CST + +// 三微秒后 +carbon.Parse("2020-08-05 13:14:15.222222222").AddMicroseconds(3).ToString() // 2020-08-05 13:14:15.222225222 +0800 CST +// 一微秒后 +carbon.Parse("2020-08-05 13:14:15.222222222").AddMicrosecond().ToString() // 2020-08-05 13:14:15.222223222 +0800 CST +// 三微秒前 +carbon.Parse("2020-08-05 13:14:15.222222222").SubMicroseconds(3).ToString() // 2020-08-05 13:14:15.222219222 +0800 CST +// 一微秒前 +carbon.Parse("2020-08-05 13:14:15.222222222").SubMicrosecond().ToString() // 2020-08-05 13:14:15.222221222 +0800 CST + +// 三纳秒后 +carbon.Parse("2020-08-05 13:14:15.222222222").AddNanoseconds(3).ToString() // 2020-08-05 13:14:15.222222225 +0800 CST +// 一纳秒后 +carbon.Parse("2020-08-05 13:14:15.222222222").AddNanossecond().ToString() // 2020-08-05 13:14:15.222222223 +0800 CST +// 三纳秒前 +carbon.Parse("2020-08-05 13:14:15.222222222").SubNanosseconds(3).ToString() // 2020-08-05 13:14:15.222222219 +0800 CST +// 一纳秒前 +carbon.Parse("2020-08-05 13:14:15.222222222").SubNanossecond().ToString() // 2020-08-05 13:14:15.222222221 +0800 CST +``` + +##### 时间差值 + +```go +// 相差多少年 +carbon.Parse("2021-08-05 13:14:15").DiffInYears(carbon.Parse("2020-08-05 13:14:15")) // -1 +// 相差多少年(绝对值) +carbon.Parse("2021-08-05 13:14:15").DiffAbsInYears(carbon.Parse("2020-08-05 13:14:15")) // 1 + +// 相差多少月 +carbon.Parse("2020-08-05 13:14:15").DiffInMonths(carbon.Parse("2020-07-05 13:14:15")) // -1 +// 相差多少月(绝对值) +carbon.Parse("2020-08-05 13:14:15").DiffAbsInMonths(carbon.Parse("2020-07-05 13:14:15")) // 1 + +// 相差多少周 +carbon.Parse("2020-08-05 13:14:15").DiffInWeeks(carbon.Parse("2020-07-28 13:14:15")) // -1 +// 相差多少周(绝对值) +carbon.Parse("2020-08-05 13:14:15").DiffAbsInWeeks(carbon.Parse("2020-07-28 13:14:15")) // 1 + +// 相差多少天 +carbon.Parse("2020-08-05 13:14:15").DiffInDays(carbon.Parse("2020-08-04 13:14:15")) // -1 +// 相差多少天(绝对值) +carbon.Parse("2020-08-05 13:14:15").DiffAbsInDays(carbon.Parse("2020-08-04 13:14:15")) // 1 + +// 相差多少小时 +carbon.Parse("2020-08-05 13:14:15").DiffInHours(carbon.Parse("2020-08-05 12:14:15")) // -1 +// 相差多少小时(绝对值) +carbon.Parse("2020-08-05 13:14:15").DiffAbsInHours(carbon.Parse("2020-08-05 12:14:15")) // 1 + +// 相差多少分 +carbon.Parse("2020-08-05 13:14:15").DiffInMinutes(carbon.Parse("2020-08-05 13:13:15")) // -1 +// 相差多少分(绝对值) +carbon.Parse("2020-08-05 13:14:15").DiffAbsInMinutes(carbon.Parse("2020-08-05 13:13:15")) // 1 + +// 相差多少秒 +carbon.Parse("2020-08-05 13:14:15").DiffInSeconds(carbon.Parse("2020-08-05 13:14:14")) // -1 +// 相差多少秒(绝对值) +carbon.Parse("2020-08-05 13:14:15").DiffAbsInSeconds(carbon.Parse("2020-08-05 13:14:14")) // 1 + +// 相差字符串 +carbon.Now().DiffInString() // just now +carbon.Now().AddYearsNoOverflow(1).DiffInString() // -1 year +carbon.Now().SubYearsNoOverflow(1).DiffInString() // 1 year +// 相差字符串(绝对值) +carbon.Now().DiffAbsInString(carbon.Now()) // just now +carbon.Now().AddYearsNoOverflow(1).DiffAbsInString(carbon.Now()) // 1 year +carbon.Now().SubYearsNoOverflow(1).DiffAbsInString(carbon.Now()) // 1 year + +// 相差时长 +now := carbon.Now() +now.DiffInDuration(now).String() // 0s +now.AddHour().DiffInDuration(now).String() // 1h0m0s +now.SubHour().DiffInDuration(now).String() // -1h0m0s +// 相差时长(绝对值) +now.DiffAbsInDuration(now).String() // 0s +now.AddHour().DiffAbsInDuration(now).String() // 1h0m0s +now.SubHour().DiffAbsInDuration(now).String() // 1h0m0s + +// 对人类友好的可读格式时间差 +carbon.Parse("2020-08-05 13:14:15").DiffForHumans() // just now +carbon.Parse("2019-08-05 13:14:15").DiffForHumans() // 1 year ago +carbon.Parse("2018-08-05 13:14:15").DiffForHumans() // 2 years ago +carbon.Parse("2021-08-05 13:14:15").DiffForHumans() // 1 year from now +carbon.Parse("2022-08-05 13:14:15").DiffForHumans() // 2 years from now + +carbon.Parse("2020-08-05 13:14:15").DiffForHumans(carbon.Now()) // 1 year before +carbon.Parse("2019-08-05 13:14:15").DiffForHumans(carbon.Now()) // 2 years before +carbon.Parse("2018-08-05 13:14:15").DiffForHumans(carbon.Now()) // 1 year after +carbon.Parse("2022-08-05 13:14:15").DiffForHumans(carbon.Now()) // 2 years after +``` + +##### 时间极值 + +```go +c0 := carbon.Parse("2023-04-01") +c1 := carbon.Parse("2023-03-28") +c2 := carbon.Parse("2023-04-16") +// 返回最近的 Carbon 实例 +c0.Closest(c1, c2) // c1 +// 返回最远的 Carbon 实例 +c0.Farthest(c1, c2) // c2 + +yesterday := carbon.Yesterday() +today := carbon.Now() +tomorrow := carbon.Tomorrow() +// 返回最大的 Carbon 实例 +carbon.Max(yesterday, today, tomorrow) // tomorrow +// 返回最小的 Carbon 实例 +carbon.Min(yesterday, today, tomorrow) // yesterday + +// 返回 Carbon 的最大值 +carbon.MaxValue().ToString() // 9999-12-31 23:59:59.999999999 +0000 UTC +// 返回 Carbon 的最小值 +carbon.MinValue().ToString() // -9998-01-01 00:00:00 +0000 UTC +``` + +##### 时间判断 + +```go +// 是否是夏令时 +carbon.Parse("").IsDST() // false +carbon.Parse("0").IsDST() // false +carbon.Parse("0000-00-00 00:00:00").IsDST() // false +carbon.Parse("0000-00-00").IsDST() // false +carbon.Parse("00:00:00").IsDST() // false +carbon.Parse("2023-01-01", "Australia/Brisbane").IsDST() // false +carbon.Parse("2023-01-01", "Australia/Sydney").IsDST() // true + +// 是否是零值时间(0001-01-01 00:00:00 +0000 UTC) +carbon.Parse("").IsZero() // true +carbon.Parse("0").IsZero() // true +carbon.Parse("0000-00-00 00:00:00").IsZero() // true +carbon.Parse("0000-00-00").IsZero() // true +carbon.Parse("00:00:00").IsZero() // true +carbon.Parse("2020-08-05 00:00:00").IsZero() // false +carbon.Parse("2020-08-05").IsZero() // false +carbon.Parse("2020-08-05").SetTimezone("xxx").IsZero() // false + +// 是否是有效时间 +carbon.Parse("").IsValid() // false +carbon.Parse("0").IsValid() // false +carbon.Parse("0000-00-00 00:00:00").IsValid() // false +carbon.Parse("0000-00-00").IsValid() // false +carbon.Parse("00:00:00").IsValid() // false +carbon.Parse("2020-08-05 00:00:00").IsValid() // true +carbon.Parse("2020-08-05").IsValid() // true +carbon.Parse("2020-08-05").SetTimezone("xxx").IsValid() // false + +// 是否是无效时间 +carbon.Parse("").IsInvalid() // true +carbon.Parse("0").IsInvalid() // true +carbon.Parse("0000-00-00 00:00:00").IsInvalid() // true +carbon.Parse("0000-00-00").IsInvalid() // true +carbon.Parse("00:00:00").IsInvalid() // true +carbon.Parse("2020-08-05 00:00:00").IsInvalid() // false +carbon.Parse("2020-08-05").IsInvalid() // false +carbon.Parse("2020-08-05").SetTimezone("xxx").IsInvalid() // true + +// 是否是上午 +carbon.Parse("2020-08-05 00:00:00").IsAM() // true +carbon.Parse("2020-08-05 08:00:00").IsAM() // true +carbon.Parse("2020-08-05 12:00:00").IsAM() // false +carbon.Parse("2020-08-05 13:00:00").IsAM() // false +// 是否是下午 +carbon.Parse("2020-08-05 00:00:00").IsPM() // false +carbon.Parse("2020-08-05 08:00:00").IsPM() // false +carbon.Parse("2020-08-05 12:00:00").IsPM() // true +carbon.Parse("2020-08-05 13:00:00").IsPM() // true + +// 是否是当前时间 +carbon.Now().IsNow() // true +// 是否是未来时间 +carbon.Tomorrow().IsFuture() // true +// 是否是过去时间 +carbon.Yesterday().IsPast() // true + +// 是否是闰年 +carbon.Parse("2020-08-05 13:14:15").IsLeapYear() // true +// 是否是长年 +carbon.Parse("2020-08-05 13:14:15").IsLongYear() // true + +// 是否是一月 +carbon.Parse("2020-08-05 13:14:15").IsJanuary() // false +// 是否是二月 +carbon.Parse("2020-08-05 13:14:15").IsFebruary() // false +// 是否是三月 +carbon.Parse("2020-08-05 13:14:15").IsMarch() // false +// 是否是四月 +carbon.Parse("2020-08-05 13:14:15").IsApril() // false +// 是否是五月 +carbon.Parse("2020-08-05 13:14:15").IsMay() // false +// 是否是六月 +carbon.Parse("2020-08-05 13:14:15").IsJune() // false +// 是否是七月 +carbon.Parse("2020-08-05 13:14:15").IsJuly() // false +// 是否是八月 +carbon.Parse("2020-08-05 13:14:15").IsAugust() // false +// 是否是九月 +carbon.Parse("2020-08-05 13:14:15").IsSeptember() // true +// 是否是十月 +carbon.Parse("2020-08-05 13:14:15").IsOctober() // false +// 是否是十一月 +carbon.Parse("2020-08-05 13:14:15").IsNovember() // false +// 是否是十二月 +carbon.Parse("2020-08-05 13:14:15").IsDecember() // false + +// 是否是周一 +carbon.Parse("2020-08-05 13:14:15").IsMonday() // false +// 是否是周二 +carbon.Parse("2020-08-05 13:14:15").IsTuesday() // true +// 是否是周三 +carbon.Parse("2020-08-05 13:14:15").IsWednesday() // false +// 是否是周四 +carbon.Parse("2020-08-05 13:14:15").IsThursday() // false +// 是否是周五 +carbon.Parse("2020-08-05 13:14:15").IsFriday() // false +// 是否是周六 +carbon.Parse("2020-08-05 13:14:15").IsSaturday() // false +// 是否是周日 +carbon.Parse("2020-08-05 13:14:15").IsSunday() // false + +// 是否是工作日 +carbon.Parse("2020-08-05 13:14:15").IsWeekday() // false +// 是否是周末 +carbon.Parse("2020-08-05 13:14:15").IsWeekend() // true + +// 是否是昨天 +carbon.Parse("2020-08-04 13:14:15").IsYesterday() // true +carbon.Parse("2020-08-04 00:00:00").IsYesterday() // true +carbon.Parse("2020-08-04").IsYesterday() // true +// 是否是今天 +carbon.Parse("2020-08-05 13:14:15").IsToday() // true +carbon.Parse("2020-08-05 00:00:00").IsToday() // true +carbon.Parse("2020-08-05").IsToday() // true +// 是否是明天 +carbon.Parse("2020-08-06 13:14:15").IsTomorrow() // true +carbon.Parse("2020-08-06 00:00:00").IsTomorrow() // true +carbon.Parse("2020-08-06").IsTomorrow() // true + +// 是否是同一世纪 +carbon.Parse("2020-08-05 13:14:15").IsSameCentury(carbon.Parse("3020-08-05 13:14:15")) // false +carbon.Parse("2020-08-05 13:14:15").IsSameCentury(carbon.Parse("2099-08-05 13:14:15")) // true +// 是否是同一年代 +carbon.Parse("2020-08-05 13:14:15").IsSameDecade(carbon.Parse("2030-08-05 13:14:15")) // false +carbon.Parse("2020-08-05 13:14:15").IsSameDecade(carbon.Parse("2120-08-05 13:14:15")) // true +// 是否是同一年 +carbon.Parse("2020-08-05 00:00:00").IsSameYear(carbon.Parse("2021-08-05 13:14:15")) // false +carbon.Parse("2020-01-01 00:00:00").IsSameYear(carbon.Parse("2020-12-31 13:14:15")) // true +// 是否是同一季节 +carbon.Parse("2020-08-05 00:00:00").IsSameQuarter(carbon.Parse("2020-09-05 13:14:15")) // false +carbon.Parse("2020-01-01 00:00:00").IsSameQuarter(carbon.Parse("2021-01-31 13:14:15")) // true +// 是否是同一月 +carbon.Parse("2020-01-01 00:00:00").IsSameMonth(carbon.Parse("2021-01-31 13:14:15")) // false +carbon.Parse("2020-01-01 00:00:00").IsSameMonth(carbon.Parse("2020-01-31 13:14:15")) // true +// 是否是同一天 +carbon.Parse("2020-08-05 13:14:15").IsSameDay(carbon.Parse("2021-08-05 13:14:15")) // false +carbon.Parse("2020-08-05 00:00:00").IsSameDay(carbon.Parse("2020-08-05 13:14:15")) // true +// 是否是同一小时 +carbon.Parse("2020-08-05 13:14:15").IsSameHour(carbon.Parse("2021-08-05 13:14:15")) // false +carbon.Parse("2020-08-05 13:00:00").IsSameHour(carbon.Parse("2020-08-05 13:14:15")) // true +// 是否是同一分钟 +carbon.Parse("2020-08-05 13:14:15").IsSameMinute(carbon.Parse("2021-08-05 13:14:15")) // false +carbon.Parse("2020-08-05 13:14:00").IsSameMinute(carbon.Parse("2020-08-05 13:14:15")) // true +// 是否是同一秒 +carbon.Parse("2020-08-05 13:14:15").IsSameSecond(carbon.Parse("2021-08-05 13:14:15")) // false +carbon.Parse("2020-08-05 13:14:15").IsSameSecond(carbon.Parse("2020-08-05 13:14:15")) // true + +// 是否大于 +carbon.Parse("2020-08-05 13:14:15").Gt(carbon.Parse("2020-08-04 13:14:15")) // true +carbon.Parse("2020-08-05 13:14:15").Gt(carbon.Parse("2020-08-05 13:14:15")) // false +carbon.Parse("2020-08-05 13:14:15").Compare(">", carbon.Parse("2020-08-04 13:14:15")) // true +carbon.Parse("2020-08-05 13:14:15").Compare(">", carbon.Parse("2020-08-05 13:14:15")) // false + +// 是否小于 +carbon.Parse("2020-08-05 13:14:15").Lt(carbon.Parse("2020-08-06 13:14:15")) // true +carbon.Parse("2020-08-05 13:14:15").Lt(carbon.Parse("2020-08-05 13:14:15")) // false +carbon.Parse("2020-08-05 13:14:15").Compare("<", carbon.Parse("2020-08-06 13:14:15")) // true +carbon.Parse("2020-08-05 13:14:15").Compare("<", carbon.Parse("2020-08-05 13:14:15")) // false + +// 是否等于 +carbon.Parse("2020-08-05 13:14:15").Eq(carbon.Parse("2020-08-05 13:14:15")) // true +carbon.Parse("2020-08-05 13:14:15").Eq(carbon.Parse("2020-08-05 13:14:00")) // false +carbon.Parse("2020-08-05 13:14:15").Compare("=", carbon.Parse("2020-08-05 13:14:15")) // true +carbon.Parse("2020-08-05 13:14:15").Compare("=", carbon.Parse("2020-08-05 13:14:00")) // false + +// 是否不等于 +carbon.Parse("2020-08-05 13:14:15").Ne(carbon.Parse("2020-08-06 13:14:15")) // true +carbon.Parse("2020-08-05 13:14:15").Ne(carbon.Parse("2020-08-05 13:14:15")) // false +carbon.Parse("2020-08-05 13:14:15").Compare("!=", carbon.Parse("2020-08-06 13:14:15")) // true +carbon.Parse("2020-08-05 13:14:15").Compare("<>", carbon.Parse("2020-08-05 13:14:15")) // false + +// 是否大于等于 +carbon.Parse("2020-08-05 13:14:15").Gte(carbon.Parse("2020-08-04 13:14:15")) // true +carbon.Parse("2020-08-05 13:14:15").Gte(carbon.Parse("2020-08-05 13:14:15")) // true +carbon.Parse("2020-08-05 13:14:15").Compare(">=", carbon.Parse("2020-08-04 13:14:15")) // true +carbon.Parse("2020-08-05 13:14:15").Compare(">=", carbon.Parse("2020-08-05 13:14:15")) // true + +// 是否小于等于 +carbon.Parse("2020-08-05 13:14:15").Lte(carbon.Parse("2020-08-06 13:14:15")) // true +carbon.Parse("2020-08-05 13:14:15").Lte(carbon.Parse("2020-08-05 13:14:15")) // true +carbon.Parse("2020-08-05 13:14:15").Compare("<=", carbon.Parse("2020-08-06 13:14:15")) // true +carbon.Parse("2020-08-05 13:14:15").Compare("<=", carbon.Parse("2020-08-05 13:14:15")) // true + +// 是否在两个时间之间(不包括这两个时间) +carbon.Parse("2020-08-05 13:14:15").Between(carbon.Parse("2020-08-05 13:14:15"), carbon.Parse("2020-08-06 13:14:15")) // false +carbon.Parse("2020-08-05 13:14:15").Between(carbon.Parse("2020-08-04 13:14:15"), carbon.Parse("2020-08-06 13:14:15")) // true + +// 是否在两个时间之间(包括开始时间) +carbon.Parse("2020-08-05 13:14:15").BetweenIncludedStart(carbon.Parse("2020-08-05 13:14:15"), carbon.Parse("2020-08-06 13:14:15")) // true +carbon.Parse("2020-08-05 13:14:15").BetweenIncludedStart(carbon.Parse("2020-08-04 13:14:15"), carbon.Parse("2020-08-06 13:14:15")) // true + +// 是否在两个时间之间(包括结束时间) +carbon.Parse("2020-08-05 13:14:15").BetweenIncludedEnd(carbon.Parse("2020-08-04 13:14:15"), carbon.Parse("2020-08-05 13:14:15")) // true +carbon.Parse("2020-08-05 13:14:15").BetweenIncludedEnd(carbon.Parse("2020-08-04 13:14:15"), carbon.Parse("2020-08-06 13:14:15")) // true + +// 是否在两个时间之间(包括这两个时间) +carbon.Parse("2020-08-05 13:14:15").BetweenIncludedBoth(carbon.Parse("2020-08-05 13:14:15"), carbon.Parse("2020-08-06 13:14:15")) // true +carbon.Parse("2020-08-05 13:14:15").BetweenIncludedBoth(carbon.Parse("2020-08-04 13:14:15"), carbon.Parse("2020-08-05 13:14:15")) // true +``` + +> 关于长年(LongYear)的定义, 请查看 https://en.wikipedia.org/wiki/ISO_8601#Week_dates + +##### 时间设置 + +```go +// 设置时区 +carbon.SetTimezone(carbon.PRC).Now().ToDateTimeString() // 2020-08-05 13:14:15 +carbon.SetTimezone(carbon.Tokyo).Now().ToDateTimeString() // 2020-08-05 14:14:15 +carbon.SetTimezone(carbon.Tokyo).Now().SetTimezone(carbon.PRC).ToDateTimeString() // 2020-08-05 12:14:15 + +// 设置地区 +utc, _ := time.LoadLocation(carbon.UTC) +carbon.SetLocation(utc).Now().ToDateTimeString() // 2022-06-28 09:25:38 +tokyo, _ := time.LoadLocation(carbon.Tokyo) +carbon.SetLocation(tokyo).Now().ToDateTimeString() // 2022-06-28 18:25:38 + +// 设置区域 +carbon.Parse("2020-07-05 13:14:15").SetLocale("en").DiffForHumans() // 1 month ago +carbon.Parse("2020-07-05 13:14:15").SetLocale("zh-CN").DiffForHumans() // 1 月前 + +// 设置年月日时分秒 +carbon.Parse("2020-01-01").SetDateTime(2019, 2, 2, 13, 14, 15).ToString() // 2019-02-02 13:14:15 +0800 CST +carbon.Parse("2020-01-01").SetDateTime(2019, 2, 31, 13, 14, 15).ToString() // 2019-03-03 13:14:15 +0800 CST +// 设置年月日时分秒毫秒 +carbon.Parse("2020-01-01").SetDateTimeMilli(2019, 2, 2, 13, 14, 15, 999).ToString() // 2019-02-02 13:14:15.999 +0800 CST +carbon.Parse("2020-01-01").SetDateTimeMilli(2019, 2, 31, 13, 14, 15, 999).ToString() // 2019-03-03 13:14:15.999 +0800 CST +// 设置年月日时分秒微秒 +carbon.Parse("2020-01-01").SetDateTimeMicro(2019, 2, 2, 13, 14, 15, 999999).ToString() // 2019-02-02 13:14:15.999999 +0800 CST +carbon.Parse("2020-01-01").SetDateTimeMicro(2019, 2, 31, 13, 14, 15, 999999).ToString() // 2019-03-03 13:14:15.999999 +0800 CST +// 设置年月日时分秒纳秒 +carbon.Parse("2020-01-01").SetDateTimeNano(2019, 2, 2, 13, 14, 15, 999999999).ToString() // 2019-02-02 13:14:15.999999999 +0800 CST +carbon.Parse("2020-01-01").SetDateTimeNano(2019, 2, 31, 13, 14, 15, 999999999).ToString() // 2019-03-03 13:14:15.999999999 +0800 CST + +// 设置年月日 +carbon.Parse("2020-01-01").SetDate(2019, 2, 2).ToString() // 2019-02-02 00:00:00 +0800 CST +carbon.Parse("2020-01-01").SetDate(2019, 2, 31).ToString() // 2019-03-03 00:00:00 +0800 CST +// 设置年月日毫秒 +carbon.Parse("2020-01-01").SetDateMilli(2019, 2, 2, 999).ToString() // 2019-02-02 00:00:00.999 +0800 CST +carbon.Parse("2020-01-01").SetDateMilli(2019, 2, 31, 999).ToString() // 2019-03-03 00:00:00.999 +0800 CST +// 设置年月日微秒 +carbon.Parse("2020-01-01").SetDateMicro(2019, 2, 2, 999999).ToString() // 2019-02-02 00:00:00.999999 +0800 CST +carbon.Parse("2020-01-01").SetDateMicro(2019, 2, 31, 999999).ToString() // 2019-03-03 00:00:00.999999 +0800 CST +// 设置年月日纳秒 +carbon.Parse("2020-01-01").SetDateNano(2019, 2, 2, 999999999).ToString() // 2019-02-02 00:00:00.999999999 +0800 CST +carbon.Parse("2020-01-01").SetDateNano(2019, 2, 31, 999999999).ToString() // 2019-03-03 00:00:00.999999999 +0800 CST + +// 设置时分秒 +carbon.Parse("2020-01-01").SetTime(13, 14, 15).ToString() // 2020-01-01 13:14:15 +0800 CST +carbon.Parse("2020-01-01").SetTime(13, 14, 90).ToString() // 2020-01-01 13:15:30 +0800 CST +// 设置时分秒毫秒 +carbon.Parse("2020-01-01").SetTimeMilli(13, 14, 15, 999).ToString() // 2020-01-01 13:14:15.999 +0800 CST +carbon.Parse("2020-01-01").SetTimeMilli(13, 14, 90, 999).ToString() // 2020-01-01 13:15:30.999 +0800 CST +// 设置时分秒微秒 +carbon.Parse("2020-01-01").SetTimeMicro(13, 14, 15, 999999).ToString() // 2020-01-01 13:14:15.999999 +0800 CST +carbon.Parse("2020-01-01").SetTimeMicro(13, 14, 90, 999999).ToString() // 2020-01-01 13:15:30.999999 +0800 CST +// 设置时分秒纳秒 +carbon.Parse("2020-01-01").SetTimeNano(13, 14, 15, 999999999).ToString() // 2020-01-01 13:14:15.999999999 +0800 CST +carbon.Parse("2020-01-01").SetTimeNano(13, 14, 90, 999999999).ToString() // 2020-01-01 13:15:30.999999999 +0800 CST + +// 设置年份 +carbon.Parse("2020-02-29").SetYear(2021).ToDateString() // 2021-03-01 +// 设置年份(月份不溢出) +carbon.Parse("2020-02-29").SetYearNoOverflow(2021).ToDateString() // 2021-02-28 + +// 设置月份 +carbon.Parse("2020-01-31").SetMonth(2).ToDateString() // 2020-03-02 +// 设置月份(月份不溢出) +carbon.Parse("2020-01-31").SetMonthNoOverflow(2).ToDateString() // 2020-02-29 + +// 设置一周的开始日期 +carbon.Parse("2020-08-02").SetWeekStartsAt(carbon.Monday).Week() // 6 +carbon.Parse("2020-08-02").SetWeekStartsAt(carbon.Sunday).Week() // 0 + +// 设置日期 +carbon.Parse("2019-08-05").SetDay(31).ToDateString() // 2020-08-31 +carbon.Parse("2020-02-01").SetDay(31).ToDateString() // 2020-03-02 + +// 设置小时 +carbon.Parse("2020-08-05 13:14:15").SetHour(10).ToDateTimeString() // 2020-08-05 10:14:15 +carbon.Parse("2020-08-05 13:14:15").SetHour(24).ToDateTimeString() // 2020-08-06 00:14:15 + +// 设置分钟 +carbon.Parse("2020-08-05 13:14:15").SetMinute(10).ToDateTimeString() // 2020-08-05 13:10:15 +carbon.Parse("2020-08-05 13:14:15").SetMinute(60).ToDateTimeString() // 2020-08-05 14:00:15 + +// 设置秒 +carbon.Parse("2020-08-05 13:14:15").SetSecond(10).ToDateTimeString() // 2020-08-05 13:14:10 +carbon.Parse("2020-08-05 13:14:15").SetSecond(60).ToDateTimeString() // 2020-08-05 13:15:00 + +// 设置毫秒 +carbon.Parse("2020-08-05 13:14:15").SetMillisecond(100).Millisecond() // 100 +carbon.Parse("2020-08-05 13:14:15").SetMillisecond(999).Millisecond() // 999 + +// 设置微妙 +carbon.Parse("2020-08-05 13:14:15").SetMicrosecond(100000).Microsecond() // 100000 +carbon.Parse("2020-08-05 13:14:15").SetMicrosecond(999999).Microsecond() // 999999 + +// 设置纳秒 +carbon.Parse("2020-08-05 13:14:15").SetNanosecond(100000000).Nanosecond() // 100000000 +carbon.Parse("2020-08-05 13:14:15").SetNanosecond(999999999).Nanosecond() // 999999999 +``` + +##### 时间获取 + +```go +// 获取本年总天数 +carbon.Parse("2019-08-05 13:14:15").DaysInYear() // 365 +carbon.Parse("2020-08-05 13:14:15").DaysInYear() // 366 +// 获取本月总天数 +carbon.Parse("2020-02-01 13:14:15").DaysInMonth() // 29 +carbon.Parse("2020-04-01 13:14:15").DaysInMonth() // 30 +carbon.Parse("2020-08-01 13:14:15").DaysInMonth() // 31 + +// 获取本年第几天 +carbon.Parse("2020-08-05 13:14:15").DayOfYear() // 218 +// 获取本年第几周 +carbon.Parse("2019-12-31 13:14:15").WeekOfYear() // 1 +carbon.Parse("2020-08-05 13:14:15").WeekOfYear() // 32 +// 获取本月第几天 +carbon.Parse("2020-08-05 13:14:15").DayOfMonth() // 5 +// 获取本月第几周 +carbon.Parse("2020-08-05 13:14:15").WeekOfMonth() // 1 +// 获取本周第几天 +carbon.Parse("2020-08-05 13:14:15").DayOfWeek() // 3 + +// 获取当前年月日时分秒 +carbon.Parse("2020-08-05 13:14:15").DateTime() // 2020,8,5,13,14,15 +// 获取当前年月日时分秒毫秒 +carbon.Parse("2020-08-05 13:14:15").DateTimeMilli() // 2020,8,5,13,14,15,999 +// 获取当前年月日时分秒微秒 +carbon.Parse("2020-08-05 13:14:15").DateTimeMicro() // 2020,8,5,13,14,15,999999 +// 获取当前年月日时分秒纳秒 +carbon.Parse("2020-08-05 13:14:15").DateTimeNano() // 2020,8,5,13,14,15,999999999 + +// 获取当前年月日 +carbon.Parse("2020-08-05 13:14:15.999999999").Date() // 2020,8,5 +// 获取当前年月日毫秒 +carbon.Parse("2020-08-05 13:14:15.999999999").DateMilli() // 2020,8,5,999 +// 获取当前年月日微秒 +carbon.Parse("2020-08-05 13:14:15.999999999").DateMicro() // 2020,8,5,999999 +// 获取当前年月日纳秒 +carbon.Parse("2020-08-05 13:14:15.999999999").DateNano() // 2020,8,5,999999999 + +// 获取当前时分秒 +carbon.Parse("2020-08-05 13:14:15.999999999").Time() // 13,14,15 +// 获取当前时分秒毫秒 +carbon.Parse("2020-08-05 13:14:15.999999999").TimeMilli() // 13,14,15,999 +// 获取当前时分秒微秒 +carbon.Parse("2020-08-05 13:14:15.999999999").TimeMicro() // 13,14,15,999999 +// 获取当前时分秒纳秒 +carbon.Parse("2020-08-05 13:14:15.999999999").TimeNano() // 13,14,15,999999999 + +// 获取当前世纪 +carbon.Parse("2020-08-05 13:14:15").Century() // 21 +// 获取当前年代 +carbon.Parse("2019-08-05 13:14:15").Decade() // 10 +carbon.Parse("2021-08-05 13:14:15").Decade() // 20 +// 获取当前年份 +carbon.Parse("2020-08-05 13:14:15").Year() // 2020 +// 获取当前季度 +carbon.Parse("2020-08-05 13:14:15").Quarter() // 3 +// 获取当前月份 +carbon.Parse("2020-08-05 13:14:15").Month() // 8 +// 获取当前周(从0开始) +carbon.Parse("2020-08-02 13:14:15").Week() // 0 +carbon.Parse("2020-08-02").SetWeekStartsAt(carbon.Sunday).Week() // 0 +carbon.Parse("2020-08-02").SetWeekStartsAt(carbon.Monday).Week() // 6 +// 获取当前天数 +carbon.Parse("2020-08-05 13:14:15").Day() // 5 +// 获取当前小时 +carbon.Parse("2020-08-05 13:14:15").Hour() // 13 +// 获取当前分钟 +carbon.Parse("2020-08-05 13:14:15").Minute() // 14 +// 获取当前秒钟 +carbon.Parse("2020-08-05 13:14:15").Second() // 15 +// 获取当前毫秒 +carbon.Parse("2020-08-05 13:14:15.999").Millisecond() // 999 +// 获取当前微秒 +carbon.Parse("2020-08-05 13:14:15.999").Microsecond() // 999000 +// 获取当前纳秒 +carbon.Parse("2020-08-05 13:14:15.999").Nanosecond() // 999000000 + +// 获取秒级时间戳 +carbon.Parse("2020-08-05 13:14:15").Timestamp() // 1596604455 +// 获取毫秒级时间戳 +carbon.Parse("2020-08-05 13:14:15").TimestampMilli() // 1596604455000 +// 获取微秒级时间戳 +carbon.Parse("2020-08-05 13:14:15").TimestampMicro() // 1596604455000000 +// 获取纳秒级时间戳 +carbon.Parse("2020-08-05 13:14:15").TimestampNano() // 1596604455000000000 + +// 获取时区 +carbon.SetTimezone(carbon.PRC).Timezone() // CST +carbon.SetTimezone(carbon.Tokyo).Timezone() // JST + +// 获取位置 +carbon.SetTimezone(carbon.PRC).Location() // PRC +carbon.SetTimezone(carbon.Tokyo).Location() // Asia/Tokyo + +// 获取距离UTC时区的偏移量,单位秒 +carbon.SetTimezone(carbon.PRC).Offset() // 28800 +carbon.SetTimezone(carbon.Tokyo).Offset() // 32400 + +// 获取当前区域 +carbon.Now().Locale() // en +carbon.Now().SetLocale("zh-CN").Locale() // zh-CN + +// 获取当前星座 +carbon.Now().Constellation() // Leo +carbon.Now().SetLocale("en").Constellation() // Leo +carbon.Now().SetLocale("zh-CN").Constellation() // 狮子座 + +// 获取当前季节 +carbon.Now().Season() // Summer +carbon.Now().SetLocale("en").Season() // Summer +carbon.Now().SetLocale("zh-CN").Season() // 夏季 + +// 获取年龄 +carbon.Parse("2002-01-01 13:14:15").Age() // 17 +carbon.Parse("2002-12-31 13:14:15").Age() // 18 +``` + +##### 时间输出 + +```go +// 输出日期时间字符串 +carbon.Parse("2020-08-05T13:14:15.999999999+08:00").ToDateTimeString() // 2020-08-05 13:14:15 +// 输出日期时间字符串,包含毫秒 +carbon.Parse("2020-08-05T13:14:15.999999999+08:00").ToDateTimeMilliString() // 2020-08-05 13:14:15.999 +// 输出日期时间字符串,包含微秒 +carbon.Parse("2020-08-05T13:14:15.999999999+08:00").ToDateTimeMicroString() // 2020-08-05 13:14:15.999999 +// 输出日期时间字符串,包含纳秒 +carbon.Parse("2020-08-05T13:14:15.999999999+08:00").ToDateTimeNanoString() // 2020-08-05 13:14:15.999999999 + +// 输出简写日期时间字符串 +carbon.Parse("2020-08-05T13:14:15.999999999+08:00").ToShortDateTimeString() // 20200805131415 +// 输出简写日期时间字符串,包含毫秒 +carbon.Parse("2020-08-05T13:14:15.999999999+08:00").ToShortDateTimeMilliString() // 20200805131415.999 +// 输出简写日期时间字符串,包含微秒 +carbon.Parse("2020-08-05T13:14:15.999999999+08:00").ToShortDateTimeMicroString() // 20200805131415.999999 +// 输出简写日期时间字符串,包含纳秒 +carbon.Parse("2020-08-05T13:14:15.999999999+08:00").ToShortDateTimeNanoString() // 20200805131415.999999999 + +// 输出日期字符串 +carbon.Parse("2020-08-05 13:14:15.999999999").ToDateString() // 2020-08-05 +// 输出日期字符串,包含毫秒 +carbon.Parse("2020-08-05 13:14:15.999999999").ToDateMilliString() // 2020-08-05.999 +// 输出日期字符串,包含微秒 +carbon.Parse("2020-08-05 13:14:15.999999999").ToDateMicroString() // 2020-08-05.999999 +// 输出日期字符串,包含纳秒 +carbon.Parse("2020-08-05 13:14:15.999999999").ToDateNanoString() // 2020-08-05.999999999 + +// 输出简写日期字符串 +carbon.Parse("2020-08-05 13:14:15.999999999").ToShortDateString() // 20200805 +// 输出简写日期字符串,包含毫秒 +carbon.Parse("2020-08-05 13:14:15.999999999").ToShortDateMilliString() // 20200805.999 +// 输出简写日期字符串,包含微秒 +carbon.Parse("2020-08-05 13:14:15.999999999").ToShortDateMicroString() // 20200805.999999 +// 输出简写日期字符串,包含纳秒 +carbon.Parse("2020-08-05 13:14:15.999999999").ToShortDateNanoString() // 20200805.999999999 + +// 输出时间字符串 +carbon.Parse("2020-08-05 13:14:15.999999999").ToTimeString() // 13:14:15 +// 输出时间字符串,包含毫秒 +carbon.Parse("2020-08-05 13:14:15.999999999").ToTimeMilliString() // 13:14:15.999 +// 输出时间字符串,包含微秒 +carbon.Parse("2020-08-05 13:14:15.999999999").ToTimeMicroString() // 13:14:15.999999 +// 输出时间字符串,包含纳秒 +carbon.Parse("2020-08-05 13:14:15.999999999").ToTimeNanoString() // 13:14:15.999999999 + +// 输出简写时间字符串 +carbon.Parse("2020-08-05 13:14:15.999999999").ToShortTimeString() // 131415 +// 输出简写时间字符串,包含毫秒 +carbon.Parse("2020-08-05 13:14:15.999999999").ToShortTimeMilliString() // 131415.999 +// 输出简写时间字符串,包含微秒 +carbon.Parse("2020-08-05 13:14:15.999999999").ToShortTimeMicroString() // 131415.999999 +// 输出简写时间字符串,包含纳秒 +carbon.Parse("2020-08-05 13:14:15.999999999").ToShortTimeNanoString() // 131415.999999999 + +// 输出 Ansic 格式字符串 +carbon.Parse("2020-08-05 13:14:15").ToAnsicString() // Wed Aug 5 13:14:15 2020 +// 输出 Atom 格式字符串 +carbon.Parse("2020-08-05 13:14:15").ToAtomString() // 2020-08-05T13:14:15+08:00 +// 输出 UnixDate 格式字符串 +carbon.Parse("2020-08-05 13:14:15").ToUnixDateString() // Wed Aug 5 13:14:15 CST 2020 +// 输出 RubyDate 格式字符串 +carbon.Parse("2020-08-05 13:14:15").ToRubyDateString() // Wed Aug 05 13:14:15 +0800 2020 +// 输出 Kitchen 格式字符串 +carbon.Parse("2020-08-05 13:14:15").ToKitchenString() // 1:14PM +// 输出 Cookie 格式字符串 +carbon.Parse("2020-08-05 13:14:15").ToCookieString() // Wednesday, 05-Aug-2020 13:14:15 CST +// 输出 DayDateTime 格式字符串 +carbon.Parse("2020-08-05 13:14:15").ToDayDateTimeString() // Wed, Aug 5, 2020 1:14 PM +// 输出 RSS 格式字符串 +carbon.Parse("2020-08-05 13:14:15").ToRssString() // Wed, 05 Aug 2020 13:14:15 +0800 +// 输出 W3C 格式字符串 +carbon.Parse("2020-08-05 13:14:15").ToW3cString() // 2020-08-05T13:14:15+08:00 + +// 输出 ISO8601 格式字符串 +carbon.Parse("2020-08-05 13:14:15.999999999").ToIso8601String() // 2020-08-05T13:14:15+08:00 +// 输出 ISO8601Milli 格式字符串 +carbon.Parse("2020-08-05 13:14:15.999999999").ToIso8601MilliString() // 2020-08-05T13:14:15.999+08:00 +// 输出 ISO8601Micro 格式字符串 +carbon.Parse("2020-08-05 13:14:15.999999999").ToIso8601MicroString() // 2020-08-05T13:14:15.999999+08:00 +// 输出 ISO8601Nano 格式字符串 +carbon.Parse("2020-08-05 13:14:15.999999999").ToIso8601NanoString() // 2020-08-05T13:14:15.999999999+08:00 +// 输出 ISO8601Zulu 格式字符串 +carbon.Parse("2020-08-05 13:14:15.999999999").ToIso8601ZuluString() // 2020-08-05T13:14:15Z +// 输出 ISO8601ZuluMilli 格式字符串 +carbon.Parse("2020-08-05 13:14:15.999999999").ToIso8601ZuluMilliString() // 2020-08-05T13:14:15.999Z +// 输出 ISO8601ZuluMicro 格式字符串 +carbon.Parse("2020-08-05 13:14:15.999999999").ToIso8601ZuluMicroString() // 2020-08-05T13:14:15.999999Z +// 输出 ISO8601ZuluNano 格式字符串 +carbon.Parse("2020-08-05 13:14:15.999999999").ToIso8601ZuluNanoString() // 2020-08-05T13:14:15.999999999Z + +// 输出 RFC822 格式字符串 +carbon.Parse("2020-08-05 13:14:15").ToRfc822String() // 05 Aug 20 13:14 CST +// 输出 RFC822Z 格式字符串 +carbon.Parse("2020-08-05 13:14:15").ToRfc822zString() // 05 Aug 20 13:14 +0800 +// 输出 RFC850 格式字符串 +carbon.Parse("2020-08-05 13:14:15").ToRfc850String() // Wednesday, 05-Aug-20 13:14:15 CST +// 输出 RFC1036 格式字符串 +carbon.Parse("2020-08-05 13:14:15").ToRfc1036String() // Wed, 05 Aug 20 13:14:15 +0800 +// 输出 RFC1123 格式字符串 +carbon.Parse("2020-08-05 13:14:15").ToRfc1123String() // Wed, 05 Aug 2020 13:14:15 CST +// 输出 RFC1123Z 格式字符串 +carbon.Parse("2020-08-05 13:14:15").ToRfc1123zString() // Wed, 05 Aug 2020 13:14:15 +0800 +// 输出 RFC2822 格式字符串 +carbon.Parse("2020-08-05 13:14:15").ToRfc2822String() // Wed, 05 Aug 2020 13:14:15 +0800 +// 输出 RFC7231 格式字符串 +carbon.Parse("2020-08-05 13:14:15").ToRfc7231String() // Wed, 05 Aug 2020 13:14:15 GMT + +// 输出 RFC3339 格式字符串 +carbon.Parse("2020-08-05T13:14:15.999999999+08:00").ToRfc3339String() // 2020-08-05T13:14:15+08:00 +// 输出 RFC3339Milli 格式字符串 +carbon.Parse("2020-08-05T13:14:15.999999999+08:00").ToRfc3339MilliString() // 2020-08-05T13:14:15.999+08:00 +// 输出 RFC3339Micro 格式字符串 +carbon.Parse("2020-08-05T13:14:15.999999999+08:00").ToRfc3339MicroString() // 2020-08-05T13:14:15.999999+08:00 +// 输出 RFC3339Nano 格式字符串 +carbon.Parse("2020-08-05T13:14:15.999999999+08:00").ToRfc3339NanoString() // 2020-08-05T13:14:15.999999999+08:00 + +// 输出日期时间字符串 +fmt.Printf("%s", carbon.Parse("2020-08-05 13:14:15")) // 2020-08-05 13:14:15 + +// 输出"2006-01-02 15:04:05.999999999 -0700 MST"格式字符串 +carbon.Parse("2020-08-05 13:14:15").ToString() // 2020-08-05 13:14:15.999999 +0800 CST + +// 输出 "Jan 2, 2006" 格式字符串 +carbon.Parse("2020-08-05 13:14:15").ToFormattedDateString() // Aug 5, 2020 +// 输出 "Mon, Jan 2, 2006" 格式字符串 +carbon.Parse("2020-08-05 13:14:15").ToFormattedDayDateString() // Wed, Aug 5, 2020 + +// 输出指定布局的字符串 +carbon.Parse("2020-08-05 13:14:15").Layout(carbon.ISO8601Layout) // 2020-08-05T13:14:15+08:00 +carbon.Parse("2020-08-05 13:14:15").Layout("20060102150405") // 20200805131415 +carbon.Parse("2020-08-05 13:14:15").Layout("2006年01月02日 15时04分05秒") // 2020年08月05日 13时14分15秒 +carbon.Parse("2020-08-05 13:14:15").Layout("It is 2006-01-02 15:04:05") // It is 2020-08-05 13:14:15 + +// 输出指定格式的字符串(如果使用的字母与格式化字符冲突时,请使用\符号转义该字符) +carbon.Parse("2020-08-05 13:14:15").Format("YmdHis") // 20200805131415 +carbon.Parse("2020-08-05 13:14:15").Format("Y年m月d日 H时i分s秒") // 2020年08月05日 13时14分15秒 +carbon.Parse("2020-08-05 13:14:15").Format("l jS \\o\\f F Y h:i:s A") // Wednesday 5th of August 2020 01:14:15 PM +carbon.Parse("2020-08-05 13:14:15").Format("\\I\\t \\i\\s Y-m-d H:i:s") // It is 2020-08-05 13:14:15 +``` + +> 更多格式化输出符号请查看附录 格式化符号表 + +##### 星座 + +```go +// 获取星座 +carbon.Parse("2020-08-05 13:14:15").Constellation() // Leo + +// 是否是白羊座 +carbon.Parse("2020-08-05 13:14:15").IsAries() // false +// 是否是金牛座 +carbon.Parse("2020-08-05 13:14:15").IsTaurus() // false +// 是否是双子座 +carbon.Parse("2020-08-05 13:14:15").IsGemini() // false +// 是否是巨蟹座 +carbon.Parse("2020-08-05 13:14:15").IsCancer() // false +// 是否是狮子座 +carbon.Parse("2020-08-05 13:14:15").IsLeo() // true +// 是否是处女座 +carbon.Parse("2020-08-05 13:14:15").IsVirgo() // false +// 是否是天秤座 +carbon.Parse("2020-08-05 13:14:15").IsLibra() // false +// 是否是天蝎座 +carbon.Parse("2020-08-05 13:14:15").IsScorpio() // false +// 是否是射手座 +carbon.Parse("2020-08-05 13:14:15").IsSagittarius() // false +// 是否是摩羯座 +carbon.Parse("2020-08-05 13:14:15").IsCapricorn() // false +// 是否是水瓶座 +carbon.Parse("2020-08-05 13:14:15").IsAquarius() // false +// 是否是双鱼座 +carbon.Parse("2020-08-05 13:14:15").IsPisces() // false +``` + +##### 季节 + +> 按照气象划分,即3-5月为春季,6-8月为夏季,9-11月为秋季,12-2月为冬季 + +```go +// 获取季节 +carbon.Parse("2020-08-05 13:14:15").Season() // Summer + +// 本季节开始时间 +carbon.Parse("2020-08-05 13:14:15").StartOfSeason().ToDateTimeString() // 2020-06-01 00:00:00 +// 本季节结束时间 +carbon.Parse("2020-08-05 13:14:15").EndOfSeason().ToDateTimeString() // 2020-08-31 23:59:59 + +// 是否是春季 +carbon.Parse("2020-08-05 13:14:15").IsSpring() // false +// 是否是夏季 +carbon.Parse("2020-08-05 13:14:15").IsSummer() // true +// 是否是秋季 +carbon.Parse("2020-08-05 13:14:15").IsAutumn() // false +// 是否是冬季 +carbon.Parse("2020-08-05 13:14:15").IsWinter() // false +``` + +##### JSON +```go +type Person struct { + Name string `json:"name"` + Age int `json:"age"` + Birthday0 carbon.Carbon `json:"birthday0"` + Birthday1 carbon.DateTime `json:"birthday1"` + Birthday2 carbon.DateTimeMilli `json:"birthday2"` + Birthday3 carbon.DateTimeMicro `json:"birthday3"` + Birthday4 carbon.DateTimeNano `json:"birthday4"` + GraduatedAt1 carbon.Date `json:"graduated_at1"` + GraduatedAt2 carbon.DateMilli `json:"graduated_at2"` + GraduatedAt3 carbon.DateMicro `json:"graduated_at3"` + GraduatedAt4 carbon.DateNano `json:"graduated_at4"` + OperatedAt1 carbon.Time `json:"operated_at1"` + OperatedAt2 carbon.TimeMilli `json:"operated_at2"` + OperatedAt3 carbon.TimeMicro `json:"operated_at3"` + OperatedAt4 carbon.TimeNano `json:"operated_at4"` + CreatedAt1 carbon.Timestamp `json:"created_at1"` + CreatedAt2 carbon.TimestampMilli `json:"created_at2"` + CreatedAt3 carbon.TimestampMicro `json:"created_at3"` + CreatedAt4 carbon.TimestampNano `json:"created_at4"` +} + +person := Person { + Name: "gouguoyin", + Age: 18, + Birthday0: carbon.Now().SubYears(18), + Birthday1: carbon.NewDateTime(carbon.Now().SubYears(18)), + Birthday2: carbon.NewDateTimeMilli(carbon.Now().SubYears(18)), + Birthday3: carbon.NewDateTimeMicro(carbon.Now().SubYears(18)), + Birthday4: carbon.NewDateTimeNano(carbon.Now().SubYears(18)), + GraduatedAt1: carbon.NewDate(carbon.Now()), + GraduatedAt2: carbon.NewDateMilli(carbon.Now()), + GraduatedAt3: carbon.NewDateMicro(carbon.Now()), + GraduatedAt4: carbon.NewDateNano(carbon.Now()), + OperatedAt1: carbon.NewTime(carbon.Now()), + OperatedAt2: carbon.NewTimeMilli(carbon.Now()), + OperatedAt3: carbon.NewTimeMicro(carbon.Now()), + OperatedAt4: carbon.NewTimeNano(carbon.Now()), + CreatedAt1: carbon.NewTimestamp(carbon.Now()), + CreatedAt2: carbon.NewTimestampMilli(carbon.Now()), + CreatedAt3: carbon.NewTimestampMicro(carbon.Now()), + CreatedAt4: carbon.NewTimestampNano(carbon.Now()), +} + +data, err := json.Marshal(&person) +if err != nil { + // 错误处理 + log.Fatal(err) +} +fmt.Printf("%s", data) +// 输出 +{ + "name": "gouguoyin", + "age": 18, + "birthday0": "2003-07-16 13:14:15", + "birthday1": "2003-07-16 13:14:15", + "birthday2": "2003-07-16 13:14:15.999", + "birthday3": "2003-07-16 13:14:15.999999", + "birthday4": "2003-07-16 13:14:15.999999999", + "graduated_at1": "2020-08-05", + "graduated_at2": "2020-08-05.999", + "graduated_at3": "2020-08-05.999999", + "graduated_at4": "2020-08-05.999999999", + "operated_at1": "13:14:15", + "operated_at2": "13:14:15.999", + "operated_at3": "13:14:15.999999", + "operated_at4": "13:14:15.999999999", + "created_at1": 1596604455, + "created_at2": 1596604455999, + "created_at3": 1596604455999999, + "created_at4": 1596604455999999999 +} + +err := json.Unmarshal([]byte(data), &person) +if err != nil { + // 错误处理 + log.Fatal(err) +} + +person.Birthday0.String() // 2003-07-16 13:14:15 +person.Birthday1.String() // 2003-07-16 13:14:15 +person.Birthday2.String() // 2003-07-16 13:14:15.999 +person.Birthday3.String() // 2003-07-16 13:14:15.999999 +person.Birthday4.String() // 2003-07-16 13:14:15.999999999 + +person.GraduatedAt1.String() // 2020-08-05 +person.GraduatedAt2.String() // 2020-08-05.999 +person.GraduatedAt3.String() // 2020-08-05.999999 +person.GraduatedAt4.String() // 2020-08-05.999999999 + +person.OperatedAt1.String() // 13:14:15 +person.OperatedAt2.String() // 13:14:15.999 +person.OperatedAt3.String() // 13:14:15.999999 +person.OperatedAt4.String() // 13:14:15.999999999 + +person.CreatedAt1.String() // "1596604455" +person.CreatedAt2.String() // "1596604455999" +person.CreatedAt3.String() // "1596604455999999" +person.CreatedAt4.String() // "1596604455999999999" + +person.CreatedAt1.Int64() // 1596604455 +person.CreatedAt2.Int64() // 1596604455999 +person.CreatedAt3.Int64() // 1596604455999999 +person.CreatedAt4.Int64() // 1596604455999999999 +``` + +##### 日历 + +目前支持的日历有 + +* [儒略日/简化儒略日](./calendar/julian/README.cn.md "儒略日/简化儒略日") +* [中国农历](./calendar/lunar/README.cn.md "中国农历") +* [波斯历/伊朗历](./calendar/persian/README.cn.md "波斯历/伊朗历") + +##### 国际化 + +目前支持的语言有 + +* [简体中文(zh-CN)](./lang/zh-CN.json "简体中文"): 由 [gouguoyin](https://github.com/gouguoyin "gouguoyin") 翻译 +* [繁体中文(zh-TW)](./lang/zh-TW.json "繁体中文"): 由 [gouguoyin](https://github.com/gouguoyin "gouguoyin") 翻译 +* [英语(en)](./lang/en.json "英语"): 由 [gouguoyin](https://github.com/gouguoyin "gouguoyin") 翻译 +* [日语(jp)](./lang/jp.json "日语"): 由 [gouguoyin](https://github.com/gouguoyin "gouguoyin") 翻译 +* [韩语(kr)](./lang/kr.json "韩语"): 由 [nannul](https://github.com/nannul "nannul") 翻译 +* [德语(de)](./lang/de.json "德语"): 由 [benzammour](https://github.com/benzammour "benzammour") 翻译 +* [西班牙语(es)](./lang/es.json "西班牙语"): 由 [hgisinger](https://github.com/hgisinger "hgisinger") 翻译 +* [土耳其语(tr)](./lang/tr.json "土耳其语"): 由 [emresenyuva](https://github.com/emresenyuva "emresenyuva") 翻译 +* [葡萄牙语(pt)](./lang/pt.json "葡萄牙语"): 由 [felipear89](https://github.com/felipear89 "felipear89") 翻译 +* [俄罗斯语(ru)](./lang/ru.json "俄罗斯语"): 由 [zemlyak](https://github.com/zemlyak "zemlyak") 翻译 +* [乌克兰语(uk)](./lang/uk.json "乌克兰语"): 由 [open-git](https://github.com/open-git "open-git") 翻译 +* [罗马尼亚语(ro)](./lang/ro.json "罗马尼亚语"): 由 [DrOctavius](https://github.com/DrOctavius "DrOctavius") 翻译 +* [印度尼西亚语(id)](./lang/id.json "印度尼西亚语"): 由 [justpoypoy](https://github.com/justpoypoy "justpoypoy") 翻译 +* [意大利语(it)](./lang/it.json "意大利语"): 由 [nicoloHevelop](https://github.com/justpoypoy "nicoloHevelop") 翻译 +* [马来西亚巴哈马语(ms-MY)](./lang/ms-MY.json "马来西亚巴哈马语"): 由 [hollowaykeanho](https://github.com/hollowaykeanho "hollowaykeanho") 翻译 +* [法语(fr)](./lang/fr.json "法语"): 由 [hollowaykeanho](https://github.com/hollowaykeanho "hollowaykeanho") 翻译 +* [泰语(th)](./lang/th.json "泰语"): 由 [izcream](https://github.com/izcream "izcream") 翻译 +* [瑞典语(se)](./lang/se.json "瑞典语"): 由 [jwanglof](https://github.com/jwanglof "jwanglof") 翻译 +* [波斯语(fa)](./lang/fa.json "波斯语"): 由 [erfanMomeniii](https://github.com/ErfanMomeniii "ErfanMomeniii") 翻译 +* [波兰语(nl)](./lang/nl.json "波兰语"): 由 [RemcoE33](https://github.com/RemcoE33 "RemcoE33") 翻译 +* [越南语(vi)](./lang/vi.json "越南语"): 由 [culy247](https://github.com/culy247 "culy247") 翻译 +* [印地语(hi)](./lang/hi.json "印地语"): 由 [chauhan17nitin](https://github.com/chauhan17nitin "chauhan17nitin") 翻译 +* [波兰语(pl)](./lang/pl.json "波兰语"): 由 [gouguoyin](https://github.com/gouguoyin "gouguoyin") 翻译 +* [保加利亚语(bg)](./lang/bg.json "保加利亚语"): 由 [yuksbg](https://github.com/yuksbg "yuksbg") 翻译 +* [阿拉伯语(ar)](./lang/bg.json "阿拉伯语"): 由 [zumoshi](https://github.com/yuksbg "zumoshi") 翻译 +* [匈牙利语(hu)](./lang/hu.json "匈牙利语"): 由 [kenlas](https://github.com/kenlas "kenlas") 翻译 +* [丹麦语(dk)](./lang/dk.json "丹麦语"): 由 [Munk91](https://github.com/Munk91 "Munk91") 翻译 + +目前支持的方法有 + +* `Constellation()`:获取星座,如 `白羊座` +* `Season()`:获取季节,如 `夏季` +* `DiffForHumans()`:获取对人类友好的可读格式时间差,如 `一小时前` +* `ToMonthString()`:输出完整月份字符串,如 `一月` +* `ToShortMonthString()`:输出缩写月份字符串,如 `1月` +* `ToWeekString()`:输出完整星期字符串,如 `星期一` +* `ToShortWeekString()`:输出缩写星期字符串,如 `周一` + +###### 设置区域 + +```go +lang := carbon.NewLanguage() +lang.SetLocale("zh-CN") + +c := carbon.SetLanguage(lang) +if c.Error != nil { + // 错误处理 + log.Fatal(c.Error) +} + +c.Now().AddHours(1).DiffForHumans() // 1 小时后 +c.Now().AddHours(1).ToMonthString() // 八月 +c.Now().AddHours(1).ToShortMonthString() // 8月 +c.Now().AddHours(1).ToWeekString() // 星期二 +c.Now().AddHours(1).ToShortWeekString() // 周二 +c.Now().AddHours(1).Constellation() // 狮子座 +c.Now().AddHours(1).Season() // 夏季 +``` + +###### 重写部分翻译资源(其余仍然按照指定的 `locale` 文件内容翻译) + +```go +lang := carbon.NewLanguage() + +resources := map[string]string { + "hour": "%dh", +} +lang.SetLocale("en").SetResources(resources) + +c := carbon.SetLanguage(lang) +if c.Error != nil { + // 错误处理 + log.Fatal(c.Error) +} + +c.Now().AddYears(1).DiffForHumans() // 1 year from now +c.Now().AddHours(1).DiffForHumans() // 1h from now +c.Now().ToMonthString() // August +c.Now().ToShortMonthString() // Aug +c.Now().ToWeekString() // Tuesday +c.Now().ToShortWeekString() // Tue +c.Now().Constellation() // Leo +c.Now().Season() // Summer +``` + +###### 重写全部翻译资源(无需指定 `locale`) + +```go +lang := carbon.NewLanguage() +resources := map[string]string { + "months": "january|february|march|april|may|june|july|august|september|october|november|december", + "short_months": "jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec", + "weeks": "sunday|monday|tuesday|wednesday|thursday|friday|saturday", + "short_weeks": "sun|mon|tue|wed|thu|fri|sat", + "seasons": "spring|summer|autumn|winter", + "constellations": "aries|taurus|gemini|cancer|leo|virgo|libra|scorpio|sagittarius|capricornus|aquarius|pisce", + "year": "1 yr|%d yrs", + "month": "1 mo|%d mos", + "week": "%dw", + "day": "%dd", + "hour": "%dh", + "minute": "%dm", + "second": "%ds", + "now": "just now", + "ago": "%s ago", + "from_now": "in %s", + "before": "%s before", + "after": "%s after", +} +lang.SetResources(resources) + +c := carbon.SetLanguage(lang) +c.Now().AddYears(1).DiffForHumans() // in 1 yr +c.Now().AddHours(1).DiffForHumans() // in 1h +c.Now().ToMonthString() // august +c.Now().ToShortMonthString() // aug +c.Now().ToWeekString() // tuesday +c.Now().ToShortWeekString() // tue +c.Now().Constellation() // leo +c.Now().Season() // summer +``` + +##### 模拟测试 + +```go +c := carbon.SetTimezone(carbon.UTC) + +c.Now().ToDateString() // 2023-12-27 +c.Now().IsSetTestNow() // false + +c.SetTestNow(carbon.Parse("2020-08-05")) +c.Now().ToDateString() // 2020-08-05 +c.Now().IsSetTestNow() // true + +c.UnSetTestNow() +c.Now().ToDateString() // 2023-12-27 +c.Now().IsSetTestNow() // false +``` + +##### 错误处理 + +> 如果有多个错误发生,只返回第一个错误,前一个错误排除后才返回下一个错误 + +```go +c := carbon.SetTimezone("xxx").Parse("2020-08-05") +if c.Error != nil { + // 错误处理 + log.Fatal(c.Error) +} +// 输出 +invalid timezone "xxx", please see the file "$GOROOT/lib/time/zoneinfo.zip" for all valid timezones +``` + +#### 附录 + +##### 格式化符号表 + +| 符号 | 描述 | 长度 | 范围 | 示例 | +| :------------: | :------------: |:--------------:|:----------------:| :------------: | +| d | 月份中的第几天,有前导零 | 2 | 01-31 | 02 | +| D | 缩写单词表示的周几 | 3 | Mon-Sun | Mon | +| j | 月份中的第几天,没有前导零 | - | 1-31 | 2 | +| S | 第几天的英文缩写后缀,一般和j配合使用 | 2 | st/nd/rd/th | th | +| l | 完整单词表示的周几 | - | Monday-Sunday | Monday | +| F | 完整单词表示的月份 | - | January-December | January | +| m | 数字表示的月份,有前导零 | 2 | 01-12 | 01 | +| M | 缩写单词表示的月份 | 3 | Jan-Dec | Jan | +| n | 数字表示的月份,没有前导零 | - | 1-12 | 1 | +| Y | 4 位数字完整表示的年份 | 4 | 0000-9999 | 2006 | +| y | 2 位数字表示的年份 | 2 | 00-99 | 06 | +| a | 小写的上午和下午标识 | 2 | am/pm | pm | +| A | 大写的上午和下午标识 | 2 | AM/PM | PM | +| g | 小时,12 小时格式 | - | 1-12 | 3 | +| G | 小时,24 小时格式 | - | 0-23 | 15 | +| h | 小时,12 小时格式 | 2 | 00-11 | 03 | +| H | 小时,24 小时格式 | 2 | 00-23 | 15 | +| i | 分钟 | 2 | 01-59 | 04 | +| s | 秒数 | 2 | 01-59 | 05 | +| O | 与格林威治时间相差的小时数 | - | - | -0700 | +| P | 与格林威治时间相差的小时数,小时和分钟之间有冒号分隔 | - | - | -07:00 | +| T | 时区缩写 | - | - | MST | +| W | ISO8601 格式数字表示的年份中的第几周 | 2 | 01-52 | 01 | +| N | ISO8601 格式数字表示的星期中的第几天 | 2 | 01-07 | 02 | +| L | 是否为闰年,如果是闰年为 1,否则为 0 | 1 | 0-1 | 0 | +| U | 秒级时间戳 | - | - | 1596604455 | +| V | 毫级时间戳 | - | - | 1596604455666 | +| X | 微级时间戳 | - | - | 1596604455666666 | +| Z | 纳级时间戳 | - | - | 1596604455666666666 | +| v | 毫秒 | - | 1-999 | 999 | +| u | 微秒 | - | 1-999999 | 999999 | +| x | 纳秒 | - | 1-999999999 | 999999999 | +| w | 数字表示的周几 | 1 | 0-6 | 1 | +| t | 月份中的总天数 | 2 | 28-31 | 31 | +| z | 年份中的第几天 | - | 1-365 | 2 | +| e | 当前位置 | - | - | America/New_York | +| Q | 当前季节 | 1 | 1-4 | 1 | +| C | 当前世纪数 | - | 0-99 | 21 | + +#### 常见问题 + +1、v1 和 v2 版本有什么区别? +> v1 和 v2 版本的 API 没有任何区别,只是 `language.go` 里翻译资源文件内嵌的实现方式不同,v1 版本是由第三方扩展库 [packr](https://github.com/gobuffalo/packr) +> 实现的, +> v2 版本是由 `golang1.16` 后内置标准库 [embed](https://pkg.go.dev/embed) 实现的。如果你的 go 版本大于 1.16推荐使用 v2 版本,否则必须使用 v1 版本。 + +2、window 系统下部署二进制文件时区报错 + +> window 系统如果没有安装 golang 环境,部署时会报 `GOROOT/lib/time/zoneinfo.zip: no such file or directory` 异常,原因是由于 window +> 系统没有内置时区文件,只需要手动下载并指定 `zoneinfo.zip` 路径即可,如 `go/lib/time/zoneinfo.zip` + +```go +os.Setenv("ZONEINFO", "./go/lib/time/zoneinfo.zip") +``` + +3、docker 容器部署二进制文件时区报错 + +> docker 容器如果没有安装 golang 环境,部署时会报 `open /usr/local/go/lib/time/zoneinfo.zip: no such file or directory` +> 异常,只需要把 `zoneinfo.zip` 复制到容器中即可,即在 Dockerfile 中加入 + +```go +COPY ./zoneinfo.zip /usr/local/go/lib/time/zoneinfo.zip +``` + +#### 参考项目 + +* [briannesbitt/carbon](https://github.com/briannesbitt/Carbon) +* [nodatime/nodatime](https://github.com/nodatime/nodatime) +* [jinzhu/now](https://github.com/jinzhu/now) +* [goframe/gtime](https://github.com/gogf/gf/tree/master/os/gtime) +* [jodaOrg/joda-time](https://github.com/jodaOrg/joda-time) +* [arrow-py/arrow](https://github.com/arrow-py/arrow) +* [moment/moment](https://github.com/moment/moment) +* [iamkun/dayjs](https://github.com/iamkun/dayjs) + +#### 贡献者 +感谢以下所有为 `Carbon` 做出贡献的人: + + + +#### 赞助 + +`Carbon` 是一个非商业开源项目, 如果你想支持 `Carbon`, 你可以为开发者 [购买一杯咖啡](https://www.gouguoyin.com/zanzhu.html) + +#### 致谢 + +`Carbon`已获取免费的 JetBrains 开源许可证,在此表示感谢 + +JetBrains diff --git a/vendor/github.com/dromara/carbon/v2/README.jp.md b/vendor/github.com/dromara/carbon/v2/README.jp.md new file mode 100644 index 000000000..9300c1ad6 --- /dev/null +++ b/vendor/github.com/dromara/carbon/v2/README.jp.md @@ -0,0 +1,1562 @@ +# Carbon + +[![Carbon Release](https://img.shields.io/github/release/dromara/carbon.svg)](https://github.com/dromara/carbon/releases) +[![Go Test](https://github.com/dromara/carbon/actions/workflows/test.yml/badge.svg)](https://github.com/dromara/carbon/actions) +[![Go Report Card](https://goreportcard.com/badge/github.com/dromara/carbon/v2)](https://goreportcard.com/report/github.com/dromara/carbon/v2) +[![Go Coverage](https://codecov.io/gh/dromara/carbon/branch/master/graph/badge.svg)](https://codecov.io/gh/dromara/carbon) +[![Carbon Doc](https://img.shields.io/badge/go.dev-reference-brightgreen?logo=go&logoColor=white&style=flat)](https://pkg.go.dev/github.com/dromara/carbon/v2) +[![License](https://img.shields.io/github/license/dromara/carbon)](https://github.com/dromara/carbon/blob/master/LICENSE) + +日本語 | [English](README.md) | [简体中文](README.cn.md) + +#### イントロ + +シンプルでセマンティックで開発者に優しい golang 時間処理ライブラリ + +Carbon は [awesome-go](https://github.com/avelino/awesome-go#date-and-time "awesome-go") に含まれています + +#### リポジトリ + +[github.com/dromara/carbon](https://github.com/dromara/carbon "github.com/dromara/carbon") + +[gitee.com/dromara/carbon](https://gitee.com/dromara/carbon "gitee.com/dromara/carbon") + +[gitcode.com/dromara/carbon](https://gitcode.com/dromara/carbon "gitcode.com/dromara/carbon") + +#### インストール + +##### go version >= 1.17 + +```go +// github から使う +go get -u github.com/dromara/carbon/v2 +import "github.com/dromara/carbon/v2" + +// gitee から使う +go get -u gitee.com/dromara/carbon/v2 +import "gitee.com/dromara/carbon/v2" + +// gitcode から使う +go get -u gitcode.com/dromara/carbon/v2 +import "gitcode.com/dromara/carbon/v2" +``` + +`Carbon` は [dromara](https://dromara.org/ "dromara") 組織に寄付されたためリポジトリのURLが変更されました。以前のリポジトリ `golang-module/carbon` を使用している場合は`go.mod`で新しいリポジトリURLに変更するか下記コマンドを実行します + +```go +go mod edit -replace github.com/golang-module/carbon/v2=github.com/dromara/carbon/v2 +``` + +#### 使い方と例 + +> 現在時刻が 2020-08-05 13:14:15.999999999 +0800 CST であると仮定します。 + +##### グローバルのデフォルト値設定 + +```go +carbon.SetDefault(carbon.Default{ + Layout: carbon.DateTimeLayout, + Timezone: carbon.Japan, + WeekStartsAt: carbon.Sunday, + Locale: "jp", // 値の範囲: langディレクトリ下の翻訳ファイル名でファイル拡張子は含まない +}) +``` + +>エントリファイル(` main.go `など)に設定することをお勧めします + +##### Carbon と time.Time 間の変換 + +```go +// time.Time を Carbon に変換 +carbon.CreateFromStdTime(time.Now()) +// Carbon を time.Time に変換 +carbon.Now().StdTime() +``` + +##### 昨日、現在、明日 + +```go +// 現在時刻 +fmt.Printf("%s", carbon.Now()) // 2020-08-05 13:14:15 +carbon.Now().String() // 2020-08-05 13:14:15 +carbon.Now().ToString() // 2020-08-05 13:14:15 +0800 CST +carbon.Now().ToDateTimeString() // 2020-08-05 13:14:15 +// 現在の日付 +carbon.Now().ToDateString() // 2020-08-05 +// 現在の時間 +carbon.Now().ToTimeString() // 13:14:15 +// タイムゾーン指定の現在 +carbon.Now(Carbon.NewYork).ToDateTimeString() // 2020-08-05 14:14:15 +// 現在の秒タイムスタンプ +carbon.Now().Timestamp() // 1596604455 +// 現在のミリ秒タイムスタンプ +carbon.Now().TimestampMilli() // 1596604455999 +// 現在のマイクロ秒タイムスタンプ +carbon.Now().TimestampMicro() // 1596604455999999 +// 現在のナノ秒タイムスタンプ +carbon.Now().TimestampNano() // 1596604455999999999 + +// 昨日の現在時刻 +fmt.Printf("%s", carbon.Yesterday()) // 2020-08-04 13:14:15 +carbon.Yesterday().String() // 2020-08-04 13:14:15 +carbon.Yesterday().ToString() // 2020-08-04 13:14:15 +0800 CST +carbon.Yesterday().ToDateTimeString() // 2020-08-04 13:14:15 +// 昨日の日付 +carbon.Yesterday().ToDateString() // 2020-08-04 +// 昨日の時間 +carbon.Yesterday().ToTimeString() // 13:14:15 +// 日付指定の昨日 +carbon.Parse("2021-01-28 13:14:15").Yesterday().ToDateTimeString() // 2021-01-27 13:14:15 +// タイムゾーン指定の昨日 +carbon.Yesterday(Carbon.NewYork).ToDateTimeString() // 2020-08-04 14:14:15 +// 昨日の秒タイムスタンプ +carbon.Yesterday().Timestamp() // 1596518055 +// 昨日のミリ秒タイムスタンプ +carbon.Yesterday().TimestampMilli() // 1596518055999 +// 昨日のマイクロ秒タイムスタンプ +carbon.Yesterday().TimestampMicro() // 1596518055999999 +// 昨日のナノ秒タイムスタンプ +carbon.Yesterday().TimestampNano() // 1596518055999999999 + +// 明日の現在時刻 +fmt.Printf("%s", carbon.Tomorrow()) // 2020-08-06 13:14:15 +carbon.Tomorrow().String() // 2020-08-06 13:14:15 +carbon.Tomorrow().ToString() // 2020-08-06 13:14:15 +0800 CST +carbon.Tomorrow().ToDateTimeString() // 2020-08-06 13:14:15 +// 明日の日付 +carbon.Tomorrow().ToDateString() // 2020-08-06 +// 明日の時間 +carbon.Tomorrow().ToTimeString() // 13:14:15 +// 日付指定の明日 +carbon.Parse("2021-01-28 13:14:15").Tomorrow().ToDateTimeString() // 2021-01-29 13:14:15 +// タイムゾーン指定の明日 +carbon.Tomorrow(Carbon.NewYork).ToDateTimeString() // 2020-08-06 14:14:15 +// 明日の秒タイムスタンプ +carbon.Tomorrow().Timestamp() // 1596690855 +// 明日のミリ秒タイムスタンプ +carbon.Tomorrow().TimestampMilli() // 1596690855999 +// 明日のマイクロ秒タイムスタンプ +carbon.Tomorrow().TimestampMicro() // 1596690855999999 +// 明日のナノ秒タイムスタンプ +carbon.Tomorrow().TimestampNano() // 1596690855999999999 +``` + +##### Carbon インスタンスを作成する + +```go +// 秒タイムスタンプから Carbon インスタンスを作成します +carbon.CreateFromTimestamp(-1).ToString() // 1970-01-01 07:59:59 +0800 CST +carbon.CreateFromTimestamp(0).ToString() // 1970-01-01 08:00:00 +0800 CST +carbon.CreateFromTimestamp(1).ToString() // 1970-01-01 08:00:01 +0800 CST +carbon.CreateFromTimestamp(1649735755).ToString() // 2022-04-12 11:55:55 +0800 CST +// ミリ秒のタイムスタンプから Carbon インスタンスを作成します +carbon.CreateFromTimestampMilli(1649735755981).ToString() // 2022-04-12 11:55:55.981 +0800 CST +// マイクロ秒タイムスタンプから Carbon インスタンスを作成します +carbon.CreateFromTimestampMicro(1649735755981566).ToString() // 2022-04-12 11:55:55.981566 +0800 CST +// ナノタイムスタンプから Carbon インスタンスを作成します +carbon.CreateFromTimestampNano(1649735755981566000).ToString() // 2022-04-12 11:55:55.981566 +0800 CST + +// 日付と時間から Carbon インスタンスを作成します +carbon.CreateFromDateTime(2020, 8, 5, 13, 14, 15).ToDateTimeString() // 2020-08-05 13:14:15 +// 日付と時間、ミリ秒から Carbon インスタンスを作成します +carbon.CreateFromDateTimeMilli(2020, 1, 1, 13, 14, 15, 999).ToString() // 2020-01-01 13:14:15.999 +0800 CST +// 日付と時間、マイクロ秒から Carbon インスタンスを作成します +carbon.CreateFromDateTimeMicro(2020, 1, 1, 13, 14, 15, 999999).ToString() // 2020-01-01 13:14:15.999999 +0800 CST +// 日付と時間、ナノ秒から Carbon インスタンスを作成します +carbon.CreateFromDateTimeNano(2020, 1, 1, 13, 14, 15, 999999999).ToString() // 2020-01-01 13:14:15.999999999 +0800 CST + +// 日付から Carbon インスタンスを作成します +carbon.CreateFromDate(2020, 8, 5).ToString() // 2020-08-05 00:00:00 +0800 CST +// 日付とミリ秒から Carbon インスタンスを作成します +carbon.CreateFromDateMilli(2020, 8, 5, 999).ToString() // 2020-08-05 00:00:00.999 +0800 CST +// 日付とマイクロ秒から Carbon インスタンスを作成します +carbon.CreateFromDateMicro(2020, 8, 5, 999999).ToString() // 2020-08-05 00:00:00.999999 +0800 CST +// 日付とナノ秒から Carbon インスタンスを作成します +carbon.CreateFromDateNano(2020, 8, 5, 999999999).ToString() // 2020-08-05 00:00:00.999999999 +0800 CST + +// 時間から Carbon インスタンスを作成します(日付のデフォルトは現在の年月日です) +carbon.CreateFromTime(13, 14, 15).ToString() // 2020-08-05 13:14:15 +0800 CST +// 時間、ミリ秒から Carbon インスタンスを作成します(年月日のデフォルトは現在の年月日です) +carbon.CreateFromTimeMilli(13, 14, 15, 999).ToString() // 2020-08-05 13:14:15.999 +0800 CST +// 時間、マイクロ秒から Carbon インスタンスを作成します(年月日のデフォルトは現在の年月日です) +carbon.CreateFromTimeMicro(13, 14, 15, 999999).ToString() // 2020-08-05 13:14:15.999999 +0800 CST +// 時間、ナノ秒から Carbon インスタンスを作成します(年月日のデフォルトは現在の年月日です) +carbon.CreateFromTimeNano(13, 14, 15, 999999999).ToString() // 2020-08-05 13:14:15.999999999 +0800 CST +``` + +##### 時間文字列を Carbon インスタンスにパース + +```go +carbon.Parse("").ToDateTimeString() // 空の文字列 +carbon.Parse("0").ToDateTimeString() // 空の文字列 +carbon.Parse("00:00:00").ToDateTimeString() // 空の文字列 +carbon.Parse("0000-00-00").ToDateTimeString() // 空の文字列 +carbon.Parse("0000-00-00 00:00:00").ToDateTimeString() // 空の文字列 + +carbon.Parse("now").ToString() // 2020-08-05 13:14:15 +0800 CST +carbon.Parse("yesterday").ToString() // 2020-08-04 13:14:15 +0800 CST +carbon.Parse("tomorrow").ToString() // 2020-08-06 13:14:15 +0800 CST + +carbon.Parse("2020").ToString() // 2020-01-01 00:00:00 +0800 CST +carbon.Parse("2020-8").ToString() // 2020-08-01 00:00:00 +0800 CST +carbon.Parse("2020-08").ToString() // 2020-08-01 00:00:00 +0800 CST +carbon.Parse("2020-8-5").ToString() // 2020-08-05 00:00:00 +0800 CST +carbon.Parse("2020-8-05").ToString() // 2020-08-05 00:00:00 +0800 CST +carbon.Parse("2020-08-05").ToString() // 2020-08-05 00:00:00 +0800 CST +carbon.Parse("2020-08-05.999").ToString() // 2020-08-05 00:00:00.999 +0800 CST +carbon.Parse("2020-08-05.999999").ToString() // 2020-08-05 00:00:00.999999 +0800 CST +carbon.Parse("2020-08-05.999999999").ToString() // 2020-08-05 00:00:00.999999999 +0800 CST + +carbon.Parse("2020-8-5 13:14:15").ToString() // 2020-08-05 13:14:15 +0800 CST +carbon.Parse("2020-8-05 13:14:15").ToString() // 2020-08-05 13:14:15 +0800 CST +carbon.Parse("2020-08-5 13:14:15").ToString() // 2020-08-05 13:14:15 +0800 CST +carbon.Parse("2020-08-05 13:14:15").ToString() // 2020-08-05 13:14:15 +0800 CST +carbon.Parse("2020-08-05 13:14:15.999").ToString() // 2020-08-05 13:14:15.999 +0800 CST +carbon.Parse("2020-08-05 13:14:15.999999").ToString() // 2020-08-05 13:14:15.999999 +0800 CST +carbon.Parse("2020-08-05 13:14:15.999999999").ToString() // 2020-08-05 13:14:15.999999999 +0800 CST + +carbon.Parse("2020-8-5T13:14:15+08:00").ToString() // 2020-08-05 13:14:15 +0800 CST +carbon.Parse("2020-8-05T13:14:15+08:00").ToString() // 2020-08-05 13:14:15 +0800 CST +carbon.Parse("2020-08-05T13:14:15+08:00").ToString() // 2020-08-05 13:14:15 +0800 CST +carbon.Parse("2020-08-05T13:14:15.999+08:00").ToString() // 2020-08-05 13:14:15.999 +0800 CST +carbon.Parse("2020-08-05T13:14:15.999999+08:00").ToString() // 2020-08-05 13:14:15.999999 +0800 CST +carbon.Parse("2020-08-05T13:14:15.999999999+08:00").ToString() // 2020-08-05 13:14:15.999999999 +0800 CST + +carbon.Parse("20200805").ToString() // 2020-08-05 00:00:00 +0800 CST +carbon.Parse("20200805131415").ToString() // 2020-08-05 13:14:15 +0800 CST +carbon.Parse("20200805131415.999").ToString() // 2020-08-05 13:14:15.999 +0800 CST +carbon.Parse("20200805131415.999999").ToString() // 2020-08-05 13:14:15.999999 +0800 CST +carbon.Parse("20200805131415.999999999").ToString() // 2020-08-05 13:14:15.999999999 +0800 CST +carbon.Parse("20200805131415.999+08:00").ToString() // 2020-08-05 13:14:15.999 +0800 CST +carbon.Parse("20200805131415.999999+08:00").ToString() // 2020-08-05 13:14:15.999999 +0800 CST +carbon.Parse("20200805131415.999999999+08:00").ToString() // 2020-08-05 13:14:15.999999999 +0800 CST +``` + +##### フォーマットして文字列を Carbon インスタンスにパース + +```go +carbon.ParseByFormat("2020|08|05 13|14|15", "Y|m|d H|i|s").ToDateTimeString() // 2020-08-05 13:14:15 +carbon.ParseByFormat("It is 2020-08-05 13:14:15", "\\I\\t \\i\\s Y-m-d H:i:s").ToDateTimeString() // 2020-08-05 13:14:15 +carbon.ParseByFormat("今天是 2020年08月05日13时14分15秒", "今天是 Y年m月d日H时i分s秒").ToDateTimeString() // 2020-08-05 13:14:15 +``` + +##### レイアウトし、文字列を Carbon インスタンスにパース + +```go +carbon.ParseByLayout("2020|08|05 13|14|15", "2006|01|02 15|04|05").ToDateTimeString() // 2020-08-05 13:14:15 +carbon.ParseByLayout("It is 2020-08-05 13:14:15", "It is 2006-01-02 15:04:05").ToDateTimeString() // 2020-08-05 13:14:15 +carbon.ParseByLayout("今天是 2020年08月05日13时14分15秒", "今天是 2006年01月02日15时04分05秒").ToDateTimeString() // 2020-08-05 13:14:15 +carbon.ParseByLayout("2020-08-05 13:14:15", "2006-01-02 15:04:05", carbon.Tokyo).ToDateTimeString() // 2020-08-05 14:14:15 +``` + +##### 境界 + +```go +// 世紀始め +carbon.Parse("2020-08-05 13:14:15").StartOfCentury().ToDateTimeString() // 2000-01-01 00:00:00 +// 世紀終わり +carbon.Parse("2020-08-05 13:14:15").EndOfCentury().ToDateTimeString() // 2999-12-31 23:59:59 + +// 十年紀始め +carbon.Parse("2020-08-05 13:14:15").StartOfDecade().ToDateTimeString() // 2020-01-01 00:00:00 +carbon.Parse("2021-08-05 13:14:15").StartOfDecade().ToDateTimeString() // 2020-01-01 00:00:00 +carbon.Parse("2029-08-05 13:14:15").StartOfDecade().ToDateTimeString() // 2020-01-01 00:00:00 +// 十年紀終わり +carbon.Parse("2020-08-05 13:14:15").EndOfDecade().ToDateTimeString() // 2029-12-31 23:59:59 +carbon.Parse("2021-08-05 13:14:15").EndOfDecade().ToDateTimeString() // 2029-12-31 23:59:59 +carbon.Parse("2029-08-05 13:14:15").EndOfDecade().ToDateTimeString() // 2029-12-31 23:59:59 + +// 今年始め +carbon.Parse("2020-08-05 13:14:15").StartOfYear().ToDateTimeString() // 2020-01-01 00:00:00 +// 今年終わり +carbon.Parse("2020-08-05 13:14:15").EndOfYear().ToDateTimeString() // 2020-12-31 23:59:59 + +// 四半期始め +carbon.Parse("2020-08-05 13:14:15").StartOfQuarter().ToDateTimeString() // 2020-07-01 00:00:00 +// 四半期終わり +carbon.Parse("2020-08-05 13:14:15").EndOfQuarter().ToDateTimeString() // 2020-09-30 23:59:59 + +// 月始め +carbon.Parse("2020-08-05 13:14:15").StartOfMonth().ToDateTimeString() // 2020-08-01 00:00:00 +// 月終わり +carbon.Parse("2020-08-05 13:14:15").EndOfMonth().ToDateTimeString() // 2020-08-31 23:59:59 + +// 周始め +carbon.Parse("2020-08-05 13:14:15").StartOfWeek().ToDateTimeString() // 2020-08-02 00:00:00 +carbon.Parse("2020-08-05 13:14:15").SetWeekStartsAt(carbon.Sunday).StartOfWeek().ToDateTimeString() // 2020-08-02 00:00:00 +carbon.Parse("2020-08-05 13:14:15").SetWeekStartsAt(carbon.Monday).StartOfWeek().ToDateTimeString() // 2020-08-03 00:00:00 +// 周終わり +carbon.Parse("2020-08-05 13:14:15").EndOfWeek().ToDateTimeString() // 2020-08-08 23:59:59 +carbon.Parse("2020-08-05 13:14:15").SetWeekStartsAt(carbon.Sunday).EndOfWeek().ToDateTimeString() // 2020-08-08 23:59:59 +carbon.Parse("2020-08-05 13:14:15").SetWeekStartsAt(carbon.Monday).EndOfWeek().ToDateTimeString() // 2020-08-09 23:59:59 + +// 日始め +carbon.Parse("2020-08-05 13:14:15").StartOfDay().ToDateTimeString() // 2020-08-05 00:00:00 +// 日終わり +carbon.Parse("2020-08-05 13:14:15").EndOfDay().ToDateTimeString() // 2020-08-05 23:59:59 + +// 時間始め +carbon.Parse("2020-08-05 13:14:15").StartOfHour().ToDateTimeString() // 2020-08-05 13:00:00 +// 時間終わり +carbon.Parse("2020-08-05 13:14:15").EndOfHour().ToDateTimeString() // 2020-08-05 13:59:59 + +// 分始め +carbon.Parse("2020-08-05 13:14:15").StartOfMinute().ToDateTimeString() // 2020-08-05 13:14:00 +// 分終わり +carbon.Parse("2020-08-05 13:14:15").EndOfMinute().ToDateTimeString() // 2020-08-05 13:14:59 + +// 秒始め +carbon.Parse("2020-08-05 13:14:15").StartOfSecond().ToString() // 2020-08-05 13:14:15 +0800 CST +// 秒終わり +carbon.Parse("2020-08-05 13:14:15").EndOfSecond().ToString() // 2020-08-05 13:14:15.999999999 +0800 CST +``` + +##### 大きな時間更新 + +```go +// 3世紀追加 +carbon.Parse("2020-02-29 13:14:15").AddCenturies(3).ToDateTimeString() // 2320-02-29 13:14:15 +// 3世紀追加(オーバーフローなし) +carbon.Parse("2020-02-29 13:14:15").AddCenturiesNoOverflow(3).ToDateTimeString() // 2320-02-29 13:14:15 +// 1世紀追加 +carbon.Parse("2020-02-29 13:14:15").AddCentury().ToDateTimeString() // 2120-02-29 13:14:15 +// 1世紀追加(オーバーフローなし) +carbon.Parse("2020-02-29 13:14:15").AddCenturyNoOverflow().ToDateTimeString() // 2120-02-29 13:14:15 +// 3世紀減らす +carbon.Parse("2020-02-29 13:14:15").SubCenturies(3).ToDateTimeString() // 1720-02-29 13:14:15 +// 3世紀減らす(オーバーフローなし) +carbon.Parse("2020-02-29 13:14:15").SubCenturiesNoOverflow(3).ToDateTimeString() // 1720-02-29 13:14:15 +// 1世紀減らす +carbon.Parse("2020-02-29 13:14:15").SubCentury().ToDateTimeString() // 1920-02-29 13:14:15 +// 1世紀減らす(オーバーフローなし) +carbon.Parse("2020-02-29 13:14:15").SubCenturyNoOverflow().ToDateTimeString() // 1920-02-29 13:14:15 + +// 30年紀追加 +carbon.Parse("2020-02-29 13:14:15").AddDecades(3).ToDateTimeString() // 2050-03-01 13:14:15 +// 30年紀追加(オーバーフローなし) +carbon.Parse("2020-02-29 13:14:15").AddDecadesNoOverflow(3).ToDateTimeString() // 2050-02-28 13:14:15 +// 10年紀追加 +carbon.Parse("2020-02-29 13:14:15").AddDecade().ToDateTimeString() // 2030-03-01 13:14:15 +// 10年紀追加(オーバーフローなし) +carbon.Parse("2020-02-29 13:14:15").AddDecadeNoOverflow().ToDateTimeString() // 2030-02-28 13:14:15 +// 30年紀減らす +carbon.Parse("2020-02-29 13:14:15").SubDecades(3).ToDateTimeString() // 1990-03-01 13:14:15 +// 30年紀減らす(オーバーフローなし) +carbon.Parse("2020-02-29 13:14:15").SubDecadesNoOverflow(3).ToDateTimeString() // 1990-02-28 13:14:15 +// 10年紀減らす +carbon.Parse("2020-02-29 13:14:15").SubDecade().ToDateTimeString() // 2010-03-01 13:14:15 +// 10年紀減らす(オーバーフローなし) +carbon.Parse("2020-02-29 13:14:15").SubDecadeNoOverflow().ToDateTimeString() // 2010-02-28 13:14:15 + +// 3年追加 +carbon.Parse("2020-02-29 13:14:15").AddYears(3).ToDateTimeString() // 2023-03-01 13:14:15 +// 3年追加(オーバーフローなし) +carbon.Parse("2020-02-29 13:14:15").AddYearsNoOverflow(3).ToDateTimeString() // 2023-02-28 13:14:15 +// 1年追加 +carbon.Parse("2020-02-29 13:14:15").AddYear().ToDateTimeString() // 2021-03-01 13:14:15 +// 1年追加追加(オーバーフローなし) +carbon.Parse("2020-02-29 13:14:15").AddYearNoOverflow().ToDateTimeString() // 2021-02-28 13:14:15 +// 3年減らす +carbon.Parse("2020-02-29 13:14:15").SubYears(3).ToDateTimeString() // 2017-03-01 13:14:15 +// 3年減らす(オーバーフローなし) +carbon.Parse("2020-02-29 13:14:15").SubYearsNoOverflow(3).ToDateTimeString() // 2017-02-28 13:14:15 +// 1年減らす +carbon.Parse("2020-02-29 13:14:15").SubYear().ToDateTimeString() // 2019-03-01 13:14:15 +// 1年減らす(オーバーフローなし) +carbon.Parse("2020-02-29 13:14:15").SubYearNoOverflow().ToDateTimeString() // 2019-02-28 13:14:15 + +// 3四半期追加 +carbon.Parse("2019-05-31 13:14:15").AddQuarters(3).ToDateTimeString() // 2020-03-02 13:14:15 +// 3四半期追加(オーバーフローなし) +carbon.Parse("2019-05-31 13:14:15").AddQuartersNoOverflow(3).ToDateTimeString() // 2020-02-29 13:14:15 +// 1四半期追加 +carbon.Parse("2019-11-30 13:14:15").AddQuarter().ToDateTimeString() // 2020-03-01 13:14:15 +// 1四半期追加(オーバーフローなし) +carbon.Parse("2019-11-30 13:14:15").AddQuarterNoOverflow().ToDateTimeString() // 2020-02-29 13:14:15 +// 3四半期減らす +carbon.Parse("2019-08-31 13:14:15").SubQuarters(3).ToDateTimeString() // 2019-03-03 13:14:15 +// 3四半期減らす(オーバーフローなし) +carbon.Parse("2019-08-31 13:14:15").SubQuartersNoOverflow(3).ToDateTimeString() // 2019-02-28 13:14:15 +// 1四半期減らす +carbon.Parse("2020-05-31 13:14:15").SubQuarter().ToDateTimeString() // 2020-03-02 13:14:15 +// 1四半期減らす(オーバーフローなし) +carbon.Parse("2020-05-31 13:14:15").SubQuarterNoOverflow().ToDateTimeString() // 2020-02-29 13:14:15 + +// 3ヶ月追加 +carbon.Parse("2020-02-29 13:14:15").AddMonths(3).ToDateTimeString() // 2020-05-29 13:14:15 +// 3ヶ月追加(オーバーフローなし) +carbon.Parse("2020-02-29 13:14:15").AddMonthsNoOverflow(3).ToDateTimeString() // 2020-05-29 13:14:15 +// 1ヶ月追加 +carbon.Parse("2020-01-31 13:14:15").AddMonth().ToDateTimeString() // 2020-03-02 13:14:15 +// 1ヶ月追加(オーバーフローなし) +carbon.Parse("2020-01-31 13:14:15").AddMonthNoOverflow().ToDateTimeString() // 2020-02-29 13:14:15 +// 3ヶ月減らす +carbon.Parse("2020-02-29 13:14:15").SubMonths(3).ToDateTimeString() // 2019-11-29 13:14:15 +// 3ヶ月減らす(オーバーフローなし) +carbon.Parse("2020-02-29 13:14:15").SubMonthsNoOverflow(3).ToDateTimeString() // 2019-11-29 13:14:15 +// 1ヶ月減らす +carbon.Parse("2020-03-31 13:14:15").SubMonth().ToDateTimeString() // 2020-03-02 13:14:15 +// 1か月減らす(オーバーフローなし) +carbon.Parse("2020-03-31 13:14:15").SubMonthNoOverflow().ToDateTimeString() // 2020-02-29 13:14:15 + +// 3週間追加 +carbon.Parse("2020-02-29 13:14:15").AddWeeks(3).ToDateTimeString() // 2020-03-21 13:14:15 +// 1週間追加 +carbon.Parse("2020-02-29 13:14:15").AddWeek().ToDateTimeString() // 2020-03-07 13:14:15 +// 3週間減らす +carbon.Parse("2020-02-29 13:14:15").SubWeeks(3).ToDateTimeString() // 2020-02-08 13:14:15 +// 1週間減らす +carbon.Parse("2020-02-29 13:14:15").SubWeek().ToDateTimeString() // 2020-02-22 13:14:15 + +// 3日追加 +carbon.Parse("2020-08-05 13:14:15").AddDays(3).ToDateTimeString() // 2020-08-08 13:14:15 +// 1日追加 +carbon.Parse("2020-08-05 13:14:15").AddDay().ToDateTimeString() // 2020-08-05 13:14:15 +// 3日減らす +carbon.Parse("2020-08-05 13:14:15").SubDays(3).ToDateTimeString() // 2020-08-02 13:14:15 +// 1日減らす +carbon.Parse("2020-08-05 13:14:15").SubDay().ToDateTimeString() // 2020-08-04 13:14:15 + +// 3時間追加 +carbon.Parse("2020-08-05 13:14:15").AddHours(3).ToDateTimeString() // 2020-08-05 16:14:15 +// 2時間半追加 +carbon.Parse("2020-08-05 13:14:15").AddDuration("2.5h").ToDateTimeString() // 2020-08-05 15:44:15 +carbon.Parse("2020-08-05 13:14:15").AddDuration("2h30m").ToDateTimeString() // 2020-08-05 15:44:15 +// 1時間追加 +carbon.Parse("2020-08-05 13:14:15").AddHour().ToDateTimeString() // 2020-08-05 14:14:15 +// 3時間減らす +carbon.Parse("2020-08-05 13:14:15").SubHours(3).ToDateTimeString() // 2020-08-05 10:14:15 +// 2時間半減らす +carbon.Parse("2020-08-05 13:14:15").SubDuration("2.5h").ToDateTimeString() // 2020-08-05 10:44:15 +carbon.Parse("2020-08-05 13:14:15").SubDuration("2h30m").ToDateTimeString() // 2020-08-05 10:44:15 +// 1時間減らす +carbon.Parse("2020-08-05 13:14:15").SubHour().ToDateTimeString() // 2020-08-05 12:14:15 + +// 3分追加 +carbon.Parse("2020-08-05 13:14:15").AddMinutes(3).ToDateTimeString() // 2020-08-05 13:17:15 +// 2分半追加 +carbon.Parse("2020-08-05 13:14:15").AddDuration("2.5m").ToDateTimeString() // 2020-08-05 13:16:45 +carbon.Parse("2020-08-05 13:14:15").AddDuration("2m30s").ToDateTimeString() // 2020-08-05 13:16:45 +// 1分追加 +carbon.Parse("2020-08-05 13:14:15").AddMinute().ToDateTimeString() // 2020-08-05 13:15:15 +// 3分減らす +carbon.Parse("2020-08-05 13:14:15").SubMinutes(3).ToDateTimeString() // 2020-08-05 13:11:15 +// 2分半減らす +carbon.Parse("2020-08-05 13:14:15").SubDuration("2.5m").ToDateTimeString() // 2020-08-05 13:11:45 +carbon.Parse("2020-08-05 13:14:15").SubDuration("2m30s").ToDateTimeString() // 2020-08-05 13:11:45 +// 1分減らす +carbon.Parse("2020-08-05 13:14:15").SubMinute().ToDateTimeString() // 2020-08-05 13:13:15 + +// 3秒追加 +carbon.Parse("2020-08-05 13:14:15").AddSeconds(3).ToDateTimeString() // 2020-08-05 13:14:18 +// 2秒半追加 +carbon.Parse("2020-08-05 13:14:15").AddDuration("2.5s").ToDateTimeString() // 2020-08-05 13:14:17 +// 1秒追加 +carbon.Parse("2020-08-05 13:14:15").AddSecond().ToDateTimeString() // 2020-08-05 13:14:16 +// 3秒減らす +carbon.Parse("2020-08-05 13:14:15").SubSeconds(3).ToDateTimeString() // 2020-08-05 13:14:12 +// 2秒半減らす +carbon.Parse("2020-08-05 13:14:15").SubDuration("2.5s").ToDateTimeString() // 2020-08-05 13:14:12 +// 1秒減らす +carbon.Parse("2020-08-05 13:14:15").SubSecond().ToDateTimeString() // 2020-08-05 13:14:14 + +// 3ミリ秒追加 +carbon.Parse("2020-08-05 13:14:15.222222222").AddMilliseconds(3).ToString() // 2020-08-05 13:14:15.225222222 +0800 CST +// 1ミリ秒追加 +carbon.Parse("2020-08-05 13:14:15.222222222").AddMillisecond().ToString() // 2020-08-05 13:14:15.223222222 +0800 CST +// 3ミリ秒減らす +carbon.Parse("2020-08-05 13:14:15.222222222").SubMilliseconds(3).ToString() // 2020-08-05 13:14:15.219222222 +0800 CST +// 1ミリ秒減らす +carbon.Parse("2020-08-05 13:14:15.222222222").SubMillisecond().ToString() // 2020-08-05 13:14:15.221222222 +0800 CST + +// 3マイクロ秒追加 +carbon.Parse("2020-08-05 13:14:15.222222222").AddMicroseconds(3).ToString() // 2020-08-05 13:14:15.222225222 +0800 CST +// 1マイクロ秒追加 +carbon.Parse("2020-08-05 13:14:15.222222222").AddMicrosecond().ToString() // 2020-08-05 13:14:15.222223222 +0800 CST +// 3マイクロ秒減らす +carbon.Parse("2020-08-05 13:14:15.222222222").SubMicroseconds(3).ToString() // 2020-08-05 13:14:15.222219222 +0800 CST +// 1マイクロ秒減らす +carbon.Parse("2020-08-05 13:14:15.222222222").SubMicrosecond().ToString() // 2020-08-05 13:14:15.222221222 +0800 CST + +// 3ナノ秒追加 +carbon.Parse("2020-08-05 13:14:15.222222222").AddNanoseconds(3).ToString() // 2020-08-05 13:14:15.222222225 +0800 CST +// 1ナノ秒追加 +carbon.Parse("2020-08-05 13:14:15.222222222").AddNanossecond().ToString() // 2020-08-05 13:14:15.222222223 +0800 CST +// 3ナノ秒減らす +carbon.Parse("2020-08-05 13:14:15.222222222").SubNanosseconds(3).ToString() // 2020-08-05 13:14:15.222222219 +0800 CST +// 1ナノ秒減らす +carbon.Parse("2020-08-05 13:14:15.222222222").SubNanossecond().ToString() // 2020-08-05 13:14:15.222222221 +0800 CST +``` + +##### 時間差分 + +```go +// 年差 +carbon.Parse("2021-08-05 13:14:15").DiffInYears(carbon.Parse("2020-08-05 13:14:15")) // -1 +// 年差(絶対値) +carbon.Parse("2021-08-05 13:14:15").DiffAbsInYears(carbon.Parse("2020-08-05 13:14:15")) // 1 + +// 月差 +carbon.Parse("2020-08-05 13:14:15").DiffInMonths(carbon.Parse("2020-07-05 13:14:15")) // -1 +// 月差(絶対値) +carbon.Parse("2020-08-05 13:14:15").DiffAbsInMonths(carbon.Parse("2020-07-05 13:14:15")) // 1 + +// 週差 +carbon.Parse("2020-08-05 13:14:15").DiffInWeeks(carbon.Parse("2020-07-28 13:14:15")) // -1 +// 週差(絶対値) +carbon.Parse("2020-08-05 13:14:15").DiffAbsInWeeks(carbon.Parse("2020-07-28 13:14:15")) // 1 + +// 日差 +carbon.Parse("2020-08-05 13:14:15").DiffInDays(carbon.Parse("2020-08-04 13:14:15")) // -1 +// 日差(絶対値) +carbon.Parse("2020-08-05 13:14:15").DiffAbsInDays(carbon.Parse("2020-08-04 13:14:15")) // 1 + +// 時間差 +carbon.Parse("2020-08-05 13:14:15").DiffInHours(carbon.Parse("2020-08-05 12:14:15")) // -1 +// 時間差(絶対値) +carbon.Parse("2020-08-05 13:14:15").DiffAbsInHours(carbon.Parse("2020-08-05 12:14:15")) // 1 + +// 分差 +carbon.Parse("2020-08-05 13:14:15").DiffInMinutes(carbon.Parse("2020-08-05 13:13:15")) // -1 +// 分差(絶対値) +carbon.Parse("2020-08-05 13:14:15").DiffAbsInMinutes(carbon.Parse("2020-08-05 13:13:15")) // 1 + +// 秒差 +carbon.Parse("2020-08-05 13:14:15").DiffInSeconds(carbon.Parse("2020-08-05 13:14:14")) // -1 +// 秒差(絶対値) +carbon.Parse("2020-08-05 13:14:15").DiffAbsInSeconds(carbon.Parse("2020-08-05 13:14:14")) // 1 + +// 時間差を文字列で返す +carbon.Now().DiffInString() // just now +carbon.Now().AddYearsNoOverflow(1).DiffInString() // -1 year +carbon.Now().SubYearsNoOverflow(1).DiffInString() // 1 year +// 時間差を文字列で返す(絶対値) +carbon.Now().DiffAbsInString(carbon.Now()) // just now +carbon.Now().AddYearsNoOverflow(1).DiffAbsInString(carbon.Now()) // 1 year +carbon.Now().SubYearsNoOverflow(1).DiffAbsInString(carbon.Now()) // 1 year + +// 継続時間差 +now := carbon.Now() +now.DiffInDuration(now).String() // 0s +now.AddHour().DiffInDuration(now).String() // 1h0m0s +now.SubHour().DiffInDuration(now).String() // -1h0m0s +// 継続時間差(絶対値) +now.DiffAbsInDuration(now).String() // 0s +now.AddHour().DiffAbsInDuration(now).String() // 1h0m0s +now.SubHour().DiffAbsInDuration(now).String() // 1h0m0s + +// 人が読みやすいフォーマットで時間差を取得 +carbon.Parse("2020-08-05 13:14:15").DiffForHumans() // just now +carbon.Parse("2019-08-05 13:14:15").DiffForHumans() // 1 year ago +carbon.Parse("2018-08-05 13:14:15").DiffForHumans() // 2 years ago +carbon.Parse("2021-08-05 13:14:15").DiffForHumans() // 1 year from now +carbon.Parse("2022-08-05 13:14:15").DiffForHumans() // 2 years from now + +carbon.Parse("2020-08-05 13:14:15").DiffForHumans(carbon.Now()) // 1 year before +carbon.Parse("2019-08-05 13:14:15").DiffForHumans(carbon.Now()) // 2 years before +carbon.Parse("2018-08-05 13:14:15").DiffForHumans(carbon.Now()) // 1 year after +carbon.Parse("2022-08-05 13:14:15").DiffForHumans(carbon.Now()) // 2 years after +``` + +##### 極值 + +```go +c0 := carbon.Parse("2023-04-01") +c1 := carbon.Parse("2023-03-28") +c2 := carbon.Parse("2023-04-16") +// 最近のCarbonインスタンスを返す +c0.Closest(c1, c2) // c1 +// 遠いCarbonインスタンスを返す +c0.Farthest(c1, c2) // c2 + +yesterday := carbon.Yesterday() +today := carbon.Now() +tomorrow := carbon.Tomorrow() +// 最大の Carbon インスタンスを返します +carbon.Max(yesterday, today, tomorrow) // tomorrow +// 最小の Carbon インスタンスを返します +carbon.Min(yesterday, today, tomorrow) // yesterday + +// Carbonの最大値を戻す +carbon.MaxCarbon().ToString() // 9999-12-31 23:59:59.999999999 +0000 UTC +// Carbonの最小値を戻す +carbon.MinCarbon().ToString() // -9998-01-01 00:00:00 +0000 UTC +``` + +##### 比較 + +```go +// 夏時間かどうか +carbon.Parse("").IsDST() // false +carbon.Parse("0").IsDST() // false +carbon.Parse("0000-00-00 00:00:00").IsDST() // false +carbon.Parse("0000-00-00").IsDST() // false +carbon.Parse("00:00:00").IsDST() // false +carbon.Parse("2023-01-01", "Australia/Brisbane").IsDST() // false +carbon.Parse("2023-01-01", "Australia/Sydney").IsDST() // true + +// ゼロ値の時間かどうか(0001-01-01 00:00:00 +0000 UTC) +carbon.Parse("").IsZero() // true +carbon.Parse("0").IsZero() // true +carbon.Parse("0000-00-00 00:00:00").IsZero() // true +carbon.Parse("0000-00-00").IsZero() // true +carbon.Parse("00:00:00").IsZero() // true +carbon.Parse("2020-08-05 00:00:00").IsZero() // false +carbon.Parse("2020-08-05").IsZero() // false +carbon.Parse("2020-08-05").SetTimezone("xxx").IsZero() // false + +// 有効な時間かどうか +carbon.Parse("").IsValid() // false +carbon.Parse("0").IsValid() // false +carbon.Parse("0000-00-00 00:00:00").IsValid() // false +carbon.Parse("0000-00-00").IsValid() // false +carbon.Parse("00:00:00").IsValid() // false +carbon.Parse("2020-08-05 00:00:00").IsValid() // true +carbon.Parse("2020-08-05").IsValid() // true +carbon.Parse("2020-08-05").SetTimezone("xxx").IsValid() // false + +// 無効な時間かどうか +carbon.Parse("").IsInvalid() // true +carbon.Parse("0").IsInvalid() // true +carbon.Parse("0000-00-00 00:00:00").IsInvalid() // true +carbon.Parse("0000-00-00").IsInvalid() // true +carbon.Parse("00:00:00").IsInvalid() // true +carbon.Parse("2020-08-05 00:00:00").IsInvalid() // false +carbon.Parse("2020-08-05").IsInvalid() // false +carbon.Parse("2020-08-05").SetTimezone("xxx").IsInvalid() // true + +// 午前かどうか +carbon.Parse("2020-08-05 00:00:00").IsAM() // true +carbon.Parse("2020-08-05 08:00:00").IsAM() // true +carbon.Parse("2020-08-05 12:00:00").IsAM() // false +carbon.Parse("2020-08-05 13:00:00").IsAM() // false +// 午後かどうか +carbon.Parse("2020-08-05 00:00:00").IsPM() // false +carbon.Parse("2020-08-05 08:00:00").IsPM() // false +carbon.Parse("2020-08-05 12:00:00").IsPM() // true +carbon.Parse("2020-08-05 13:00:00").IsPM() // true + +// 現在かどうか +carbon.Now().IsNow() // true +// 未来かどうか +carbon.Tomorrow().IsFuture() // true +// 過去かどうか +carbon.Yesterday().IsPast() // true + +// 閏年かどうか +carbon.Parse("2020-08-05 13:14:15").IsLeapYear() // true +// ISO8601で定められたLong Yearかどうか +carbon.Parse("2020-08-05 13:14:15").IsLongYear() // true + +// 1月かどうか +carbon.Parse("2020-08-05 13:14:15").IsJanuary() // false +// 2月かどうか +carbon.Parse("2020-08-05 13:14:15").IsFebruary() // false +// 3月かどうか +carbon.Parse("2020-08-05 13:14:15").IsMarch() // false +// 4月かどうか +carbon.Parse("2020-08-05 13:14:15").IsApril() // false +// 5月かどうか +carbon.Parse("2020-08-05 13:14:15").IsMay() // false +// 6月かどうか +carbon.Parse("2020-08-05 13:14:15").IsJune() // false +// 7月かどうか +carbon.Parse("2020-08-05 13:14:15").IsJuly() // false +// 8月かどうか +carbon.Parse("2020-08-05 13:14:15").IsAugust() // false +// 9月かどうか +carbon.Parse("2020-08-05 13:14:15").IsSeptember() // true +// 10月かどうか +carbon.Parse("2020-08-05 13:14:15").IsOctober() // false +// 11月かどうか +carbon.Parse("2020-08-05 13:14:15").IsNovember() // false +// 12月かどうか +carbon.Parse("2020-08-05 13:14:15").IsDecember() // false + +// 月曜日かどうか +carbon.Parse("2020-08-05 13:14:15").IsMonday() // false +// 火曜日かどうか +carbon.Parse("2020-08-05 13:14:15").IsTuesday() // true +// 水曜日かどうか +carbon.Parse("2020-08-05 13:14:15").IsWednesday() // false +// 木曜日かどうか +carbon.Parse("2020-08-05 13:14:15").IsThursday() // false +// 金曜日かどうか +carbon.Parse("2020-08-05 13:14:15").IsFriday() // false +// 土曜日かどうか +carbon.Parse("2020-08-05 13:14:15").IsSaturday() // false +// 日曜日かどうか +carbon.Parse("2020-08-05 13:14:15").IsSunday() // false + +// 平日かどうか +carbon.Parse("2020-08-05 13:14:15").IsWeekday() // false +// 週末かどうか +carbon.Parse("2020-08-05 13:14:15").IsWeekend() // true + +// 昨日かどうか +carbon.Parse("2020-08-04 13:14:15").IsYesterday() // true +carbon.Parse("2020-08-04 00:00:00").IsYesterday() // true +carbon.Parse("2020-08-04").IsYesterday() // true +// 今日かどうか +carbon.Parse("2020-08-05 13:14:15").IsToday() // true +carbon.Parse("2020-08-05 00:00:00").IsToday() // true +carbon.Parse("2020-08-05").IsToday() // true +// 明日かどうか +carbon.Parse("2020-08-06 13:14:15").IsTomorrow() // true +carbon.Parse("2020-08-06 00:00:00").IsTomorrow() // true +carbon.Parse("2020-08-06").IsTomorrow() // true + +// 同世紀かどうか +carbon.Parse("2020-08-05 13:14:15").IsSameCentury(carbon.Parse("3020-08-05 13:14:15")) // false +carbon.Parse("2020-08-05 13:14:15").IsSameCentury(carbon.Parse("2099-08-05 13:14:15")) // true +// 同十年紀かどうか +carbon.Parse("2020-08-05 13:14:15").IsSameDecade(carbon.Parse("2030-08-05 13:14:15")) // false +carbon.Parse("2020-08-05 13:14:15").IsSameDecade(carbon.Parse("2120-08-05 13:14:15")) // true +// 同年かどうか +carbon.Parse("2020-08-05 00:00:00").IsSameYear(carbon.Parse("2021-08-05 13:14:15")) // false +carbon.Parse("2020-01-01 00:00:00").IsSameYear(carbon.Parse("2020-12-31 13:14:15")) // true +// 同四半期かどうか +carbon.Parse("2020-08-05 00:00:00").IsSameQuarter(carbon.Parse("2020-09-05 13:14:15")) // false +carbon.Parse("2020-01-01 00:00:00").IsSameQuarter(carbon.Parse("2021-01-31 13:14:15")) // true +// 同月かどうか +carbon.Parse("2020-01-01 00:00:00").IsSameMonth(carbon.Parse("2021-01-31 13:14:15")) // false +carbon.Parse("2020-01-01 00:00:00").IsSameMonth(carbon.Parse("2020-01-31 13:14:15")) // true +// 同日かどうか +carbon.Parse("2020-08-05 13:14:15").IsSameDay(carbon.Parse("2021-08-05 13:14:15")) // false +carbon.Parse("2020-08-05 00:00:00").IsSameDay(carbon.Parse("2020-08-05 13:14:15")) // true +// 同時間かどうか +carbon.Parse("2020-08-05 13:14:15").IsSameHour(carbon.Parse("2021-08-05 13:14:15")) // false +carbon.Parse("2020-08-05 13:00:00").IsSameHour(carbon.Parse("2020-08-05 13:14:15")) // true +// 同分かどうか +carbon.Parse("2020-08-05 13:14:15").IsSameMinute(carbon.Parse("2021-08-05 13:14:15")) // false +carbon.Parse("2020-08-05 13:14:00").IsSameMinute(carbon.Parse("2020-08-05 13:14:15")) // true +// 同秒かどうか +carbon.Parse("2020-08-05 13:14:15").IsSameSecond(carbon.Parse("2021-08-05 13:14:15")) // false +carbon.Parse("2020-08-05 13:14:15").IsSameSecond(carbon.Parse("2020-08-05 13:14:15")) // true + +// 超過かどうか +carbon.Parse("2020-08-05 13:14:15").Gt(carbon.Parse("2020-08-04 13:14:15")) // true +carbon.Parse("2020-08-05 13:14:15").Gt(carbon.Parse("2020-08-05 13:14:15")) // false +carbon.Parse("2020-08-05 13:14:15").Compare(">", carbon.Parse("2020-08-04 13:14:15")) // true +carbon.Parse("2020-08-05 13:14:15").Compare(">", carbon.Parse("2020-08-05 13:14:15")) // false + +// 未満かどうか +carbon.Parse("2020-08-05 13:14:15").Lt(carbon.Parse("2020-08-06 13:14:15")) // true +carbon.Parse("2020-08-05 13:14:15").Lt(carbon.Parse("2020-08-05 13:14:15")) // false +carbon.Parse("2020-08-05 13:14:15").Compare("<", carbon.Parse("2020-08-06 13:14:15")) // true +carbon.Parse("2020-08-05 13:14:15").Compare("<", carbon.Parse("2020-08-05 13:14:15")) // false + +// 等しいかどうか +carbon.Parse("2020-08-05 13:14:15").Eq(carbon.Parse("2020-08-05 13:14:15")) // true +carbon.Parse("2020-08-05 13:14:15").Eq(carbon.Parse("2020-08-05 13:14:00")) // false +carbon.Parse("2020-08-05 13:14:15").Compare("=", carbon.Parse("2020-08-05 13:14:15")) // true +carbon.Parse("2020-08-05 13:14:15").Compare("=", carbon.Parse("2020-08-05 13:14:00")) // false + +// と等しくないかどうか +carbon.Parse("2020-08-05 13:14:15").Ne(carbon.Parse("2020-08-06 13:14:15")) // true +carbon.Parse("2020-08-05 13:14:15").Ne(carbon.Parse("2020-08-05 13:14:15")) // false +carbon.Parse("2020-08-05 13:14:15").Compare("!=", carbon.Parse("2020-08-06 13:14:15")) // true +carbon.Parse("2020-08-05 13:14:15").Compare("<>", carbon.Parse("2020-08-05 13:14:15")) // false + +// 以上かどうか +carbon.Parse("2020-08-05 13:14:15").Gte(carbon.Parse("2020-08-04 13:14:15")) // true +carbon.Parse("2020-08-05 13:14:15").Gte(carbon.Parse("2020-08-05 13:14:15")) // true +carbon.Parse("2020-08-05 13:14:15").Compare(">=", carbon.Parse("2020-08-04 13:14:15")) // true +carbon.Parse("2020-08-05 13:14:15").Compare(">=", carbon.Parse("2020-08-05 13:14:15")) // true + +// 以下かどうか +carbon.Parse("2020-08-05 13:14:15").Lte(carbon.Parse("2020-08-06 13:14:15")) // true +carbon.Parse("2020-08-05 13:14:15").Lte(carbon.Parse("2020-08-05 13:14:15")) // true +carbon.Parse("2020-08-05 13:14:15").Compare("<=", carbon.Parse("2020-08-06 13:14:15")) // true +carbon.Parse("2020-08-05 13:14:15").Compare("<=", carbon.Parse("2020-08-05 13:14:15")) // true + +// 二つの Carbon インスタンスの間に含まれているか(開始時間、終了時間を含まない) +carbon.Parse("2020-08-05 13:14:15").Between(carbon.Parse("2020-08-05 13:14:15"), carbon.Parse("2020-08-06 13:14:15")) // false +carbon.Parse("2020-08-05 13:14:15").Between(carbon.Parse("2020-08-04 13:14:15"), carbon.Parse("2020-08-06 13:14:15")) // true + +// 二つの Carbon インスタンスの間に含まれているか(開始時間を含む) +carbon.Parse("2020-08-05 13:14:15").BetweenIncludedStart(carbon.Parse("2020-08-05 13:14:15"), carbon.Parse("2020-08-06 13:14:15")) // true +carbon.Parse("2020-08-05 13:14:15").BetweenIncludedStart(carbon.Parse("2020-08-04 13:14:15"), carbon.Parse("2020-08-06 13:14:15")) // true + +// 二つの Carbon インスタンスの間に含まれているか(終了時間を含む) +carbon.Parse("2020-08-05 13:14:15").BetweenIncludedEnd(carbon.Parse("2020-08-04 13:14:15"), carbon.Parse("2020-08-05 13:14:15")) // true +carbon.Parse("2020-08-05 13:14:15").BetweenIncludedEnd(carbon.Parse("2020-08-04 13:14:15"), carbon.Parse("2020-08-06 13:14:15")) // true + +// 二つの Carbon インスタンスの間に含まれているか(開始時間、終了時間を含む) +carbon.Parse("2020-08-05 13:14:15").BetweenIncludedBoth(carbon.Parse("2020-08-05 13:14:15"), carbon.Parse("2020-08-06 13:14:15")) // true +carbon.Parse("2020-08-05 13:14:15").BetweenIncludedBoth(carbon.Parse("2020-08-04 13:14:15"), carbon.Parse("2020-08-05 13:14:15")) // true +``` + +> 長年の定義については、読んでください https://en.wikipedia.org/wiki/ISO_8601#Week_dates + +##### 設定 + +```go +// タイムゾーンを設定 +carbon.SetTimezone(carbon.PRC).Now().ToDateTimeString() // 2020-08-05 13:14:15 +carbon.SetTimezone(carbon.Tokyo).Now().ToDateTimeString() // 2020-08-05 14:14:15 +carbon.SetTimezone(carbon.Tokyo).Now().SetTimezone(carbon.PRC).ToDateTimeString() // 2020-08-05 12:14:15 + +// リージョンを設定 +utc, _ := time.LoadLocation(carbon.UTC) +carbon.SetLocation(utc).Now().ToDateTimeString() // 2022-06-28 09:25:38 +tokyo, _ := time.LoadLocation(carbon.Tokyo) +carbon.SetLocation(tokyo).Now().ToDateTimeString() // 2022-06-28 18:25:38 + +// ロケールを設定 +carbon.Parse("2020-07-05 13:14:15").SetLocale("en").DiffForHumans()) // 1 month ago +carbon.Parse("2020-07-05 13:14:15").SetLocale("jp").DiffForHumans() // 1 ヶ月前 + +// 年月日時分秒を設定する +carbon.Parse("2020-01-01").SetDateTime(2019, 2, 2, 13, 14, 15).ToString() // 2019-02-02 13:14:15 +0800 CST +carbon.Parse("2020-01-01").SetDateTime(2019, 2, 31, 13, 14, 15).ToString() // 2019-03-03 13:14:15 +0800 CST +// 年月日時分秒ミリ秒を設定する +carbon.Parse("2020-01-01").SetDateTimeMilli(2019, 2, 2, 13, 14, 15, 999).ToString() // 2019-02-02 13:14:15.999 +0800 CST +carbon.Parse("2020-01-01").SetDateTimeMilli(2019, 2, 31, 13, 14, 15, 999).ToString() // 2019-03-03 13:14:15.999 +0800 CST +// 年月日時分秒微秒を設定する +carbon.Parse("2020-01-01").SetDateTimeMicro(2019, 2, 2, 13, 14, 15, 999999).ToString() // 2019-02-02 13:14:15.999999 +0800 CST +carbon.Parse("2020-01-01").SetDateTimeMicro(2019, 2, 31, 13, 14, 15, 999999).ToString() // 2019-03-03 13:14:15.999999 +0800 CST +// 年月日時分秒ナノ秒を設定する +carbon.Parse("2020-01-01").SetDateTimeNano(2019, 2, 2, 13, 14, 15, 999999999).ToString() // 2019-02-02 13:14:15.999999999 +0800 CST +carbon.Parse("2020-01-01").SetDateTimeNano(2019, 2, 31, 13, 14, 15, 999999999).ToString() // 2019-03-03 13:14:15.999999999 +0800 CST + +// 年月日を設定する +carbon.Parse("2020-01-01").SetDate(2019, 2, 2).ToString() // 2019-02-02 00:00:00 +0800 CST +carbon.Parse("2020-01-01").SetDate(2019, 2, 31).ToString() // 2019-03-03 00:00:00 +0800 CST +// 年月日ミリ秒を設定する +carbon.Parse("2020-01-01").SetDateMilli(2019, 2, 2, 999).ToString() // 2019-02-02 00:00:00.999 +0800 CST +carbon.Parse("2020-01-01").SetDateMilli(2019, 2, 31, 999).ToString() // 2019-03-03 00:00:00.999 +0800 CST +// 年月日微秒を設定する +carbon.Parse("2020-01-01").SetDateMicro(2019, 2, 2, 999999).ToString() // 2019-02-02 00:00:00.999999 +0800 CST +carbon.Parse("2020-01-01").SetDateMicro(2019, 2, 31, 999999).ToString() // 2019-03-03 00:00:00.999999 +0800 CST +// 年月日ナノ秒を設定する +carbon.Parse("2020-01-01").SetDateNano(2019, 2, 2, 999999999).ToString() // 2019-02-02 00:00:00.999999999 +0800 CST +carbon.Parse("2020-01-01").SetDateNano(2019, 2, 31, 999999999).ToString() // 2019-03-03 00:00:00.999999999 +0800 CST + +// 時分秒を設定する +carbon.Parse("2020-01-01").SetTime(13, 14, 15).ToString() // 2020-01-01 13:14:15 +0800 CST +carbon.Parse("2020-01-01").SetTime(13, 14, 90).ToString() // 2020-01-01 13:15:30 +0800 CST +// 時分秒ミリ秒を設定する +carbon.Parse("2020-01-01").SetTimeMilli(13, 14, 15, 999).ToString() // 2020-01-01 13:14:15.999 +0800 CST +carbon.Parse("2020-01-01").SetTimeMilli(13, 14, 90, 999).ToString() // 2020-01-01 13:15:30.999 +0800 CST +// 時分秒微秒を設定する +carbon.Parse("2020-01-01").SetTimeMicro(13, 14, 15, 999999).ToString() // 2020-01-01 13:14:15.999999 +0800 CST +carbon.Parse("2020-01-01").SetTimeMicro(13, 14, 90, 999999).ToString() // 2020-01-01 13:15:30.999999 +0800 CST +// 時分秒ナノ秒を設定する +carbon.Parse("2020-01-01").SetTimeNano(13, 14, 15, 999999999).ToString() // 2020-01-01 13:14:15.999999999 +0800 CST +carbon.Parse("2020-01-01").SetTimeNano(13, 14, 90, 999999999).ToString() // 2020-01-01 13:15:30.999999999 +0800 CST + +// 年を設定する +carbon.Parse("2020-02-29").SetYear(2021).ToDateString() // 2021-03-01 +// 年を設定する(オーバーフローなし) +carbon.Parse("2020-02-29").SetYearNoOverflow(2021).ToDateString() // 2021-02-28 + +// 月を設定する +carbon.Parse("2020-01-31").SetMonth(2).ToDateString() // 2020-03-02 +// 月を設定する(オーバーフローなし) +carbon.Parse("2020-01-31").SetMonthNoOverflow(2).ToDateString() // 2020-02-29 + +// 週の開始日を設定する +carbon.Parse("2020-08-02").SetWeekStartsAt(carbon.Sunday).Week() // 0 +carbon.Parse("2020-08-02").SetWeekStartsAt(carbon.Monday).Week() // 6 + +// 日数を設定する +carbon.Parse("2019-08-05").SetDay(31).ToDateString() // 2020-08-31 +carbon.Parse("2020-02-01").SetDay(31).ToDateString() // 2020-03-02 + +// 時間を設定する +carbon.Parse("2020-08-05 13:14:15").SetHour(10).ToDateTimeString() // 2020-08-05 10:14:15 +carbon.Parse("2020-08-05 13:14:15").SetHour(24).ToDateTimeString() // 2020-08-06 00:14:15 + +// 分を設定する +carbon.Parse("2020-08-05 13:14:15").SetMinute(10).ToDateTimeString() // 2020-08-05 13:10:15 +carbon.Parse("2020-08-05 13:14:15").SetMinute(60).ToDateTimeString() // 2020-08-05 14:00:15 + +// 秒を設定する +carbon.Parse("2020-08-05 13:14:15").SetSecond(10).ToDateTimeString() // 2020-08-05 13:14:10 +carbon.Parse("2020-08-05 13:14:15").SetSecond(60).ToDateTimeString() // 2020-08-05 13:15:00 + +// ミリ秒を設定 +carbon.Parse("2020-08-05 13:14:15").SetMillisecond(100).Millisecond() // 100 +carbon.Parse("2020-08-05 13:14:15").SetMillisecond(999).Millisecond() // 999 + +// 微妙に設定 +carbon.Parse("2020-08-05 13:14:15").SetMicrosecond(100000).Microsecond() // 100000 +carbon.Parse("2020-08-05 13:14:15").SetMicrosecond(999999).Microsecond() // 999999 + +// ナノ秒を設定する +carbon.Parse("2020-08-05 13:14:15").SetNanosecond(100000000).Nanosecond() // 100000000 +carbon.Parse("2020-08-05 13:14:15").SetNanosecond(999999999).Nanosecond() // 999999999 +``` + +##### 取得 + +```go +// 年の総日数を取得 +carbon.Parse("2019-08-05 13:14:15").DaysInYear() // 365 +carbon.Parse("2020-08-05 13:14:15").DaysInYear() // 366 +// 月の総日数を取得 +carbon.Parse("2020-02-01 13:14:15").DaysInMonth() // 29 +carbon.Parse("2020-04-01 13:14:15").DaysInMonth() // 30 +carbon.Parse("2020-08-01 13:14:15").DaysInMonth() // 31 + +// 年間積算日を取得 +carbon.Parse("2020-08-05 13:14:15").DayOfYear() // 218 +// 本年の何週目かを取得 +carbon.Parse("2019-12-31 13:14:15").WeekOfYear() // 1 +carbon.Parse("2020-08-05 13:14:15").WeekOfYear() // 32 +// 今月の何日目(1から)かを取得 +carbon.Parse("2020-08-05 13:14:15").DayOfMonth() // 5 +// 今月の何週目かを取得 +carbon.Parse("2020-08-05 13:14:15").WeekOfMonth() // 1 +// 今週の何日目かを取得(1が月曜日) +carbon.Parse("2020-08-05 13:14:15").DayOfWeek() // 3 + +// 現在の年月日時分秒を取得 +carbon.Parse("2020-08-05 13:14:15").DateTime() // 2020,8,5,13,14,15 +// 現在の年月日時分秒ミリ秒を取得 +carbon.Parse("2020-08-05 13:14:15").DateTimeMilli() // 2020,8,5,13,14,15,999 +// 現在の年月日時分秒マイクロ秒を取得 +carbon.Parse("2020-08-05 13:14:15").DateTimeMicro() // 2020,8,5,13,14,15,999999 +// 現在の年月日時分秒ナノ秒を取得 +carbon.Parse("2020-08-05 13:14:15").DateTimeNano() // 2020,8,5,13,14,15,999999999 + +// 現在の年月日を取得 +carbon.Parse("2020-08-05 13:14:15.999999999").Date() // 2020,8,5 +// 現在の年月日ミリ秒を取得 +carbon.Parse("2020-08-05 13:14:15.999999999").DateMilli() // 2020,8,5,999 +// 現在の年月日マイクロ秒を取得 +carbon.Parse("2020-08-05 13:14:15.999999999").DateMicro() // 2020,8,5,999999 +// 現在の年月日ナノ秒を取得 +carbon.Parse("2020-08-05 13:14:15.999999999").DateNano() // 2020,8,5,999999999 + +// 現在の時分秒を取得 +carbon.Parse("2020-08-05 13:14:15.999999999").Time() // 13,14,15 +// 現在の時分秒ミリ秒を取得 +carbon.Parse("2020-08-05 13:14:15.999999999").TimeMilli() // 13,14,15,999 +// 現在の時分秒マイクロ秒を取得 +carbon.Parse("2020-08-05 13:14:15.999999999").TimeMicro() // 13,14,15,999999 +// 現在の時分秒ナノ秒を取得 +carbon.Parse("2020-08-05 13:14:15.999999999").TimeNano() // 13,14,15,999999999 + +// 現在の世紀を取得 +carbon.Parse("2020-08-05 13:14:15").Century() // 21 +// 現在の十年紀を取得 +carbon.Parse("2019-08-05 13:14:15").Decade() // 10 +carbon.Parse("2021-08-05 13:14:15").Decade() // 20 +// 現在の年を取得 +carbon.Parse("2020-08-05 13:14:15").Year() // 2020 +// 現在の四半期を取得 +carbon.Parse("2020-08-05 13:14:15").Quarter() // 3 +// 現在の月を取得 +carbon.Parse("2020-08-05 13:14:15").Month() // 8 +// 現在の週を取得(0から開始) +carbon.Parse("2020-08-02 13:14:15").Week() // 0 +carbon.Parse("2020-08-02").SetWeekStartsAt(carbon.Sunday).Week() // 0 +carbon.Parse("2020-08-02").SetWeekStartsAt(carbon.Monday).Week() // 6 +// 現在の日数を取得 +carbon.Parse("2020-08-05 13:14:15").Day() // 5 +// 現在の時間を取得 +carbon.Parse("2020-08-05 13:14:15").Hour() // 13 +// 現在の分を取得 +carbon.Parse("2020-08-05 13:14:15").Minute() // 14 +// 現在の秒を取得 +carbon.Parse("2020-08-05 13:14:15").Second() // 15 +// 現在のミリ秒を取得 +carbon.Parse("2020-08-05 13:14:15.999").Millisecond() // 999 +// 現在のマイクロ秒を取得 +carbon.Parse("2020-08-05 13:14:15.999").Microsecond() // 999000 +// 現在のナノ秒を取得 +carbon.Parse("2020-08-05 13:14:15.999").Nanosecond() // 999000000 + +// 秒タイムスタンプを取得 +carbon.Parse("2020-08-05 13:14:15").Timestamp() // 1596604455 +// ミリ秒のタイムスタンプを取得 +carbon.Parse("2020-08-05 13:14:15").TimestampMilli() // 1596604455000 +// マイクロ秒タイムスタンプを取得 +carbon.Parse("2020-08-05 13:14:15").TimestampMicro() // 1596604455000000 +// ナノ秒タイムスタンプを取得 +carbon.Parse("2020-08-05 13:14:15").TimestampNano() // 1596604455000000000 + +// タイムゾーン名を取得 +carbon.SetTimezone(carbon.PRC).Timezone() // CST +carbon.SetTimezone(carbon.Tokyo).Timezone() // JST + +// ロケーション名を取得 +carbon.SetTimezone(carbon.PRC).Location() // PRC +carbon.SetTimezone(carbon.Tokyo).Location() // Asia/Tokyo + +// UTCタイムゾーンオフセットの秒を取得 +carbon.SetTimezone(carbon.PRC).Offset() // 28800 +carbon.SetTimezone(carbon.Tokyo).Offset() // 32400 + +// ロケール名を取得 +carbon.Now().Locale() // en +carbon.Now().SetLocale("zh-CN").Locale() // zh-CN + +// 星座を取得 +carbon.Now().Constellation() // Leo +carbon.Now().SetLocale("en").Constellation() // Leo +carbon.Now().SetLocale("jp").Constellation() // しし座 + +// 季節を取得 +carbon.Now().Season() // Summer +carbon.Now().SetLocale("en").Season() // Summer +carbon.Now().SetLocale("jp").Season() // 夏 + +// 年齢を取得 +carbon.Parse("2002-01-01 13:14:15").Age() // 17 +carbon.Parse("2002-12-31 13:14:15").Age() // 18 +``` + +##### 出力 + +```go +// datetimeを文字列出力 +carbon.Parse("2020-08-05 13:14:15").ToDateTimeString() // 2020-08-05 13:14:15 +// ミリ秒を含むdatetimeを文字列出力 +carbon.Parse("2020-08-05T13:14:15.999999999+08:00").ToDateTimeMilliString() // 2020-08-05 13:14:15.999 +// マイクロ秒を含むdatetimeを文字列出力 +carbon.Parse("2020-08-05T13:14:15.999999999+08:00").ToDateTimeMicroString() // 2020-08-05 13:14:15.999999 +// ナノ秒を含むdatetimeを文字列出力 +carbon.Parse("2020-08-05T13:14:15.999999999+08:00").ToDateTimeNanoString() // 2020-08-05 13:14:15.999999999 + +// datetimeを略語形式の文字列出力 +carbon.Parse("2020-08-05T13:14:15.999999999+08:00").ToShortDateTimeString() // 20200805131415 +// ミリ秒を含むdatetimeを略語形式の文字列出力 +carbon.Parse("2020-08-05T13:14:15.999999999+08:00").ToShortDateTimeMilliString() // 20200805131415.999 +// マイクロ秒を含むdatetimeを略語形式の文字列出力 +carbon.Parse("2020-08-05T13:14:15.999999999+08:00").ToShortDateTimeMicroString() // 20200805131415.999999 +// ナノ秒を含むdatetimeを略語形式の文字列出力 +carbon.Parse("2020-08-05T13:14:15.999999999+08:00").ToShortDateTimeNanoString() // 20200805131415.999999999 + +// dateを文字列出力 +carbon.Parse("2020-08-05 13:14:15.999999999").ToDateString() // 2020-08-05 +// ミリ秒を含むdateを文字列出力 +carbon.Parse("2020-08-05 13:14:15.999999999").ToDateMilliString() // 2020-08-05.999 +// マイクロ秒を含むdateを文字列出力 +carbon.Parse("2020-08-05 13:14:15.999999999").ToDateMicroString() // 2020-08-05.999999 +// ナノ秒を含むdateを文字列出力 +carbon.Parse("2020-08-05 13:14:15.999999999").ToDateNanoString() // 2020-08-05.999999999 + +// dateを略語形式の文字列出力 +carbon.Parse("2020-08-05 13:14:15.999999999").ToShortDateString() // 20200805 +// ミリ秒を含むdateを略語形式の文字列出力 +carbon.Parse("2020-08-05 13:14:15.999999999").ToShortDateMilliString() // 20200805.999 +// マイクロ秒を含むdateを略語形式の文字列出力 +carbon.Parse("2020-08-05 13:14:15.999999999").ToShortDateMicroString() // 20200805.999999 +// ナノ秒を含むdateを略語形式の文字列出力 +carbon.Parse("2020-08-05 13:14:15.999999999").ToShortDateNanoString() // 20200805.999999999 + +// 時間を文字列出力 +carbon.Parse("2020-08-05 13:14:15.999999999").ToTimeString() // 13:14:15 +// ミリ秒を含む時間を文字列出力 +carbon.Parse("2020-08-05 13:14:15.999999999").ToTimeMilliString() // 13:14:15.999 +// マイクロ秒を含む時間を文字列出力 +carbon.Parse("2020-08-05 13:14:15.999999999").ToTimeMicroString() // 13:14:15.999999 +// ナノ秒を含む時間を文字列出力 +carbon.Parse("2020-08-05 13:14:15.999999999").ToTimeNanoString() // 13:14:15.999999999 + +// 時間を略語形式の出力 +carbon.Parse("2020-08-05 13:14:15.999999999").ToShortTimeString() // 131415 +// ミリ秒を含む時間を略語形式の出力 +carbon.Parse("2020-08-05 13:14:15.999999999").ToShortTimeMilliString() // 131415.999 +// マイクロ秒を含む時間を略語形式の出力 +carbon.Parse("2020-08-05 13:14:15.999999999").ToShortTimeMicroString() // 131415.999999 +// ナノ秒を含む時間を略語形式の出力 +carbon.Parse("2020-08-05 13:14:15.999999999").ToShortTimeNanoString() // 131415.999999999 + +// Ansic フォーマット文字列の出力 +carbon.Parse("2020-08-05 13:14:15").ToAnsicString() // Wed Aug 5 13:14:15 2020 +// Atom フォーマット文字列の出力 +carbon.Parse("2020-08-05 13:14:15").ToAtomString() // 2020-08-05T13:14:15+08:00 +// UnixDate フォーマット文字列の出力 +carbon.Parse("2020-08-05 13:14:15").ToUnixDateString() // Wed Aug 5 13:14:15 CST 2020 +// RubyDate フォーマット文字列の出力 +carbon.Parse("2020-08-05 13:14:15").ToRubyDateString() // Wed Aug 05 13:14:15 +0800 2020 +// Kitchen フォーマット文字列の出力 +carbon.Parse("2020-08-05 13:14:15").ToKitchenString() // 1:14PM +// Cookie フォーマット文字列の出力 +carbon.Parse("2020-08-05 13:14:15").ToCookieString() // Wednesday, 05-Aug-2020 13:14:15 CST +// DayDateTime フォーマット文字列の出力 +carbon.Parse("2020-08-05 13:14:15").ToDayDateTimeString() // Wed, Aug 5, 2020 1:14 PM +// RSS フォーマット文字列の出力 +carbon.Parse("2020-08-05 13:14:15").ToRssString() // Wed, 05 Aug 2020 13:14:15 +0800 +// W3C フォーマット文字列の出力 +carbon.Parse("2020-08-05 13:14:15").ToW3cString() // 2020-08-05T13:14:15+08:00 + +// ISO8601 フォーマット文字列の出力 +carbon.Parse("2020-08-05 13:14:15.999999999").ToIso8601String() // 2020-08-05T13:14:15+08:00 +// ISO8601Milli フォーマット文字列の出力 +carbon.Parse("2020-08-05 13:14:15.999999999").ToIso8601MilliString() // 2020-08-05T13:14:15.999+08:00 +// ISO8601Micro フォーマット文字列の出力 +carbon.Parse("2020-08-05 13:14:15.999999999").ToIso8601MicroString() // 2020-08-05T13:14:15.999999+08:00 +// ISO8601Nano フォーマット文字列の出力 +carbon.Parse("2020-08-05 13:14:15.999999999").ToIso8601NanoString() // 2020-08-05T13:14:15.999999999+08:00 +// ISO8601Zulu フォーマット文字列の出力 +carbon.Parse("2020-08-05 13:14:15.999999999").ToIso8601ZuluString() // 2020-08-05T13:14:15Z +// ISO8601ZuluMilli フォーマット文字列の出力 +carbon.Parse("2020-08-05 13:14:15.999999999").ToIso8601ZuluMilliString() // 2020-08-05T13:14:15.999Z +// ISO8601ZuluMicro フォーマット文字列の出力 +carbon.Parse("2020-08-05 13:14:15.999999999").ToIso8601ZuluMicroString() // 2020-08-05T13:14:15.999999Z +// ISO8601ZuluNano フォーマット文字列の出力 +carbon.Parse("2020-08-05 13:14:15.999999999").ToIso8601ZuluNanoString() // 2020-08-05T13:14:15.999999999Z + +// RFC822 フォーマット文字列の出力 +carbon.Parse("2020-08-05 13:14:15").ToRfc822String() // 05 Aug 20 13:14 CST +// RFC822Z フォーマット文字列の出力 +carbon.Parse("2020-08-05 13:14:15").ToRfc822zString() // 05 Aug 20 13:14 +0800 +// RFC850 フォーマット文字列の出力 +carbon.Parse("2020-08-05 13:14:15").ToRfc850String() // Wednesday, 05-Aug-20 13:14:15 CST +// RFC1036 フォーマット文字列の出力 +carbon.Parse("2020-08-05 13:14:15").ToRfc1036String() // Wed, 05 Aug 20 13:14:15 +0800 +// RFC1123 フォーマット文字列の出力 +carbon.Parse("2020-08-05 13:14:15").ToRfc1123String() // Wed, 05 Aug 2020 13:14:15 CST +// RFC1123Z フォーマット文字列の出力 +carbon.Parse("2020-08-05 13:14:15").ToRfc1123zString() // Wed, 05 Aug 2020 13:14:15 +0800 +// RFC2822 フォーマット文字列の出力 +carbon.Parse("2020-08-05 13:14:15").ToRfc2822String() // Wed, 05 Aug 2020 13:14:15 +0800 +// RFC7231 フォーマット文字列の出力 +carbon.Parse("2020-08-05 13:14:15").ToRfc7231String() // Wed, 05 Aug 2020 13:14:15 GMT + +// RFC3339 フォーマット文字列の出力 +carbon.Parse("2020-08-05T13:14:15.999999999+08:00").ToRfc3339String() // 2020-08-05T13:14:15+08:00 +// RFC3339 フォーマット文字列の出力(ミリ秒を含む) +carbon.Parse("2020-08-05T13:14:15.999999999+08:00").ToRfc3339MilliString() // 2020-08-05T13:14:15.999+08:00 +// RFC3339 フォーマット文字列の出力(マイクロ秒を含む) +carbon.Parse("2020-08-05T13:14:15.999999999+08:00").ToRfc3339MicroString() // 2020-08-05T13:14:15.999999+08:00 +// RFC3339 フォーマット文字列の出力(ナノ秒を含む) +carbon.Parse("2020-08-05T13:14:15.999999999+08:00").ToRfc3339NanoString() // 2020-08-05T13:14:15.999999999+08:00 + +// 日付時間文字列の出力 +fmt.Printf("%s", carbon.Parse("2020-08-05 13:14:15")) // 2020-08-05 13:14:15 + +// "2006-01-02 15:04:05.999999999 -0700 MST" フォーマット文字列の出力 +carbon.Parse("2020-08-05 13:14:15").ToString() // 2020-08-05 13:14:15.999999 +0800 CST + +// "Jan 2, 2006" フォーマット文字列の出力 +carbon.Parse("2020-08-05 13:14:15").ToFormattedDateString() // Aug 5, 2020 +// "Mon, Jan 2, 2006" フォーマット文字列の出力 +carbon.Parse("2020-08-05 13:14:15").ToFormattedDayDateString() // Wed, Aug 5, 2020 + +// レイアウトを指定する文字列の出力 +carbon.Parse("2020-08-05 13:14:15").Layout(carbon.ISO8601Layout) // 2020-08-05T13:14:15+08:00 +carbon.Parse("2020-08-05 13:14:15").Layout("20060102150405") // 20200805131415 +carbon.Parse("2020-08-05 13:14:15").Layout("2006年01月02日 15时04分05秒") // 2020年08月05日 13时14分15秒 +carbon.Parse("2020-08-05 13:14:15").Layout("It is 2006-01-02 15:04:05") // It is 2020-08-05 13:14:15 + +// 指定されたフォーマットの文字列の出力 +carbon.Parse("2020-08-05 13:14:15").Format("YmdHis") // 20200805131415 +carbon.Parse("2020-08-05 13:14:15").Format("Y年m月d日 H时i分s秒") // 2020年08月05日 13时14分15秒 +carbon.Parse("2020-08-05 13:14:15").Format("l jS \\o\\f F Y h:i:s A") // Wednesday 5th of August 2020 01:14:15 PM +carbon.Parse("2020-08-05 13:14:15").Format("\\I\\t \\i\\s Y-m-d H:i:s") // It is 2020-08-05 13:14:15 +``` + +> もっとフォーマットした出力記号は付録を見てください 書式設定記号表 + +##### 星座 + +```go +// 星座を取得 +carbon.Parse("2020-08-05 13:14:15").Constellation() // Leo + +// おひつじ座かどうか +carbon.Parse("2020-08-05 13:14:15").IsAries() // false +// おうし座かどうか +carbon.Parse("2020-08-05 13:14:15").IsTaurus() // false +// ふたご座かどうか +carbon.Parse("2020-08-05 13:14:15").IsGemini() // false +// かに座かどうか +carbon.Parse("2020-08-05 13:14:15").IsCancer() // false +// しし座かどうか +carbon.Parse("2020-08-05 13:14:15").IsLeo() // true +// おとめ座かどうか +carbon.Parse("2020-08-05 13:14:15").IsVirgo() // false +// てんびん座かどうか +carbon.Parse("2020-08-05 13:14:15").IsLibra() // false +// さそり座かどうか +carbon.Parse("2020-08-05 13:14:15").IsScorpio() // false +// いて座かどうか +carbon.Parse("2020-08-05 13:14:15").IsSagittarius() // false +// やぎ座かどうか +carbon.Parse("2020-08-05 13:14:15").IsCapricorn() // false +// みずがめ座かどうか +carbon.Parse("2020-08-05 13:14:15").IsAquarius() // false +// うお座かどうか +carbon.Parse("2020-08-05 13:14:15").IsPisces() // false +``` + +##### 季節 + +> 気象区分によると、3-5月は春で、6-8月は夏で、9-11月は秋で、12-2月は冬です + +```go +// 季節を取得 +carbon.Parse("2020-08-05 13:14:15").Season() // Summer + +// この季節の開始日 +carbon.Parse("2020-08-05 13:14:15").StartOfSeason().ToDateTimeString() // 2020-06-01 00:00:00 +// この季節の最終日 +carbon.Parse("2020-08-05 13:14:15").EndOfSeason().ToDateTimeString() // 2020-08-31 23:59:59 + +// 春かどうか +carbon.Parse("2020-08-05 13:14:15").IsSpring() // false +// 夏かどうか +carbon.Parse("2020-08-05 13:14:15").IsSummer() // true +// 秋かどうか +carbon.Parse("2020-08-05 13:14:15").IsAutumn() // false +// 冬かどうか +carbon.Parse("2020-08-05 13:14:15").IsWinter() // false +``` + +##### JSON + +```go +type Person struct { + Name string `json:"name"` + Age int `json:"age"` + Birthday0 carbon.Carbon `json:"birthday0"` + Birthday1 carbon.DateTime `json:"birthday1"` + Birthday2 carbon.DateTimeMilli `json:"birthday2"` + Birthday3 carbon.DateTimeMicro `json:"birthday3"` + Birthday4 carbon.DateTimeNano `json:"birthday4"` + GraduatedAt1 carbon.Date `json:"graduated_at1"` + GraduatedAt2 carbon.DateMilli `json:"graduated_at2"` + GraduatedAt3 carbon.DateMicro `json:"graduated_at3"` + GraduatedAt4 carbon.DateNano `json:"graduated_at4"` + OperatedAt1 carbon.Time `json:"operated_at1"` + OperatedAt2 carbon.TimeMilli `json:"operated_at2"` + OperatedAt3 carbon.TimeMicro `json:"operated_at3"` + OperatedAt4 carbon.TimeNano `json:"operated_at4"` + CreatedAt1 carbon.Timestamp `json:"created_at1"` + CreatedAt2 carbon.TimestampMilli `json:"created_at2"` + CreatedAt3 carbon.TimestampMicro `json:"created_at3"` + CreatedAt4 carbon.TimestampNano `json:"created_at4"` +} + +person := Person { + Name: "gouguoyin", + Age: 18, + Birthday0: carbon.Now().SubYears(18), + Birthday1: carbon.NewDateTime(carbon.Now().SubYears(18)), + Birthday2: carbon.NewDateTimeMilli(carbon.Now().SubYears(18)), + Birthday3: carbon.NewDateTimeMicro(carbon.Now().SubYears(18)), + Birthday4: carbon.NewDateTimeNano(carbon.Now().SubYears(18)), + GraduatedAt1: carbon.NewDate(carbon.Now()), + GraduatedAt2: carbon.NewDateMilli(carbon.Now()), + GraduatedAt3: carbon.NewDateMicro(carbon.Now()), + GraduatedAt4: carbon.NewDateNano(carbon.Now()), + OperatedAt1: carbon.NewTime(carbon.Now()), + OperatedAt2: carbon.NewTimeMilli(carbon.Now()), + OperatedAt3: carbon.NewTimeMicro(carbon.Now()), + OperatedAt4: carbon.NewTimeNano(carbon.Now()), + CreatedAt1: carbon.NewTimestamp(carbon.Now()), + CreatedAt2: carbon.NewTimestampMilli(carbon.Now()), + CreatedAt3: carbon.NewTimestampMicro(carbon.Now()), + CreatedAt4: carbon.NewTimestampNano(carbon.Now()), +} + +data, err := json.Marshal(&person) +if err != nil { + // エラー処理... + log.Fatal(err) +} +fmt.Printf("%s", data) +// 出力 +{ + "name": "gouguoyin", + "age": 18, + "birthday0": "2003-07-16 13:14:15", + "birthday1": "2003-07-16 13:14:15", + "birthday2": "2003-07-16 13:14:15.999", + "birthday3": "2003-07-16 13:14:15.999999", + "birthday4": "2003-07-16 13:14:15.999999999", + "graduated_at1": "2020-08-05", + "graduated_at2": "2020-08-05.999", + "graduated_at3": "2020-08-05.999999", + "graduated_at4": "2020-08-05.999999999", + "operated_at1": "13:14:15", + "operated_at2": "13:14:15.999", + "operated_at3": "13:14:15.999999", + "operated_at4": "13:14:15.999999999", + "created_at1": 1596604455, + "created_at2": 1596604455999, + "created_at3": 1596604455999999, + "created_at4": 1596604455999999999 +} + +err := json.Unmarshal([]byte(data), &person) +if err != nil { + // エラー処理... + log.Fatal(err) +} + +person.Birthday0.String() // 2003-07-16 13:14:15 +person.Birthday1.String() // 2003-07-16 13:14:15 +person.Birthday2.String() // 2003-07-16 13:14:15.999 +person.Birthday3.String() // 2003-07-16 13:14:15.999999 +person.Birthday4.String() // 2003-07-16 13:14:15.999999999 + +person.GraduatedAt1.String() // 2020-08-05 +person.GraduatedAt2.String() // 2020-08-05.999 +person.GraduatedAt3.String() // 2020-08-05.999999 +person.GraduatedAt4.String() // 2020-08-05.999999999 + +person.OperatedAt1.String() // 13:14:15 +person.OperatedAt2.String() // 13:14:15.999 +person.OperatedAt3.String() // 13:14:15.999999 +person.OperatedAt4.String() // 13:14:15.999999999 + +person.CreatedAt1.String() // "1596604455" +person.CreatedAt2.String() // "1596604455999" +person.CreatedAt3.String() // "1596604455999999" +person.CreatedAt4.String() // "1596604455999999999" + +person.CreatedAt1.Int64() // 1596604455 +person.CreatedAt2.Int64() // 1596604455999 +person.CreatedAt3.Int64() // 1596604455999999 +person.CreatedAt4.Int64() // 1596604455999999999 +``` + +##### カレンダー + +現在サポートされているカレンダー + +* [儒略の日/簡略化儒略の日](./calendar/julian/README.jp.md "儒略日/简化儒略日") +* [中国の旧暦](./calendar/lunar/README.jp.md "中国の旧暦") +* [ペルシャ暦/イラン暦](./calendar/persian/README.jp.md "ペルシャ暦/イラン暦") + +##### i18n + +現在サポートされている言語 + +* [简体中国語(zh-CN)](./lang/zh-CN.json "简体中国語"):[gouguoyin](https://github.com/gouguoyin "gouguoyin") に翻訳 +* [繁体中国語(zh-TW)](./lang/zh-TW.json "繁体中国語"):[gouguoyin](https://github.com/gouguoyin "gouguoyin") に翻訳 +* [英語(en)](./lang/en.json "英語"):[gouguoyin](https://github.com/gouguoyin "gouguoyin") に翻訳 +* [日本語(jp)](./lang/jp.json "日本語"):[gouguoyin](https://github.com/gouguoyin "gouguoyin") に翻訳 +* [韓国語(kr)](./lang/kr.json "韓国語"):[benzammour](https://github.com/benzammour "benzammour") に翻訳 +* [ドイツ語(de)](./lang/de.json "ドイツ語"):[benzammour](https://github.com/benzammour "benzammour") に翻訳 +* [スペイン語(es)](./lang/es.json "スペイン語"):[hgisinger](https://github.com/hgisinger "hgisinger") に翻訳 +* [トルコ語(tr)](./lang/tr.json "トルコ語"):[emresenyuva](https://github.com/emresenyuva "emresenyuva") に翻訳 +* [ポルトガル語(pt)](./lang/pt.json "ポルトガル語"):[felipear89](https://github.com/felipear89 "felipear89") に翻訳 +* [ロシア語(ru)](./lang/ru.json "ロシア語"):[zemlyak](https://github.com/zemlyak "zemlyak") に翻訳 +* [ウクライナ語(uk)](./lang/uk.json "ウクライナ語"):[open-git](https://github.com/open-git "open-git") に翻訳 +* [ルーマニア語(ro)](./lang/ro.json "ルーマニア語"): [DrOctavius](https://github.com/DrOctavius "DrOctavius") に翻訳 +* [インドネシア語(id)](./lang/id.json "インドネシア語"): [justpoypoy](https://github.com/justpoypoy "justpoypoy") に翻訳 +* [イタリア語(it)](./lang/it.json "イタリア語"): [nicoloHevelop](https://github.com/hollowaykeanho "nicoloHevelop") に翻訳 +* [マレーシアバハマ語(ms-MY)](./lang/ms-MY.json "マレーシアバハマ語"): [hollowaykeanho](https://github.com/hollowaykeanho "hollowaykeanho") に翻訳 +* [フランス語(fr)](./lang/fr.json "フランス語"): [hollowaykeanho](https://github.com/hollowaykeanho "hollowaykeanho") に翻訳 +* [タイ語(th)](./lang/th.json "タイ語"): [izcream](https://github.com/izcream "izcream") に翻訳 +* [スウェーデン語(se)](./lang/se.json "スウェーデン語"): [jwanglof](https://github.com/jwanglof "jwanglof") に翻訳 +* [ペルシア語(fa)](./lang/fa.json "ペルシア語"): [Iranian](https://github.com/Iranian "Iranian") に翻訳 +* [ポーランド語(nl)](./lang/nl.json "ポーランド語"): [RemcoE33](https://github.com/RemcoE33 "RemcoE33") に翻訳 +* [ベトナム語(vi)](./lang/vi.json "ベトナム語"): [culy247](https://github.com/culy247 "culy247") に翻訳 +* [ヒンディー語(hi)](./lang/hi.json "ヒンディー語"): [chauhan17nitin](https://github.com/chauhan17nitin "chauhan17nitin") に翻訳 +* [ポーランド語(pl)](./lang/pl.json "ポーランド語"): [gouguoyin](https://github.com/gouguoyin "gouguoyin") に翻訳 +* [ブルガリア語(bg)](./lang/bg.json "ブルガリア語"): [yuksbg](https://github.com/yuksbg "yuksbg") に翻訳 +* [アラビア語(ar)](./lang/ar.json "アラビア語"): [zumoshi](https://github.com/zumoshi "zumoshi") に翻訳 +* [ハンガリー語(hu)](./lang/hu.json "ハンガリー語"): [kenlas](https://github.com/kenlas "kenlas") に翻訳 +* [デンマーク語(dk)](./lang/dk.json "デンマーク語"): [Munk91](https://github.com/Munk91 "Munk91") に翻訳 + +現在サポートされている方法 + +* `Constellation()`:星座を取得,例えば `おひつじ座` +* `Season()`:シーズンを取得,例えば `春` +* `DiffForHumans()`:人が読みやすい形の時間差を取得します,例えば `1時間前` +* `ToMonthString()`:月文字列の出力,例えば `いちがつ` +* `ToShortMonthString()`:略語月文字列の出力,例えば `1がつ` +* `ToWeekString()`:週文字列の出力,例えば `日曜日` +* `ToShortWeekString()`:略語週文字列の出力,例えば `日` + +###### エリアの設定 + +```go +lang := carbon.NewLanguage() +lang.SetLocale("jp") + +c := carbon.SetLanguage(lang) +if c.Error != nil { + // エラー処理 + log.Fatal(c.Error) +} + +c.Now().AddHours(1).DiffForHumans() // 1 時間後 +c.Now().AddHours(1).ToMonthString() // はちがつ +c.Now().AddHours(1).ToShortMonthString() // 8がつ +c.Now().AddHours(1).ToWeekString() // 日曜日 +c.Now().AddHours(1).ToShortWeekString() // 日 +c.Now().AddHours(1).Constellation() // しし座 +c.Now().AddHours(1).Season() // 夏 +``` + +###### 翻訳リソースの一部を書き換える(残りはまだ指定された `locale` ファイルの内容によって翻訳されます) + +```go +lang := carbon.NewLanguage() + +resources := map[string]string { + "hour": "%dh", +} +lang.SetLocale("en").SetResources(resources) + +c := carbon.SetLanguage(lang) +if c.Error != nil { + // エラー処理 + log.Fatal(c.Error) +} + +c.Now().AddYears(1).DiffForHumans() // 1 year from now +c.Now().AddHours(1).DiffForHumans() // 1h from now +c.Now().ToMonthString() // August +c.Now().ToShortMonthString() // Aug +c.Now().ToWeekString() // Tuesday +c.Now().ToShortWeekString() // Tue +c.Now().Constellation() // Leo +c.Now().Season() // Summer +``` + +###### すべての翻訳リソースを書き換える + +```go +lang := carbon.NewLanguage() +resources := map[string]string { + "months": "january|february|march|april|may|june|july|august|september|october|november|december", + "short_months": "jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec", + "weeks": "sunday|monday|tuesday|wednesday|thursday|friday|saturday", + "short_weeks": "sun|mon|tue|wed|thu|fri|sat", + "seasons": "spring|summer|autumn|winter", + "constellations": "aries|taurus|gemini|cancer|leo|virgo|libra|scorpio|sagittarius|capricornus|aquarius|pisce", + "year": "1 yr|%d yrs", + "month": "1 mo|%d mos", + "week": "%dw", + "day": "%dd", + "hour": "%dh", + "minute": "%dm", + "second": "%ds", + "now": "just now", + "ago": "%s ago", + "from_now": "in %s", + "before": "%s before", + "after": "%s after", +} +lang.SetResources(resources) + +c := carbon.SetLanguage(lang) +c.Now().AddYears(1).DiffForHumans() // in 1 yr +c.Now().AddHours(1).DiffForHumans() // in 1h +c.Now().ToMonthString() // august +c.Now().ToShortMonthString() // aug +c.Now().ToWeekString() // tuesday +c.Now().ToShortWeekString() // tue +c.Now().Constellation() // leo +c.Now().Season() // summer +``` + +##### テスト + +```go +c := carbon.SetTimezone(carbon.UTC) + +c.Now().ToDateString() // 2023-12-27 +c.Now().IsSetTestNow() // false + +c.SetTestNow(carbon.Parse("2020-08-05")) +c.Now().ToDateString() // 2020-08-05 +c.Now().IsSetTestNow() // true + +c.UnSetTestNow() +c.Now().ToDateString() // 2023-12-27 +c.Now().IsSetTestNow() // false +``` + +##### エラー処理 + +> 複数のエラーが発生した場合は最初のエラーだけを返します。前のエラーは削除された後に次のエラーに戻ります + +```go +c := carbon.SetTimezone("xxx").Parse("2020-08-05") +if c.Error != nil { + // エラー処理... + log.Fatal(c.Error) +} +// 出力 +invalid timezone "xxx", please see the file "$GOROOT/lib/time/zoneinfo.zip" for all valid timezones +``` + +#### 付録 + +##### 書式設定記号表 + +| 記号 | 説明 | 長さ | 範囲 | 例 | +| :------------: | :------------: |:------:|:----------------:| :------------: | +| d | 月の日(2桁でパディング) | 2 | 01-31 | 02 | +| D | 略語の曜日 | 3 | Mon-Sun | Mon | +| j | 月の日(パディングしない) | - | 1-31 | 2 | +| S | 何日目の英語の略語の接尾語,普通はjと協力して使います | 2 | st/nd/rd/th | th | +| l | 曜日 | - | Monday-Sunday | Monday | +| F | 月 | - | January-December | January | +| m | 月(2桁でパディング) | 2 | 01-12 | 01 | +| M | 略語の月 | 3 | Jan-Dec | Jan | +| n | 月(パディングしない) | - | 1-12 | 1 | +| Y | 年 | 4 | 0000-9999 | 2006 | +| y | 年(下2桁) | 2 | 00-99 | 06 | +| a | 小文字の午前と午後 | 2 | am/pm | pm | +| A | 大文字の午前と午後 | 2 | AM/PM | PM | +| g | 時間, 12時間のフォーマット | - | 1-12 | 3 | +| G | 時間, 24時間のフォーマット | - | 0-23 | 15 | +| h | 時間, 12時間のフォーマット | 2 | 00-11 | 03 | +| H | 時間, 24時間のフォーマット | 2 | 00-23 | 15 | +| i | 分 | 2 | 01-59 | 04 | +| s | 秒 | 2 | 01-59 | 05 | +| O | グリニッジとの時間差の時間数 | - | - | -0700 | +| P | グリニッジと時間の差の時間数, 時間と分の間にコロンあり | - | - | -07:00 | +| T | タイムゾーンの略語 | - | - | MST | +| W | ISO8601 フォーマットの数字は年の中の第何週(2桁でパディング) | 2 | 1-52 | 01 | +| N | ISO8601 フォーマットの数字は曜日(2桁でパディング) | 2 | 01-07 | 02 | +| L | うるう年かどうか, うるう年が1であれば, 0 | 1 | 0-1 | 0 | +| U | 秒タイムスタンプ | - | - | 1596604455 | +| V | ミリ秒のタイムスタンプ | - | - | 1596604455666 | +| X | マイクロ秒タイムスタンプ | - | - | 1596604455666666 | +| Z | ナノ秒タイムスタンプ | - | - | 1596604455666666666 | +| v | ミリ秒 | - | 1-999 | 999 | +| u | マイクロ秒| - | 1-999999 | 999999 | +| x | ナノ秒 | - | 1-999999999 | 999999999 | +| w | 数字表示の曜日 | 1 | 0-6 | 1 | +| t | 月の総日数 | 2 | 28-31 | 31 | +| z | 年間積算日 | - | 1-365 | 2 | +| e | リージョン | - | - | America/New_York | +| Q | 四半期 | 1 | 1-4 | 1 | +| C | 世紀 | - | 0-99 | 21 | + +#### FAQ + +1、v1とv2のバージョンの違いは何ですか? +> APIのv1バージョンとv2バージョンに違いはありませんが `language.go` +> での翻訳リソースファイルの実装は異なります。v1は、サードパーティの拡張ライブラリ [packr](https://github.com/gobuffalo/packr) によって実装されています,v2は、 `golang1.16` +> の後に組み込みの標準ライブラリ [embed](https://pkg.go.dev/embed) によって実装されています。goバージョンが1.16より大きい場合は、v2バージョンを使用することをお勧めします。それ以外の場合は、v1バージョンを使用する必要があります。 + +#### 参考 + +* [briannesbitt/carbon](https://github.com/briannesbitt/Carbon) +* [nodatime/nodatime](https://github.com/nodatime/nodatime) +* [jinzhu/now](https://github.com/jinzhu/now) +* [goframe/gtime](https://github.com/gogf/gf/tree/master/os/gtime) +* [jodaOrg/joda-time](https://github.com/jodaOrg/joda-time) +* [arrow-py/arrow](https://github.com/arrow-py/arrow) +* [moment/moment](https://github.com/moment/moment) +* [iamkun/dayjs](https://github.com/iamkun/dayjs) + +#### コントリビューター +`Carbon` に貢献してくれた以下のすべてに感謝します: + + + +#### スポンサー + +`Carbon` は非営利のオープンソースプロジェクトです,`Carbon` をサポートしたい場合は、開発者のために [コーヒーを1杯購入](https://opencollective.com/go-carbon) できます + +#### 謝辞 + +`Carbon` は無料の JetBrains オープンソースライセンスを取得しました,これに感謝します + +JetBrains diff --git a/vendor/github.com/dromara/carbon/v2/README.md b/vendor/github.com/dromara/carbon/v2/README.md new file mode 100644 index 000000000..8c717e3a7 --- /dev/null +++ b/vendor/github.com/dromara/carbon/v2/README.md @@ -0,0 +1,1561 @@ +# Carbon + +[![Carbon Release](https://img.shields.io/github/release/dromara/carbon.svg)](https://github.com/dromara/carbon/releases) +[![Go Test](https://github.com/dromara/carbon/actions/workflows/test.yml/badge.svg)](https://github.com/dromara/carbon/actions) +[![Go Report Card](https://goreportcard.com/badge/github.com/dromara/carbon/v2)](https://goreportcard.com/report/github.com/dromara/carbon/v2) +[![Go Coverage](https://codecov.io/gh/dromara/carbon/branch/master/graph/badge.svg)](https://codecov.io/gh/dromara/carbon) +[![Carbon Doc](https://img.shields.io/badge/go.dev-reference-brightgreen?logo=go&logoColor=white&style=flat)](https://pkg.go.dev/github.com/dromara/carbon/v2) +[![License](https://img.shields.io/github/license/dromara/carbon)](https://github.com/dromara/carbon/blob/master/LICENSE) + +English | [简体中文](README.cn.md) | [日本語](README.jp.md) + +#### Introduction + +A simple, semantic and developer-friendly golang package for time, has been included +by [awesome-go](https://github.com/avelino/awesome-go#date-and-time "awesome-go") + +#### Repository + +[github.com/dromara/carbon](https://github.com/dromara/carbon "github.com/dromara/carbon") + +[gitee.com/dromara/carbon](https://gitee.com/dromara/carbon "gitee.com/dromara/carbon") + +[gitcode.com/dromara/carbon](https://gitcode.com/dromara/carbon "gitcode.com/dromara/carbon") + +#### Installation + +##### go version >= 1.17 + +```go +// By github +go get -u github.com/dromara/carbon/v2 +import "github.com/dromara/carbon/v2" + +// By gitee +go get -u gitee.com/dromara/carbon/v2 +import "gitee.com/dromara/carbon/v2" + +// By gitcode +go get -u gitcode.com/dromara/carbon/v2 +import "gitee.com/dromara/gitcode/v2" +``` + +`Carbon` was donated to the [dromara](https://dromara.org/ "dromara") organization, the repository url has changed. If the previous repository used was `golang-module/carbon`, please replace the original repository with the new repository in `go.mod`, or execute the following command + +```go +go mod edit -replace github.com/golang-module/carbon/v2=github.com/dromara/carbon/v2 +``` + +#### Usage and example + +> Assuming the current time is 2020-08-05 13:14:15.999999999 +0800 CST + +##### Set globally default values + +```go +carbon.SetDefault(carbon.Default{ + Layout: carbon.DateTimeLayout, + Timezone: carbon.UTC, + WeekStartsAt: carbon.Sunday, + Locale: "en", // value range: translate file name in the lang directory, excluding file suffix +}) +``` +> Suggest setting in the entry file such as `main.go` + +##### Convert between `Carbon` and `time.Time` + +```go +// Convert standard Time.time to Carbon +carbon.CreateFromStdTime(time.Now()) +// Convert Carbon to standard Time.time +carbon.Now().StdTime() +``` + +##### Yesterday, today and tomorrow + +```go +// Return datetime of today +fmt.Printf("%s", carbon.Now()) // 2020-08-05 13:14:15 +carbon.Now().String() // 2020-08-05 13:14:15 +carbon.Now().ToString() // 2020-08-05 13:14:15 +0800 CST +carbon.Now().ToDateTimeString() // 2020-08-05 13:14:15 +// Return date of today +carbon.Now().ToDateString() // 2020-08-05 +// Return time of today +carbon.Now().ToTimeString() // 13:14:15 +// Return datetime of today in a given timezone +carbon.Now(Carbon.NewYork).ToDateTimeString() // 2020-08-05 14:14:15 +// Return timestamp with second of today +carbon.Now().Timestamp() // 1596604455 +// Return timestamp with millisecond of today +carbon.Now().TimestampMilli() // 1596604455999 +// Return timestamp with microsecond of today +carbon.Now().TimestampMicro() // 1596604455999999 +// Return timestamp with nanosecond of today +carbon.Now().TimestampNano() // 1596604455999999999 + +// Return datetime of yesterday +fmt.Printf("%s", carbon.Yesterday()) // 2020-08-04 13:14:15 +carbon.Yesterday().String() // 2020-08-04 13:14:15 +carbon.Yesterday().ToString() // 2020-08-04 13:14:15 +0800 CST +carbon.Yesterday().ToDateTimeString() // 2020-08-04 13:14:15 +// Return date of yesterday +carbon.Yesterday().ToDateString() // 2020-08-04 +// Return time of yesterday +carbon.Yesterday().ToTimeString() // 13:14:15 +// Return datetime of yesterday on a given day +carbon.Parse("2021-01-28 13:14:15").Yesterday().ToDateTimeString() // 2021-01-27 13:14:15 +// Return datetime of yesterday in a given timezone +carbon.Yesterday(Carbon.NewYork).ToDateTimeString() // 2020-08-04 14:14:15 +// Return timestamp with second of yesterday +carbon.Yesterday().Timestamp() // 1596518055 +// Return timestamp with millisecond of yesterday +carbon.Yesterday().TimestampMilli() // 1596518055999 +// Return timestamp with microsecond of yesterday +carbon.Yesterday().TimestampMicro() // 1596518055999999 +// Return timestamp with nanosecond of yesterday +carbon.Yesterday().TimestampNano() // 1596518055999999999 + +// Return datetime of tomorrow +fmt.Printf("%s", carbon.Tomorrow()) // 2020-08-06 13:14:15 +carbon.Tomorrow().String() // 2020-08-06 13:14:15 +carbon.Tomorrow().ToString() // 2020-08-06 13:14:15 +0800 CST +carbon.Tomorrow().ToDateTimeString() // 2020-08-06 13:14:15 +// Return date of tomorrow +carbon.Tomorrow().ToDateString() // 2020-08-06 +// Return time of tomorrow +carbon.Tomorrow().ToTimeString() // 13:14:15 +// Return datetime of tomorrow on a given day +carbon.Parse("2021-01-28 13:14:15").Tomorrow().ToDateTimeString() // 2021-01-29 13:14:15 +// Return datetime of tomorrow in a given timezone +carbon.Tomorrow(Carbon.NewYork).ToDateTimeString() // 2020-08-06 14:14:15 +// Return timestamp with second of tomorrow +carbon.Tomorrow().Timestamp() // 1596690855 +// Return timestamp with millisecond of tomorrow +carbon.Tomorrow().TimestampMilli() // 1596690855999 +// Return timestamp with microsecond of tomorrow +carbon.Tomorrow().TimestampMicro() // 1596690855999999 +// Return timestamp with nanosecond of tomorrow +carbon.Tomorrow().TimestampNano() // 1596690855999999999 +``` + +##### Create a `Carbon` instance + +```go +// Create a Carbon instance from a given timestamp with second +carbon.CreateFromTimestamp(-1).ToString() // 1970-01-01 07:59:59 +0800 CST +carbon.CreateFromTimestamp(0).ToString() // 1970-01-01 08:00:00 +0800 CST +carbon.CreateFromTimestamp(1).ToString() // 1970-01-01 08:00:01 +0800 CST +carbon.CreateFromTimestamp(1649735755).ToString() // 2022-04-12 11:55:55 +0800 CST +// Create a Carbon instance from a given timestamp with millisecond +carbon.CreateFromTimestampMilli(1649735755981).ToString() // 2022-04-12 11:55:55.981 +0800 CST +// Create a Carbon instance from a given timestamp with microsecond +carbon.CreateFromTimestampMicro(1649735755981566).ToString() // 2022-04-12 11:55:55.981566 +0800 CST +// Create a Carbon instance from a given timestamp with nanosecond +carbon.CreateFromTimestampNano(1649735755981566000).ToString() // 2022-04-12 11:55:55.981566 +0800 CST + +// Create a Carbon instance from a given date and time +carbon.CreateFromDateTime(2020, 8, 5, 13, 14, 15).ToString() // 2020-08-05 13:14:15 +0800 CST +// Create a Carbon instance from a given date and time with millisecond +carbon.CreateFromDateTimeMilli(2020, 8, 5, 13, 14, 15, 999).ToString() // 2020-08-05 13:14:15.999 +0800 CST +// Create a Carbon instance from a given date and time with microsecond +carbon.CreateFromDateTimeMicro(2020, 8, 5, 13, 14, 15, 999999).ToString() // 2020-08-05 13:14:15.999999 +0800 CST +// Create a Carbon instance from a given date and time with nanosecond +carbon.CreateFromDateTimeNano(2020, 8, 5, 13, 14, 15, 999999999).ToString() // 2020-08-05 13:14:15.999999999 +0800 CST + +// Create a Carbon instance from a given year, month and day +carbon.CreateFromDate(2020, 8, 5).ToString() // 2020-08-05 00:00:00 +0800 CST +// Create a Carbon instance from a given year, month and day with millisecond +carbon.CreateFromDateMilli(2020, 8, 5, 999).ToString() // 2020-08-05 00:00:00.999 +0800 CST +// Create a Carbon instance from a given year, month and day with microsecond +carbon.CreateFromDateMicro(2020, 8, 5, 999999).ToString() // 2020-08-05 00:00:00.999999 +0800 CST +// Create a Carbon instance from a given year, month and day with nanosecond +carbon.CreateFromDateNano(2020, 8, 5, 999999999).ToString() // 2020-08-05 00:00:00.999999999 +0800 CST + +// Create a Carbon instance from a given hour, minute and second +carbon.CreateFromTime(13, 14, 15).ToString() // 2020-08-05 13:14:15 +0800 CST +// Create a Carbon instance from a given hour, minute and second with millisecond +carbon.CreateFromTimeMilli(13, 14, 15, 999).ToString() // 2020-08-05 13:14:15.999 +0800 CST +// Create a Carbon instance from a given hour, minute and second with microsecond +carbon.CreateFromTimeMicro(13, 14, 15, 999999).ToString() // 2020-08-05 13:14:15.999999 +0800 CST +// Create a Carbon instance from a given hour, minute and second with nanosecond +carbon.CreateFromTimeNano(13, 14, 15, 999999999).ToString() // 2020-08-05 13:14:15.999999999 +0800 CST +``` + +##### Parse a time string as a `Carbon` instance + +```go +carbon.Parse("").ToDateTimeString() // empty string +carbon.Parse("0").ToDateTimeString() // empty string +carbon.Parse("00:00:00").ToDateTimeString() // empty string +carbon.Parse("0000-00-00").ToDateTimeString() // empty string +carbon.Parse("0000-00-00 00:00:00").ToDateTimeString() // empty string + +carbon.Parse("now").ToString() // 2020-08-05 13:14:15 +0800 CST +carbon.Parse("yesterday").ToString() // 2020-08-04 13:14:15 +0800 CST +carbon.Parse("tomorrow").ToString() // 2020-08-06 13:14:15 +0800 CST + +carbon.Parse("2020").ToString() // 2020-01-01 00:00:00 +0800 CST +carbon.Parse("2020-8").ToString() // 2020-08-01 00:00:00 +0800 CST +carbon.Parse("2020-08").ToString() // 2020-08-01 00:00:00 +0800 CST +carbon.Parse("2020-8-5").ToString() // 2020-08-05 00:00:00 +0800 CST +carbon.Parse("2020-8-05").ToString() // 2020-08-05 00:00:00 +0800 CST +carbon.Parse("2020-08-05").ToString() // 2020-08-05 00:00:00 +0800 CST +carbon.Parse("2020-08-05.999").ToString() // 2020-08-05 00:00:00.999 +0800 CST +carbon.Parse("2020-08-05.999999").ToString() // 2020-08-05 00:00:00.999999 +0800 CST +carbon.Parse("2020-08-05.999999999").ToString() // 2020-08-05 00:00:00.999999999 +0800 CST + +carbon.Parse("2020-8-5 13:14:15").ToString() // 2020-08-05 13:14:15 +0800 CST +carbon.Parse("2020-8-05 13:14:15").ToString() // 2020-08-05 13:14:15 +0800 CST +carbon.Parse("2020-08-5 13:14:15").ToString() // 2020-08-05 13:14:15 +0800 CST +carbon.Parse("2020-08-05 13:14:15").ToString() // 2020-08-05 13:14:15 +0800 CST +carbon.Parse("2020-08-05 13:14:15.999").ToString() // 2020-08-05 13:14:15.999 +0800 CST +carbon.Parse("2020-08-05 13:14:15.999999").ToString() // 2020-08-05 13:14:15.999999 +0800 CST +carbon.Parse("2020-08-05 13:14:15.999999999").ToString() // 2020-08-05 13:14:15.999999999 +0800 CST + +carbon.Parse("2020-8-5T13:14:15+08:00").ToString() // 2020-08-05 13:14:15 +0800 CST +carbon.Parse("2020-8-05T13:14:15+08:00").ToString() // 2020-08-05 13:14:15 +0800 CST +carbon.Parse("2020-08-05T13:14:15+08:00").ToString() // 2020-08-05 13:14:15 +0800 CST +carbon.Parse("2020-08-05T13:14:15.999+08:00").ToString() // 2020-08-05 13:14:15.999 +0800 CST +carbon.Parse("2020-08-05T13:14:15.999999+08:00").ToString() // 2020-08-05 13:14:15.999999 +0800 CST +carbon.Parse("2020-08-05T13:14:15.999999999+08:00").ToString() // 2020-08-05 13:14:15.999999999 +0800 CST + +carbon.Parse("20200805").ToString() // 2020-08-05 00:00:00 +0800 CST +carbon.Parse("20200805131415").ToString() // 2020-08-05 13:14:15 +0800 CST +carbon.Parse("20200805131415.999").ToString() // 2020-08-05 13:14:15.999 +0800 CST +carbon.Parse("20200805131415.999999").ToString() // 2020-08-05 13:14:15.999999 +0800 CST +carbon.Parse("20200805131415.999999999").ToString() // 2020-08-05 13:14:15.999999999 +0800 CST +carbon.Parse("20200805131415.999+08:00").ToString() // 2020-08-05 13:14:15.999 +0800 CST +carbon.Parse("20200805131415.999999+08:00").ToString() // 2020-08-05 13:14:15.999999 +0800 CST +carbon.Parse("20200805131415.999999999+08:00").ToString() // 2020-08-05 13:14:15.999999999 +0800 CST +``` + +##### Parse a time string as a `Carbon` instance by format + +```go +carbon.ParseByFormat("2020|08|05 13|14|15", "Y|m|d H|i|s").ToDateTimeString() // 2020-08-05 13:14:15 +carbon.ParseByFormat("It is 2020-08-05 13:14:15", "\\I\\t \\i\\s Y-m-d H:i:s").ToDateTimeString() // 2020-08-05 13:14:15 +carbon.ParseByFormat("今天是 2020年08月05日13时14分15秒", "今天是 Y年m月d日H时i分s秒").ToDateTimeString() // 2020-08-05 13:14:15 +``` + +##### Parse a time string as a `Carbon` instance by layout + +```go +carbon.ParseByLayout("2020|08|05 13|14|15", "2006|01|02 15|04|05").ToDateTimeString() // 2020-08-05 13:14:15 +carbon.ParseByLayout("It is 2020-08-05 13:14:15", "It is 2006-01-02 15:04:05").ToDateTimeString() // 2020-08-05 13:14:15 +carbon.ParseByLayout("今天是 2020年08月05日13时14分15秒", "今天是 2006年01月02日15时04分05秒").ToDateTimeString() // 2020-08-05 13:14:15 +``` + +##### Boundary + +```go +// Start of the century +carbon.Parse("2020-08-05 13:14:15").StartOfCentury().ToDateTimeString() // 2000-01-01 00:00:00 +// End of the century +carbon.Parse("2020-08-05 13:14:15").EndOfCentury().ToDateTimeString() // 2999-12-31 23:59:59 + +// Start of the decade +carbon.Parse("2020-08-05 13:14:15").StartOfDecade().ToDateTimeString() // 2020-01-01 00:00:00 +carbon.Parse("2021-08-05 13:14:15").StartOfDecade().ToDateTimeString() // 2020-01-01 00:00:00 +carbon.Parse("2029-08-05 13:14:15").StartOfDecade().ToDateTimeString() // 2020-01-01 00:00:00 +// End of the decade +carbon.Parse("2020-08-05 13:14:15").EndOfDecade().ToDateTimeString() // 2029-12-31 23:59:59 +carbon.Parse("2021-08-05 13:14:15").EndOfDecade().ToDateTimeString() // 2029-12-31 23:59:59 +carbon.Parse("2029-08-05 13:14:15").EndOfDecade().ToDateTimeString() // 2029-12-31 23:59:59 + +// Start of the year +carbon.Parse("2020-08-05 13:14:15").StartOfYear().ToDateTimeString() // 2020-01-01 00:00:00 +// End of the year +carbon.Parse("2020-08-05 13:14:15").EndOfYear().ToDateTimeString() // 2020-12-31 23:59:59 + +// Start of the quarter +carbon.Parse("2020-08-05 13:14:15").StartOfQuarter().ToDateTimeString() // 2020-07-01 00:00:00 +// End of the quarter +carbon.Parse("2020-08-05 13:14:15").EndOfQuarter().ToDateTimeString() // 2020-09-30 23:59:59 + +// Start of the month +carbon.Parse("2020-08-05 13:14:15").StartOfMonth().ToDateTimeString() // 2020-08-01 00:00:00 +// End of the month +carbon.Parse("2020-08-05 13:14:15").EndOfMonth().ToDateTimeString() // 2020-08-31 23:59:59 + +// Start of the week +carbon.Parse("2020-08-05 13:14:15").StartOfWeek().ToDateTimeString() // 2020-08-02 00:00:00 +carbon.Parse("2020-08-05 13:14:15").SetWeekStartsAt(carbon.Sunday).StartOfWeek().ToDateTimeString() // 2020-08-02 00:00:00 +carbon.Parse("2020-08-05 13:14:15").SetWeekStartsAt(carbon.Monday).StartOfWeek().ToDateTimeString() // 2020-08-03 00:00:00 +// End of the week +carbon.Parse("2020-08-05 13:14:15").EndOfWeek().ToDateTimeString() // 2020-08-08 23:59:59 +carbon.Parse("2020-08-05 13:14:15").SetWeekStartsAt(carbon.Sunday).EndOfWeek().ToDateTimeString() // 2020-08-08 23:59:59 +carbon.Parse("2020-08-05 13:14:15").SetWeekStartsAt(carbon.Monday).EndOfWeek().ToDateTimeString() // 2020-08-09 23:59:59 + +// Start of the day +carbon.Parse("2020-08-05 13:14:15").StartOfDay().ToDateTimeString() // 2020-08-05 00:00:00 +// End of the day +carbon.Parse("2020-08-05 13:14:15").EndOfDay().ToDateTimeString() // 2020-08-05 23:59:59 + +// Start of the hour +carbon.Parse("2020-08-05 13:14:15").StartOfHour().ToDateTimeString() // 2020-08-05 13:00:00 +// End of the hour +carbon.Parse("2020-08-05 13:14:15").EndOfHour().ToDateTimeString() // 2020-08-05 13:59:59 + +// Start of the minute +carbon.Parse("2020-08-05 13:14:15").StartOfMinute().ToDateTimeString() // 2020-08-05 13:14:00 +// End of the minute +carbon.Parse("2020-08-05 13:14:15").EndOfMinute().ToDateTimeString() // 2020-08-05 13:14:59 + +// Start of the second +carbon.Parse("2020-08-05 13:14:15").StartOfSecond().ToString() // 2020-08-05 13:14:15 +0800 CST +// End of the second +carbon.Parse("2020-08-05 13:14:15").EndOfSecond().ToString() // 2020-08-05 13:14:15.999999999 +0800 CST +``` + +##### Traveler + +```go +// Add three centuries +carbon.Parse("2020-02-29 13:14:15").AddCenturies(3).ToDateTimeString() // 2320-02-29 13:14:15 +// Add three centuries without overflowing month +carbon.Parse("2020-02-29 13:14:15").AddCenturiesNoOverflow(3).ToDateTimeString() // 2320-02-29 13:14:15 +// Add one century +carbon.Parse("2020-02-29 13:14:15").AddCentury().ToDateTimeString() // 2120-02-29 13:14:15 +// Add one century without overflowing month +carbon.Parse("2020-02-29 13:14:15").AddCenturyNoOverflow().ToDateTimeString() // 2120-02-29 13:14:15 +// Subtract three centuries +carbon.Parse("2020-02-29 13:14:15").SubCenturies(3).ToDateTimeString() // 1720-02-29 13:14:15 +// Subtract three centuries without overflowing month +carbon.Parse("2020-02-29 13:14:15").SubCenturiesNoOverflow(3).ToDateTimeString() // 1720-02-29 13:14:15 +// Subtract one century +carbon.Parse("2020-02-29 13:14:15").SubCentury().ToDateTimeString() // 1920-02-29 13:14:15 +// Subtract one century without overflowing month +carbon.Parse("2020-02-29 13:14:15").SubCenturyNoOverflow().ToDateTimeString() // 1920-02-20 13:14:15 + +// Add three decades +carbon.Parse("2020-02-29 13:14:15").AddDecades(3).ToDateTimeString() // 2050-03-01 13:14:15 +// Add three decades without overflowing month +carbon.Parse("2020-02-29 13:14:15").AddDecadesNoOverflow(3).ToDateTimeString() // 2050-02-28 13:14:15 +// Add one decade +carbon.Parse("2020-02-29 13:14:15").AddDecade().ToDateTimeString() // 2030-03-01 13:14:15 +// Add one decade without overflowing month +carbon.Parse("2020-02-29 13:14:15").AddDecadeNoOverflow().ToDateTimeString() // 2030-02-28 13:14:15 +// Subtract three decades +carbon.Parse("2020-02-29 13:14:15").SubDecades(3).ToDateTimeString() // 1990-03-01 13:14:15 +// Subtract three decades without overflowing month +carbon.Parse("2020-02-29 13:14:15").SubDecadesNoOverflow(3).ToDateTimeString() // 1990-02-28 13:14:15 +// Subtract one decade +carbon.Parse("2020-02-29 13:14:15").SubDecade().ToDateTimeString() // 2010-03-01 13:14:15 +// Subtract one decade without overflowing month +carbon.Parse("2020-02-29 13:14:15").SubDecadeNoOverflow().ToDateTimeString() // 2010-02-28 13:14:15 + +// Add three years +carbon.Parse("2020-02-29 13:14:15").AddYears(3).ToDateTimeString() // 2023-03-01 13:14:15 +// Add three years without overflowing month +carbon.Parse("2020-02-29 13:14:15").AddYearsNoOverflow(3).ToDateTimeString() // 2023-02-28 13:14:15 +// Add one year +carbon.Parse("2020-02-29 13:14:15").AddYear().ToDateTimeString() // 2021-03-01 13:14:15 +// Add one year without overflowing month +carbon.Parse("2020-02-29 13:14:15").AddYearNoOverflow().ToDateTimeString() // 2021-02-28 13:14:15 +// Subtract three years +carbon.Parse("2020-02-29 13:14:15").SubYears(3).ToDateTimeString() // 2017-03-01 13:14:15 +// Subtract three years without overflowing month +carbon.Parse("2020-02-29 13:14:15").SubYearsNoOverflow(3).ToDateTimeString() // 2017-02-28 13:14:15 +// Subtract one year +carbon.Parse("2020-02-29 13:14:15").SubYear().ToDateTimeString() // 2019-03-01 13:14:15 +// Subtract one year without overflowing month +carbon.Parse("2020-02-29 13:14:15").SubYearNoOverflow().ToDateTimeString() // 2019-02-28 13:14:15 + +// Add three quarters +carbon.Parse("2019-05-31 13:14:15").AddQuarters(3).ToDateTimeString() // 2020-03-02 13:14:15 +// Add three quarters without overflowing month +carbon.Parse("2019-05-31 13:14:15").AddQuartersNoOverflow(3).ToDateTimeString() // 2020-02-29 13:14:15 +// Add one quarter +carbon.Parse("2019-11-30 13:14:15").AddQuarter().ToDateTimeString() // 2020-03-01 13:14:15 +// Add one quarter without overflowing month +carbon.Parse("2019-11-30 13:14:15").AddQuarterNoOverflow().ToDateTimeString() // 2020-02-29 13:14:15 +// Subtract three quarters +carbon.Parse("2019-08-31 13:14:15").SubQuarters(3).ToDateTimeString() // 2019-03-03 13:14:15 +// Subtract three quarters without overflowing month +carbon.Parse("2019-08-31 13:14:15").SubQuartersNoOverflow(3).ToDateTimeString() // 2019-02-28 13:14:15 +// Subtract one quarter +carbon.Parse("2020-05-31 13:14:15").SubQuarter().ToDateTimeString() // 2020-03-02 13:14:15 +// Subtract one quarter without overflowing month +carbon.Parse("2020-05-31 13:14:15").SubQuarterNoOverflow().ToDateTimeString() // 2020-02-29 13:14:15 + +// Add three months +carbon.Parse("2020-02-29 13:14:15").AddMonths(3).ToDateTimeString() // 2020-05-29 13:14:15 +// Add three months without overflowing month +carbon.Parse("2020-02-29 13:14:15").AddMonthsNoOverflow(3).ToDateTimeString() // 2020-05-29 13:14:15 +// Add one month +carbon.Parse("2020-01-31 13:14:15").AddMonth().ToDateTimeString() // 2020-03-02 13:14:15 +// Add one month without overflowing month +carbon.Parse("2020-01-31 13:14:15").AddMonthNoOverflow().ToDateTimeString() // 2020-02-29 13:14:15 +// Subtract three months +carbon.Parse("2020-02-29 13:14:15").SubMonths(3).ToDateTimeString() // 2019-11-29 13:14:15 +// Subtract three months without overflowing month +carbon.Parse("2020-02-29 13:14:15").SubMonthsNoOverflow(3).ToDateTimeString() // 2019-11-29 13:14:15 +// Subtract one month +carbon.Parse("2020-03-31 13:14:15").SubMonth().ToDateTimeString() // 2020-03-02 13:14:15 +// Subtract one month without overflowing month +carbon.Parse("2020-03-31 13:14:15").SubMonthNoOverflow().ToDateTimeString() // 2020-02-29 13:14:15 + +// Add three weeks +carbon.Parse("2020-02-29 13:14:15").AddWeeks(3).ToDateTimeString() // 2020-03-21 13:14:15 +// Add one week +carbon.Parse("2020-02-29 13:14:15").AddWeek().ToDateTimeString() // 2020-03-07 13:14:15 +// Subtract three weeks +carbon.Parse("2020-02-29 13:14:15").SubWeeks(3).ToDateTimeString() // 2020-02-08 13:14:15 +// Subtract three week +carbon.Parse("2020-02-29 13:14:15").SubWeek().ToDateTimeString() // 2020-02-22 13:14:15 + +// Add three days +carbon.Parse("2020-08-05 13:14:15").AddDays(3).ToDateTimeString() // 2020-08-08 13:14:15 +// Add one day +carbon.Parse("2020-08-05 13:14:15").AddDay().ToDateTimeString() // 2020-08-05 13:14:15 +// Subtract three days +carbon.Parse("2020-08-05 13:14:15").SubDays(3).ToDateTimeString() // 2020-08-02 13:14:15 +// Subtract one day +carbon.Parse("2020-08-05 13:14:15").SubDay().ToDateTimeString() // 2020-08-04 13:14:15 + +// Add three hours +carbon.Parse("2020-08-05 13:14:15").AddHours(3).ToDateTimeString() // 2020-08-05 16:14:15 +// Add two and a half hours +carbon.Parse("2020-08-05 13:14:15").AddDuration("2.5h").ToDateTimeString() // 2020-08-05 15:44:15 +carbon.Parse("2020-08-05 13:14:15").AddDuration("2h30m").ToDateTimeString() // 2020-08-05 15:44:15 +// Add one hour +carbon.Parse("2020-08-05 13:14:15").AddHour().ToDateTimeString() // 2020-08-05 14:14:15 +// Subtract three hours +carbon.Parse("2020-08-05 13:14:15").SubHours(3).ToDateTimeString() // 2020-08-05 10:14:15 +// Subtract two and a half hours +carbon.Parse("2020-08-05 13:14:15").SubDuration("2.5h").ToDateTimeString() // 2020-08-05 10:44:15 +carbon.Parse("2020-08-05 13:14:15").SubDuration("2h30m").ToDateTimeString() // 2020-08-05 10:44:15 +// Subtract one hour +carbon.Parse("2020-08-05 13:14:15").SubHour().ToDateTimeString() // 2020-08-05 12:14:15 + +// Add three minutes +carbon.Parse("2020-08-05 13:14:15").AddMinutes(3).ToDateTimeString() // 2020-08-05 13:17:15 +// Add two and a half minutes +carbon.Parse("2020-08-05 13:14:15").AddDuration("2.5m").ToDateTimeString() // 2020-08-05 13:16:45 +carbon.Parse("2020-08-05 13:14:15").AddDuration("2m30s").ToDateTimeString() // 2020-08-05 13:16:45 +// Add one minute +carbon.Parse("2020-08-05 13:14:15").AddMinute().ToDateTimeString() // 2020-08-05 13:15:15 +// Subtract three minutes +carbon.Parse("2020-08-05 13:14:15").SubMinutes(3).ToDateTimeString() // 2020-08-05 13:11:15 +// Subtract two and a half minutes +carbon.Parse("2020-08-05 13:14:15").SubDuration("2.5m").ToDateTimeString() // 2020-08-05 13:11:45 +// Subtract one minute +carbon.Parse("2020-08-05 13:14:15").SubMinute().ToDateTimeString() // 2020-08-05 13:13:15 + +// Add three seconds +carbon.Parse("2020-08-05 13:14:15").AddSeconds(3).ToDateTimeString() // 2020-08-05 13:14:18 +// Add two and a half seconds +carbon.Parse("2020-08-05 13:14:15").AddDuration("2.5s").ToDateTimeString() // 2020-08-05 13:14:17 +// Add one second +carbon.Parse("2020-08-05 13:14:15").AddSecond().ToDateTimeString() // 2020-08-05 13:14:16 +// Subtract three seconds +carbon.Parse("2020-08-05 13:14:15").SubSeconds(3).ToDateTimeString() // 2020-08-05 13:14:12 +// Subtract two and a half seconds +carbon.Parse("2020-08-05 13:14:15").SubDuration("2.5s").ToDateTimeString() // 2020-08-05 13:14:12 +// Subtract one second +carbon.Parse("2020-08-05 13:14:15").SubSecond().ToDateTimeString() // 2020-08-05 13:14:14 + +// Add three milliseconds +carbon.Parse("2020-08-05 13:14:15.222222222").AddMilliseconds(3).ToString() // 2020-08-05 13:14:15.225222222 +0800 CST +// Add one millisecond +carbon.Parse("2020-08-05 13:14:15.222222222").AddMillisecond().ToString() // 2020-08-05 13:14:15.223222222 +0800 CST +// Subtract three milliseconds +carbon.Parse("2020-08-05 13:14:15.222222222").SubMilliseconds(3).ToString() // 2020-08-05 13:14:15.219222222 +0800 CST +// Subtract one millisecond +carbon.Parse("2020-08-05 13:14:15.222222222").SubMillisecond().ToString() // 2020-08-05 13:14:15.221222222 +0800 CST + +// Add three microseconds +carbon.Parse("2020-08-05 13:14:15.222222222").AddMicroseconds(3).ToString() // 2020-08-05 13:14:15.222225222 +0800 CST +// Add one microsecond +carbon.Parse("2020-08-05 13:14:15.222222222").AddMicrosecond().ToString() // 2020-08-05 13:14:15.222223222 +0800 CST +// Subtract three microseconds +carbon.Parse("2020-08-05 13:14:15.222222222").SubMicroseconds(3).ToString() // 2020-08-05 13:14:15.222219222 +0800 CST +// Subtract one microsecond +carbon.Parse("2020-08-05 13:14:15.222222222").SubMicrosecond().ToString() // 2020-08-05 13:14:15.222221222 +0800 CST + +// Add three nanoseconds +carbon.Parse("2020-08-05 13:14:15.222222222").AddNanoseconds(3).ToString() // 2020-08-05 13:14:15.222222225 +0800 CST +// Add one nanosecond +carbon.Parse("2020-08-05 13:14:15.222222222").AddNanossecond().ToString() // 2020-08-05 13:14:15.222222223 +0800 CST +// Subtract three nanoseconds +carbon.Parse("2020-08-05 13:14:15.222222222").SubNanosseconds(3).ToString() // 2020-08-05 13:14:15.222222219 +0800 CST +// Subtract one nanosecond +carbon.Parse("2020-08-05 13:14:15.222222222").SubNanossecond().ToString() // 2020-08-05 13:14:15.222222221 +0800 CST +``` + +##### Difference + +```go +// Difference in years +carbon.Parse("2021-08-05 13:14:15").DiffInYears(carbon.Parse("2020-08-05 13:14:15")) // -1 +// Difference in years with absolute value +carbon.Parse("2021-08-05 13:14:15").DiffAbsInYears(carbon.Parse("2020-08-05 13:14:15")) // 1 + +// Difference in months +carbon.Parse("2020-08-05 13:14:15").DiffInMonths(carbon.Parse("2020-07-05 13:14:15")) // -1 +// Difference in months with absolute value +carbon.Parse("2020-08-05 13:14:15").DiffAbsInMonths(carbon.Parse("2020-07-05 13:14:15")) // 1 + +// Difference in weeks +carbon.Parse("2020-08-05 13:14:15").DiffInWeeks(carbon.Parse("2020-07-28 13:14:15")) // -1 +// Difference in weeks with absolute value +carbon.Parse("2020-08-05 13:14:15").DiffAbsInWeeks(carbon.Parse("2020-07-28 13:14:15")) // 1 + +// Difference in days +carbon.Parse("2020-08-05 13:14:15").DiffInDays(carbon.Parse("2020-08-04 13:14:15")) // -1 +// Difference in days with absolute value +carbon.Parse("2020-08-05 13:14:15").DiffAbsInDays(carbon.Parse("2020-08-04 13:14:15")) // 1 + +// Difference in hours +carbon.Parse("2020-08-05 13:14:15").DiffInHours(carbon.Parse("2020-08-05 12:14:15")) // -1 +// Difference in hours with absolute value +carbon.Parse("2020-08-05 13:14:15").DiffAbsInHours(carbon.Parse("2020-08-05 12:14:15")) // 1 + +// Difference in minutes +carbon.Parse("2020-08-05 13:14:15").DiffInMinutes(carbon.Parse("2020-08-05 13:13:15")) // -1 +// Difference in minutes with absolute value +carbon.Parse("2020-08-05 13:14:15").DiffAbsInMinutes(carbon.Parse("2020-08-05 13:13:15")) // 1 + +// Difference in seconds +carbon.Parse("2020-08-05 13:14:15").DiffInSeconds(carbon.Parse("2020-08-05 13:14:14")) // -1 +// Difference in seconds with absolute value +carbon.Parse("2020-08-05 13:14:15").DiffAbsInSeconds(carbon.Parse("2020-08-05 13:14:14")) // 1 + +// Difference in string +carbon.Now().DiffInString() // just now +carbon.Now().AddYearsNoOverflow(1).DiffInString() // -1 year +carbon.Now().SubYearsNoOverflow(1).DiffInString() // 1 year +// Difference in string with absolute value +carbon.Now().DiffAbsInString(carbon.Now()) // just now +carbon.Now().AddYearsNoOverflow(1).DiffAbsInString(carbon.Now()) // 1 year +carbon.Now().SubYearsNoOverflow(1).DiffAbsInString(carbon.Now()) // 1 year + +// Difference in duration +now := carbon.Now() +now.DiffInDuration(now).String() // 0s +now.AddHour().DiffInDuration(now).String() // 1h0m0s +now.SubHour().DiffInDuration(now).String() // -1h0m0s +// Difference in duration with absolute value +now.DiffAbsInDuration(now).String() // 0s +now.AddHour().DiffAbsInDuration(now).String() // 1h0m0s +now.SubHour().DiffAbsInDuration(now).String() // 1h0m0s + +// Difference in a human-readable format +carbon.Parse("2020-08-05 13:14:15").DiffForHumans() // just now +carbon.Parse("2019-08-05 13:14:15").DiffForHumans() // 1 year ago +carbon.Parse("2018-08-05 13:14:15").DiffForHumans() // 2 years ago +carbon.Parse("2021-08-05 13:14:15").DiffForHumans() // 1 year from now +carbon.Parse("2022-08-05 13:14:15").DiffForHumans() // 2 years from now +// Difference in a human-readable format from now time +carbon.Parse("2020-08-05 13:14:15").DiffForHumans(carbon.Now()) // 1 year before +carbon.Parse("2019-08-05 13:14:15").DiffForHumans(carbon.Now()) // 2 years before +carbon.Parse("2018-08-05 13:14:15").DiffForHumans(carbon.Now()) // 1 year after +carbon.Parse("2022-08-05 13:14:15").DiffForHumans(carbon.Now()) // 2 years after +``` + +##### Extremum + +```go +c0 := carbon.Parse("2023-04-01") +c1 := carbon.Parse("2023-03-28") +c2 := carbon.Parse("2023-04-16") +// Return the closest Carbon instance +c0.Closest(c1, c2) // c1 +// Return the farthest Carbon instance +c0.Farthest(c1, c2) // c2 + +yesterday := carbon.Yesterday() +today := carbon.Now() +tomorrow := carbon.Tomorrow() +// Return the maximum Carbon instance +carbon.Max(yesterday, today, tomorrow) // tomorrow +// Return the minimum Carbon instance +carbon.Min(yesterday, today, tomorrow) // yesterday + +// Return a Carbon instance for the greatest supported date +carbon.MaxValue().ToString() // 9999-12-31 23:59:59.999999999 +0000 UTC +// Return a Carbon instance for the lowest supported date +carbon.MinValue().ToString() // -9998-01-01 00:00:00 +0000 UTC +``` + +##### Comparison + +```go +// Whether is daylight saving time +carbon.Parse("").IsDST() // false +carbon.Parse("0").IsDST() // false +carbon.Parse("0000-00-00 00:00:00").IsDST() // false +carbon.Parse("0000-00-00").IsDST() // false +carbon.Parse("00:00:00").IsDST() // false +carbon.Parse("2023-01-01", "Australia/Brisbane").IsDST() // false +carbon.Parse("2023-01-01", "Australia/Sydney").IsDST() // true + +// Whether is zero time(0001-01-01 00:00:00 +0000 UTC) +carbon.Parse("").IsZero() // true +carbon.Parse("0").IsZero() // true +carbon.Parse("0000-00-00 00:00:00").IsZero() // true +carbon.Parse("0000-00-00").IsZero() // true +carbon.Parse("00:00:00").IsZero() // true +carbon.Parse("2020-08-05 00:00:00").IsZero() // false +carbon.Parse("2020-08-05").IsZero() // false +carbon.Parse("2020-08-05").SetTimezone("xxx").IsZero() // false + +// Whether is valid time +carbon.Parse("").IsValid() // false +carbon.Parse("0").IsValid() // false +carbon.Parse("0000-00-00 00:00:00").IsValid() // false +carbon.Parse("0000-00-00").IsValid() // false +carbon.Parse("00:00:00").IsValid() // false +carbon.Parse("2020-08-05 00:00:00").IsValid() // true +carbon.Parse("2020-08-05").IsValid() // true +carbon.Parse("2020-08-05").SetTimezone("xxx").IsValid() // false + +// Whether is invalid time +carbon.Parse("").IsInvalid() // true +carbon.Parse("0").IsInvalid() // true +carbon.Parse("0000-00-00 00:00:00").IsInvalid() // true +carbon.Parse("0000-00-00").IsInvalid() // true +carbon.Parse("00:00:00").IsInvalid() // true +carbon.Parse("2020-08-05 00:00:00").IsInvalid() // false +carbon.Parse("2020-08-05").IsInvalid() // false +carbon.Parse("2020-08-05").SetTimezone("xxx").IsInvalid() // true + +// Whether is before noon +carbon.Parse("2020-08-05 00:00:00").IsAM() // true +carbon.Parse("2020-08-05 08:00:00").IsAM() // true +carbon.Parse("2020-08-05 12:00:00").IsAM() // false +carbon.Parse("2020-08-05 13:00:00").IsAM() // false +// Whether is after noon +carbon.Parse("2020-08-05 00:00:00").IsPM() // false +carbon.Parse("2020-08-05 08:00:00").IsPM() // false +carbon.Parse("2020-08-05 12:00:00").IsPM() // true +carbon.Parse("2020-08-05 13:00:00").IsPM() // true + +// Whether is now time +carbon.Now().IsNow() // true +// Whether is future time +carbon.Tomorrow().IsFuture() // true +// Whether is pass time +carbon.Yesterday().IsPast() // true + +// Whether is a leap year +carbon.Parse("2020-08-05 13:14:15").IsLeapYear() // true +// Whether is a long year +carbon.Parse("2020-08-05 13:14:15").IsLongYear() // true + +// Whether is January +carbon.Parse("2020-08-05 13:14:15").IsJanuary() // false +// Whether is February +carbon.Parse("2020-08-05 13:14:15").IsFebruary() // false +// Whether is March +carbon.Parse("2020-08-05 13:14:15").IsMarch() // false +// Whether is April +carbon.Parse("2020-08-05 13:14:15").IsApril() // false +// Whether is May +carbon.Parse("2020-08-05 13:14:15").IsMay() // false +// Whether is June +carbon.Parse("2020-08-05 13:14:15").IsJune() // false +// Whether is July +carbon.Parse("2020-08-05 13:14:15").IsJuly() // false +// Whether is August +carbon.Parse("2020-08-05 13:14:15").IsAugust() // false +// Whether is September +carbon.Parse("2020-08-05 13:14:15").IsSeptember() // true +// Whether is October +carbon.Parse("2020-08-05 13:14:15").IsOctober() // false +// Whether is November +carbon.Parse("2020-08-05 13:14:15").IsNovember() // false +// Whether is December +carbon.Parse("2020-08-05 13:14:15").IsDecember() // false + +// Whether is Monday +carbon.Parse("2020-08-05 13:14:15").IsMonday() // false +// Whether is Tuesday +carbon.Parse("2020-08-05 13:14:15").IsTuesday() // true +// Whether is Wednesday +carbon.Parse("2020-08-05 13:14:15").IsWednesday() // false +// Whether is Thursday +carbon.Parse("2020-08-05 13:14:15").IsThursday() // false +// Whether is Friday +carbon.Parse("2020-08-05 13:14:15").IsFriday() // false +// Whether is Saturday +carbon.Parse("2020-08-05 13:14:15").IsSaturday() // false +// Whether is Sunday +carbon.Parse("2020-08-05 13:14:15").IsSunday() // false +// Whether is weekday +carbon.Parse("2020-08-05 13:14:15").IsWeekday() // false +// Whether is weekend +carbon.Parse("2020-08-05 13:14:15").IsWeekend() // true + +// Whether is yesterday +carbon.Parse("2020-08-04 13:14:15").IsYesterday() // true +carbon.Parse("2020-08-04 00:00:00").IsYesterday() // true +carbon.Parse("2020-08-04").IsYesterday() // true +// Whether is today +carbon.Parse("2020-08-05 13:14:15").IsToday() // true +carbon.Parse("2020-08-05 00:00:00").IsToday() // true +carbon.Parse("2020-08-05").IsToday() // true +// Whether is tomorrow +carbon.Parse("2020-08-06 13:14:15").IsTomorrow() // true +carbon.Parse("2020-08-06 00:00:00").IsTomorrow() // true +carbon.Parse("2020-08-06").IsTomorrow() // true + +// Whether is same century +carbon.Parse("2020-08-05 13:14:15").IsSameCentury(carbon.Parse("3020-08-05 13:14:15")) // false +carbon.Parse("2020-08-05 13:14:15").IsSameCentury(carbon.Parse("2099-08-05 13:14:15")) // true +// Whether is same decade +carbon.Parse("2020-08-05 13:14:15").IsSameDecade(carbon.Parse("2030-08-05 13:14:15")) // false +carbon.Parse("2020-08-05 13:14:15").IsSameDecade(carbon.Parse("2120-08-05 13:14:15")) // true +// Whether is same year +carbon.Parse("2020-08-05 00:00:00").IsSameYear(carbon.Parse("2021-08-05 13:14:15")) // false +carbon.Parse("2020-01-01 00:00:00").IsSameYear(carbon.Parse("2020-12-31 13:14:15")) // true +// Whether is same quarter +carbon.Parse("2020-08-05 00:00:00").IsSameQuarter(carbon.Parse("2020-09-05 13:14:15")) // false +carbon.Parse("2020-01-01 00:00:00").IsSameQuarter(carbon.Parse("2021-01-31 13:14:15")) // true +// Whether is same month +carbon.Parse("2020-01-01 00:00:00").IsSameMonth(carbon.Parse("2021-01-31 13:14:15")) // false +carbon.Parse("2020-01-01 00:00:00").IsSameMonth(carbon.Parse("2020-01-31 13:14:15")) // true +// Whether is same day +carbon.Parse("2020-08-05 13:14:15").IsSameDay(carbon.Parse("2021-08-05 13:14:15")) // false +carbon.Parse("2020-08-05 00:00:00").IsSameDay(carbon.Parse("2020-08-05 13:14:15")) // true +// Whether is same hour +carbon.Parse("2020-08-05 13:14:15").IsSameHour(carbon.Parse("2021-08-05 13:14:15")) // false +carbon.Parse("2020-08-05 13:00:00").IsSameHour(carbon.Parse("2020-08-05 13:14:15")) // true +// Whether is same minute +carbon.Parse("2020-08-05 13:14:15").IsSameMinute(carbon.Parse("2021-08-05 13:14:15")) // false +carbon.Parse("2020-08-05 13:14:00").IsSameMinute(carbon.Parse("2020-08-05 13:14:15")) // true +// Whether is same second +carbon.Parse("2020-08-05 13:14:15").IsSameSecond(carbon.Parse("2021-08-05 13:14:15")) // false +carbon.Parse("2020-08-05 13:14:15").IsSameSecond(carbon.Parse("2020-08-05 13:14:15")) // true + +// Whether greater than +carbon.Parse("2020-08-05 13:14:15").Gt(carbon.Parse("2020-08-04 13:14:15")) // true +carbon.Parse("2020-08-05 13:14:15").Gt(carbon.Parse("2020-08-05 13:14:15")) // false +carbon.Parse("2020-08-05 13:14:15").Compare(">", carbon.Parse("2020-08-04 13:14:15")) // true +carbon.Parse("2020-08-05 13:14:15").Compare(">", carbon.Parse("2020-08-05 13:14:15")) // false + +// Whether less than +carbon.Parse("2020-08-05 13:14:15").Lt(carbon.Parse("2020-08-06 13:14:15")) // true +carbon.Parse("2020-08-05 13:14:15").Lt(carbon.Parse("2020-08-05 13:14:15")) // false +carbon.Parse("2020-08-05 13:14:15").Compare("<", carbon.Parse("2020-08-06 13:14:15")) // true +carbon.Parse("2020-08-05 13:14:15").Compare("<", carbon.Parse("2020-08-05 13:14:15")) // false + +// Whether equal +carbon.Parse("2020-08-05 13:14:15").Eq(carbon.Parse("2020-08-05 13:14:15")) // true +carbon.Parse("2020-08-05 13:14:15").Eq(carbon.Parse("2020-08-05 13:14:00")) // false +carbon.Parse("2020-08-05 13:14:15").Compare("=", carbon.Parse("2020-08-05 13:14:15")) // true +carbon.Parse("2020-08-05 13:14:15").Compare("=", carbon.Parse("2020-08-05 13:14:00")) // false + +// Whether not equal +carbon.Parse("2020-08-05 13:14:15").Ne(carbon.Parse("2020-08-06 13:14:15")) // true +carbon.Parse("2020-08-05 13:14:15").Ne(carbon.Parse("2020-08-05 13:14:15")) // false +carbon.Parse("2020-08-05 13:14:15").Compare("!=", carbon.Parse("2020-08-06 13:14:15")) // true +carbon.Parse("2020-08-05 13:14:15").Compare("<>", carbon.Parse("2020-08-05 13:14:15")) // false + +// Whether greater than or equal +carbon.Parse("2020-08-05 13:14:15").Gte(carbon.Parse("2020-08-04 13:14:15")) // true +carbon.Parse("2020-08-05 13:14:15").Gte(carbon.Parse("2020-08-05 13:14:15")) // true +carbon.Parse("2020-08-05 13:14:15").Compare(">=", carbon.Parse("2020-08-04 13:14:15")) // true +carbon.Parse("2020-08-05 13:14:15").Compare(">=", carbon.Parse("2020-08-05 13:14:15")) // true + +// Whether less than or equal +carbon.Parse("2020-08-05 13:14:15").Lte(carbon.Parse("2020-08-06 13:14:15")) // true +carbon.Parse("2020-08-05 13:14:15").Lte(carbon.Parse("2020-08-05 13:14:15")) // true +carbon.Parse("2020-08-05 13:14:15").Compare("<=", carbon.Parse("2020-08-06 13:14:15")) // true +carbon.Parse("2020-08-05 13:14:15").Compare("<=", carbon.Parse("2020-08-05 13:14:15")) // true + +// Whether between two Carbon instances, excluded the start and end Carbon instance +carbon.Parse("2020-08-05 13:14:15").Between(carbon.Parse("2020-08-05 13:14:15"), carbon.Parse("2020-08-06 13:14:15")) // false +carbon.Parse("2020-08-05 13:14:15").Between(carbon.Parse("2020-08-04 13:14:15"), carbon.Parse("2020-08-06 13:14:15")) // true + +// Whether between two Carbon instances, included the start Carbon instance +carbon.Parse("2020-08-05 13:14:15").BetweenIncludedStart(carbon.Parse("2020-08-05 13:14:15"), carbon.Parse("2020-08-06 13:14:15")) // true +carbon.Parse("2020-08-05 13:14:15").BetweenIncludedStart(carbon.Parse("2020-08-04 13:14:15"), carbon.Parse("2020-08-06 13:14:15")) // true + +// Whether between two Carbon instances, included the end Carbon instance +carbon.Parse("2020-08-05 13:14:15").BetweenIncludedEnd(carbon.Parse("2020-08-04 13:14:15"), carbon.Parse("2020-08-05 13:14:15")) // true +carbon.Parse("2020-08-05 13:14:15").BetweenIncludedEnd(carbon.Parse("2020-08-04 13:14:15"), carbon.Parse("2020-08-06 13:14:15")) // true + +// Whether between two Carbon instances, included the start and end Carbon instance +carbon.Parse("2020-08-05 13:14:15").BetweenIncludedBoth(carbon.Parse("2020-08-05 13:14:15"), carbon.Parse("2020-08-06 13:14:15")) // true +carbon.Parse("2020-08-05 13:14:15").BetweenIncludedBoth(carbon.Parse("2020-08-04 13:14:15"), carbon.Parse("2020-08-05 13:14:15")) // true +``` + +> For the definition of long year, please see https://en.wikipedia.org/wiki/ISO_8601#Week_dates + +##### Setter + +```go +// Set timezone +carbon.SetTimezone(carbon.PRC).Now().ToDateTimeString() // 2020-08-05 13:14:15 +carbon.SetTimezone(carbon.Tokyo).Now().ToDateTimeString() // 2020-08-05 14:14:15 +carbon.SetTimezone(carbon.Tokyo).Now().SetTimezone(carbon.PRC).ToDateTimeString() // 2020-08-05 12:14:15 + +// Set location +utc, _ := time.LoadLocation(carbon.UTC) +carbon.SetLocation(utc).Now().ToDateTimeString() // 2022-06-28 09:25:38 +tokyo, _ := time.LoadLocation(carbon.Tokyo) +carbon.SetLocation(tokyo).Now().ToDateTimeString() // 2022-06-28 18:25:38 + +// Set locale +carbon.Parse("2020-07-05 13:14:15").SetLocale("en").DiffForHumans() // 1 month before +carbon.Parse("2020-07-05 13:14:15").SetLocale("zh-CN").DiffForHumans() // 1 月前 + +// Set year, month, day, hour, minute and second +carbon.Parse("2020-01-01").SetDateTime(2019, 2, 2, 13, 14, 15).ToString() // 2019-02-02 13:14:15 +0800 CST +carbon.Parse("2020-01-01").SetDateTime(2019, 2, 31, 13, 14, 15).ToString() // 2019-03-03 13:14:15 +0800 CST +// Set year, month, day, hour, minute, second and millisecond +carbon.Parse("2020-01-01").SetDateTimeMilli(2019, 2, 2, 13, 14, 15, 999).ToString() // 2019-02-02 13:14:15.999 +0800 CST +carbon.Parse("2020-01-01").SetDateTimeMilli(2019, 2, 31, 13, 14, 15, 999).ToString() // 2019-03-03 13:14:15.999 +0800 CST +// Set year, month, day, hour, minute, second and microsecond +carbon.Parse("2020-01-01").SetDateTimeMicro(2019, 2, 2, 13, 14, 15, 999999).ToString() // 2019-02-02 13:14:15.999999 +0800 CST +carbon.Parse("2020-01-01").SetDateTimeMicro(2019, 2, 31, 13, 14, 15, 999999).ToString() // 2019-03-03 13:14:15.999999 +0800 CST +// Set year, month, day, hour, minute, second and nanosecond +carbon.Parse("2020-01-01").SetDateTimeNano(2019, 2, 2, 13, 14, 15, 999999999).ToString() // 2019-02-02 13:14:15.999999999 +0800 CST +carbon.Parse("2020-01-01").SetDateTimeNano(2019, 2, 31, 13, 14, 15, 999999999).ToString() // 2019-03-03 13:14:15.999999999 +0800 CST + +// Set year, month and day +carbon.Parse("2020-01-01").SetDate(2019, 2, 2).ToString() // 2019-02-02 00:00:00 +0800 CST +carbon.Parse("2020-01-01").SetDate(2019, 2, 31).ToString() // 2019-03-03 00:00:00 +0800 CST +// Set year, month, day and millisecond +carbon.Parse("2020-01-01").SetDateMilli(2019, 2, 2, 999).ToString() // 2019-02-02 00:00:00.999 +0800 CST +carbon.Parse("2020-01-01").SetDateMilli(2019, 2, 31, 999).ToString() // 2019-03-03 00:00:00.999 +0800 CST +// Set year, month, day and microsecond +carbon.Parse("2020-01-01").SetDateMicro(2019, 2, 2, 999999).ToString() // 2019-02-02 00:00:00.999999 +0800 CST +carbon.Parse("2020-01-01").SetDateMicro(2019, 2, 31, 999999).ToString() // 2019-03-03 00:00:00.999999 +0800 CST +// Set year, month, day and nanosecond +carbon.Parse("2020-01-01").SetDateNano(2019, 2, 2, 999999999).ToString() // 2019-02-02 00:00:00.999999999 +0800 CST +carbon.Parse("2020-01-01").SetDateNano(2019, 2, 31, 999999999).ToString() // 2019-03-03 00:00:00.999999999 +0800 CST + +// Set hour, minute and second +carbon.Parse("2020-01-01").SetTime(13, 14, 15).ToString() // 2020-01-01 13:14:15 +0800 CST +carbon.Parse("2020-01-01").SetTime(13, 14, 90).ToString() // 2020-01-01 13:15:30 +0800 CST +// Set hour, minute, second and millisecond +carbon.Parse("2020-01-01").SetTimeMilli(13, 14, 15, 999).ToString() // 2020-01-01 13:14:15.999 +0800 CST +carbon.Parse("2020-01-01").SetTimeMilli(13, 14, 90, 999).ToString() // 2020-01-01 13:15:30.999 +0800 CST +// Set hour, minute, second and microsecond +carbon.Parse("2020-01-01").SetTimeMicro(13, 14, 15, 999999).ToString() // 2020-01-01 13:14:15.999999 +0800 CST +carbon.Parse("2020-01-01").SetTimeMicro(13, 14, 90, 999999).ToString() // 2020-01-01 13:15:30.999999 +0800 CST +// Set hour, minute, second and nanosecond +carbon.Parse("2020-01-01").SetTimeNano(13, 14, 15, 999999999).ToString() // 2020-01-01 13:14:15.999999999 +0800 CST +carbon.Parse("2020-01-01").SetTimeNano(13, 14, 90, 999999999).ToString() // 2020-01-01 13:15:30.999999999 +0800 CST + +// Set year +carbon.Parse("2020-02-29").SetYear(2021).ToDateString() // 2021-03-01 +// Set year without overflowing month +carbon.Parse("2020-02-29").SetYearNoOverflow(2021).ToDateString() // 2021-02-28 + +// Set month +carbon.Parse("2020-01-31").SetMonth(2).ToDateString() // 2020-03-02 +// Set month without overflowing month +carbon.Parse("2020-01-31").SetMonthNoOverflow(2).ToDateString() // 2020-02-29 + +// Set start day of the week +carbon.Parse("2020-08-02").SetWeekStartsAt(carbon.Sunday).Week() // 0 +carbon.Parse("2020-08-02").SetWeekStartsAt(carbon.Monday).Week() // 6 + +// Set day +carbon.Parse("2019-08-05").SetDay(31).ToDateString() // 2020-08-31 +carbon.Parse("2020-02-01").SetDay(31).ToDateString() // 2020-03-02 + +// Set hour +carbon.Parse("2020-08-05 13:14:15").SetHour(10).ToDateTimeString() // 2020-08-05 10:14:15 +carbon.Parse("2020-08-05 13:14:15").SetHour(24).ToDateTimeString() // 2020-08-06 00:14:15 + +// Set minute +carbon.Parse("2020-08-05 13:14:15").SetMinute(10).ToDateTimeString() // 2020-08-05 13:10:15 +carbon.Parse("2020-08-05 13:14:15").SetMinute(60).ToDateTimeString() // 2020-08-05 14:00:15 + +// Set second +carbon.Parse("2020-08-05 13:14:15").SetSecond(10).ToDateTimeString() // 2020-08-05 13:14:10 +carbon.Parse("2020-08-05 13:14:15").SetSecond(60).ToDateTimeString() // 2020-08-05 13:15:00 + +// Set millisecond +carbon.Parse("2020-08-05 13:14:15").SetMillisecond(100).Millisecond() // 100 +carbon.Parse("2020-08-05 13:14:15").SetMillisecond(999).Millisecond() // 999 + +// Set microsecond +carbon.Parse("2020-08-05 13:14:15").SetMicrosecond(100000).Microsecond() // 100000 +carbon.Parse("2020-08-05 13:14:15").SetMicrosecond(999999).Microsecond() // 999999 + +// Set nanosecond +carbon.Parse("2020-08-05 13:14:15").SetNanosecond(100000000).Nanosecond() // 100000000 +carbon.Parse("2020-08-05 13:14:15").SetNanosecond(999999999).Nanosecond() // 999999999 +``` + +##### Getter + +```go +// Get total days of the year +carbon.Parse("2019-08-05 13:14:15").DaysInYear() // 365 +carbon.Parse("2020-08-05 13:14:15").DaysInYear() // 366 +// Get total days of the month +carbon.Parse("2020-02-01 13:14:15").DaysInMonth() // 29 +carbon.Parse("2020-04-01 13:14:15").DaysInMonth() // 30 +carbon.Parse("2020-08-01 13:14:15").DaysInMonth() // 31 + +// Get day of the year +carbon.Parse("2020-08-05 13:14:15").DayOfYear() // 218 +// Get week of the year +carbon.Parse("2020-08-05 13:14:15").WeekOfYear() // 32 +// Get day of the month +carbon.Parse("2020-08-05 13:14:15").DayOfMonth() // 5 +// Get week of the month +carbon.Parse("2020-08-05 13:14:15").WeekOfMonth() // 1 +// Get day of the week +carbon.Parse("2020-08-05 13:14:15").DayOfWeek() // 3 + +// Get current year, month, day, hour, minute and second +carbon.Parse("2020-08-05 13:14:15").DateTime() // 2020, 8, 5, 13, 14, 15 +// Get current year, month, day, hour, minute, second and millisecond +carbon.Parse("2020-08-05 13:14:15").DateTimeMilli() // 2020, 8, 5, 13, 14, 15, 999 +// Get current year, month, day, hour, minute, second and microsecond +carbon.Parse("2020-08-05 13:14:15").DateTimeMicro() // 2020, 8, 5, 13, 14, 15, 999999 +// Get current year, month, day, hour, minute, second and nanosecond +carbon.Parse("2020-08-05 13:14:15").DateTimeNano() // 2020, 8, 5, 13, 14, 15, 999999999 + +// Get current year, month and day +carbon.Parse("2020-08-05 13:14:15.999999999").Date() // 2020, 8, 5 +// Get current year, month, day and millisecond +carbon.Parse("2020-08-05 13:14:15.999999999").DateMilli() // 2020, 8, 5, 999 +// Get current year, month, day and microsecond +carbon.Parse("2020-08-05 13:14:15.999999999").DateMicro() // 2020, 8, 5, 999999 +// Get current year, month, day and nanosecond +carbon.Parse("2020-08-05 13:14:15.999999999").DateNano() // 2020, 8, 5, 999999999 + +// Get current hour, minute and second +carbon.Parse("2020-08-05 13:14:15.999999999").Time() // 13, 14, 15 +// Get current hour, minute, second and millisecond +carbon.Parse("2020-08-05 13:14:15.999999999").TimeMilli() // 13, 14, 15, 999 +// Get current hour, minute, second and microsecond +carbon.Parse("2020-08-05 13:14:15.999999999").TimeMicro() // 13, 14, 15, 999999 +// Get current hour, minute, second and nanosecond +carbon.Parse("2020-08-05 13:14:15.999999999").TimeNano() // 13, 14, 15, 999999999 + +// Get current century +carbon.Parse("2020-08-05 13:14:15").Century() // 21 +// Get current decade +carbon.Parse("2019-08-05 13:14:15").Decade() // 10 +carbon.Parse("2021-08-05 13:14:15").Decade() // 20 +// Get current year +carbon.Parse("2020-08-05 13:14:15").Year() // 2020 +// Get current quarter +carbon.Parse("2020-08-05 13:14:15").Quarter() // 3 +// Get current month +carbon.Parse("2020-08-05 13:14:15").Month() // 8 +// Get current week(start from 0) +carbon.Parse("2020-08-02 13:14:15").Week() // 0 +carbon.Parse("2020-08-02").SetWeekStartsAt(carbon.Sunday).Week() // 0 +carbon.Parse("2020-08-02").SetWeekStartsAt(carbon.Monday).Week() // 6 +// Get current day +carbon.Parse("2020-08-05 13:14:15").Day() // 5 +// Get current hour +carbon.Parse("2020-08-05 13:14:15").Hour() // 13 +// Get current minute +carbon.Parse("2020-08-05 13:14:15").Minute() // 14 +// Get current second +carbon.Parse("2020-08-05 13:14:15").Second() // 15 +// Get current millisecond +carbon.Parse("2020-08-05 13:14:15.999").Millisecond() // 999 +// Get current microsecond +carbon.Parse("2020-08-05 13:14:15.999").Microsecond() // 999000 +// Get current nanosecond +carbon.Parse("2020-08-05 13:14:15.999").Nanosecond() // 999000000 + +// Get timestamp with second +carbon.Parse("2020-08-05 13:14:15").Timestamp() // 1596604455 +// Get timestamp with millisecond +carbon.Parse("2020-08-05 13:14:15").TimestampMilli() // 1596604455000 +// Get timestamp with microsecond +carbon.Parse("2020-08-05 13:14:15").TimestampMicro() // 1596604455000000 +// Get timestamp with nanosecond +carbon.Parse("2020-08-05 13:14:15").TimestampNano() // 1596604455000000000 + +// Get timezone name +carbon.SetTimezone(carbon.PRC).Timezone() // CST +carbon.SetTimezone(carbon.Tokyo).Timezone() // JST + +// Get location name +carbon.SetTimezone(carbon.PRC).Location() // PRC +carbon.SetTimezone(carbon.Tokyo).Location() // Asia/Tokyo + +// Get offset seconds from the UTC timezone +carbon.SetTimezone(carbon.PRC).Offset() // 28800 +carbon.SetTimezone(carbon.Tokyo).Offset() // 32400 + +// Get locale name +carbon.Now().SetLocale("en").Locale() // en +carbon.Now().SetLocale("zh-CN").Locale() // zh-CN + +// Get constellation name +carbon.Now().Constellation() // Leo +carbon.Now().SetLocale("en").Constellation() // Leo +carbon.Now().SetLocale("zh-CN").Constellation() // 狮子座 + +// Get season name +carbon.Now().Season() // Summer +carbon.Now().SetLocale("en").Season() // Summer +carbon.Now().SetLocale("zh-CN").Season() // 夏季 + +// Get current age +carbon.Parse("2002-01-01 13:14:15").Age() // 17 +carbon.Parse("2002-12-31 13:14:15").Age() // 18 +``` + +##### Output + +```go +// Output datetime format string +carbon.Parse("2020-08-05 13:14:15").ToDateTimeString() // 2020-08-05 13:14:15 +// Output datetime with millisecond format string +carbon.Parse("2020-08-05T13:14:15.999999999+08:00").ToDateTimeMilliString() // 2020-08-05 13:14:15.999 +// Output datetime with microsecond format string +carbon.Parse("2020-08-05T13:14:15.999999999+08:00").ToDateTimeMicroString() // 2020-08-05 13:14:15.999999 +// Output datetime with nanosecond format string +carbon.Parse("2020-08-05T13:14:15.999999999+08:00").ToDateTimeNanoString() // 2020-08-05 13:14:15.999999999 + +// Output short datetime format string +carbon.Parse("2020-08-05T13:14:15.999999999+08:00").ToShortDateTimeString() // 20200805131415 +// Output short datetime with millisecond format string +carbon.Parse("2020-08-05T13:14:15.999999999+08:00").ToShortDateTimeMilliString() // 20200805131415.999 +// Output short datetime with microsecond format string +carbon.Parse("2020-08-05T13:14:15.999999999+08:00").ToShortDateTimeMicroString() // 20200805131415.999999 +// Output short datetime with nanosecond format string +carbon.Parse("2020-08-05T13:14:15.999999999+08:00").ToShortDateTimeNanoString() // 20200805131415.999999999 + +// Output date format string +carbon.Parse("2020-08-05 13:14:15.999999999").ToDateString() // 2020-08-05 +// Output date with millisecond format string +carbon.Parse("2020-08-05 13:14:15.999999999").ToDateMilliString() // 2020-08-05.999 +// Output date with microsecond format string +carbon.Parse("2020-08-05 13:14:15.999999999").ToDateMicroString() // 2020-08-05.999999 +// Output date with nanosecond format string +carbon.Parse("2020-08-05 13:14:15.999999999").ToDateNanoString() // 2020-08-05.999999999 + +// Output short date format string +carbon.Parse("2020-08-05 13:14:15.999999999").ToShortDateString() // 20200805 +// Output short date with millisecond format string +carbon.Parse("2020-08-05 13:14:15.999999999").ToShortDateMilliString() // 20200805.999 +// Output short date with microsecond format string +carbon.Parse("2020-08-05 13:14:15.999999999").ToShortDateMicroString() // 20200805.999999 +// Output short date with nanosecond format string +carbon.Parse("2020-08-05 13:14:15.999999999").ToShortDateNanoString() // 20200805.999999999 + +// Output time format string +carbon.Parse("2020-08-05 13:14:15.999999999").ToTimeString() // 13:14:15 +// Output time with millisecond format string +carbon.Parse("2020-08-05 13:14:15.999999999").ToTimeMilliString() // 13:14:15.999 +// Output time with microsecond format string +carbon.Parse("2020-08-05 13:14:15.999999999").ToTimeMicroString() // 13:14:15.999999 +// Output time with nanosecond format string +carbon.Parse("2020-08-05 13:14:15.999999999").ToTimeNanoString() // 13:14:15.999999999 + +// Output short time format string +carbon.Parse("2020-08-05 13:14:15.999999999").ToShortTimeString() // 131415 +// Output short time with millisecond format string +carbon.Parse("2020-08-05 13:14:15.999999999").ToShortTimeMilliString() // 131415.999 +// Output short time with microsecond format string +carbon.Parse("2020-08-05 13:14:15.999999999").ToShortTimeMicroString() // 131415.999999 +// Output short time with nanosecond format string +carbon.Parse("2020-08-05 13:14:15.999999999").ToShortTimeNanoString() // 131415.999999999 + +// Output Ansic format string +carbon.Parse("2020-08-05 13:14:15").ToAnsicString() // Wed Aug 5 13:14:15 2020 +// Output Atom format string +carbon.Parse("2020-08-05 13:14:15").ToAtomString() // 2020-08-05T13:14:15+08:00 +// Output Unix date format string +carbon.Parse("2020-08-05 13:14:15").ToUnixDateString() // Wed Aug 5 13:14:15 CST 2020 +// Output Ruby date format string +carbon.Parse("2020-08-05 13:14:15").ToRubyDateString() // Wed Aug 05 13:14:15 +0800 2020 +// Output Kitchen format string +carbon.Parse("2020-08-05 13:14:15").ToKitchenString() // 1:14PM +// Output Cookie format string +carbon.Parse("2020-08-05 13:14:15").ToCookieString() // Wednesday, 05-Aug-2020 13:14:15 CST +// Output day, date and time format string +carbon.Parse("2020-08-05 13:14:15").ToDayDateTimeString() // Wed, Aug 5, 2020 1:14 PM +// Output RSS format string +carbon.Parse("2020-08-05 13:14:15").ToRssString() // Wed, 05 Aug 2020 13:14:15 +0800 +// Output W3C format string +carbon.Parse("2020-08-05 13:14:15").ToW3cString() // 2020-08-05T13:14:15+08:00 + +// Output ISO8601 format string +carbon.Parse("2020-08-05 13:14:15.999999999").ToIso8601String() // 2020-08-05T13:14:15+08:00 +// Output ISO8601 with millisecond format string +carbon.Parse("2020-08-05 13:14:15.999999999").ToIso8601MilliString() // 2020-08-05T13:14:15.999+08:00 +// Output ISO8601 with microsecond format string +carbon.Parse("2020-08-05 13:14:15.999999999").ToIso8601MicroString() // 2020-08-05T13:14:15.999999+08:00 +// Output ISO8601 with nanosecond format string +carbon.Parse("2020-08-05 13:14:15.999999999").ToIso8601NanoString() // 2020-08-05T13:14:15.999999999+08:00 +// Output ISO8601Zulu format string +carbon.Parse("2020-08-05 13:14:15.999999999").ToIso8601ZuluString() // 2020-08-05T13:14:15Z +// Output ISO8601Zulu with millisecond format string +carbon.Parse("2020-08-05 13:14:15.999999999").ToIso8601ZuluMilliString() // 2020-08-05T13:14:15.999Z +// Output ISO8601Zulu with microsecond format string +carbon.Parse("2020-08-05 13:14:15.999999999").ToIso8601ZuluMicroString() // 2020-08-05T13:14:15.999999Z +// Output ISO8601Zulu with nanosecond format string +carbon.Parse("2020-08-05 13:14:15.999999999").ToIso8601ZuluNanoString() // 2020-08-05T13:14:15.999999999Z + +// Output RFC822 format string +carbon.Parse("2020-08-05 13:14:15").ToRfc822String() // 05 Aug 20 13:14 CST +// Output RFC822Z format string +carbon.Parse("2020-08-05 13:14:15").ToRfc822zString() // 05 Aug 20 13:14 +0800 +// Output RFC850 format string +carbon.Parse("2020-08-05 13:14:15").ToRfc850String() // Wednesday, 05-Aug-20 13:14:15 CST +// Output RFC1036 format string +carbon.Parse("2020-08-05 13:14:15").ToRfc1036String() // Wed, 05 Aug 20 13:14:15 +0800 +// Output RFC1123 format string +carbon.Parse("2020-08-05 13:14:15").ToRfc1123String() // Wed, 05 Aug 2020 13:14:15 CST +// Output RFC1123Z format string +carbon.Parse("2020-08-05 13:14:15").ToRfc1123zString() // Wed, 05 Aug 2020 13:14:15 +0800 +// Output RFC2822 format string +carbon.Parse("2020-08-05 13:14:15").ToRfc2822String() // Wed, 05 Aug 2020 13:14:15 +0800 +// Output RFC7231 format string +carbon.Parse("2020-08-05 13:14:15").ToRfc7231String() // Wed, 05 Aug 2020 13:14:15 GMT + +// Output RFC3339 format string +carbon.Parse("2020-08-05T13:14:15.999999999+08:00").ToRfc3339String() // 2020-08-05T13:14:15+08:00 +// Output RFC3339 with millisecond format string +carbon.Parse("2020-08-05T13:14:15.999999999+08:00").ToRfc3339MilliString() // 2020-08-05T13:14:15.999+08:00 +// Output RFC3339 with microsecond format string +carbon.Parse("2020-08-05T13:14:15.999999999+08:00").ToRfc3339MicroString() // 2020-08-05T13:14:15.999999+08:00 +// Output RFC3339 with nanosecond format string +carbon.Parse("2020-08-05T13:14:15.999999999+08:00").ToRfc3339NanoString() // 2020-08-05T13:14:15.999999999+08:00 + +// Output datetime format string +fmt.Printf("%s", carbon.Parse("2020-08-05 13:14:15")) // 2020-08-05 13:14:15 + +// Output "2006-01-02 15:04:05.999999999 -0700 MST" format string +carbon.Parse("2020-08-05 13:14:15").ToString() // 2020-08-05 13:14:15.999999 +0800 CST + +// Output "Jan 2, 2006" format string +carbon.Parse("2020-08-05 13:14:15").ToFormattedDateString() // Aug 5, 2020 +// Output "Mon, Jan 2, 2006" format string +carbon.Parse("2020-08-05 13:14:15").ToFormattedDayDateString() // Wed, Aug 5, 2020 + +// Output string by layout +carbon.Parse("2020-08-05 13:14:15").Layout(carbon.ISO8601Layout) // 2020-08-05T13:14:15+08:00 +carbon.Parse("2020-08-05 13:14:15").Layout("20060102150405") // 20200805131415 +carbon.Parse("2020-08-05 13:14:15").Layout("2006年01月02日 15时04分05秒") // 2020年08月05日 13时14分15秒 +carbon.Parse("2020-08-05 13:14:15").Layout("It is 2006-01-02 15:04:05") // It is 2020-08-05 13:14:15 + +// Output string by format +carbon.Parse("2020-08-05 13:14:15").Format("YmdHis") // 20200805131415 +carbon.Parse("2020-08-05 13:14:15").Format("Y年m月d日 H时i分s秒") // 2020年08月05日 13时14分15秒 +carbon.Parse("2020-08-05 13:14:15").Format("l jS \\o\\f F Y h:i:s A") // Wednesday 5th of August 2020 01:14:15 PM +carbon.Parse("2020-08-05 13:14:15").Format("\\I\\t \\i\\s Y-m-d H:i:s") // It is 2020-08-05 13:14:15 +``` + +> For more supported format signs, please see the Format sign table + +##### Constellation + +```go +// Get constellation name +carbon.Parse("2020-08-05 13:14:15").Constellation() // Leo + +// Whether is Aries +carbon.Parse("2020-08-05 13:14:15").IsAries() // false +// Whether is Taurus +carbon.Parse("2020-08-05 13:14:15").IsTaurus() // false +// Whether is Gemini +carbon.Parse("2020-08-05 13:14:15").IsGemini() // false +// Whether is Cancer +carbon.Parse("2020-08-05 13:14:15").IsCancer() // false +// Whether is Leo +carbon.Parse("2020-08-05 13:14:15").IsLeo() // true +// Whether is Virgo +carbon.Parse("2020-08-05 13:14:15").IsVirgo() // false +// Whether is Libra +carbon.Parse("2020-08-05 13:14:15").IsLibra() // false +// Whether is Scorpio +carbon.Parse("2020-08-05 13:14:15").IsScorpio() // false +// Whether is Sagittarius +carbon.Parse("2020-08-05 13:14:15").IsSagittarius() // false +// Whether is Capricorn +carbon.Parse("2020-08-05 13:14:15").IsCapricorn() // false +// Whether is Aquarius +carbon.Parse("2020-08-05 13:14:15").IsAquarius() // false +// Whether is Pisces +carbon.Parse("2020-08-05 13:14:15").IsPisces() // false +``` + +##### Season + +> According to the meteorological division method, March to May is spring, June to August is summer, September to November is autumn, and December to February is winter + +```go +// Get season name +carbon.Parse("2020-08-05 13:14:15").Season() // Summer + +// Start of the season +carbon.Parse("2020-08-05 13:14:15").StartOfSeason().ToDateTimeString() // 2020-06-01 00:00:00 +// End of the season +carbon.Parse("2020-08-05 13:14:15").EndOfSeason().ToDateTimeString() // 2020-08-31 23:59:59 + +// Whether is spring +carbon.Parse("2020-08-05 13:14:15").IsSpring() // false +// Whether is summer +carbon.Parse("2020-08-05 13:14:15").IsSummer() // true +// Whether is autumn +carbon.Parse("2020-08-05 13:14:15").IsAutumn() // false +// Whether is winter +carbon.Parse("2020-08-05 13:14:15").IsWinter() // false +``` + +##### JSON + +```go +type Person struct { + Name string `json:"name"` + Age int `json:"age"` + Birthday0 carbon.Carbon `json:"birthday0"` + Birthday1 carbon.DateTime `json:"birthday1"` + Birthday2 carbon.DateTimeMilli `json:"birthday2"` + Birthday3 carbon.DateTimeMicro `json:"birthday3"` + Birthday4 carbon.DateTimeNano `json:"birthday4"` + GraduatedAt1 carbon.Date `json:"graduated_at1"` + GraduatedAt2 carbon.DateMilli `json:"graduated_at2"` + GraduatedAt3 carbon.DateMicro `json:"graduated_at3"` + GraduatedAt4 carbon.DateNano `json:"graduated_at4"` + OperatedAt1 carbon.Time `json:"operated_at1"` + OperatedAt2 carbon.TimeMilli `json:"operated_at2"` + OperatedAt3 carbon.TimeMicro `json:"operated_at3"` + OperatedAt4 carbon.TimeNano `json:"operated_at4"` + CreatedAt1 carbon.Timestamp `json:"created_at1"` + CreatedAt2 carbon.TimestampMilli `json:"created_at2"` + CreatedAt3 carbon.TimestampMicro `json:"created_at3"` + CreatedAt4 carbon.TimestampNano `json:"created_at4"` +} + +person := Person { + Name: "gouguoyin", + Age: 18, + Birthday0: carbon.Now().SubYears(18), + Birthday1: carbon.NewDateTime(carbon.Now().SubYears(18)), + Birthday2: carbon.NewDateTimeMilli(carbon.Now().SubYears(18)), + Birthday3: carbon.NewDateTimeMicro(carbon.Now().SubYears(18)), + Birthday4: carbon.NewDateTimeNano(carbon.Now().SubYears(18)), + GraduatedAt1: carbon.NewDate(carbon.Now()), + GraduatedAt2: carbon.NewDateMilli(carbon.Now()), + GraduatedAt3: carbon.NewDateMicro(carbon.Now()), + GraduatedAt4: carbon.NewDateNano(carbon.Now()), + OperatedAt1: carbon.NewTime(carbon.Now()), + OperatedAt2: carbon.NewTimeMilli(carbon.Now()), + OperatedAt3: carbon.NewTimeMicro(carbon.Now()), + OperatedAt4: carbon.NewTimeNano(carbon.Now()), + CreatedAt1: carbon.NewTimestamp(carbon.Now()), + CreatedAt2: carbon.NewTimestampMilli(carbon.Now()), + CreatedAt3: carbon.NewTimestampMicro(carbon.Now()), + CreatedAt4: carbon.NewTimestampNano(carbon.Now()), +} + +data, err := json.Marshal(&person) +if err != nil { + // Error handle... + log.Fatal(err) +} +fmt.Printf("%s", data) +// Output +{ + "name": "gouguoyin", + "age": 18, + "birthday0": "2003-07-16 13:14:15", + "birthday1": "2003-07-16 13:14:15", + "birthday2": "2003-07-16 13:14:15.999", + "birthday3": "2003-07-16 13:14:15.999999", + "birthday4": "2003-07-16 13:14:15.999999999", + "graduated_at1": "2020-08-05", + "graduated_at2": "2020-08-05.999", + "graduated_at3": "2020-08-05.999999", + "graduated_at4": "2020-08-05.999999999", + "operated_at1": "13:14:15", + "operated_at2": "13:14:15.999", + "operated_at3": "13:14:15.999999", + "operated_at4": "13:14:15.999999999", + "created_at1": 1596604455, + "created_at2": 1596604455999, + "created_at3": 1596604455999999, + "created_at4": 1596604455999999999 +} + +err := json.Unmarshal([]byte(data), &person) +if err != nil { + // Error handle... + log.Fatal(err) +} + +person.Birthday0.String() // 2003-07-16 13:14:15 +person.Birthday1.String() // 2003-07-16 13:14:15 +person.Birthday2.String() // 2003-07-16 13:14:15.999 +person.Birthday3.String() // 2003-07-16 13:14:15.999999 +person.Birthday4.String() // 2003-07-16 13:14:15.999999999 + +person.GraduatedAt1.String() // 2020-08-05 +person.GraduatedAt2.String() // 2020-08-05.999 +person.GraduatedAt3.String() // 2020-08-05.999999 +person.GraduatedAt4.String() // 2020-08-05.999999999 + +person.OperatedAt1.String() // 13:14:15 +person.OperatedAt2.String() // 13:14:15.999 +person.OperatedAt3.String() // 13:14:15.999999 +person.OperatedAt4.String() // 13:14:15.999999999 + +person.CreatedAt1.String() // "1596604455" +person.CreatedAt2.String() // "1596604455999" +person.CreatedAt3.String() // "1596604455999999" +person.CreatedAt4.String() // "1596604455999999999" + +person.CreatedAt1.Int64() // 1596604455 +person.CreatedAt2.Int64() // 1596604455999 +person.CreatedAt3.Int64() // 1596604455999999 +person.CreatedAt4.Int64() // 1596604455999999999 +``` + +##### Calendar + +The following calendars are supported + +* [Julian Day/Modified Julian Day](./calendar/julian/README.md "JD/MJD") +* [Chinese Lunar](./calendar/lunar/README.md "Chinese Lunar") +* [Persian/Jalaali](./calendar/persian/README.md "Persian/Jalaali") + +##### I18n + +The following languages are supported + +* [Simplified Chinese(zh-CN)](./lang/zh-CN.json "Simplified Chinese"):translated + by [gouguoyin](https://github.com/gouguoyin "gouguoyin") +* [Traditional Chinese(zh-TW)](./lang/zh-TW.json "Traditional Chinese"):translated + by [gouguoyin](https://github.com/gouguoyin "gouguoyin") +* [English(en)](./lang/en.json "English"):translated + by [gouguoyin](https://github.com/gouguoyin "gouguoyin") +* [Japanese(jp)](./lang/jp.json "Japanese"):translated + by [gouguoyin](https://github.com/gouguoyin "gouguoyin") +* [Korean(kr)](./lang/kr.json "Korean"):translated by [nannul](https://github.com/nannul "nannul") +* [German(de)](./lang/de.json "German"):translated by [benzammour](https://github.com/benzammour "benzammour") +* [Spanish(es)](./lang/es.json "Spanish"):translated by [hgisinger](https://github.com/hgisinger "hgisinger") +* [Turkish(tr)](./lang/tr.json "Turkish"): translated by [emresenyuva](https://github.com/emresenyuva "emresenyuva") +* [Portuguese(pt)](./lang/pt.json "Portuguese"): translated by [felipear89](https://github.com/felipear89 "felipear89") +* [Russian(ru)](./lang/ru.json "Russian"): translated by [zemlyak](https://github.com/zemlyak "zemlyak") +* [Ukrainian(uk)](./lang/uk.json "Ukrainian"): translated by [open-git](https://github.com/open-git "open-git") +* [Romanian(ro)](./lang/ro.json "Romanian"): translated by [DrOctavius](https://github.com/DrOctavius "DrOctavius") +* [Indonesian(id)](./lang/id.json "Indonesian"): translated by [justpoypoy](https://github.com/justpoypoy "justpoypoy") +* [Italian(it)](../blob/master/lang/it.json "Italian"): translated by [nicoloHevelop](https://github.com/nicoloHevelop "nicoloHevelop") +* [Bahasa Malaysia(ms-MY)](./lang/ms-MY.json "Bahasa Malaysia"): translated + by [hollowaykeanho](https://github.com/hollowaykeanho "hollowaykeanho") +* [French(fr)](./lang/fr.json "French"): translated + by [hollowaykeanho](https://github.com/hollowaykeanho "hollowaykeanho") +* [Thailand(th)](./lang/th.json "Thailand"): translated by [izcream](https://github.com/izcream "izcream") +* [Swedish(se)](./lang/se.json "Swedish"): translated by [jwanglof](https://github.com/jwanglof "jwanglof") +* [Farsi(fa)](./lang/fa.json "Farsi"): translated by [erfanMomeniii](https://github.com/erfanMomeniii "erfanMomeniii") +* [Dutch(nl)](./lang/nl.json "Dutch"): translated by [RemcoE33](https://github.com/RemcoE33 "RemcoE33") +* [VietNamese(vi)](./lang/vi.json "VietNam"): translated by [culy247](https://github.com/culy247 "culy247") +* [Hindi(hi)](./lang/hi.json "India"): translated by [chauhan17nitin](https://github.com/chauhan17nitin "chauhan17nitin") +* [Polish(pl)](./lang/pl.json "Polish"): translated by [gouguoyin](https://github.com/gouguoyin "gouguoyin") +* [Bulgarian(bg)](./lang/bg.json "Bulgarian"): translated by [yuksbg](https://github.com/yuksbg "yuksbg") +* [Arabic(ar)](./lang/ar.json "Arabic"): translated by [zumoshi](https://github.com/zumoshi "zumoshi") +* [Hungarian(hu)](./lang/hu.json "Hungarian"): translated by [kenlas](https://github.com/kenlas "kenlas") +* [Dansk(dk)](./lang/dk.json "Dansk"): translated by [Munk91](https://github.com/Munk91 "Munk91") + +The following methods are supported + +* `Constellation()`:get constellation name, like `Aries` +* `Season()`:get season name, like `Spring` +* `DiffForHumans()`:get the difference with human-readable format string, like `1 year from now` +* `ToMonthString()`:output month format string, like `January` +* `ToShortMonthString()`:output short month format string, like `Jan` +* `ToWeekString()`:output week format string, like `Sunday` +* `ToShortWeekString()`:output short week format string, like `Sun` + +###### Set locale + +```go +lang := carbon.NewLanguage() +lang.SetLocale("en") + +c := carbon.SetLanguage(lang) +if c.Error != nil { + // Error handle... + log.Fatal(c.Error) +} + +c.Now().AddHours(1).DiffForHumans() // 1 hour from now +c.Now().AddHours(1).ToMonthString() // August +c.Now().AddHours(1).ToShortMonthString() // Aug +c.Now().AddHours(1).ToWeekString() // Wednesday +c.Now().AddHours(1).ToShortWeekString() // Wed +c.Now().AddHours(1).Constellation() // Leo +c.Now().AddHours(1).Season() // Summer +``` + +###### Reset some resources(the rests still translate from the given locale) + +```go +lang := carbon.NewLanguage() + +resources := map[string]string { + "hour": "%dh", +} +lang.SetLocale("en").SetResources(resources) + +c := carbon.SetLanguage(lang) +if c.Error != nil { + // Error handle... + log.Fatal(c.Error) +} + +c.Now().AddYears(1).DiffForHumans() // 1 year from now +c.Now().AddHours(1).DiffForHumans() // 1h from now +c.Now().ToMonthString() // August +c.Now().ToShortMonthString() // Aug +c.Now().ToWeekString() // Tuesday +c.Now().ToShortWeekString() // Tue +c.Now().Constellation() // Leo +c.Now().Season() // Summer +``` + +###### Reset all resources + +```go +lang := carbon.NewLanguage() +resources := map[string]string { + "months": "january|february|march|april|may|june|july|august|september|october|november|december", + "short_months": "jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec", + "weeks": "sunday|monday|tuesday|wednesday|thursday|friday|saturday", + "short_weeks": "sun|mon|tue|wed|thu|fri|sat", + "seasons": "spring|summer|autumn|winter", + "constellations": "aries|taurus|gemini|cancer|leo|virgo|libra|scorpio|sagittarius|capricornus|aquarius|pisce", + "year": "1 yr|%d yrs", + "month": "1 mo|%d mos", + "week": "%dw", + "day": "%dd", + "hour": "%dh", + "minute": "%dm", + "second": "%ds", + "now": "just now", + "ago": "%s ago", + "from_now": "in %s", + "before": "%s before", + "after": "%s after", +} +lang.SetResources(resources) + +c := carbon.SetLanguage(lang) +c.Now().AddYears(1).DiffForHumans() // in 1 yr +c.Now().AddHours(1).DiffForHumans() // in 1h +c.Now().ToMonthString() // august +c.Now().ToShortMonthString() // aug +c.Now().ToWeekString() // tuesday +c.Now().ToShortWeekString() // tue +c.Now().Constellation() // leo +c.Now().Season() // summer +``` + +##### Testing + +```go +c := carbon.SetTimezone(carbon.UTC) + +c.Now().ToDateString() // 2023-12-27 +c.Now().IsSetTestNow() // false + +c.SetTestNow(carbon.Parse("2020-08-05")) +c.Now().ToDateString() // 2020-08-05 +c.Now().IsSetTestNow() // true + +c.UnSetTestNow() +c.Now().ToDateString() // 2023-12-27 +c.Now().IsSetTestNow() // false +``` + +##### Error + +> If more than one error occurs, only the first error is returned + +```go +c := carbon.SetTimezone("xxx").Parse("2020-08-05") +if c.Error != nil { + // Error handle... + log.Fatal(c.Error) +} +// Output +invalid timezone "xxx", please see the file "$GOROOT/lib/time/zoneinfo.zip" for all valid timezones +``` + +#### Appendix + +##### Format sign table + +| sign | desc | length | range | example | +|:----:|:------------------------------------------------------------------------------------------------------:|:------:|:----------------:|:-------------------------------:| +| d | Day of the month, padded to 2 | 2 | 01-31 | 02 | +| D | Day of the week, as an abbreviate localized string | 3 | Mon-Sun | Mon | +| j | Day of the month, no padding | - | 1-31 | 2 | +| S | English ordinal suffix for the day of the month, 2 characters. Eg: st, nd, rd or th. Works well with j | 2 | st/nd/rd/th | th | +| l | Day of the week, as an unabbreviated localized string | - | Monday-Sunday | Monday | +| F | Month as an unabbreviated localized string | - | January-December | January | +| m | Month, padded to 2 | 2 | 01-12 | 01 | +| M | Month as an abbreviated localized string | 3 | Jan-Dec | Jan | +| n | Month, no padding | - | 1-12 | 1 | +| Y | Four-digit year | 4 | 0000-9999 | 2006 | +| y | Two-digit year | 2 | 00-99 | 06 | +| a | Lowercase morning or afternoon sign | 2 | am/pm | pm | +| A | Uppercase morning or afternoon sign | 2 | AM/PM | PM | +| g | Hour in 12-hour format, no padding | - | 1-12 | 3 | +| G | Hour in 24-hour format, no padding | - | 0-23 | 15 | +| h | Hour in 12-hour format, padded to 2 | 2 | 00-11 | 03 | +| H | Hour in 24-hour format, padded to 2 | 2 | 00-23 | 15 | +| i | Minute, padded to 2 | 2 | 01-59 | 04 | +| s | Second, padded to 2 | 2 | 01-59 | 05 | +| O | Difference to Greenwich time (GMT) without colon between hours and minutes | - | - | -0700 | +| P | Difference to Greenwich time (GMT) with colon between hours and minutes | - | - | -07:00 | +| T | Abbreviated timezone | - | - | MST | +| W | week of the year, padded to 2 | 2 | 01-52 | 01 | +| N | day of the week, padded to 2 | 2 | 01-07 | 02 | +| L | Whether it's a leap year | 1 | 0-1 | 0 | +| U | Unix timestamp with seconds | - | - | 1596604455 | +| V | Unix timestamp with millisecond | - | - | 1596604455666 | +| X | Unix timestamp with microsecond | - | - | 1596604455666666 | +| Z | Unix timestamp with nanoseconds | - | - | 1596604455666666666 | +| v | Millisecond | - | 1-999 | 999 | +| u | Microsecond | - | 1-999999 | 999999 | +| x | Nanosecond | - | 1-999999999 | 999999999 | +| w | Day of the week | 1 | 0-6 | 1 | +| t | Total days of the month | 2 | 28-31 | 31 | +| z | Day of the year | - | 1-365 | 2 | +| e | Location | - | - | America/New_York | +| Q | Quarter | 1 | 1-4 | 1 | +| C | Century | - | 0-99 | 21 | + +#### FAQ + +1、What is the difference between v1 and v2? +> There is no difference between v1 and v2 of the API, but the implementation of the translation resource files in `language.go` is different. The v1 is implemented by the third-party extension library [packr](https://github.com/gobuffalo/packr), and the v2 is implemented by the standard library [embed](https://pkg.go.dev/embed) after `golang1.16`. If your golang version is `1.16+`, the v2 is recommended, otherwise, the v1 is required. + +#### References + +* [briannesbitt/carbon](https://github.com/briannesbitt/Carbon) +* [nodatime/nodatime](https://github.com/nodatime/nodatime) +* [jinzhu/now](https://github.com/jinzhu/now) +* [goframe/gtime](https://github.com/gogf/gf/tree/master/os/gtime) +* [jodaOrg/joda-time](https://github.com/jodaOrg/joda-time) +* [arrow-py/arrow](https://github.com/arrow-py/arrow) +* [moment/moment](https://github.com/moment/moment) +* [iamkun/dayjs](https://github.com/iamkun/dayjs) + +#### Contributors +Thanks to all of the following who contributed to `Carbon`: + + + +#### Sponsors + +`Carbon` is a non-commercial open source project. If you want to support `Carbon`, you can [buy a cup of coffee](https://opencollective.com/go-carbon) for developer. + +#### Thanks + +`Carbon` had been being developed with GoLand under the free JetBrains Open Source license, I would like to express my +thanks here. + +JetBrains diff --git a/vendor/github.com/dromara/carbon/v2/boundary.go b/vendor/github.com/dromara/carbon/v2/boundary.go new file mode 100644 index 000000000..879fadfa3 --- /dev/null +++ b/vendor/github.com/dromara/carbon/v2/boundary.go @@ -0,0 +1,201 @@ +package carbon + +// StartOfCentury returns a Carbon instance for start of the century. +// 本世纪开始时间 +func (c Carbon) StartOfCentury() Carbon { + if c.Error != nil { + return c + } + return c.create(c.Year()/YearsPerCentury*YearsPerCentury, 1, 1, 0, 0, 0, 0) +} + +// EndOfCentury returns a Carbon instance for end of the century. +// 本世纪结束时间 +func (c Carbon) EndOfCentury() Carbon { + if c.Error != nil { + return c + } + return c.create(c.Year()/YearsPerCentury*YearsPerCentury+99, 12, 31, 23, 59, 59, 999999999) +} + +// StartOfDecade returns a Carbon instance for start of the decade. +// 本年代开始时间 +func (c Carbon) StartOfDecade() Carbon { + if c.Error != nil { + return c + } + return c.create(c.Year()/YearsPerDecade*YearsPerDecade, 1, 1, 0, 0, 0, 0) +} + +// EndOfDecade returns a Carbon instance for end of the decade. +// 本年代结束时间 +func (c Carbon) EndOfDecade() Carbon { + if c.Error != nil { + return c + } + return c.create(c.Year()/YearsPerDecade*YearsPerDecade+9, 12, 31, 23, 59, 59, 999999999) +} + +// StartOfYear returns a Carbon instance for start of the year. +// 本年开始时间 +func (c Carbon) StartOfYear() Carbon { + if c.Error != nil { + return c + } + return c.create(c.Year(), 1, 1, 0, 0, 0, 0) +} + +// EndOfYear returns a Carbon instance for end of the year. +// 本年结束时间 +func (c Carbon) EndOfYear() Carbon { + if c.Error != nil { + return c + } + return c.create(c.Year(), 12, 31, 23, 59, 59, 999999999) +} + +// StartOfQuarter returns a Carbon instance for start of the quarter. +// 本季度开始时间 +func (c Carbon) StartOfQuarter() Carbon { + if c.Error != nil { + return c + } + year, quarter, day := c.Year(), c.Quarter(), 1 + return c.create(year, 3*quarter-2, day, 0, 0, 0, 0) +} + +// EndOfQuarter returns a Carbon instance for end of the quarter. +// 本季度结束时间 +func (c Carbon) EndOfQuarter() Carbon { + if c.Error != nil { + return c + } + year, quarter, day := c.Year(), c.Quarter(), 30 + switch quarter { + case 1, 4: + day = 31 + case 2, 3: + day = 30 + } + return c.create(year, 3*quarter, day, 23, 59, 59, 999999999) +} + +// StartOfMonth returns a Carbon instance for start of the month. +// 本月开始时间 +func (c Carbon) StartOfMonth() Carbon { + if c.Error != nil { + return c + } + year, month, _ := c.Date() + return c.create(year, month, 1, 0, 0, 0, 0) +} + +// EndOfMonth returns a Carbon instance for end of the month. +// 本月结束时间 +func (c Carbon) EndOfMonth() Carbon { + if c.Error != nil { + return c + } + year, month, _ := c.Date() + return c.create(year, month+1, 0, 23, 59, 59, 999999999) +} + +// StartOfWeek returns a Carbon instance for start of the week. +// 本周开始时间 +func (c Carbon) StartOfWeek() Carbon { + if c.Error != nil { + return c + } + dayOfWeek, weekStartsAt := c.DayOfWeek(), int(c.weekStartsAt) + return c.SubDays((DaysPerWeek + dayOfWeek - weekStartsAt) % DaysPerWeek).StartOfDay() +} + +// EndOfWeek returns a Carbon instance for end of the week. +// 本周结束时间 +func (c Carbon) EndOfWeek() Carbon { + if c.Error != nil { + return c + } + dayOfWeek, weekEndsAt := c.DayOfWeek(), int(c.weekStartsAt)+DaysPerWeek-1 + return c.AddDays((DaysPerWeek - dayOfWeek + weekEndsAt) % DaysPerWeek).EndOfDay() +} + +// StartOfDay returns a Carbon instance for start of the day. +// 本日开始时间 +func (c Carbon) StartOfDay() Carbon { + if c.Error != nil { + return c + } + year, month, day := c.Date() + return c.create(year, month, day, 0, 0, 0, 0) +} + +// EndOfDay returns a Carbon instance for end of the day. +// 本日结束时间 +func (c Carbon) EndOfDay() Carbon { + if c.Error != nil { + return c + } + year, month, day := c.Date() + return c.create(year, month, day, 23, 59, 59, 999999999) +} + +// StartOfHour returns a Carbon instance for start of the hour. +// 小时开始时间 +func (c Carbon) StartOfHour() Carbon { + if c.Error != nil { + return c + } + year, month, day := c.Date() + return c.create(year, month, day, c.Hour(), 0, 0, 0) +} + +// EndOfHour returns a Carbon instance for end of the hour. +// 小时结束时间 +func (c Carbon) EndOfHour() Carbon { + if c.Error != nil { + return c + } + year, month, day := c.Date() + return c.create(year, month, day, c.Hour(), 59, 59, 999999999) +} + +// StartOfMinute returns a Carbon instance for start of the minute. +// 分钟开始时间 +func (c Carbon) StartOfMinute() Carbon { + if c.Error != nil { + return c + } + year, month, day, hour, minute, _ := c.DateTime() + return c.create(year, month, day, hour, minute, 0, 0) +} + +// EndOfMinute returns a Carbon instance for end of the minute. +// 分钟结束时间 +func (c Carbon) EndOfMinute() Carbon { + if c.Error != nil { + return c + } + year, month, day, hour, minute, _ := c.DateTime() + return c.create(year, month, day, hour, minute, 59, 999999999) +} + +// StartOfSecond returns a Carbon instance for start of the second. +// 秒开始时间 +func (c Carbon) StartOfSecond() Carbon { + if c.Error != nil { + return c + } + year, month, day, hour, minute, second := c.DateTime() + return c.create(year, month, day, hour, minute, second, 0) +} + +// EndOfSecond returns a Carbon instance for end of the second. +// 秒结束时间 +func (c Carbon) EndOfSecond() Carbon { + if c.Error != nil { + return c + } + year, month, day, hour, minute, second := c.DateTime() + return c.create(year, month, day, hour, minute, second, 999999999) +} diff --git a/vendor/github.com/dromara/carbon/v2/calendar.go b/vendor/github.com/dromara/carbon/v2/calendar.go new file mode 100644 index 000000000..00fbd4ae9 --- /dev/null +++ b/vendor/github.com/dromara/carbon/v2/calendar.go @@ -0,0 +1,61 @@ +package carbon + +import ( + "github.com/dromara/carbon/v2/calendar/julian" + "github.com/dromara/carbon/v2/calendar/lunar" + "github.com/dromara/carbon/v2/calendar/persian" +) + +// Lunar converts Carbon instance to Lunar instance. +// 将 Carbon 实例转化为 Lunar 实例 +func (c Carbon) Lunar() (l lunar.Lunar) { + if c.Error != nil { + l.Error = c.Error + return + } + return lunar.FromGregorian(c.StdTime()).ToLunar() +} + +// CreateFromLunar creates a Carbon instance from Lunar date and time. +// 从 农历日期 创建 Carbon 实例 +func CreateFromLunar(year, month, day, hour, minute, second int, isLeapMonth bool) Carbon { + t := lunar.FromLunar(year, month, day, hour, minute, second, isLeapMonth).ToGregorian().Time + return CreateFromStdTime(t) +} + +// Julian converts Carbon instance to Julian instance. +// 将 Carbon 实例转化为 Julian 实例 +func (c Carbon) Julian() (j julian.Julian) { + if c.Error != nil { + return + } + return julian.FromGregorian(c.StdTime()).ToJulian() +} + +// CreateFromJulian creates a Carbon instance from Julian Day or Modified Julian Day. +// 从 儒略日/简化儒略日 创建 Carbon 实例 +func CreateFromJulian(f float64) Carbon { + t := julian.FromJulian(f).ToGregorian().Time + return CreateFromStdTime(t) +} + +// Persian converts Carbon instance to Persian instance. +// 将 Carbon 实例转化为 Persian 实例 +func (c Carbon) Persian() (p persian.Persian) { + if c.Error != nil { + return + } + return persian.FromGregorian(c.StdTime()).ToPersian() +} + +// CreateFromPersian creates a Carbon instance from Persian date and time. +// 从 波斯日期 创建 Carbon 实例 +func CreateFromPersian(year, month, day, hour, minute, second int) (c Carbon) { + p := persian.FromPersian(year, month, day, hour, minute, second) + if p.Error != nil { + c.Error = p.Error + return + } + t := p.ToGregorian().Time + return CreateFromStdTime(t) +} diff --git a/vendor/github.com/dromara/carbon/v2/calendar/gregorian.go b/vendor/github.com/dromara/carbon/v2/calendar/gregorian.go new file mode 100644 index 000000000..647c2e3b7 --- /dev/null +++ b/vendor/github.com/dromara/carbon/v2/calendar/gregorian.go @@ -0,0 +1,280 @@ +// Package calendar is part of the carbon package. +package calendar + +import ( + "fmt" + "time" +) + +var InvalidDateError = func() error { + return fmt.Errorf("invalid gregorian date, please make sure the date is valid") +} + +// month constants +// 月份常量 +const ( + January = "January" // 一月 + February = "February" // 二月 + March = "March" // 三月 + April = "April" // 四月 + May = "May" // 五月 + June = "June" // 六月 + July = "July" // 七月 + August = "August" // 八月 + September = "September" // 九月 + October = "October" // 十月 + November = "November" // 十一月 + December = "December" // 十二月 +) + +// week constants +// 星期常量 +const ( + Monday = "Monday" // 周一 + Tuesday = "Tuesday" // 周二 + Wednesday = "Wednesday" // 周三 + Thursday = "Thursday" // 周四 + Friday = "Friday" // 周五 + Saturday = "Saturday" // 周六 + Sunday = "Sunday" // 周日 +) + +// number constants +// 数字常量 +const ( + YearsPerMillennium = 1000 // 每千年1000年 + YearsPerCentury = 100 // 每世纪100年 + YearsPerDecade = 10 // 每十年10年 + QuartersPerYear = 4 // 每年4个季度 + MonthsPerYear = 12 // 每年12月 + MonthsPerQuarter = 3 // 每季度3月 + WeeksPerNormalYear = 52 // 每常规年52周 + weeksPerLongYear = 53 // 每长年53周 + WeeksPerMonth = 4 // 每月4周 + DaysPerLeapYear = 366 // 每闰年366天 + DaysPerNormalYear = 365 // 每常规年365天 + DaysPerWeek = 7 // 每周7天 + HoursPerWeek = 168 // 每周168小时 + HoursPerDay = 24 // 每天24小时 + MinutesPerDay = 1440 // 每天1440分钟 + MinutesPerHour = 60 // 每小时60分钟 + SecondsPerWeek = 604800 // 每周604800秒 + SecondsPerDay = 86400 // 每天86400秒 + SecondsPerHour = 3600 // 每小时3600秒 + SecondsPerMinute = 60 // 每分钟60秒 +) + +// layout constants +// 布局模板常量 +const ( + AtomLayout = RFC3339Layout + ANSICLayout = time.ANSIC + CookieLayout = "Monday, 02-Jan-2006 15:04:05 MST" + KitchenLayout = time.Kitchen + RssLayout = time.RFC1123Z + RubyDateLayout = time.RubyDate + UnixDateLayout = time.UnixDate + W3cLayout = RFC3339Layout + + RFC1036Layout = "Mon, 02 Jan 06 15:04:05 -0700" + RFC1123Layout = time.RFC1123 + RFC1123ZLayout = time.RFC1123Z + RFC2822Layout = time.RFC1123Z + RFC3339Layout = "2006-01-02T15:04:05Z07:00" + RFC3339MilliLayout = "2006-01-02T15:04:05.999Z07:00" + RFC3339MicroLayout = "2006-01-02T15:04:05.999999Z07:00" + RFC3339NanoLayout = "2006-01-02T15:04:05.999999999Z07:00" + RFC7231Layout = "Mon, 02 Jan 2006 15:04:05 MST" + RFC822Layout = time.RFC822 + RFC822ZLayout = time.RFC822Z + RFC850Layout = time.RFC850 + + ISO8601Layout = "2006-01-02T15:04:05-07:00" + ISO8601MilliLayout = "2006-01-02T15:04:05.999-07:00" + ISO8601MicroLayout = "2006-01-02T15:04:05.999999-07:00" + ISO8601NanoLayout = "2006-01-02T15:04:05.999999999-07:00" + + DayDateTimeLayout = "Mon, Jan 2, 2006 3:04 PM" + DateTimeLayout = "2006-01-02 15:04:05" + DateTimeMilliLayout = "2006-01-02 15:04:05.999" + DateTimeMicroLayout = "2006-01-02 15:04:05.999999" + DateTimeNanoLayout = "2006-01-02 15:04:05.999999999" + ShortDateTimeLayout = "20060102150405" + ShortDateTimeMilliLayout = "20060102150405.999" + ShortDateTimeMicroLayout = "20060102150405.999999" + ShortDateTimeNanoLayout = "20060102150405.999999999" + + DateLayout = "2006-01-02" + DateMilliLayout = "2006-01-02.999" + DateMicroLayout = "2006-01-02.999999" + DateNanoLayout = "2006-01-02.999999999" + ShortDateLayout = "20060102" + ShortDateMilliLayout = "20060102.999" + ShortDateMicroLayout = "20060102.999999" + ShortDateNanoLayout = "20060102.999999999" + + TimeLayout = "15:04:05" + TimeMilliLayout = "15:04:05.999" + TimeMicroLayout = "15:04:05.999999" + TimeNanoLayout = "15:04:05.999999999" + ShortTimeLayout = "150405" + ShortTimeMilliLayout = "150405.999" + ShortTimeMicroLayout = "150405.999999" + ShortTimeNanoLayout = "150405.999999999" +) + +// Gregorian defines a Gregorian struct. +// 定义 Gregorian 结构体 +type Gregorian struct { + Time time.Time + Error error +} + +// NewGregorian returns a new Gregorian instance. +// 初始化 Gregorian 结构体 +func NewGregorian(t time.Time) (g Gregorian) { + if t.IsZero() { + return + } + g.Time = t + return +} + +// MaxValue returns a Gregorian instance for the greatest supported date. +// 返回 Gregorian 的最大值 +func MaxValue() Gregorian { + return NewGregorian(time.Date(9999, 12, 31, 23, 59, 59, 999999999, time.UTC)) +} + +// MinValue returns a Gregorian instance for the lowest supported date. +// 返回 Gregorian 的最小值 +func MinValue() Gregorian { + return NewGregorian(time.Date(-9998, 1, 1, 0, 0, 0, 0, time.UTC)) +} + +// Date gets gregorian year, month, and day like 2020, 8, 5. +// 获取公历年、月、日 +func (g Gregorian) Date() (year, month, day int) { + if g.IsZero() { + return 0, 0, 0 + } + var tm time.Month + year, tm, day = g.Time.Date() + month = int(tm) + return +} + +// Clock gets gregorian hour, minute, and second like 13, 14, 15. +// 获取公历时、分、秒 +func (g Gregorian) Clock() (hour, minute, second int) { + if g.IsZero() { + return 0, 0, 0 + } + return g.Time.Clock() +} + +// Year gets gregorian year like 2020. +// 获取公历年 +func (g Gregorian) Year() int { + if g.IsZero() { + return 0 + } + return g.Time.Year() +} + +// Month gets gregorian month like 8. +// 获取公历月,如 8 +func (g Gregorian) Month() int { + if g.IsZero() { + return 0 + } + return int(g.Time.Month()) +} + +// Week gets gregorian week day like 0. +// 获取周 +func (g Gregorian) Week() int { + if g.IsZero() { + return 0 + } + return int(g.Time.Weekday()) +} + +// Day gets gregorian day like 5. +// 获取公历日,如 0 +func (g Gregorian) Day() int { + if g.IsZero() { + return 0 + } + return g.Time.Day() +} + +// Hour gets gregorian hour like 13. +// 获取公历小时,如 13 +func (g Gregorian) Hour() int { + if g.IsZero() { + return 0 + } + return g.Time.Hour() +} + +// Minute gets gregorian minute like 14. +// 获取公历分钟数,如 14 +func (g Gregorian) Minute() int { + if g.IsZero() { + return 0 + } + return g.Time.Minute() +} + +// Second gets gregorian second like 15. +// 获取公历秒数,如 15 +func (g Gregorian) Second() int { + if g.IsZero() { + return 0 + } + return g.Time.Second() +} + +// Location gets gregorian timezone information. +// 获取时区信息 +func (g Gregorian) Location() *time.Location { + return g.Time.Location() +} + +// String implements Stringer interface and outputs a string in YYYY-MM-DD HH::ii::ss format like "2019-12-07 00:00:00". +// 实现 Stringer 接口, 输出 YYYY-MM-DD HH::ii::ss 格式字符串,如 "2019-12-07 00:00:00" +func (g Gregorian) String() string { + if g.IsZero() { + return "" + } + return g.Time.Format(DateTimeLayout) +} + +// IsZero reports whether is zero time. +// 是否是零值时间 +func (g Gregorian) IsZero() bool { + return g.Time.IsZero() +} + +// IsValid reports whether is a valid gregorian date. +// 是否是有效的年份 +func (g Gregorian) IsValid() bool { + if g.Year() >= MinValue().Year() && g.Year() <= MaxValue().Year() && g.Month() >= MinValue().Month() && g.Month() <= MaxValue().Month() && g.Day() >= MinValue().Day() && g.Day() <= MaxValue().Day() { + return true + } + return false +} + +// IsLeapYear reports whether is a leap year. +// 是否是闰年 +func (g Gregorian) IsLeapYear() bool { + if g.IsZero() { + return false + } + year := g.Year() + if year%400 == 0 || (year%4 == 0 && year%100 != 0) { + return true + } + return false +} diff --git a/vendor/github.com/dromara/carbon/v2/calendar/julian/README.cn.md b/vendor/github.com/dromara/carbon/v2/calendar/julian/README.cn.md new file mode 100644 index 000000000..412de5413 --- /dev/null +++ b/vendor/github.com/dromara/carbon/v2/calendar/julian/README.cn.md @@ -0,0 +1,61 @@ +# 儒略日/简化儒略日 + +简体中文 | [English](README.md) | [日本語](README.jp.md) + +#### 用法示例 +##### 将 `公历` 转换成 `儒略日` +```go +// 默认保留 6 位小数精度 +carbon.Parse("2024-01-24 12:00:00").Julian().JD() // 2460334 +carbon.Parse("2024-01-24 13:14:15").Julian().JD() // 2460334.051563 + +// 保留 4 位小数精度 +carbon.Parse("2024-01-24 12:00:00").Julian().JD(4) // 2460334 +carbon.Parse("2024-01-24 13:14:15").Julian().JD(4) // 2460334.0516 +``` + +##### 将 `公历` 转换成 `简化儒略日` +```go +// 默认保留 6 位小数精度 +carbon.Parse("2024-01-24 12:00:00").Julian().MJD() // 60333.5 +carbon.Parse("2024-01-24 13:14:15").Julian().MJD() // 60333.551563 + +// 保留 4 位小数精度 +carbon.Parse("2024-01-24 12:00:00").Julian().MJD(4) // 60333.5 +carbon.Parse("2024-01-24 13:14:15").Julian().MJD(4) // 60333.5516 +``` + +##### 将 `儒略日` 转换成 `简化儒略日` +```go +// 默认保留 6 位小数精度 +carbon.CreateFromJulian(2460334).Julian().MJD() // 60333.5 +carbon.CreateFromJulian(2460334.051563).Julian().MJD() // 60332.551563 + +// 保留 4 位小数精度 +carbon.CreateFromJulian(2460334).Julian().MJD(4) // 60333.5 +carbon.CreateFromJulian(2460334.051563).Julian().MJD(4) // 60332.5516 +``` + +##### 将 `简化儒略日` 转换成 `儒略日` +```go +// 默认保留 6 位小数精度 +carbon.CreateFromJulian(60333.5).Julian().JD()() // 2460334 +carbon.CreateFromJulian(60333.551563).Julian().JD()() // 2460333.051563 + +// 保留 4 位小数精度 +carbon.CreateFromJulian(60333.5).Julian().JD(4) // 2460334 +carbon.CreateFromJulian(60333.551563).Julian().JD(4) // 2460333.0516 +``` + +##### 将 `儒略日`/`简化儒略日` 转换成 `公历` +```go +// 将 儒略日 转换成 公历 +carbon.CreateFromJulian(2460334).ToDateTimeString() // 2024-01-24 12:00:00 +carbon.CreateFromJulian(2460334.051563).ToDateTimeString() // 2024-01-24 13:14:15 + +// 将 简化儒略日 转换成 公历 +carbon.CreateFromJulian(60333.5).ToDateTimeString() // 2024-01-24 12:00:00 +carbon.CreateFromJulian(60333.551563).ToDateTimeString() // 2024-01-24 13:14:15 +``` + + diff --git a/vendor/github.com/dromara/carbon/v2/calendar/julian/README.jp.md b/vendor/github.com/dromara/carbon/v2/calendar/julian/README.jp.md new file mode 100644 index 000000000..0d3129119 --- /dev/null +++ b/vendor/github.com/dromara/carbon/v2/calendar/julian/README.jp.md @@ -0,0 +1,60 @@ +# 儒略の日/簡略儒略の日 + +日本語 | [English](README.md) | [简体中文](README.cn.md) + +#### 使い方の例 + +##### `西暦` を `儒略日` に変換する +```go +// デフォルトの保持 6 ビット小数点精度 +carbon.Parse("2024-01-24 12:00:00").Julian().JD() // 2460334 +carbon.Parse("2024-01-24 13:14:15").Julian().JD() // 2460334.051563 + +// 4 ビット小数点精度の保持 +carbon.Parse("2024-01-24 12:00:00").Julian().JD(4) // 2460334 +carbon.Parse("2024-01-24 13:14:15").Julian().JD(4) // 2460334.0516 +``` + +##### `西暦` を `簡略儒略日` に変換する +```go +// デフォルトの保持 6 ビット小数点精度 +carbon.Parse("2024-01-24 12:00:00").Julian().MJD() // 60333.5 +carbon.Parse("2024-01-24 13:14:15").Julian().MJD() // 60333.551563 + +// 4 ビット小数点精度の保持 +carbon.Parse("2024-01-24 12:00:00").Julian().MJD(4) // 60333.5 +carbon.Parse("2024-01-24 13:14:15").Julian().MJD(4) // 60333.5516 +``` + +##### `儒略日` を `簡略儒略日` に変換する +```go +// デフォルトの保持 6 ビット小数点精度 +carbon.CreateFromJulian(2460334).Julian().MJD() // 60333.5 +carbon.CreateFromJulian(2460334.051563).Julian().MJD() // 60332.551563 + +// 4 ビット小数点精度の保持 +carbon.CreateFromJulian(2460334).Julian().MJD(4) // 60333.5 +carbon.CreateFromJulian(2460334.051563).Julian().MJD(4) // 60332.5516 +``` + +##### `簡略儒略日` を `儒略日` に変換する +```go +// デフォルトの保持 6 ビット小数点精度 +carbon.CreateFromJulian(60333.5).Julian().JD()() // 2460334 +carbon.CreateFromJulian(60333.551563).Julian().JD()() // 2460333.051563 + +// 4 ビット小数点精度の保持 +carbon.CreateFromJulian(60333.5).Julian().JD(4) // 2460334 +carbon.CreateFromJulian(60333.551563).Julian().JD(4) // 2460333.0516 +``` + +##### `儒略日`/`簡略儒略日` を `公历` に変換する +```go +// 儒略日 を 公历 に変換する +carbon.CreateFromJulian(2460334).ToDateTimeString() // 2024-01-24 12:00:00 +carbon.CreateFromJulian(2460334.051563).ToDateTimeString() // 2024-01-24 13:14:15 + +// 簡略儒略日 を 公历 に変換する +carbon.CreateFromJulian(60333.5).ToDateTimeString() // 2024-01-24 12:00:00 +carbon.CreateFromJulian(60333.551563).ToDateTimeString() // 2024-01-24 13:14:15 +``` \ No newline at end of file diff --git a/vendor/github.com/dromara/carbon/v2/calendar/julian/README.md b/vendor/github.com/dromara/carbon/v2/calendar/julian/README.md new file mode 100644 index 000000000..98584c2ab --- /dev/null +++ b/vendor/github.com/dromara/carbon/v2/calendar/julian/README.md @@ -0,0 +1,60 @@ +# Julian Day/Modified Julian Day + +English | [简体中文](README.cn.md) | [日本語](README.jp.md) + +#### Usage and example + +##### Convert `Gregorian` calendar to `Julian Day` +```go +// By default, 6 decimal places are retained for precision +carbon.Parse("2024-01-24 12:00:00").Julian().JD() // 2460334 +carbon.Parse("2024-01-24 13:14:15").Julian().JD() // 2460334.051563 + +// 4 decimal places are retained for precision +carbon.Parse("2024-01-24 12:00:00").Julian().JD(4) // 2460334 +carbon.Parse("2024-01-24 13:14:15").Julian().JD(4) // 2460334.0516 +``` + +##### Convert `Gregorian` calendar to `Modified Julian Day` +```go +// By default, 6 decimal places are retained for precision +carbon.Parse("2024-01-24 12:00:00").Julian().MJD() // 60333.5 +carbon.Parse("2024-01-24 13:14:15").Julian().MJD() // 60333.551563 + +// 4 decimal places are retained for precision +carbon.Parse("2024-01-24 12:00:00").Julian().MJD(4) // 60333.5 +carbon.Parse("2024-01-24 13:14:15").Julian().MJD(4) // 60333.5516 +``` + +##### Convert `Julian Day` to `Modified Julian Day` +```go +// By default, 6 decimal places are retained for precision +carbon.CreateFromJulian(2460334).Julian().MJD() // 60333.5 +carbon.CreateFromJulian(2460334.051563).Julian().MJD() // 60332.551563 + +// 4 decimal places are retained for precision +carbon.CreateFromJulian(2460334).Julian().MJD(4) // 60333.5 +carbon.CreateFromJulian(2460334.051563).Julian().MJD(4) // 60332.5516 +``` + +##### Convert `Modified Julian Day` to `Julian Day` +```go +// By default, 6 decimal places are retained for precision +carbon.CreateFromJulian(60333.5).Julian().JD()() // 2460334 +carbon.CreateFromJulian(60333.551563).Julian().JD()() // 2460333.051563 + +// 4 decimal places are retained for precision +carbon.CreateFromJulian(60333.5).Julian().JD(4) // 2460334 +carbon.CreateFromJulian(60333.551563).Julian().JD(4) // 2460333.0516 +``` + +##### Convert `Julian Day`/`Modified Julian Day` to `Gregorian` calendar +```go +// Convert Julian Day to Gregorian calendar +carbon.CreateFromJulian(2460334).ToDateTimeString() // 2024-01-24 12:00:00 +carbon.CreateFromJulian(2460334.051563).ToDateTimeString() // 2024-01-24 13:14:15 + +// Convert Modified Julian Day to Gregorian calendar +carbon.CreateFromJulian(60333.5).ToDateTimeString() // 2024-01-24 12:00:00 +carbon.CreateFromJulian(60333.551563).ToDateTimeString() // 2024-01-24 13:14:15 +``` \ No newline at end of file diff --git a/vendor/github.com/dromara/carbon/v2/calendar/julian/julian.go b/vendor/github.com/dromara/carbon/v2/calendar/julian/julian.go new file mode 100644 index 000000000..4cde2f281 --- /dev/null +++ b/vendor/github.com/dromara/carbon/v2/calendar/julian/julian.go @@ -0,0 +1,161 @@ +// Package julian is part of the carbon package. +package julian + +import ( + "math" + "strconv" + "time" + + "github.com/dromara/carbon/v2/calendar" +) + +var ( + // julian day or modified julian day decimal precision + // 儒略日或简化儒略日小数精度 + decimalPrecision = 6 + + // difference between Julian Day and Modified Julian Day + // 儒略日和简化儒略日之间的差值 + diffJdFromMjd = 2400000.5 +) + +// Gregorian defines a Gregorian struct. +// 定义 Gregorian 结构体 +type Gregorian struct { + calendar.Gregorian +} + +// Julian defines a Julian struct. +// 定义 Julian 结构体 +type Julian struct { + jd, mjd float64 +} + +// FromGregorian creates a Gregorian instance from time.Time. +// 从标准 time.Time 创建 Gregorian 实例 +func FromGregorian(t time.Time) (g Gregorian) { + if t.IsZero() { + return + } + g.Time = t + return g +} + +// FromJulian creates a Julian instance from julian day or modified julian day. +// 从 儒略日 或 简化儒略日 创建 Julian 实例 +func FromJulian(f float64) (j Julian) { + // get length of the integer part + l := len(strconv.Itoa(int(math.Ceil(f)))) + switch l { + // modified julian day + case 5: + j.mjd = f + j.jd = f + diffJdFromMjd + // julian day + case 7: + j.jd = f + j.mjd = f - diffJdFromMjd + default: + j.jd = 0 + j.mjd = 0 + } + return +} + +// ToJulian converts Gregorian instance to Julian instance. +// 将 Gregorian 实例转化为 Julian 实例 +func (g Gregorian) ToJulian() (j Julian) { + if g.IsZero() { + return + } + y := g.Year() + m := g.Month() + d := float64(g.Day()) + ((float64(g.Second())/60+float64(g.Minute()))/60+float64(g.Hour()))/24 + n := 0 + f := false + if y*372+m*31+int(d) >= 588829 { + f = true + } + if m <= 2 { + m += 12 + y-- + } + if f { + n = y / 100 + n = 2 - n + n/4 + } + jd := float64(int(365.25*(float64(y)+4716))) + float64(int(30.6001*(float64(m)+1))) + d + float64(n) - 1524.5 + return FromJulian(jd) +} + +// ToGregorian converts Julian instance to Gregorian instance. +// 将 Julian 实例转化为 Gregorian 实例 +func (j Julian) ToGregorian() (g Gregorian) { + if j.IsZero() { + return + } + d := int(j.jd + 0.5) + f := j.jd + 0.5 - float64(d) + if d >= 2299161 { + c := int((float64(d) - 1867216.25) / 36524.25) + d += 1 + c - c/4 + } + d += 1524 + year := int((float64(d) - 122.1) / 365.25) + d -= int(365.25 * float64(year)) + month := int(float64(d) / 30.601) + d -= int(30.601 * float64(month)) + day := d + if month > 13 { + month -= 13 + year -= 4715 + } else { + month -= 1 + year -= 4716 + } + f *= 24 + hour := int(f) + + f -= float64(hour) + f *= 60 + minute := int(f) + + f -= float64(minute) + f *= 60 + second := int(math.Round(f)) + return FromGregorian(time.Date(year, time.Month(month), day, hour, minute, second, 0, time.Local)) +} + +// JD gets julian day like 2460332.5 +// 获取儒略日 +func (j Julian) JD(precision ...int) float64 { + if len(precision) > 0 { + decimalPrecision = precision[0] + } + return parseFloat64(j.jd, decimalPrecision) +} + +// MJD gets modified julian day like 60332 +// 获取简化儒略日 +func (j Julian) MJD(precision ...int) float64 { + if len(precision) > 0 { + decimalPrecision = precision[0] + } + return parseFloat64(j.mjd, decimalPrecision) +} + +// IsZero reports whether is zero time. +// 是否是零值时间 +func (j Julian) IsZero() bool { + if j.jd == 0 || j.mjd == 0 { + return true + } + return false +} + +// parseFloat64 round to n decimal places +// 四舍五入保留 n 位小数点 +func parseFloat64(f float64, n int) float64 { + p10 := math.Pow10(n) + return math.Round(f*p10) / p10 +} diff --git a/vendor/github.com/dromara/carbon/v2/calendar/lunar/README.cn.md b/vendor/github.com/dromara/carbon/v2/calendar/lunar/README.cn.md new file mode 100644 index 000000000..c792e5351 --- /dev/null +++ b/vendor/github.com/dromara/carbon/v2/calendar/lunar/README.cn.md @@ -0,0 +1,98 @@ +# 中国农历 + +简体中文 | [English](README.md) | [日本語](README.jp.md) + +#### 用法示例 + +> 目前仅支持公元 `1900` 年至 `2100` 年的 `200` 年时间跨度 + +##### 将 `公历` 转换成 `农历` + +```go +// 获取农历生肖 +carbon.Parse("2020-08-05 13:14:15").Lunar().Animal() // 鼠 +// 获取农历节日 +carbon.Parse("2021-02-12 13:14:15").Lunar().Festival() // 春节 + +// 获取农历年份 +carbon.Parse("2020-08-05 13:14:15").Lunar().Year() // 2020 +// 获取农历月份 +carbon.Parse("2020-08-05 13:14:15").Lunar().Month() // 6 +// 获取农历闰月月份 +carbon.Parse("2020-08-05 13:14:15").Lunar().LeapMonth() // 4 +// 获取农历日期 +carbon.Parse("2020-08-05 13:14:15").Lunar().Day() // 16 +// 获取农历时辰 +carbon.Parse("2020-08-05 13:14:15").Lunar().Hour() // 13 +// 获取农历分钟 +carbon.Parse("2020-08-05 13:14:15").Lunar().Minute() // 14 +// 获取农历秒数 +carbon.Parse("2020-08-05 13:14:15").Lunar().Second() // 15 + +// 获取农历日期时间字符串 +carbon.Parse("2020-08-05 13:14:15").Lunar().String() // 2020-06-16 13:14:15 +fmt.Printf("%s", carbon.Parse("2020-08-05 13:14:15").Lunar()) // 2020-06-16 13:14:15 +// 获取农历年字符串 +carbon.Parse("2020-08-05 13:14:15").Lunar().ToYearString() // 二零二零 +// 获取农历月字符串 +carbon.Parse("2020-08-05 13:14:15").Lunar().ToMonthString() // 六月 +// 获取农历闰月字符串 +carbon.Parse("2020-04-23 13:14:15").Lunar().ToMonthString() // 闰四月 +// 获取农历周字符串 +carbon.Parse("2020-04-23 13:14:15").Lunar().ToWeekString() // 周四 +// 获取农历天字符串 +carbon.Parse("2020-08-05 13:14:15").Lunar().ToDayString() // 十六 +// 获取农历日期字符串 +carbon.Parse("2020-08-05 13:14:15").Lunar().ToDateString() // 二零二零年六月十六 + +``` + +##### 将 `农历` 转化成 `公历` + +```go +// 将农历 二零二三年腊月十一 转化为 公历 +carbon.CreateFromLunar(2023, 12, 11, 0, 0, 0, false).ToDateTimeString() // 2024-01-21 00:00:00 +// 将农历 二零二三年二月十一 转化为 公历 +carbon.CreateFromLunar(2023, 2, 11, 0, 0, 0, false).ToDateTimeString() // 2023-03-02 00:00:00 +// 将农历 二零二三年闰二月十一 转化为 公历 +carbon.CreateFromLunar(2023, 2, 11, 0, 0, 0, true).ToDateTimeString() // 2023-04-01 00:00:00 +``` + +##### 日期判断 + +```go + +// 是否是合法农历日期 +carbon.Parse("0000-00-00 00:00:00").Lunar().IsValid() // false +carbon.Parse("2020-08-05 13:14:15").Lunar().IsValid() // true + +// 是否是农历闰年 +carbon.Parse("2020-08-05 13:14:15").Lunar().IsLeapYear() // true +// 是否是农历闰月 +carbon.Parse("2020-08-05 13:14:15").Lunar().IsLeapMonth() // false + +// 是否是鼠年 +carbon.Parse("2020-08-05 13:14:15").Lunar().IsRatYear() // true +// 是否是牛年 +carbon.Parse("2020-08-05 13:14:15").Lunar().IsOxYear() // false +// 是否是虎年 +carbon.Parse("2020-08-05 13:14:15").Lunar().IsTigerYear() // false +// 是否是兔年 +carbon.Parse("2020-08-05 13:14:15").Lunar().IsRabbitYear() // false +// 是否是龙年 +carbon.Parse("2020-08-05 13:14:15").Lunar().IsDragonYear() // false +// 是否是蛇年 +carbon.Parse("2020-08-05 13:14:15").Lunar().IsSnakeYear() // false +// 是否是马年 +carbon.Parse("2020-08-05 13:14:15").Lunar().IsHorseYear() // false +// 是否是羊年 +carbon.Parse("2020-08-05 13:14:15").Lunar().IsGoatYear() // false +// 是否是猴年 +carbon.Parse("2020-08-05 13:14:15").Lunar().IsMonkeyYear() // false +// 是否是鸡年 +carbon.Parse("2020-08-05 13:14:15").Lunar().IsRoosterYear() // false +// 是否是狗年 +carbon.Parse("2020-08-05 13:14:15").Lunar().IsDogYear() // false +// 是否是猪年 +carbon.Parse("2020-08-05 13:14:15").Lunar().IsPigYear() // false +``` \ No newline at end of file diff --git a/vendor/github.com/dromara/carbon/v2/calendar/lunar/README.jp.md b/vendor/github.com/dromara/carbon/v2/calendar/lunar/README.jp.md new file mode 100644 index 000000000..46011ad77 --- /dev/null +++ b/vendor/github.com/dromara/carbon/v2/calendar/lunar/README.jp.md @@ -0,0 +1,97 @@ +# 中国の旧暦 + +日本語 | [English](README.md) | [简体中文](README.cn.md) + +#### 使い方の例 + +> 現在は西暦` 1900 `年から` 2100 `年までの` 200 `年の時間スパンのみをサポートしている + +##### `西暦`を`旧暦`に変換する + +```go +// 旧暦の干支を手に入れる +carbon.Parse("2020-08-05 13:14:15").Lunar().Animal() // 鼠 +// 旧暦の祝日を取得する +carbon.Parse("2021-02-12 13:14:15").Lunar().Festival() // 春节 + +// 旧正月の取得 +carbon.Parse("2020-08-05 13:14:15").Lunar().Year() // 2020 +// 旧暦月の取得 +carbon.Parse("2020-08-05 13:14:15").Lunar().Month() // 6 +// 旧暦うるう月の取得 +carbon.Parse("2020-08-05 13:14:15").Lunar().LeapMonth() // 4 +// 旧暦日の取得 +carbon.Parse("2020-08-05 13:14:15").Lunar().Day() // 16 +// 旧暦時刻の取得 +carbon.Parse("2020-08-05 13:14:15").Lunar().Hour() // 13 +// 旧暦分の取得 +carbon.Parse("2020-08-05 13:14:15").Lunar().Minute() // 14 +// 旧暦の取得秒数 +carbon.Parse("2020-08-05 13:14:15").Lunar().Second() // 15 + +// 旧暦日時文字列の取得 +carbon.Parse("2020-08-05 13:14:15").Lunar().String() // 2020-06-16 13:14:15 +fmt.Printf("%s", carbon.Parse("2020-08-05 13:14:15").Lunar()) // 2020-06-16 13:14:15 +// 旧正月文字列の取得 +carbon.Parse("2020-08-05 13:14:15").Lunar().ToYearString() // 二零二零 +// 旧暦月文字列の取得 +carbon.Parse("2020-08-05 13:14:15").Lunar().ToMonthString() // 六月 +// 旧暦うるう月文字列の取得 +carbon.Parse("2020-04-23 13:14:15").Lunar().ToMonthString() // 闰四月 +// 旧暦週文字列の取得 +carbon.Parse("2020-04-23 13:14:15").Lunar().ToWeekString() // 周四 +// 旧暦日文字列の取得 +carbon.Parse("2020-08-05 13:14:15").Lunar().ToDayString() // 十六 +// 旧暦日付文字列の取得 +carbon.Parse("2020-08-05 13:14:15").Lunar().ToDateString() // 二零二零年六月十六 + +``` + +##### `旧暦`を`西暦`に変換する + +```go +// 2023 年の旧暦 12 月 11 日をグレゴリオ暦に変換します +carbon.CreateFromLunar(2023, 12, 11, 0, 0, 0, false).ToDateTimeString() // 2024-01-21 00:00:00 +// 旧暦の 2023 年 2 月 11 日をグレゴリオ暦に変換します +carbon.CreateFromLunar(2023, 2, 11, 0, 0, 0, false).ToDateTimeString() // 2023-03-02 00:00:00 +// 旧暦 2023 年、閏 2 月 11 日をグレゴリオ暦に変換します +carbon.CreateFromLunar(2023, 2, 11, 0, 0, 0, true).ToDateTimeString() // 2023-04-01 00:00:00 +``` + +##### 日付判断 +```go +// 合法的なペルシャ暦の日付かどうか +carbon.Parse("0000-00-00 00:00:00").Lunar().IsValid() // false +carbon.Parse("2020-08-05 13:14:15").Lunar().IsValid() // true + +// 旧暦うるう年かどうか +carbon.Parse("2020-08-05 13:14:15").Lunar().IsLeapYear() // true +// 旧暦うるう月かどうか +carbon.Parse("2020-08-05 13:14:15").Lunar().IsLeapMonth() // false + +// ねずみ年かどうか +carbon.Parse("2020-08-05 13:14:15").Lunar().IsRatYear() // true +// 牛年かどうか +carbon.Parse("2020-08-05 13:14:15").Lunar().IsOxYear() // false +// 寅年かどうか +carbon.Parse("2020-08-05 13:14:15").Lunar().IsTigerYear() // false +// うさぎ年かどうか +carbon.Parse("2020-08-05 13:14:15").Lunar().IsRabbitYear() // false +// 龍年かどうか +carbon.Parse("2020-08-05 13:14:15").Lunar().IsDragonYear() // false +// 蛇の年かどうか +carbon.Parse("2020-08-05 13:14:15").Lunar().IsSnakeYear() // false +// 馬年かどうか +carbon.Parse("2020-08-05 13:14:15").Lunar().IsHorseYear() // false +// 羊年かどうか +carbon.Parse("2020-08-05 13:14:15").Lunar().IsGoatYear() // false +// 申年かどうか +carbon.Parse("2020-08-05 13:14:15").Lunar().IsMonkeyYear() // false +// 鶏の年かどうか +carbon.Parse("2020-08-05 13:14:15").Lunar().IsRoosterYear() // false +// 犬年かどうか +carbon.Parse("2020-08-05 13:14:15").Lunar().IsDogYear() // false +// 豚年かどうか +carbon.Parse("2020-08-05 13:14:15").Lunar().IsPigYear() // false + +``` \ No newline at end of file diff --git a/vendor/github.com/dromara/carbon/v2/calendar/lunar/README.md b/vendor/github.com/dromara/carbon/v2/calendar/lunar/README.md new file mode 100644 index 000000000..ad7b8b67c --- /dev/null +++ b/vendor/github.com/dromara/carbon/v2/calendar/lunar/README.md @@ -0,0 +1,97 @@ +# Chinese Lunar + +English | [简体中文](README.cn.md) | [日本語](README.jp.md) + +#### Usage and example + +> Currently only `200` years from `1900` to `2100` are supported + +##### Convert `Gregorian` calendar to `Lunar` calendar + +```go +// Get Lunar year of animal +carbon.Parse("2020-08-05 13:14:15").Lunar().Animal() // 鼠 +// Get lunar festival +carbon.Parse("2021-02-12 13:14:15").Lunar().Festival() // 春节 + +// Get lunar year +carbon.Parse("2020-08-05 13:14:15").Lunar().Year() // 2020 +// Get lunar month +carbon.Parse("2020-08-05 13:14:15").Lunar().Month() // 6 +// Get lunar leap month +carbon.Parse("2020-08-05 13:14:15").Lunar().LeapMonth() // 4 +// Get lunar day +carbon.Parse("2020-08-05 13:14:15").Lunar().Day() // 16 +// Get lunar hour +carbon.Parse("2020-08-05 13:14:15").Lunar().Hour() // 13 +// Get lunar minute +carbon.Parse("2020-08-05 13:14:15").Lunar().Minute() // 14 +// Get lunar second +carbon.Parse("2020-08-05 13:14:15").Lunar().Second() // 15 + +// Get lunar date and time string +carbon.Parse("2020-08-05 13:14:15").Lunar().String() // 2020-06-16 13:14:15 +fmt.Printf("%s", carbon.Parse("2020-08-05 13:14:15").Lunar()) // 2020-06-16 13:14:15 +// Get lunar year as string +carbon.Parse("2020-08-05 13:14:15").Lunar().ToYearString() // 二零二零 +// Get lunar month as string +carbon.Parse("2020-08-05 13:14:15").Lunar().ToMonthString() // 六月 +// Get lunar leap month as string +carbon.Parse("2020-04-23 13:14:15").Lunar().ToMonthString() // 闰四月 +// Get lunar week as string +carbon.Parse("2020-04-23 13:14:15").Lunar().ToWeekString() // 周四 +// Get lunar day as string +carbon.Parse("2020-08-05 13:14:15").Lunar().ToDayString() // 十六 +// Get lunar date as string +carbon.Parse("2020-08-05 13:14:15").Lunar().ToDateString() // 二零二零年六月十六 + +``` + +##### Convert `Lunar` calendar to `Gregorian` calendar + +```go +// Convert the Lunar Calendar December 11, 2023 to the gregorian calendar +carbon.CreateFromLunar(2023, 12, 11, 0, 0, 0, false).ToDateTimeString() // 2024-01-21 00:00:00 +// Convert lunar calendar February 11, 2023 to gregorian calendar +carbon.CreateFromLunar(2023, 2, 11, 0, 0, 0, false).ToDateTimeString() // 2024-03-02 00:00:00 +// Convert the Lunar Calendar Leap February 11, 2024 to the gregorian calendar +carbon.CreateFromLunar(2023, 2, 11, 0, 0, 0, true).ToDateTimeString() // 2023-04-01 00:00:00 +``` + +##### Comparison +```go +// Whether is a valid lunar date +carbon.Parse("0000-00-00 00:00:00").Lunar().IsValid() // false +carbon.Parse("2020-08-05 13:14:15").Lunar().IsValid() // true + +// Whether is a lunar leap year +carbon.Parse("2020-08-05 13:14:15").Lunar().IsLeapYear() // true +// Whether is a lunar leap month +carbon.Parse("2020-08-05 13:14:15").Lunar().IsLeapMonth() // false + +// Whether is a lunar year of the rat +carbon.Parse("2020-08-05 13:14:15").Lunar().IsRatYear() // true +// Whether is a lunar year of the ox +carbon.Parse("2020-08-05 13:14:15").Lunar().IsOxYear() // false +// Whether is a lunar year of the tiger +carbon.Parse("2020-08-05 13:14:15").Lunar().IsTigerYear() // false +// Whether is a lunar year of the rabbit +carbon.Parse("2020-08-05 13:14:15").Lunar().IsRabbitYear() // false +// Whether is a lunar year of the dragon +carbon.Parse("2020-08-05 13:14:15").Lunar().IsDragonYear() // false +// Whether is a lunar year of the snake +carbon.Parse("2020-08-05 13:14:15").Lunar().IsSnakeYear() // false +// Whether is a lunar year of the horse +carbon.Parse("2020-08-05 13:14:15").Lunar().IsHorseYear() // false +// Whether is a lunar year of the goat +carbon.Parse("2020-08-05 13:14:15").Lunar().IsGoatYear() // false +// Whether is a lunar year of the monkey +carbon.Parse("2020-08-05 13:14:15").Lunar().IsMonkeyYear() // false +// Whether is a lunar year of the rooster +carbon.Parse("2020-08-05 13:14:15").Lunar().IsRoosterYear() // false +// Whether is a lunar year of the dog +carbon.Parse("2020-08-05 13:14:15").Lunar().IsDogYear() // false +// Whether is a lunar year of the dig +carbon.Parse("2020-08-05 13:14:15").Lunar().IsPigYear() // false + +``` \ No newline at end of file diff --git a/vendor/github.com/dromara/carbon/v2/calendar/lunar/lunar.go b/vendor/github.com/dromara/carbon/v2/calendar/lunar/lunar.go new file mode 100644 index 000000000..d32249a8e --- /dev/null +++ b/vendor/github.com/dromara/carbon/v2/calendar/lunar/lunar.go @@ -0,0 +1,590 @@ +// Package lunar is part of the carbon package. +package lunar + +import ( + "fmt" + "strings" + "time" + + "github.com/dromara/carbon/v2/calendar" +) + +var ( + numbers = []string{"零", "一", "二", "三", "四", "五", "六", "七", "八", "九"} + months = []string{"正", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "腊"} + weeks = []string{"周日", "周一", "周二", "周三", "周四", "周五", "周六"} + animals = []string{"猴", "鸡", "狗", "猪", "鼠", "牛", "虎", "兔", "龙", "蛇", "马", "羊"} + + festivals = map[string]string{ + // "month-day": "name" + "1-1": "春节", + "1-15": "元宵节", + "2-2": "龙抬头", + "3-3": "上巳节", + "5-5": "端午节", + "7-7": "七夕节", + "7-15": "中元节", + "8-15": "中秋节", + "9-9": "重阳节", + "10-1": "寒衣节", + "10-15": "下元节", + "12-8": "腊八节", + } + + years = []int{ + 0x04bd8, 0x04ae0, 0x0a570, 0x054d5, 0x0d260, 0x0d950, 0x16554, 0x056a0, 0x09ad0, 0x055d2, // 1900-1909 + 0x04ae0, 0x0a5b6, 0x0a4d0, 0x0d250, 0x1d255, 0x0b540, 0x0d6a0, 0x0ada2, 0x095b0, 0x14977, // 1910-1919 + 0x04970, 0x0a4b0, 0x0b4b5, 0x06a50, 0x06d40, 0x1ab54, 0x02b60, 0x09570, 0x052f2, 0x04970, // 1920-1929 + 0x06566, 0x0d4a0, 0x0ea50, 0x16a95, 0x05ad0, 0x02b60, 0x186e3, 0x092e0, 0x1c8d7, 0x0c950, // 1930-1939 + 0x0d4a0, 0x1d8a6, 0x0b550, 0x056a0, 0x1a5b4, 0x025d0, 0x092d0, 0x0d2b2, 0x0a950, 0x0b557, // 1940-1949 + 0x06ca0, 0x0b550, 0x15355, 0x04da0, 0x0a5d0, 0x14573, 0x052d0, 0x0a9a8, 0x0e950, 0x06aa0, // 1950-1959 + 0x0aea6, 0x0ab50, 0x04b60, 0x0aae4, 0x0a570, 0x05260, 0x0f263, 0x0d950, 0x05b57, 0x056a0, // 1960-1969 + 0x096d0, 0x04dd5, 0x04ad0, 0x0a4d0, 0x0d4d4, 0x0d250, 0x0d558, 0x0b540, 0x0b5a0, 0x195a6, // 1970-1979 + 0x095b0, 0x049b0, 0x0a974, 0x0a4b0, 0x0b27a, 0x06a50, 0x06d40, 0x0af46, 0x0ab60, 0x09570, // 1980-1989 + 0x04af5, 0x04970, 0x064b0, 0x074a3, 0x0ea50, 0x06b58, 0x05ac0, 0x0ab60, 0x096d5, 0x092e0, // 1990-1999 + 0x0c960, 0x0d954, 0x0d4a0, 0x0da50, 0x07552, 0x056a0, 0x0abb7, 0x025d0, 0x092d0, 0x0cab5, // 2000-2009 + 0x0a950, 0x0b4a0, 0x0baa4, 0x0ad50, 0x055d9, 0x04ba0, 0x0a5b0, 0x15176, 0x052b0, 0x0a930, // 2010-2019 + 0x07954, 0x06aa0, 0x0ad50, 0x05b52, 0x04b60, 0x0a6e6, 0x0a4e0, 0x0d260, 0x0ea65, 0x0d530, // 2020-2029 + 0x05aa0, 0x076a3, 0x096d0, 0x04bd7, 0x04ad0, 0x0a4d0, 0x1d0b6, 0x0d250, 0x0d520, 0x0dd45, // 2030-2039 + 0x0b5a0, 0x056d0, 0x055b2, 0x049b0, 0x0a577, 0x0a4b0, 0x0aa50, 0x1b255, 0x06d20, 0x0ada0, // 2040-2049 + 0x14b63, 0x09370, 0x049f8, 0x04970, 0x064b0, 0x168a6, 0x0ea50, 0x06b20, 0x1a6c4, 0x0aae0, // 2050-2059 + 0x0a2e0, 0x0d2e3, 0x0c960, 0x0d557, 0x0d4a0, 0x0da50, 0x05d55, 0x056a0, 0x0a6d0, 0x055d4, // 2060-2069 + 0x052d0, 0x0a9b8, 0x0a950, 0x0b4a0, 0x0b6a6, 0x0ad50, 0x055a0, 0x0aba4, 0x0a5b0, 0x052b0, // 2070-2079 + 0x0b273, 0x06930, 0x07337, 0x06aa0, 0x0ad50, 0x14b55, 0x04b60, 0x0a570, 0x054e4, 0x0d160, // 2080-2089 + 0x0e968, 0x0d520, 0x0daa0, 0x16aa6, 0x056d0, 0x04ae0, 0x0a9d4, 0x0a2d0, 0x0d150, 0x0f252, // 2090-2099 + 0x0d520, // 2100 + } + + InvalidDateError = func() error { + return fmt.Errorf("invalid invalid date, please make sure the date is valid") + } +) + +// Gregorian defines a Gregorian struct. +// 定义 Gregorian 结构体 +type Gregorian struct { + calendar.Gregorian +} + +// Lunar defines a Lunar struct. +// 定义 Lunar 结构体 +type Lunar struct { + year, month, day, hour, minute, second int + isLeapMonth bool + Error error +} + +// MaxValue returns a Lunar instance for the greatest supported date. +// 返回 Carbon 的最大值 +func MaxValue() Lunar { + return Lunar{ + year: 2100, + month: 12, + day: 31, + hour: 23, + minute: 59, + second: 59, + } +} + +// MinValue returns a Lunar instance for the lowest supported date. +// 返回 Lunar 的最小值 +func MinValue() Lunar { + return Lunar{ + year: 1900, + month: 1, + day: 1, + hour: 0, + minute: 0, + second: 0, + } +} + +// FromGregorian creates a Gregorian instance from time.Time. +// 从标准 time.Time 创建 Gregorian 实例 +func FromGregorian(t time.Time) (g Gregorian) { + if t.IsZero() { + return + } + g.Time = t + return +} + +// FromLunar creates a Lunar instance from lunar datetime. +// 从 农历日期 创建 Lunar 实例 +func FromLunar(year, month, day, hour, minute, second int, isLeapMonth bool) (l Lunar) { + l.year, l.month, l.day = year, month, day + l.hour, l.minute, l.second = hour, minute, second + l.isLeapMonth = isLeapMonth + if !l.IsValid() { + l.Error = InvalidDateError() + return + } + return +} + +// ToLunar converts Gregorian instance to Lunar instance. +// 将 Gregorian 实例转化为 Lunar 实例 +func (g Gregorian) ToLunar() (l Lunar) { + if g.IsZero() { + return + } + daysInYear, daysInMonth, leapMonth := 365, 30, 0 + maxYear, minYear := MaxValue().year, MinValue().year + + // 与 1900-01-31 相差多少天 + offset := g.diffInDays(time.Date(minYear, 1, 31, 0, 0, 0, 0, g.Location())) + for l.year = minYear; l.year <= maxYear && offset > 0; l.year++ { + daysInYear = l.getDaysInYear() + offset -= daysInYear + } + if offset < 0 { + offset += daysInYear + l.year-- + } + leapMonth = l.LeapMonth() + for l.month = 1; l.month <= 12 && offset > 0; l.month++ { + if leapMonth > 0 && l.month == (leapMonth+1) && !l.isLeapMonth { + l.month-- + l.isLeapMonth = true + daysInMonth = l.getDaysInLeapMonth() + } else { + daysInMonth = l.getDaysInMonth() + } + offset -= daysInMonth + if l.isLeapMonth && l.month == (leapMonth+1) { + l.isLeapMonth = false + } + } + // offset为0时,并且刚才计算的月份是闰月,要校正 + if offset == 0 && leapMonth > 0 && l.month == leapMonth+1 { + if l.isLeapMonth { + l.isLeapMonth = false + } else { + l.isLeapMonth = true + l.month-- + } + } + // offset小于0时,也要校正 + if offset < 0 { + offset += daysInMonth + l.month-- + } + l.day = offset + 1 + l.hour, l.minute, l.second = g.Clock() + if !l.IsValid() { + l.Error = InvalidDateError() + return + } + return +} + +// ToGregorian converts Lunar instance to Gregorian instance. +// 将 Lunar 实例转化为 Gregorian 实例 +func (l Lunar) ToGregorian() (g Gregorian) { + if !l.IsValid() { + return + } + days := l.getDaysInMonth() + offset := l.getOffsetInYear() + offset += l.getOffsetInMonth() + // 转换闰月农历 需补充该年闰月的前一个月的时差 + if l.isLeapMonth { + offset += days + } + // https://github.com/golang-module/carbon/issues/219 + ts := int64(offset+l.day)*86400 - int64(2206512000) + int64(l.hour)*3600 + int64(l.minute)*60 + int64(l.second) + g.Time = time.Unix(ts, 0) + return +} + +// Animal gets lunar animal name like "猴". +// 获取农历生肖 +func (l Lunar) Animal() string { + if !l.IsValid() { + return "" + } + return animals[l.year%calendar.MonthsPerYear] +} + +// Festival gets lunar festival name like "春节". +// 获取农历节日 +func (l Lunar) Festival() string { + if !l.IsValid() { + return "" + } + return festivals[fmt.Sprintf("%d-%d", l.month, l.day)] +} + +// Year gets lunar year like 2020. +// 获取农历年份 +func (l Lunar) Year() int { + if l.Error != nil { + return 0 + } + return l.year +} + +// Month gets lunar month like 8. +// 获取农历月份 +func (l Lunar) Month() int { + if l.Error != nil { + return 0 + } + return l.month +} + +// Day gets lunar day like 5. +// 获取农历日,如 5 +func (l Lunar) Day() int { + if l.Error != nil { + return 0 + } + return l.day +} + +// Hour gets current hour like 13. +// 获取农历时辰 +func (l Lunar) Hour() int { + if l.Error != nil { + return 0 + } + return l.hour +} + +// Minute gets current minute like 14. +// 获取农历分钟数 +func (l Lunar) Minute() int { + if l.Error != nil { + return 0 + } + return l.minute +} + +// Second gets current second like 15. +// 获取农历秒数 +func (l Lunar) Second() int { + if l.Error != nil { + return 0 + } + return l.second +} + +// LeapMonth gets lunar leap month like 2. +// 获取农历闰月月份,如 2 +func (l Lunar) LeapMonth() int { + if l.Error != nil { + return 0 + } + minYear := MinValue().year + if l.year-minYear < 0 { + return 0 + } + return years[l.year-minYear] & 0xf +} + +// String implements Stringer interface and outputs a string in YYYY-MM-DD HH::ii::ss format like "2019-12-07 00:00:00". +// 实现 Stringer 接口, 输出 YYYY-MM-DD HH::ii::ss 格式字符串,如 "2019-12-07 00:00:00" +func (l Lunar) String() string { + if !l.IsValid() { + return "" + } + return fmt.Sprintf("%04d-%02d-%02d %02d:%02d:%02d", l.year, l.month, l.day, l.hour, l.minute, l.second) +} + +// ToYearString outputs a string in lunar year format like "二零二零". +// 获取农历年份字符串,如 "二零二零" +func (l Lunar) ToYearString() (year string) { + if !l.IsValid() { + return "" + } + year = fmt.Sprintf("%d", l.year) + for index, number := range numbers { + year = strings.Replace(year, fmt.Sprintf("%d", index), number, -1) + } + return year +} + +// ToMonthString outputs a string in lunar month format like "正月". +// 获取农历月份字符串,如 "正月" +func (l Lunar) ToMonthString() (month string) { + if !l.IsValid() { + return "" + } + month = months[l.month-1] + "月" + if l.IsLeapMonth() { + return "闰" + month + } + return +} + +// ToWeekString outputs a string in week layout like "周一". +// 输出完整农历星期字符串,如 "周一" +func (l Lunar) ToWeekString() (month string) { + if !l.IsValid() { + return "" + } + return weeks[l.ToGregorian().Week()] +} + +// ToDayString outputs a string in lunar day format like "廿一". +// 获取农历日字符串,如 "廿一" +func (l Lunar) ToDayString() (day string) { + if !l.IsValid() { + return "" + } + num := numbers[l.day%10] + switch { + case l.day == 30: + day = "三十" + case l.day > 20: + day = "廿" + num + case l.day == 20: + day = "二十" + case l.day > 10: + day = "十" + num + case l.day == 10: + day = "初十" + case l.day < 10: + day = "初" + num + } + return +} + +// ToDateString outputs a string in lunar date format like "二零二零年腊月初五". +// 获取农历日期字符串,如 "二零二零年腊月初五" +func (l Lunar) ToDateString() string { + if !l.IsValid() { + return "" + } + return l.ToYearString() + "年" + l.ToMonthString() + l.ToDayString() +} + +// IsValid reports whether is a valid lunar date. +// 是否是有效的年份 +func (l Lunar) IsValid() bool { + if l.Year() >= MinValue().year && l.Year() <= MaxValue().year && l.month >= MinValue().month && l.month <= MaxValue().month && l.day >= MinValue().day && l.day <= MaxValue().day { + return true + } + return false +} + +// IsLeapYear reports whether is a lunar leap year. +// 是否是农历闰年 +func (l Lunar) IsLeapYear() bool { + if l.Error != nil { + return false + } + return l.LeapMonth() != 0 +} + +// IsLeapMonth reports whether is a lunar leap month. +// 是否是农历闰月 +func (l Lunar) IsLeapMonth() bool { + if l.Error != nil { + return false + } + return l.month == l.LeapMonth() +} + +// IsRatYear reports whether is lunar year of Rat. +// 是否是鼠年 +func (l Lunar) IsRatYear() bool { + if l.Error != nil { + return false + } + if l.year%calendar.MonthsPerYear == 4 { + return true + } + return false +} + +// IsOxYear reports whether is lunar year of Ox. +// 是否是牛年 +func (l Lunar) IsOxYear() bool { + if l.Error != nil { + return false + } + if l.year%calendar.MonthsPerYear == 5 { + return true + } + return false +} + +// IsTigerYear reports whether is lunar year of Tiger. +// 是否是虎年 +func (l Lunar) IsTigerYear() bool { + if l.Error != nil { + return false + } + if l.year%calendar.MonthsPerYear == 6 { + return true + } + return false +} + +// IsRabbitYear reports whether is lunar year of Rabbit. +// 是否是兔年 +func (l Lunar) IsRabbitYear() bool { + if l.Error != nil { + return false + } + if l.year%calendar.MonthsPerYear == 7 { + return true + } + return false +} + +// IsDragonYear reports whether is lunar year of Dragon. +// 是否是龙年 +func (l Lunar) IsDragonYear() bool { + if l.Error != nil { + return false + } + if l.year%calendar.MonthsPerYear == 8 { + return true + } + return false +} + +// IsSnakeYear reports whether is lunar year of Snake. +// 是否是蛇年 +func (l Lunar) IsSnakeYear() bool { + if l.Error != nil { + return false + } + if l.year%calendar.MonthsPerYear == 9 { + return true + } + return false +} + +// IsHorseYear reports whether is lunar year of Horse. +// 是否是马年 +func (l Lunar) IsHorseYear() bool { + if l.Error != nil { + return false + } + if l.year%calendar.MonthsPerYear == 10 { + return true + } + return false +} + +// IsGoatYear reports whether is lunar year of Goat. +// 是否是羊年 +func (l Lunar) IsGoatYear() bool { + if l.Error != nil { + return false + } + if l.year%calendar.MonthsPerYear == 11 { + return true + } + return false +} + +// IsMonkeyYear reports whether is lunar year of Monkey. +// 是否是猴年 +func (l Lunar) IsMonkeyYear() bool { + if l.Error != nil { + return false + } + if l.year%calendar.MonthsPerYear == 0 { + return true + } + return false +} + +// IsRoosterYear reports whether is lunar year of Rooster. +// 是否是鸡年 +func (l Lunar) IsRoosterYear() bool { + if l.Error != nil { + return false + } + if l.year%calendar.MonthsPerYear == 1 { + return true + } + return false +} + +// IsDogYear reports whether is lunar year of Dog. +// 是否是狗年 +func (l Lunar) IsDogYear() bool { + if l.Error != nil { + return false + } + if l.year%calendar.MonthsPerYear == 2 { + return true + } + return false +} + +// IsPigYear reports whether is lunar year of Pig. +// 是否是猪年 +func (l Lunar) IsPigYear() bool { + if l.Error != nil { + return false + } + if l.year%calendar.MonthsPerYear == 3 { + return true + } + return false +} + +func (g Gregorian) diffInDays(t time.Time) int { + return int(g.Time.Truncate(time.Hour).Sub(t).Hours() / 24) +} + +func (l Lunar) getOffsetInYear() int { + flag := false + clone, month, offset := l, 0, 0 + for month = 1; month < l.month; month++ { + leapMonth := l.LeapMonth() + if !flag { + // 处理闰月 + if leapMonth <= month && leapMonth > 0 { + offset += l.getDaysInLeapMonth() + flag = true + } + } + clone.month = month + offset += clone.getDaysInMonth() + } + return offset +} + +func (l Lunar) getOffsetInMonth() int { + clone, year, offset := l, 0, 0 + for year = MinValue().year; year < l.year; year++ { + clone.year = year + offset += clone.getDaysInYear() + } + return offset +} + +func (l Lunar) getDaysInYear() int { + var days = 348 + for i := 0x8000; i > 0x8; i >>= 1 { + if (years[l.year-MinValue().year] & i) != 0 { + days++ + } + } + return days + l.getDaysInLeapMonth() +} + +func (l Lunar) getDaysInMonth() int { + if (years[l.year-MinValue().year] & (0x10000 >> uint(l.month))) != 0 { + return 30 + } + return 29 +} + +func (l Lunar) getDaysInLeapMonth() int { + if l.LeapMonth() == 0 { + return 0 + } + if years[l.year-MinValue().year]&0x10000 != 0 { + return 30 + } + return 29 +} diff --git a/vendor/github.com/dromara/carbon/v2/calendar/persian/README.cn.md b/vendor/github.com/dromara/carbon/v2/calendar/persian/README.cn.md new file mode 100644 index 000000000..16c9486d6 --- /dev/null +++ b/vendor/github.com/dromara/carbon/v2/calendar/persian/README.cn.md @@ -0,0 +1,74 @@ +# 波斯历(伊朗历) + +简体中文 | [English](README.md) | [日本語](README.jp.md) + +#### 用法示例 + +##### 将 `公历` 转换成 `波斯历` + +```go +// 获取波斯历年份 +carbon.Parse("2020-08-05 13:14:15").Persian().Year() // 1399 +// 获取波斯历月份 +carbon.Parse("2020-08-05 13:14:15").Persian().Month() // 5 +// 获取波斯历日期 +carbon.Parse("2020-08-05 13:14:15").Persian().Day() // 15 +// 获取波斯历小时 +carbon.Parse("2020-08-05 13:14:15").Persian().Hour() // 13 +// 获取波斯历分钟 +carbon.Parse("2020-08-05 13:14:15").Persian().Minute() // 14 +// 获取波斯历秒数 +carbon.Parse("2020-08-05 13:14:15").Persian().Second() // 15 + +// 获取波斯历日期时间字符串 +carbon.Parse("2020-08-05 13:14:15").Persian().String() // 1399-05-15 13:14:15 +fmt.Printf("%s", carbon.Parse("2020-08-05 13:14:15").Persian()) // 1399-05-15 13:14:15 + +// 获取波斯历月字符串 +carbon.Parse("2020-08-05 13:14:15").Persian().ToMonthString() // Mordad +carbon.Parse("2020-08-05 13:14:15").Persian().ToMonthString("en") // Mordad +carbon.Parse("2020-08-05 13:14:15").Persian().ToMonthString("fa") // مرداد + +// 获取简写波斯历月字符串 +carbon.Parse("2020-08-05 13:14:15").Persian().ToShortMonthString() // Mor +carbon.Parse("2020-08-05 13:14:15").Persian().ToShortMonthString("en") // Mor +carbon.Parse("2020-08-05 13:14:15").Persian().ToShortMonthString("fa") // مرد + +// 获取波斯历周字符串 +carbon.Parse("2020-08-05 13:14:15").Persian().ToWeekString() // Chaharshanbeh +carbon.Parse("2020-08-05 13:14:15").Persian().ToWeekString("en") // Chaharshanbeh +carbon.Parse("2020-08-05 13:14:15").Persian().ToWeekString("fa") // چهارشنبه + +// 获取简写波斯历周字符串 +carbon.Parse("2020-08-05 13:14:15").Persian().ToShortWeekString() // Cha +carbon.Parse("2020-08-05 13:14:15").Persian().ToShortWeekString("en") // Cha +carbon.Parse("2020-08-05 13:14:15").Persian().ToShortWeekString("fa") // د + +``` + +##### 将 `波斯历` 转化成 `公历` + +```go +carbon.CreateFromPersian(1, 1, 1, 0, 0, 0).ToDateTimeString() // 2016-03-20 00:00:00 +carbon.CreateFromPersian(622, 1, 1, 0, 0, 0).ToDateTimeString() // 1243-03-21 00:00:00 +carbon.CreateFromPersian(1395, 1, 1, 0, 0, 0).ToDateTimeString() // 2016-03-20 00:00:00 +carbon.CreateFromPersian(9377, 1, 1, 0, 0, 0).ToDateTimeString() // 9998-03-19 00:00:00 +``` + +##### 日期判断 +```go +// 是否是合法的波斯历日期 +carbon.CreateFromPersian(1, 1, 1, 0, 0, 0).IsValid() // true +carbon.CreateFromPersian(622, 1, 1, 0, 0, 0).IsValid() // true +carbon.CreateFromPersian(9377, 1, 1, 0, 0, 0).IsValid() // true +carbon.CreateFromPersian(0, 0, 0, 0, 0, 0).IsValid() // false +carbon.CreateFromPersian(2024, 0, 1, 0, 0, 0).IsValid() // false +carbon.CreateFromPersian(2024, 1, 0, 0, 0, 0).IsValid() // false + +// 是否是波斯历闰年 +carbon.CreateFromPersian(1395, 1, 1, 0, 0, 0).IsLeapYear() // true +carbon.CreateFromPersian(9377, 1, 1, 0, 0, 0).IsLeapYear() // true +carbon.CreateFromPersian(622, 1, 1, 0, 0, 0).IsLeapYear() // false +carbon.CreateFromPersian(9999, 1, 1, 0, 0, 0).IsLeapYear() // false + +``` \ No newline at end of file diff --git a/vendor/github.com/dromara/carbon/v2/calendar/persian/README.jp.md b/vendor/github.com/dromara/carbon/v2/calendar/persian/README.jp.md new file mode 100644 index 000000000..c70a26ef3 --- /dev/null +++ b/vendor/github.com/dromara/carbon/v2/calendar/persian/README.jp.md @@ -0,0 +1,73 @@ +# ペルシア暦(イラン暦) + +日本語 | [English](README.md) | [简体中文](README.cn.md) + +#### 使い方の例 + +##### `西暦` を `ペルシャ暦` に変換 + +```go +// ペルシャ暦の取得 +carbon.Parse("2020-08-05 13:14:15").Persian().Year() // 1399 +// ペルシャ暦月の取得 +carbon.Parse("2020-08-05 13:14:15").Persian().Month() // 5 +// ペルシャ暦の取得日 +carbon.Parse("2020-08-05 13:14:15").Persian().Day() // 15 +// ペルシャ暦時間の取得 +carbon.Parse("2020-08-05 13:14:15").Persian().Hour() // 13 +// ペルシャ暦分の取得 +carbon.Parse("2020-08-05 13:14:15").Persian().Minute() // 14 +// ペルシャ暦秒の取得 +carbon.Parse("2020-08-05 13:14:15").Persian().Second() // 15 + +// ペルシャ暦日時文字列の取得 +carbon.Parse("2020-08-05 13:14:15").Persian().String() // 1399-05-15 13:14:15 +fmt.Printf("%s", carbon.Parse("2020-08-05 13:14:15").Persian()) // 1399-05-15 13:14:15 + +// ペルシア暦月文字列の取得 +carbon.Parse("2020-08-05 13:14:15").Persian().ToMonthString() // Mordad +carbon.Parse("2020-08-05 13:14:15").Persian().ToMonthString("en") // Mordad +carbon.Parse("2020-08-05 13:14:15").Persian().ToMonthString("fa") // مرداد + +// 略語ペルシャ暦文字列の取得 +carbon.Parse("2020-08-05 13:14:15").Persian().ToShortMonthString() // Mor +carbon.Parse("2020-08-05 13:14:15").Persian().ToShortMonthString("en") // Mor +carbon.Parse("2020-08-05 13:14:15").Persian().ToShortMonthString("fa") // مرد + +// ペルシャ暦週文字列の取得 +carbon.Parse("2020-08-05 13:14:15").Persian().ToWeekString() // Chaharshanbeh +carbon.Parse("2020-08-05 13:14:15").Persian().ToWeekString("en") // Chaharshanbeh +carbon.Parse("2020-08-05 13:14:15").Persian().ToWeekString("fa") // چهارشنبه + +// 略語ペルシャ暦週文字列の取得 +carbon.Parse("2020-08-05 13:14:15").Persian().ToShortWeekString() // Cha +carbon.Parse("2020-08-05 13:14:15").Persian().ToShortWeekString("en") // Cha +carbon.Parse("2020-08-05 13:14:15").Persian().ToShortWeekString("fa") // د +``` + +##### ペルシャ暦を西暦に変換する + +```go +carbon.CreateFromPersian(1, 1, 1, 0, 0, 0).ToDateTimeString() // 2016-03-20 00:00:00 +carbon.CreateFromPersian(622, 1, 1, 0, 0, 0).ToDateTimeString() // 1243-03-21 00:00:00 +carbon.CreateFromPersian(1395, 1, 1, 0, 0, 0).ToDateTimeString() // 2016-03-20 00:00:00 +carbon.CreateFromPersian(9377, 1, 1, 0, 0, 0).ToDateTimeString() // 9998-03-19 00:00:00 +``` + +##### 日付判断 +```go +// 合法的なペルシャ暦の日付かどうか +carbon.CreateFromPersian(1, 1, 1, 0, 0, 0).IsValid() // true +carbon.CreateFromPersian(622, 1, 1, 0, 0, 0).IsValid() // true +carbon.CreateFromPersian(9377, 1, 1, 0, 0, 0).IsValid() // true +carbon.CreateFromPersian(0, 0, 0, 0, 0, 0).IsValid() // false +carbon.CreateFromPersian(2024, 0, 1, 0, 0, 0).IsValid() // false +carbon.CreateFromPersian(2024, 1, 0, 0, 0, 0).IsValid() // false + +// ペルシア暦閏年かどうか +carbon.CreateFromPersian(1395, 1, 1, 0, 0, 0).IsLeapYear() // true +carbon.CreateFromPersian(9377, 1, 1, 0, 0, 0).IsLeapYear() // true +carbon.CreateFromPersian(622, 1, 1, 0, 0, 0).IsLeapYear() // false +carbon.CreateFromPersian(9999, 1, 1, 0, 0, 0).IsLeapYear() // false + +``` \ No newline at end of file diff --git a/vendor/github.com/dromara/carbon/v2/calendar/persian/README.md b/vendor/github.com/dromara/carbon/v2/calendar/persian/README.md new file mode 100644 index 000000000..d5cf82554 --- /dev/null +++ b/vendor/github.com/dromara/carbon/v2/calendar/persian/README.md @@ -0,0 +1,74 @@ +# Persian(Jalaali) Calendar + +English | [简体中文](README.cn.md) | [日本語](README.jp.md) + +#### Usage and example + +##### Convert `Gregorian` calendar to `Persian` calendar + +```go +// 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").Persian().Minute() // 14 +// Get persian second +carbon.Parse("2020-08-05 13:14:15").Persian().Second() // 15 + +// Get persian date and time string +carbon.Parse("2020-08-05 13:14:15").Persian().String() // 1399-05-15 13:14:15 +fmt.Printf("%s", carbon.Parse("2020-08-05 13:14:15").Persian()) // 1399-05-15 13:14:15 + +// Get persian month as string +carbon.Parse("2020-08-05 13:14:15").Persian().ToMonthString() // Mordad +carbon.Parse("2020-08-05 13:14:15").Persian().ToMonthString("en") // Mordad +carbon.Parse("2020-08-05 13:14:15").Persian().ToMonthString("fa") // مرداد + +// Get persian short month as string +carbon.Parse("2020-08-05 13:14:15").Persian().ToShortMonthString() // Mor +carbon.Parse("2020-08-05 13:14:15").Persian().ToShortMonthString("en") // Mor +carbon.Parse("2020-08-05 13:14:15").Persian().ToShortMonthString("fa") // مرد + +// Get persian week as string +carbon.Parse("2020-08-05 13:14:15").Persian().ToWeekString() // Chaharshanbeh +carbon.Parse("2020-08-05 13:14:15").Persian().ToWeekString("en") // Chaharshanbeh +carbon.Parse("2020-08-05 13:14:15").Persian().ToWeekString("fa") // چهارشنبه + +// Get persian short week as string +carbon.Parse("2020-08-05 13:14:15").Persian().ToShortWeekString() // Cha +carbon.Parse("2020-08-05 13:14:15").Persian().ToShortWeekString("en") // Cha +carbon.Parse("2020-08-05 13:14:15").Persian().ToShortWeekString("fa") // د + +``` + +##### Convert `Persian` calendar to `Gregorian` calendar + +```go +carbon.CreateFromPersian(1, 1, 1, 0, 0, 0).ToDateTimeString() // 2016-03-20 00:00:00 +carbon.CreateFromPersian(622, 1, 1, 0, 0, 0).ToDateTimeString() // 1243-03-21 00:00:00 +carbon.CreateFromPersian(1395, 1, 1, 0, 0, 0).ToDateTimeString() // 2016-03-20 00:00:00 +carbon.CreateFromPersian(9377, 1, 1, 0, 0, 0).ToDateTimeString() // 9998-03-19 00:00:00 +``` + +##### Comparison +```go +// Whether is a valid persian date +carbon.CreateFromPersian(1, 1, 1, 0, 0, 0).IsValid() // true +carbon.CreateFromPersian(622, 1, 1, 0, 0, 0).IsValid() // true +carbon.CreateFromPersian(9377, 1, 1, 0, 0, 0).IsValid() // true +carbon.CreateFromPersian(0, 0, 0, 0, 0, 0).IsValid() // false +carbon.CreateFromPersian(2024, 0, 1, 0, 0, 0).IsValid() // false +carbon.CreateFromPersian(2024, 1, 0, 0, 0, 0).IsValid() // false + +// Whether is a persian leap year +carbon.CreateFromPersian(1395, 1, 1, 0, 0, 0).IsLeapYear() // true +carbon.CreateFromPersian(9377, 1, 1, 0, 0, 0).IsLeapYear() // true +carbon.CreateFromPersian(622, 1, 1, 0, 0, 0).IsLeapYear() // false +carbon.CreateFromPersian(9999, 1, 1, 0, 0, 0).IsLeapYear() // false + +``` \ No newline at end of file diff --git a/vendor/github.com/dromara/carbon/v2/calendar/persian/persian.go b/vendor/github.com/dromara/carbon/v2/calendar/persian/persian.go new file mode 100644 index 000000000..8b2b7ae01 --- /dev/null +++ b/vendor/github.com/dromara/carbon/v2/calendar/persian/persian.go @@ -0,0 +1,321 @@ +// Package persian is part of the carbon package. +package persian + +import ( + "fmt" + "math" + "time" + + "github.com/dromara/carbon/v2/calendar" + "github.com/dromara/carbon/v2/calendar/julian" +) + +var ( + EnMonths = []string{"Farvardin", "Ordibehesht", "Khordad", "Tir", "Mordad", "Shahrivar", "Mehr", "Aban", "Azar", "Dey", "Bahman", "Esfand"} + ShortEnMonths = []string{"Far", "Ord", "Kho", "Tir", "Mor", "Sha", "Meh", "Aba", "Aza", "Dey", "Bah", "Esf"} + + FaMonths = []string{"فروردین", "اردیبهشت", "خرداد", "تیر", "مرداد", "شهریور", "مهر", "آبان", "آذر", "دی", "بهمن", "اسفند"} + ShortFaMonths = []string{"فرو", "ارد", "خرد", "تیر", "مرد", "شهر", "مهر", "آبا", "آذر", "دی", "بهم", "اسف"} + + EnWeeks = []string{"Yekshanbeh", "Doshanbeh", "Seshanbeh", "Chaharshanbeh", "Panjshanbeh", "Jomeh", "Shanbeh"} + ShortEnWeeks = []string{"Yek", "Dos", "Ses", "Cha", "Pan", "Jom", "Sha"} + + FaWeeks = []string{"نجشنبه", "دوشنبه", "سه شنبه", "چهارشنبه", "پنجشنبه", "جمعه", "شنبه"} + ShortFaWeeks = []string{"پ", "چ", "س", "د", "ی", "ش", "ج"} + + InvalidDateError = func() error { + return fmt.Errorf("invalid persian date, please make sure the date is valid") + } +) + +// Gregorian defines a Gregorian struct. +// 定义 Gregorian 结构体 +type Gregorian struct { + calendar.Gregorian +} + +// Persian defines a Persian struct. +// 定义 Persian 结构体 +type Persian struct { + year, month, day, hour, minute, second int + Error error +} + +// MaxValue returns a Persian instance for the greatest supported date. +// 返回 Persian 的最大值 +func MaxValue() Persian { + return Persian{ + year: 9377, + month: 12, + day: 31, + hour: 23, + minute: 59, + second: 59, + } +} + +// MinValue returns a Persian instance for the lowest supported date. +// 返回 Persian 的最小值 +func MinValue() Persian { + return Persian{ + year: 1, + month: 1, + day: 1, + hour: 0, + minute: 0, + second: 0, + } +} + +// FromGregorian creates a Gregorian instance from time.Time. +// 从标准 time.Time 创建 Gregorian 实例 +func FromGregorian(t time.Time) (g Gregorian) { + if t.IsZero() { + return + } + g.Time = t + return +} + +// FromPersian creates a Persian instance from persian datetime. +// 从 波斯日期 创建 Persian 实例 +func FromPersian(year, month, day, hour, minute, second int) (p Persian) { + p.year, p.month, p.day = year, month, day + p.hour, p.minute, p.second = hour, minute, second + if !p.IsValid() { + p.Error = InvalidDateError() + return + } + return +} + +// ToPersian converts Gregorian instance to Persian instance. +// 将 Gregorian 实例转化为 Persian 实例 +func (g Gregorian) ToPersian() (p Persian) { + p.hour, p.minute, p.second = g.Hour(), g.Minute(), g.Second() + gjdn := getGregorianJdn(g.Year(), g.Month(), g.Day()) + pjdn := getPersianJdn(475, 1, 1) + + diff := gjdn - pjdn + div := diff / 1029983 + mod := diff % 1029983 + p.year = (2134*mod/366+2816*(mod%366)+2815)/1028522 + mod/366 + 1 + 2820*div + 474 + pjdn = getPersianJdn(p.year, 1, 1) + fjdn := float64(gjdn - pjdn + 1) + if fjdn <= 186 { + p.month = int(math.Ceil(fjdn / 31.0)) + } else { + p.month = int(math.Ceil((fjdn - 6) / 30.0)) + } + pjdn = getPersianJdn(p.year, p.month, 1) + p.day = gjdn - pjdn + 1 + if !p.IsValid() { + p.Error = InvalidDateError() + return + } + return +} + +// ToGregorian converts Persian instance to Gregorian instance. +// 将 Persian 实例转化为 Gregorian 实例 +func (p Persian) ToGregorian() (g Gregorian) { + if !p.IsValid() { + return + } + jdn := getPersianJdn(p.year, p.month, p.day) + + l := jdn + 68569 + n := 4 * l / 146097 + l = l - (146097*n+3)/4 + i := 4000 * (l + 1) / 1461001 + l = l - 1461*i/4 + 31 + j := 80 * l / 2447 + d := l - 2447*j/80 + l = j / 11 + m := j + 2 - 12*l + y := 100*(n-49) + i + l + + g.Time = time.Date(y, time.Month(m), d, p.hour, p.minute, p.second, 0, time.Local) + return +} + +// Year gets lunar year like 2020. +// 获取年份,如 2020 +func (p Persian) Year() int { + if p.Error != nil { + return 0 + } + return p.year +} + +// Month gets lunar month like 8. +// 获取月份,如 8 +func (p Persian) Month() int { + if p.Error != nil { + return 0 + } + return p.month +} + +// Day gets lunar day like 5. +// 获取日,如 5 +func (p Persian) Day() int { + if p.Error != nil { + return 0 + } + return p.day +} + +// Hour gets current hour like 13. +// 获取小时,如 13 +func (p Persian) Hour() int { + if p.Error != nil { + return 0 + } + return p.hour +} + +// Minute gets current minute like 14. +// 获取分钟数,如 14 +func (p Persian) Minute() int { + if p.Error != nil { + return 0 + } + return p.minute +} + +// Second gets current second like 15. +// 获取秒数,如 15 +func (p Persian) Second() int { + if p.Error != nil { + return 0 + } + return p.second +} + +// 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 (p Persian) String() string { + if !p.IsValid() { + return "" + } + return fmt.Sprintf("%d-%02d-%02d %02d:%02d:%02d", p.year, p.month, p.day, p.hour, p.minute, p.second) +} + +// ToMonthString outputs a string in persian month format like "فروردین". +// 获取完整月份字符串,如 "فروردین" +func (p Persian) ToMonthString(locale ...string) (month string) { + if !p.IsValid() { + return "" + } + loc := "en" + if len(locale) > 0 { + loc = locale[0] + } + switch loc { + case "en": + return EnMonths[p.month-1] + case "fa": + return FaMonths[p.month-1] + } + return "" +} + +// ToShortMonthString outputs a short string in persian month format like "فروردین". +// 获取缩写月份字符串,如 "فروردین" +func (p Persian) ToShortMonthString(locale ...string) (month string) { + if !p.IsValid() { + return "" + } + loc := "en" + if len(locale) > 0 { + loc = locale[0] + } + switch loc { + case "en": + return ShortEnMonths[p.month-1] + case "fa": + return ShortFaMonths[p.month-1] + } + return "" +} + +// ToWeekString outputs a string in week layout like "چهارشنبه". +// 输出完整星期字符串,如 "چهارشنبه" +func (p Persian) ToWeekString(locale ...string) (month string) { + if !p.IsValid() { + return "" + } + loc := "en" + if len(locale) > 0 { + loc = locale[0] + } + switch loc { + case "en": + return EnWeeks[p.ToGregorian().Week()] + case "fa": + return FaWeeks[p.ToGregorian().Week()] + } + return "" +} + +// ToShortWeekString outputs a short string in week layout like "چهارشنبه". +// 输出缩写星期字符串,如 "چهارشنبه" +func (p Persian) ToShortWeekString(locale ...string) (month string) { + if !p.IsValid() { + return "" + } + loc := "en" + if len(locale) > 0 { + loc = locale[0] + } + switch loc { + case "en": + return ShortEnWeeks[p.ToGregorian().Week()] + case "fa": + return ShortFaWeeks[p.ToGregorian().Week()] + } + return "" +} + +// IsValid reports whether is a valid persian date. +// 是否是有效的日期 +func (p Persian) IsValid() bool { + if p.Year() >= MinValue().year && p.Year() <= MaxValue().year && p.month >= MinValue().month && p.month <= MaxValue().month && p.day >= MinValue().day && p.day <= MaxValue().day { + return true + } + return false +} + +// IsLeapYear reports whether is a persian leap year. +// 是否是闰年 +func (p Persian) IsLeapYear() bool { + if !p.IsValid() { + return false + } + return (25*p.year+11)%33 < 8 +} + +// gets Julian day number in Persian calendar +// 获取波斯历儒略日计数 +func getPersianJdn(year, month, day int) int { + year = year - 473 + if year >= 0 { + year-- + } + epy := 474 + (year % 2820) + var md int + if month <= 7 { + md = (month - 1) * 31 + } else { + md = (month-1)*30 + 6 + } + return day + md + (epy*682-110)/2816 + (epy-1)*365 + year/2820*1029983 + 1948320 +} + +// gets Julian day number in Gregorian calendar +// 获取公历儒略日计数 +func getGregorianJdn(year, month, day int) int { + jdn := julian.FromGregorian(time.Date(year, time.Month(month), day, 0, 0, 0, 0, time.Local)).ToJulian().JD(0) + return int(jdn) +} diff --git a/vendor/github.com/dromara/carbon/v2/carbon.go b/vendor/github.com/dromara/carbon/v2/carbon.go new file mode 100644 index 000000000..321e08420 --- /dev/null +++ b/vendor/github.com/dromara/carbon/v2/carbon.go @@ -0,0 +1,483 @@ +// @Package carbon +// @Description a simple, semantic and developer-friendly golang package for datetime +// @Page github.com/dromara/carbon +// @Developer gouguoyin +// @Blog www.gouguoyin.com +// @Email 245629560@qq.com + +// Package carbon is a simple, semantic and developer-friendly golang package for datetime. +package carbon + +import ( + "time" +) + +// Version current version +// 当前版本号 +const Version = "2.5.2" + +// timezone constants +// 时区常量 +const ( + Local = "Local" // 本地时间 + UTC = "UTC" // 世界协调时间 + GMT = "GMT" // 格林尼治标准时间 + CST = "CST" // 中国标准时间 + EET = "EET" // 欧洲东部标准时间 + WET = "WET" // 欧洲西部标准时间 + CET = "CET" // 欧洲中部标准时间 + EST = "EST" // 美国东部标准时间 + MST = "MST" // 美国山地标准时间 + + Cuba = "Cuba" // 古巴 + Egypt = "Egypt" // 埃及 + Eire = "Eire" // 爱尔兰 + Greenwich = "Greenwich" // 格林尼治 + Iceland = "Iceland" // 冰岛 + Iran = "Iran" // 伊朗 + Israel = "Israel" // 以色列 + Jamaica = "Jamaica" // 牙买加 + Japan = "Japan" // 日本 + Libya = "Libya" // 利比亚 + Poland = "Poland" // 波兰 + Portugal = "Portugal" // 葡萄牙 + PRC = "PRC" // 中国 + Singapore = "Singapore" // 新加坡 + Turkey = "Turkey" // 土耳其 + + Shanghai = "Asia/Shanghai" // 上海 + Chongqing = "Asia/Chongqing" // 重庆 + Harbin = "Asia/Harbin" // 哈尔滨 + Urumqi = "Asia/Urumqi" // 乌鲁木齐 + HongKong = "Asia/Hong_Kong" // 香港 + Macao = "Asia/Macao" // 澳门 + Taipei = "Asia/Taipei" // 台北 + Tokyo = "Asia/Tokyo" // 东京 + HoChiMinh = "Asia/Ho_Chi_Minh" // 胡志明 + Hanoi = "Asia/Hanoi" // 河内 + Saigon = "Asia/Saigon" // 西贡 + Seoul = "Asia/Seoul" // 首尔 + Pyongyang = "Asia/Pyongyang" // 平壤 + Bangkok = "Asia/Bangkok" // 曼谷 + Dubai = "Asia/Dubai" // 迪拜 + Qatar = "Asia/Qatar" // 卡塔尔 + Bangalore = "Asia/Bangalore" // 班加罗尔 + Kolkata = "Asia/Kolkata" // 加尔各答 + Mumbai = "Asia/Mumbai" // 孟买 + MexicoCity = "America/Mexico_City" // 墨西哥 + NewYork = "America/New_York" // 纽约 + LosAngeles = "America/Los_Angeles" // 洛杉矶 + Chicago = "America/Chicago" // 芝加哥 + SaoPaulo = "America/Sao_Paulo" // 圣保罗 + Moscow = "Europe/Moscow" // 莫斯科 + London = "Europe/London" // 伦敦 + Berlin = "Europe/Berlin" // 柏林 + Paris = "Europe/Paris" // 巴黎 + Rome = "Europe/Rome" // 罗马 + Sydney = "Australia/Sydney" // 悉尼 + Melbourne = "Australia/Melbourne" // 墨尔本 + Darwin = "Australia/Darwin" // 达尔文 +) + +// month constants +// 月份常量 +const ( + January = "January" // 一月 + February = "February" // 二月 + March = "March" // 三月 + April = "April" // 四月 + May = "May" // 五月 + June = "June" // 六月 + July = "July" // 七月 + August = "August" // 八月 + September = "September" // 九月 + October = "October" // 十月 + November = "November" // 十一月 + December = "December" // 十二月 +) + +// week constants +// 星期常量 +const ( + Monday = "Monday" // 周一 + Tuesday = "Tuesday" // 周二 + Wednesday = "Wednesday" // 周三 + Thursday = "Thursday" // 周四 + Friday = "Friday" // 周五 + Saturday = "Saturday" // 周六 + Sunday = "Sunday" // 周日 +) + +// number constants +// 数字常量 +const ( + YearsPerMillennium = 1000 // 每千年1000年 + YearsPerCentury = 100 // 每世纪100年 + YearsPerDecade = 10 // 每十年10年 + QuartersPerYear = 4 // 每年4个季度 + MonthsPerYear = 12 // 每年12月 + MonthsPerQuarter = 3 // 每季度3月 + WeeksPerNormalYear = 52 // 每常规年52周 + weeksPerLongYear = 53 // 每长年53周 + WeeksPerMonth = 4 // 每月4周 + DaysPerLeapYear = 366 // 每闰年366天 + DaysPerNormalYear = 365 // 每常规年365天 + DaysPerWeek = 7 // 每周7天 + HoursPerWeek = 168 // 每周168小时 + HoursPerDay = 24 // 每天24小时 + MinutesPerDay = 1440 // 每天1440分钟 + MinutesPerHour = 60 // 每小时60分钟 + SecondsPerWeek = 604800 // 每周604800秒 + SecondsPerDay = 86400 // 每天86400秒 + SecondsPerHour = 3600 // 每小时3600秒 + SecondsPerMinute = 60 // 每分钟60秒 +) + +// layout constants +// 布局模板常量 +const ( + AtomLayout = RFC3339Layout + ANSICLayout = time.ANSIC + CookieLayout = "Monday, 02-Jan-2006 15:04:05 MST" + KitchenLayout = time.Kitchen + RssLayout = time.RFC1123Z + RubyDateLayout = time.RubyDate + UnixDateLayout = time.UnixDate + W3cLayout = RFC3339Layout + + RFC1036Layout = "Mon, 02 Jan 06 15:04:05 -0700" + RFC1123Layout = time.RFC1123 + RFC1123ZLayout = time.RFC1123Z + RFC2822Layout = time.RFC1123Z + RFC3339Layout = "2006-01-02T15:04:05Z07:00" + RFC3339MilliLayout = "2006-01-02T15:04:05.999Z07:00" + RFC3339MicroLayout = "2006-01-02T15:04:05.999999Z07:00" + RFC3339NanoLayout = "2006-01-02T15:04:05.999999999Z07:00" + RFC7231Layout = "Mon, 02 Jan 2006 15:04:05 MST" + RFC822Layout = time.RFC822 + RFC822ZLayout = time.RFC822Z + RFC850Layout = time.RFC850 + + ISO8601Layout = "2006-01-02T15:04:05-07:00" + ISO8601MilliLayout = "2006-01-02T15:04:05.999-07:00" + ISO8601MicroLayout = "2006-01-02T15:04:05.999999-07:00" + ISO8601NanoLayout = "2006-01-02T15:04:05.999999999-07:00" + + ISO8601ZuluLayout = "2006-01-02T15:04:05Z" + ISO8601ZuluMilliLayout = "2006-01-02T15:04:05.999Z" + ISO8601ZuluMicroLayout = "2006-01-02T15:04:05.999999Z" + ISO8601ZuluNanoLayout = "2006-01-02T15:04:05.999999999Z" + + FormattedDateLayout = "Jan 2, 2006" + FormattedDayDateLayout = "Mon, Jan 2, 2006" + + DayDateTimeLayout = "Mon, Jan 2, 2006 3:04 PM" + DateTimeLayout = "2006-01-02 15:04:05" + DateTimeMilliLayout = "2006-01-02 15:04:05.999" + DateTimeMicroLayout = "2006-01-02 15:04:05.999999" + DateTimeNanoLayout = "2006-01-02 15:04:05.999999999" + ShortDateTimeLayout = "20060102150405" + ShortDateTimeMilliLayout = "20060102150405.999" + ShortDateTimeMicroLayout = "20060102150405.999999" + ShortDateTimeNanoLayout = "20060102150405.999999999" + + DateLayout = "2006-01-02" + DateMilliLayout = "2006-01-02.999" + DateMicroLayout = "2006-01-02.999999" + DateNanoLayout = "2006-01-02.999999999" + ShortDateLayout = "20060102" + ShortDateMilliLayout = "20060102.999" + ShortDateMicroLayout = "20060102.999999" + ShortDateNanoLayout = "20060102.999999999" + + TimeLayout = "15:04:05" + TimeMilliLayout = "15:04:05.999" + TimeMicroLayout = "15:04:05.999999" + TimeNanoLayout = "15:04:05.999999999" + ShortTimeLayout = "150405" + ShortTimeMilliLayout = "150405.999" + ShortTimeMicroLayout = "150405.999999" + ShortTimeNanoLayout = "150405.999999999" +) + +// format constants +// 格式模板常量 +const ( + AtomFormat = "Y-m-d\\TH:i:sP" + ANSICFormat = "D M j H:i:s Y" + CookieFormat = "l, d-M-Y H:i:s T" + KitchenFormat = "g:iA" + RssFormat = "D, d M Y H:i:s O" + RubyDateFormat = "D M d H:i:s O Y" + UnixDateFormat = "D M j H:i:s T Y" + + RFC1036Format = "D, d M y H:i:s O" + RFC1123Format = "D, d M Y H:i:s T" + RFC1123ZFormat = "D, d M Y H:i:s O" + RFC2822Format = "D, d M Y H:i:s O" + RFC3339Format = "Y-m-d\\TH:i:sP" + RFC3339MilliFormat = "Y-m-d\\TH:i:s.vP" + RFC3339MicroFormat = "Y-m-d\\TH:i:s.uP" + RFC3339NanoFormat = "Y-m-d\\TH:i:s.xP" + RFC7231Format = "D, d M Y H:i:s T" + RFC822Format = "d M y H:i T" + RFC822ZFormat = "d M y H:i O" + RFC850Format = "l, d-M-y H:i:s T" + + ISO8601Format = "Y-m-d\\TH:i:sP" + ISO8601MilliFormat = "Y-m-d\\TH:i:s.vP" + ISO8601MicroFormat = "Y-m-d\\TH:i:s.uP" + ISO8601NanoFormat = "Y-m-d\\TH:i:s.xP" + + ISO8601ZuluFormat = "Y-m-d\\TH:i:s\\Z" + ISO8601ZuluMilliFormat = "Y-m-d\\TH:i:s.v\\Z" + ISO8601ZuluMicroFormat = "Y-m-d\\TH:i:s.u\\Z" + ISO8601ZuluNanoFormat = "Y-m-d\\TH:i:s.x\\Z" + + FormattedDateFormat = "M j, Y" + FormattedDayDateFormat = "D, M j, Y" + + DayDateTimeFormat = "D, M j, Y g:i A" + DateTimeFormat = "Y-m-d H:i:s" + DateTimeMilliFormat = "Y-m-d H:i:s.v" + DateTimeMicroFormat = "Y-m-d H:i:s.u" + DateTimeNanoFormat = "Y-m-d H:i:s.x" + ShortDateTimeFormat = "YmdHis" + ShortDateTimeMilliFormat = "YmdHis.v" + ShortDateTimeMicroFormat = "YmdHis.u" + ShortDateTimeNanoFormat = "YmdHis.x" + + DateFormat = "Y-m-d" + DateMilliFormat = "Y-m-d.v" + DateMicroFormat = "Y-m-d.u" + DateNanoFormat = "Y-m-d.x" + ShortDateFormat = "Ymd" + ShortDateMilliFormat = "Ymd.v" + ShortDateMicroFormat = "Ymd.u" + ShortDateNanoFormat = "Ymd.x" + + TimeFormat = "H:i:s" + TimeMilliFormat = "H:i:s.v" + TimeMicroFormat = "H:i:s.u" + TimeNanoFormat = "H:i:s.x" + ShortTimeFormat = "His" + ShortTimeMilliFormat = "His.v" + ShortTimeMicroFormat = "His.u" + ShortTimeNanoFormat = "His.x" +) + +// Carbon defines a Carbon struct. +// 定义 Carbon 结构体 +type Carbon struct { + time time.Time + testNow int64 // nanosecond timestamp of test now time + layout string + weekStartsAt time.Weekday + loc *time.Location + lang *Language + Error error +} + +// NewCarbon returns a new Carbon instance. +// 初始化 Carbon 结构体 +func NewCarbon() Carbon { + c := Carbon{lang: NewLanguage()} + c.loc, c.Error = getLocationByTimezone(defaultTimezone) + if weekday, ok := weekdays[defaultWeekStartsAt]; ok { + c.weekStartsAt = weekday + } + c.layout = defaultLayout + return c +} + +// DateTime defines a DateTime struct. +// 定义 DateTime 结构体 +type DateTime struct { + Carbon +} + +// NewDateTime returns a new DateTime instance. +// 初始化 DateTime 结构体 +func NewDateTime(carbon Carbon) DateTime { + return DateTime{Carbon: carbon} +} + +// DateTimeMilli defines a DateTimeMilli struct. +// 定义 DateTimeMilli 结构体 +type DateTimeMilli struct { + Carbon +} + +// NewDateTimeMilli returns a new DateTimeMilli instance. +// 初始化 DateTimeMilli 结构体 +func NewDateTimeMilli(carbon Carbon) DateTimeMilli { + return DateTimeMilli{Carbon: carbon} +} + +// DateTimeMicro defines a DateTimeMicro struct. +// 定义 DateTimeMicro 结构体 +type DateTimeMicro struct { + Carbon +} + +// NewDateTimeMicro returns a new DateTimeMicro instance. +// 初始化 DateTimeMicro 结构体 +func NewDateTimeMicro(carbon Carbon) DateTimeMicro { + return DateTimeMicro{Carbon: carbon} +} + +// DateTimeNano defines a DateTimeNano struct. +// 定义 DateTimeNano 结构体 +type DateTimeNano struct { + Carbon +} + +// NewDateTimeNano returns a new DateTimeNano instance. +// 初始化 DateTimeNano 结构体 +func NewDateTimeNano(carbon Carbon) DateTimeNano { + return DateTimeNano{Carbon: carbon} +} + +// Date defines a Date struct. +// 定义 Date 结构体 +type Date struct { + Carbon +} + +// NewDate returns a new Date instance. +// 初始化 Date 结构体 +func NewDate(carbon Carbon) Date { + return Date{Carbon: carbon} +} + +// DateMilli defines a DateMilli struct. +// 定义 DateMilli 结构体 +type DateMilli struct { + Carbon +} + +// NewDateMilli returns a new DateMilli instance. +// 初始化 DateMilli 结构体 +func NewDateMilli(carbon Carbon) DateMilli { + return DateMilli{Carbon: carbon} +} + +// DateMicro defines a DateMicro struct. +// 定义 DateMicro 结构体 +type DateMicro struct { + Carbon +} + +// NewDateMicro returns a new DateMicro instance. +// 初始化 DateMicro 结构体 +func NewDateMicro(carbon Carbon) DateMicro { + return DateMicro{Carbon: carbon} +} + +// DateNano defines a DateNano struct. +// 定义 DateNano 结构体 +type DateNano struct { + Carbon +} + +// NewDateNano returns a new DateNano instance. +// 初始化 DateNano 结构体 +func NewDateNano(carbon Carbon) DateNano { + return DateNano{Carbon: carbon} +} + +// Time defines a Time struct. +// 定义 Time 结构体 +type Time struct { + Carbon +} + +// NewTime returns a new Time instance. +// 初始化 Time 结构体 +func NewTime(carbon Carbon) Time { + return Time{Carbon: carbon} +} + +// TimeMilli defines a TimeMilli struct. +// 定义 TimeMilli 结构体 +type TimeMilli struct { + Carbon +} + +// NewTimeMilli returns a new TimeMilli instance. +// 初始化 TimeMilli 结构体 +func NewTimeMilli(carbon Carbon) TimeMilli { + return TimeMilli{Carbon: carbon} +} + +// TimeMicro defines a TimeMicro struct. +// 定义 TimeMicro 结构体 +type TimeMicro struct { + Carbon +} + +// NewTimeMicro returns a new TimeMicro instance. +// 初始化 TimeMicro 结构体 +func NewTimeMicro(carbon Carbon) TimeMicro { + return TimeMicro{Carbon: carbon} +} + +// TimeNano defines a TimeNano struct. +// 定义 TimeNano 结构体 +type TimeNano struct { + Carbon +} + +// NewTimeNano returns a new TimeNano instance. +// 初始化 TimeNano 结构体 +func NewTimeNano(carbon Carbon) TimeNano { + return TimeNano{Carbon: carbon} +} + +// Timestamp defines a Timestamp struct. +// 定义 Timestamp 结构体 +type Timestamp struct { + Carbon +} + +// NewTimestamp returns a new Timestamp instance. +// 初始化 Timestamp 结构体 +func NewTimestamp(carbon Carbon) Timestamp { + return Timestamp{Carbon: carbon} +} + +// TimestampMilli defines a TimestampMilli struct. +// 定义 TimestampMilli 结构体 +type TimestampMilli struct { + Carbon +} + +// NewTimestampMilli returns a new TimestampMilli instance. +// 初始化 TimestampMilli 结构体 +func NewTimestampMilli(carbon Carbon) TimestampMilli { + return TimestampMilli{Carbon: carbon} +} + +// TimestampMicro defines a TimestampMicro struct. +// 定义 TimestampMicro 结构体 +type TimestampMicro struct { + Carbon +} + +// NewTimestampMicro returns a new TimestampMicro instance. +// 初始化 TimestampMicro 结构体 +func NewTimestampMicro(carbon Carbon) TimestampMicro { + return TimestampMicro{Carbon: carbon} +} + +// TimestampNano defines a TimestampNano struct. +// 定义 TimestampNano 结构体 +type TimestampNano struct { + Carbon +} + +// NewTimestampNano returns a new TimestampNano instance. +// 初始化 TimestampNano 结构体 +func NewTimestampNano(carbon Carbon) TimestampNano { + return TimestampNano{Carbon: carbon} +} diff --git a/vendor/github.com/dromara/carbon/v2/comparer.go b/vendor/github.com/dromara/carbon/v2/comparer.go new file mode 100644 index 000000000..1b7bbffbb --- /dev/null +++ b/vendor/github.com/dromara/carbon/v2/comparer.go @@ -0,0 +1,517 @@ +package carbon + +import ( + "time" +) + +// IsDST reports whether is daylight saving time. +// 是否是夏令时 +func (c Carbon) IsDST() bool { + return c.time.IsDST() +} + +// IsZero reports whether is zero time(0001-01-01 00:00:00 +0000 UTC). +// 是否是零值时间(0001-01-01 00:00:00 +0000 UTC) +func (c Carbon) IsZero() bool { + return c.time.IsZero() +} + +// IsValid reports whether is valid time. +// 是否是有效时间 +func (c Carbon) IsValid() bool { + if c.IsZero() { + return false + } + if c.Year() >= MinValue().Year() && c.Year() <= MaxValue().Year() && c.Month() > 0 && c.Day() > 0 { + return true + } + return false +} + +// IsInvalid reports whether is invalid time. +// 是否是无效时间 +func (c Carbon) IsInvalid() bool { + return !c.IsValid() +} + +// IsAM reports whether is before noon. +// 是否是上午 +func (c Carbon) IsAM() bool { + return c.Format("a") == "am" +} + +// IsPM reports whether is after noon. +// 是否是下午 +func (c Carbon) IsPM() bool { + return c.Format("a") == "pm" +} + +// IsNow reports whether is now time. +// 是否是当前时间 +func (c Carbon) IsNow() bool { + if c.Error != nil { + return false + } + return c.Timestamp() == c.Now().Timestamp() +} + +// IsFuture reports whether is future time. +// 是否是未来时间 +func (c Carbon) IsFuture() bool { + if c.Error != nil { + return false + } + return c.Timestamp() > c.Now().Timestamp() +} + +// IsPast reports whether is past time. +// 是否是过去时间 +func (c Carbon) IsPast() bool { + if c.Error != nil { + return false + } + return c.Timestamp() < c.Now().Timestamp() +} + +// IsLeapYear reports whether is a leap year. +// 是否是闰年 +func (c Carbon) IsLeapYear() bool { + if c.Error != nil { + return false + } + year := c.Year() + if year%400 == 0 || (year%4 == 0 && year%100 != 0) { + return true + } + return false +} + +// IsLongYear reports whether is a long year, see https://en.wikipedia.org/wiki/ISO_8601#Week_dates. +// 是否是长年 +func (c Carbon) IsLongYear() bool { + if c.Error != nil { + return false + } + _, w := time.Date(c.Year(), 12, 31, 0, 0, 0, 0, c.loc).ISOWeek() + return w == weeksPerLongYear +} + +// IsJanuary reports whether is January. +// 是否是一月 +func (c Carbon) IsJanuary() bool { + if c.Error != nil { + return false + } + return c.Month() == int(time.January) +} + +// IsFebruary reports whether is February. +// 是否是二月 +func (c Carbon) IsFebruary() bool { + if c.Error != nil { + return false + } + return c.Month() == int(time.February) +} + +// IsMarch reports whether is March. +// 是否是三月 +func (c Carbon) IsMarch() bool { + if c.Error != nil { + return false + } + return c.Month() == int(time.March) +} + +// IsApril reports whether is April. +// 是否是四月 +func (c Carbon) IsApril() bool { + if c.Error != nil { + return false + } + return c.Month() == int(time.April) +} + +// IsMay reports whether is May. +// 是否是五月 +func (c Carbon) IsMay() bool { + if c.Error != nil { + return false + } + return c.Month() == int(time.May) +} + +// IsJune reports whether is June. +// 是否是六月 +func (c Carbon) IsJune() bool { + if c.Error != nil { + return false + } + return c.Month() == int(time.June) +} + +// IsJuly reports whether is July. +// 是否是七月 +func (c Carbon) IsJuly() bool { + if c.Error != nil { + return false + } + return c.Month() == int(time.July) +} + +// IsAugust reports whether is August. +// 是否是八月 +func (c Carbon) IsAugust() bool { + if c.Error != nil { + return false + } + return c.Month() == int(time.August) +} + +// IsSeptember reports whether is September. +// 是否是九月 +func (c Carbon) IsSeptember() bool { + if c.Error != nil { + return false + } + return c.Month() == int(time.September) +} + +// IsOctober reports whether is October. +// 是否是十月 +func (c Carbon) IsOctober() bool { + if c.Error != nil { + return false + } + return c.Month() == int(time.October) +} + +// IsNovember reports whether is November. +// 是否是十一月 +func (c Carbon) IsNovember() bool { + if c.Error != nil { + return false + } + return c.Month() == int(time.November) +} + +// IsDecember reports whether is December. +// 是否是十二月 +func (c Carbon) IsDecember() bool { + if c.Error != nil { + return false + } + return c.Month() == int(time.December) +} + +// IsMonday reports whether is Monday. +// 是否是周一 +func (c Carbon) IsMonday() bool { + if c.Error != nil { + return false + } + return c.StdTime().Weekday() == time.Monday +} + +// IsTuesday reports whether is Tuesday. +// 是否是周二 +func (c Carbon) IsTuesday() bool { + if c.Error != nil { + return false + } + return c.StdTime().Weekday() == time.Tuesday +} + +// IsWednesday reports whether is Wednesday. +// 是否是周三 +func (c Carbon) IsWednesday() bool { + if c.Error != nil { + return false + } + return c.StdTime().Weekday() == time.Wednesday +} + +// IsThursday reports whether is Thursday. +// 是否是周四 +func (c Carbon) IsThursday() bool { + if c.Error != nil { + return false + } + return c.StdTime().Weekday() == time.Thursday +} + +// IsFriday reports whether is Friday. +// 是否是周五 +func (c Carbon) IsFriday() bool { + if c.Error != nil { + return false + } + return c.StdTime().Weekday() == time.Friday +} + +// IsSaturday reports whether is Saturday. +// 是否是周六 +func (c Carbon) IsSaturday() bool { + if c.Error != nil { + return false + } + return c.StdTime().Weekday() == time.Saturday +} + +// IsSunday reports whether is Sunday. +// 是否是周日 +func (c Carbon) IsSunday() bool { + if c.Error != nil { + return false + } + return c.StdTime().Weekday() == time.Sunday +} + +// IsWeekday reports whether is weekday. +// 是否是工作日 +func (c Carbon) IsWeekday() bool { + if c.Error != nil { + return false + } + return !c.IsSaturday() && !c.IsSunday() +} + +// IsWeekend reports whether is weekend. +// 是否是周末 +func (c Carbon) IsWeekend() bool { + if c.Error != nil { + return false + } + return c.IsSaturday() || c.IsSunday() +} + +// IsYesterday reports whether is yesterday. +// 是否是昨天 +func (c Carbon) IsYesterday() bool { + if c.Error != nil { + return false + } + return c.ToDateString() == Yesterday().ToDateString() +} + +// IsToday reports whether is today. +// 是否是今天 +func (c Carbon) IsToday() bool { + if c.Error != nil { + return false + } + return c.ToDateString() == Now().ToDateString() +} + +// IsTomorrow reports whether is tomorrow. +// 是否是明天 +func (c Carbon) IsTomorrow() bool { + if c.Error != nil { + return false + } + return c.ToDateString() == Tomorrow().ToDateString() +} + +// IsSameCentury reports whether is same century. +// 是否是同一世纪 +func (c Carbon) IsSameCentury(t Carbon) bool { + if c.Error != nil || t.Error != nil { + return false + } + return c.Century() == t.Century() +} + +// IsSameDecade reports whether is same decade. +// 是否是同一年代 +func (c Carbon) IsSameDecade(t Carbon) bool { + if c.Error != nil || t.Error != nil { + return false + } + return c.Decade() == t.Decade() +} + +// IsSameYear reports whether is same year. +// 是否是同一年 +func (c Carbon) IsSameYear(t Carbon) bool { + if c.Error != nil || t.Error != nil { + return false + } + return c.Year() == t.Year() +} + +// IsSameQuarter reports whether is same quarter. +// 是否是同一季节 +func (c Carbon) IsSameQuarter(t Carbon) bool { + if c.Error != nil || t.Error != nil { + return false + } + return c.Quarter() == t.Quarter() +} + +// IsSameMonth reports whether is same month. +// 是否是同一月 +func (c Carbon) IsSameMonth(t Carbon) bool { + if c.Error != nil || t.Error != nil { + return false + } + return c.Format("Ym") == t.Format("Ym") +} + +// IsSameDay reports whether is same day. +// 是否是同一天 +func (c Carbon) IsSameDay(t Carbon) bool { + if c.Error != nil || t.Error != nil { + return false + } + return c.Format("Ymd") == t.Format("Ymd") +} + +// IsSameHour reports whether is same hour. +// 是否是同一小时 +func (c Carbon) IsSameHour(t Carbon) bool { + if c.Error != nil || t.Error != nil { + return false + } + return c.Format("YmdH") == t.Format("YmdH") +} + +// IsSameMinute reports whether is same minute. +// 是否是同一分钟 +func (c Carbon) IsSameMinute(t Carbon) bool { + if c.Error != nil || t.Error != nil { + return false + } + return c.Format("YmdHi") == t.Format("YmdHi") +} + +// IsSameSecond reports whether is same second. +// 是否是同一秒 +func (c Carbon) IsSameSecond(t Carbon) bool { + if c.Error != nil || t.Error != nil { + return false + } + return c.Format("YmdHis") == t.Format("YmdHis") + +} + +// Compare compares by an operator. +// 时间比较 +func (c Carbon) Compare(operator string, t Carbon) bool { + if c.Error != nil || t.Error != nil { + return false + } + switch operator { + case "=": + return c.Eq(t) + case "<>", "!=": + return !c.Eq(t) + case ">": + return c.Gt(t) + case ">=": + return c.Gte(t) + case "<": + return c.Lt(t) + case "<=": + return c.Lte(t) + } + return false +} + +// Gt reports whether greater than. +// 是否大于 +func (c Carbon) Gt(t Carbon) bool { + if c.Error != nil || t.Error != nil { + return false + } + return c.time.After(t.time) +} + +// Lt reports whether less than. +// 是否小于 +func (c Carbon) Lt(t Carbon) bool { + if c.Error != nil || t.Error != nil { + return false + } + return c.time.Before(t.time) +} + +// Eq reports whether equal. +// 是否等于 +func (c Carbon) Eq(t Carbon) bool { + if c.Error != nil || t.Error != nil { + return false + } + return c.time.Equal(t.time) +} + +// Ne reports whether not equal. +// 是否不等于 +func (c Carbon) Ne(t Carbon) bool { + return !c.Eq(t) +} + +// Gte reports whether greater than or equal. +// 是否大于等于 +func (c Carbon) Gte(t Carbon) bool { + if c.Error != nil || t.Error != nil { + return false + } + return c.Gt(t) || c.Eq(t) +} + +// Lte reports whether less than or equal. +// 是否小于等于 +func (c Carbon) Lte(t Carbon) bool { + if c.Error != nil || t.Error != nil { + return false + } + return c.Lt(t) || c.Eq(t) +} + +// Between reports whether between two times, excluded the start and end time. +// 是否在两个时间之间(不包括这两个时间) +func (c Carbon) Between(start Carbon, end Carbon) bool { + if c.Error != nil || start.Error != nil || end.Error != nil { + return false + } + if c.Gt(start) && c.Lt(end) { + return true + } + return false +} + +// BetweenIncludedStart reports whether between two times, included the start time. +// 是否在两个时间之间(包括开始时间) +func (c Carbon) BetweenIncludedStart(start Carbon, end Carbon) bool { + if c.Error != nil || start.Error != nil || end.Error != nil { + return false + } + if c.Gte(start) && c.Lt(end) { + return true + } + return false +} + +// BetweenIncludedEnd reports whether between two times, included the end time. +// 是否在两个时间之间(包括结束时间) +func (c Carbon) BetweenIncludedEnd(start Carbon, end Carbon) bool { + if c.Error != nil || start.Error != nil || end.Error != nil { + return false + } + if c.Gt(start) && c.Lte(end) { + return true + } + return false +} + +// BetweenIncludedBoth reports whether between two times, included the start and end time. +// 是否在两个时间之间(包括这两个时间) +func (c Carbon) BetweenIncludedBoth(start Carbon, end Carbon) bool { + if c.Error != nil || start.Error != nil || end.Error != nil { + return false + } + if c.Gte(start) && c.Lte(end) { + return true + } + return false +} diff --git a/vendor/github.com/dromara/carbon/v2/constellation.go b/vendor/github.com/dromara/carbon/v2/constellation.go new file mode 100644 index 000000000..5bfba2d9c --- /dev/null +++ b/vendor/github.com/dromara/carbon/v2/constellation.go @@ -0,0 +1,246 @@ +package carbon + +import ( + "strings" +) + +var constellations = []struct { + startMonth, startDay int + endMonth, endDay int +}{ + {3, 21, 4, 19}, // Aries + {4, 20, 5, 20}, // Taurus + {5, 21, 6, 21}, // Gemini + {6, 22, 7, 22}, // Cancer + {7, 23, 8, 22}, // Leo + {8, 23, 9, 22}, // Virgo + {9, 23, 10, 23}, // Libra + {10, 24, 11, 22}, // Scorpio + {11, 23, 12, 21}, // Sagittarius + {12, 22, 1, 19}, // Capricorn + {1, 20, 2, 18}, // Aquarius + {2, 19, 3, 20}, // Pisces +} + +// Constellation gets constellation name like "Aries", i18n is supported. +// 获取星座,支持i18n +func (c Carbon) Constellation() string { + if c.IsInvalid() { + return "" + } + if len(c.lang.resources) == 0 { + c.lang.SetLocale(defaultLocale) + } + index := -1 + _, month, day := c.Date() + for i := 0; i < len(constellations); i++ { + constellation := constellations[i] + if month == constellation.startMonth && day >= constellation.startDay { + index = i + } + if month == constellation.endMonth && day <= constellation.endDay { + index = i + } + } + c.lang.rw.RLock() + defer c.lang.rw.RUnlock() + if resources, ok := c.lang.resources["constellations"]; ok { + slice := strings.Split(resources, "|") + if len(slice) == MonthsPerYear { + return slice[index] + } + } + return "" +} + +// IsAries reports whether is Aries. +// 是否是白羊座 +func (c Carbon) IsAries() bool { + if c.IsInvalid() { + return false + } + _, month, day := c.Date() + if month == 3 && day >= 21 { + return true + } + if month == 4 && day <= 19 { + return true + } + return false +} + +// IsTaurus reports whether is Taurus. +// 是否是金牛座 +func (c Carbon) IsTaurus() bool { + if c.IsInvalid() { + return false + } + _, month, day := c.Date() + if month == 4 && day >= 20 { + return true + } + if month == 5 && day <= 20 { + return true + } + return false +} + +// IsGemini reports whether is Gemini. +// 是否是双子座 +func (c Carbon) IsGemini() bool { + if c.IsInvalid() { + return false + } + _, month, day := c.Date() + if month == 5 && day >= 21 { + return true + } + if month == 6 && day <= 21 { + return true + } + return false +} + +// IsCancer reports whether is Cancer. +// 是否是巨蟹座 +func (c Carbon) IsCancer() bool { + if c.IsInvalid() { + return false + } + _, month, day := c.Date() + if month == 6 && day >= 22 { + return true + } + if month == 7 && day <= 22 { + return true + } + return false +} + +// IsLeo reports whether is Leo. +// 是否是狮子座 +func (c Carbon) IsLeo() bool { + if c.IsInvalid() { + return false + } + _, month, day := c.Date() + if month == 7 && day >= 23 { + return true + } + if month == 8 && day <= 22 { + return true + } + return false +} + +// IsVirgo reports whether is Virgo. +// 是否是处女座 +func (c Carbon) IsVirgo() bool { + if c.IsInvalid() { + return false + } + _, month, day := c.Date() + if month == 8 && day >= 23 { + return true + } + if month == 9 && day <= 22 { + return true + } + return false +} + +// IsLibra reports whether is Libra. +// 是否是天秤座 +func (c Carbon) IsLibra() bool { + if c.IsInvalid() { + return false + } + _, month, day := c.Date() + if month == 9 && day >= 23 { + return true + } + if month == 10 && day <= 23 { + return true + } + return false +} + +// IsScorpio reports whether is Scorpio. +// 是否是天蝎座 +func (c Carbon) IsScorpio() bool { + if c.IsInvalid() { + return false + } + _, month, day := c.Date() + if month == 10 && day >= 24 { + return true + } + if month == 11 && day <= 22 { + return true + } + return false +} + +// IsSagittarius reports whether is Sagittarius. +// 是否是射手座 +func (c Carbon) IsSagittarius() bool { + if c.IsInvalid() { + return false + } + _, month, day := c.Date() + if month == 11 && day >= 22 { + return true + } + if month == 12 && day <= 21 { + return true + } + return false +} + +// IsCapricorn reports whether is Capricorn. +// 是否是摩羯座 +func (c Carbon) IsCapricorn() bool { + if c.IsInvalid() { + return false + } + _, month, day := c.Date() + if month == 12 && day >= 22 { + return true + } + if month == 1 && day <= 19 { + return true + } + return false +} + +// IsAquarius reports whether is Aquarius. +// 是否是水瓶座 +func (c Carbon) IsAquarius() bool { + if c.IsInvalid() { + return false + } + _, month, day := c.Date() + if month == 1 && day >= 20 { + return true + } + if month == 2 && day <= 18 { + return true + } + return false +} + +// IsPisces reports whether is Pisces. +// 是否是双鱼座 +func (c Carbon) IsPisces() bool { + if c.IsInvalid() { + return false + } + _, month, day := c.Date() + if month == 2 && day >= 19 { + return true + } + if month == 3 && day <= 20 { + return true + } + return false +} diff --git a/vendor/github.com/dromara/carbon/v2/creator.go b/vendor/github.com/dromara/carbon/v2/creator.go new file mode 100644 index 000000000..cc496a28a --- /dev/null +++ b/vendor/github.com/dromara/carbon/v2/creator.go @@ -0,0 +1,254 @@ +package carbon + +import ( + "time" +) + +// CreateFromStdTime creates a Carbon instance from standard time.Time. +// 从标准的 time.Time 创建 Carbon 实例 +func CreateFromStdTime(tt time.Time, timezone ...string) Carbon { + c := NewCarbon() + c.loc = tt.Location() + if len(timezone) > 0 { + c.loc, c.Error = getLocationByTimezone(timezone[0]) + } + c.time = tt + return c +} + +// CreateFromTimestamp creates a Carbon instance from a given timestamp with second. +// 从给定的秒级时间戳创建 Carbon 实例 +func (c Carbon) CreateFromTimestamp(timestamp int64, timezone ...string) Carbon { + if len(timezone) > 0 { + c.loc, c.Error = getLocationByTimezone(timezone[0]) + } + if c.Error != nil { + return c + } + c.time = time.Unix(timestamp, 0) + return c +} + +// CreateFromTimestamp creates a Carbon instance from a given timestamp with second. +// 从给定的秒级时间戳创建 Carbon 实例 +func CreateFromTimestamp(timestamp int64, timezone ...string) Carbon { + return NewCarbon().CreateFromTimestamp(timestamp, timezone...) +} + +// CreateFromTimestampMilli creates a Carbon instance from a given timestamp with millisecond. +// 从给定的毫秒级时间戳创建 Carbon 实例 +func (c Carbon) CreateFromTimestampMilli(timestamp int64, timezone ...string) Carbon { + if len(timezone) > 0 { + c.loc, c.Error = getLocationByTimezone(timezone[0]) + } + if c.Error != nil { + return c + } + c.time = time.Unix(timestamp/1e3, (timestamp%1e3)*1e6) + return c +} + +// CreateFromTimestampMilli creates a Carbon instance from a given timestamp with millisecond. +// 从给定的毫秒级时间戳创建 Carbon 实例 +func CreateFromTimestampMilli(timestamp int64, timezone ...string) Carbon { + return NewCarbon().CreateFromTimestampMilli(timestamp, timezone...) +} + +// CreateFromTimestampMicro creates a Carbon instance from a given timestamp with microsecond. +// 从给定的微秒级时间戳创建 Carbon 实例 +func (c Carbon) CreateFromTimestampMicro(timestamp int64, timezone ...string) Carbon { + if len(timezone) > 0 { + c.loc, c.Error = getLocationByTimezone(timezone[0]) + } + if c.Error != nil { + return c + } + c.time = time.Unix(timestamp/1e6, (timestamp%1e6)*1e3) + return c +} + +// CreateFromTimestampMicro creates a Carbon instance from a given timestamp with microsecond. +// 从给定的微秒级时间戳创建 Carbon 实例 +func CreateFromTimestampMicro(timestamp int64, timezone ...string) Carbon { + return NewCarbon().CreateFromTimestampMicro(timestamp, timezone...) +} + +// CreateFromTimestampNano creates a Carbon instance from a given timestamp with nanosecond. +// 从给定的纳秒级时间戳创建 Carbon 实例 +func (c Carbon) CreateFromTimestampNano(timestamp int64, timezone ...string) Carbon { + if len(timezone) > 0 { + c.loc, c.Error = getLocationByTimezone(timezone[0]) + } + if c.Error != nil { + return c + } + c.time = time.Unix(timestamp/1e9, timestamp%1e9) + return c +} + +// CreateFromTimestampNano creates a Carbon instance from a given timestamp with nanosecond. +// 从给定的纳秒级时间戳创建 Carbon 实例 +func CreateFromTimestampNano(timestamp int64, timezone ...string) Carbon { + return NewCarbon().CreateFromTimestampNano(timestamp, timezone...) +} + +// CreateFromDateTime creates a Carbon instance from a given date and time. +// 从给定的年、月、日、时、分、秒创建 Carbon 实例 +func (c Carbon) CreateFromDateTime(year, month, day, hour, minute, second int, timezone ...string) Carbon { + return c.create(year, month, day, hour, minute, second, 0, timezone...) +} + +// CreateFromDateTime creates a Carbon instance from a given date and time. +// 从给定的年、月、日、时、分、秒创建 Carbon 实例 +func CreateFromDateTime(year, month, day, hour, minute, second int, timezone ...string) Carbon { + return NewCarbon().CreateFromDateTime(year, month, day, hour, minute, second, timezone...) +} + +// CreateFromDateTimeMilli creates a Carbon instance from a given date, time and millisecond. +// 从给定的年、月、日、时、分、秒、毫秒创建 Carbon 实例 +func (c Carbon) CreateFromDateTimeMilli(year, month, day, hour, minute, second, millisecond int, timezone ...string) Carbon { + return c.create(year, month, day, hour, minute, second, millisecond*1e6, timezone...) +} + +// CreateFromDateTimeMilli creates a Carbon instance from a given date, time and millisecond. +// 从给定的年、月、日、时、分、秒、毫秒创建 Carbon 实例 +func CreateFromDateTimeMilli(year, month, day, hour, minute, second, millisecond int, timezone ...string) Carbon { + return NewCarbon().CreateFromDateTimeMilli(year, month, day, hour, minute, second, millisecond, timezone...) +} + +// CreateFromDateTimeMicro creates a Carbon instance from a given date, time and microsecond. +// 从给定的年、月、日、时、分、秒、微秒创建 Carbon 实例 +func (c Carbon) CreateFromDateTimeMicro(year, month, day, hour, minute, second, microsecond int, timezone ...string) Carbon { + return c.create(year, month, day, hour, minute, second, microsecond*1e3, timezone...) +} + +// CreateFromDateTimeMicro creates a Carbon instance from a given date, time and microsecond. +// 从给定的年、月、日、时、分、秒、微秒创建 Carbon 实例 +func CreateFromDateTimeMicro(year, month, day, hour, minute, second, microsecond int, timezone ...string) Carbon { + return NewCarbon().CreateFromDateTimeMicro(year, month, day, hour, minute, second, microsecond, timezone...) +} + +// CreateFromDateTimeNano creates a Carbon instance from a given date, time and nanosecond. +// 从给定的年、月、日、时、分、秒、纳秒创建 Carbon 实例 +func (c Carbon) CreateFromDateTimeNano(year, month, day, hour, minute, second, nanosecond int, timezone ...string) Carbon { + return c.create(year, month, day, hour, minute, second, nanosecond, timezone...) +} + +// CreateFromDateTimeNano creates a Carbon instance from a given date, time and nanosecond. +// 从给定的年、月、日、时、分、秒、纳秒创建 Carbon 实例 +func CreateFromDateTimeNano(year, month, day, hour, minute, second, nanosecond int, timezone ...string) Carbon { + return NewCarbon().CreateFromDateTimeNano(year, month, day, hour, minute, second, nanosecond, timezone...) +} + +// CreateFromDate creates a Carbon instance from a given date. +// 从给定的年、月、日创建 Carbon 实例 +func (c Carbon) CreateFromDate(year, month, day int, timezone ...string) Carbon { + return c.create(year, month, day, 0, 0, 0, 0, timezone...) +} + +// CreateFromDate creates a Carbon instance from a given date. +// 从给定的年、月、日创建 Carbon 实例 +func CreateFromDate(year, month, day int, timezone ...string) Carbon { + return NewCarbon().CreateFromDate(year, month, day, timezone...) +} + +// CreateFromDateMilli creates a Carbon instance from a given date and millisecond. +// 从给定的年、月、日、毫秒创建 Carbon 实例 +func (c Carbon) CreateFromDateMilli(year, month, day, millisecond int, timezone ...string) Carbon { + return c.create(year, month, day, 0, 0, 0, millisecond*1e6, timezone...) +} + +// CreateFromDateMilli creates a Carbon instance from a given date and millisecond. +// 从给定的年、月、日、毫秒创建 Carbon 实例 +func CreateFromDateMilli(year, month, day, millisecond int, timezone ...string) Carbon { + return NewCarbon().CreateFromDateMilli(year, month, day, millisecond, timezone...) +} + +// CreateFromDateMicro creates a Carbon instance from a given date and microsecond. +// 从给定的年、月、日、微秒创建 Carbon 实例 +func (c Carbon) CreateFromDateMicro(year, month, day, microsecond int, timezone ...string) Carbon { + return c.create(year, month, day, 0, 0, 0, microsecond*1e3, timezone...) +} + +// CreateFromDateMicro creates a Carbon instance from a given date and microsecond. +// 从给定的年、月、日、微秒创建 Carbon 实例 +func CreateFromDateMicro(year, month, day, microsecond int, timezone ...string) Carbon { + return NewCarbon().CreateFromDateMicro(year, month, day, microsecond, timezone...) +} + +// CreateFromDateNano creates a Carbon instance from a given date and nanosecond. +// 从给定的年、月、日、纳秒创建 Carbon 实例 +func (c Carbon) CreateFromDateNano(year, month, day, nanosecond int, timezone ...string) Carbon { + return c.create(year, month, day, 0, 0, 0, nanosecond, timezone...) +} + +// CreateFromDateNano creates a Carbon instance from a given date and nanosecond. +// 从给定的年、月、日、纳秒创建 Carbon 实例 +func CreateFromDateNano(year, month, day, nanosecond int, timezone ...string) Carbon { + return NewCarbon().CreateFromDateNano(year, month, day, nanosecond, timezone...) +} + +// CreateFromTime creates a Carbon instance from a given time(year, month and day are taken from the current time). +// 从给定的时、分、秒创建 Carbon 实例(年、月、日取自当前时间) +func (c Carbon) CreateFromTime(hour, minute, second int, timezone ...string) Carbon { + year, month, day := c.Now(timezone...).Date() + return c.create(year, month, day, hour, minute, second, 0, timezone...) +} + +// CreateFromTime creates a Carbon instance from a given time(year, month and day are taken from the current time). +// 从给定的时、分、秒创建 Carbon 实例(年、月、日取自当前时间) +func CreateFromTime(hour, minute, second int, timezone ...string) Carbon { + return NewCarbon().CreateFromTime(hour, minute, second, timezone...) +} + +// CreateFromTimeMilli creates a Carbon instance from a given time and millisecond(year, month and day are taken from the current time). +// 从给定的时、分、秒、毫秒创建 Carbon 实例(年、月、日取自当前时间) +func (c Carbon) CreateFromTimeMilli(hour, minute, second, millisecond int, timezone ...string) Carbon { + year, month, day := c.Now(timezone...).Date() + return c.create(year, month, day, hour, minute, second, millisecond*1e6, timezone...) +} + +// CreateFromTimeMilli creates a Carbon instance from a given time and millisecond(year, month and day are taken from the current time). +// 从给定的时、分、秒、毫秒创建 Carbon 实例(年、月、日取自当前时间) +func CreateFromTimeMilli(hour, minute, second, millisecond int, timezone ...string) Carbon { + return NewCarbon().CreateFromTimeMilli(hour, minute, second, millisecond, timezone...) +} + +// CreateFromTimeMicro creates a Carbon instance from a given time and microsecond(year, month and day are taken from the current time). +// 从给定的时、分、秒、微秒创建 Carbon 实例(年、月、日取自当前时间) +func (c Carbon) CreateFromTimeMicro(hour, minute, second, microsecond int, timezone ...string) Carbon { + year, month, day := c.Now(timezone...).Date() + return c.create(year, month, day, hour, minute, second, microsecond*1e3, timezone...) +} + +// CreateFromTimeMicro creates a Carbon instance from a given time and microsecond(year, month and day are taken from the current time). +// 从给定的时、分、秒、微秒创建 Carbon 实例(年、月、日取自当前时间) +func CreateFromTimeMicro(hour, minute, second, microsecond int, timezone ...string) Carbon { + return NewCarbon().CreateFromTimeMicro(hour, minute, second, microsecond, timezone...) +} + +// CreateFromTimeNano creates a Carbon instance from a given time and nanosecond(year, month and day are taken from the current time). +// 从给定的时、分、秒、纳秒创建 Carbon 实例(年、月、日取自当前时间) +func (c Carbon) CreateFromTimeNano(hour, minute, second, nanosecond int, timezone ...string) Carbon { + year, month, day := c.Now(timezone...).Date() + return c.create(year, month, day, hour, minute, second, nanosecond, timezone...) +} + +// CreateFromTimeNano creates a Carbon instance from a given time and nanosecond(year, month and day are taken from the current time). +// 从给定的时、分、秒、纳秒创建 Carbon 实例(年、月、日取自当前时间) +func CreateFromTimeNano(hour, minute, second, nanosecond int, timezone ...string) Carbon { + return NewCarbon().CreateFromTimeNano(hour, minute, second, nanosecond, timezone...) +} + +// creates a Carbon instance from a given date, time and nanosecond. +// 从给定的年、月、日、时、分、秒、纳秒创建 Carbon 实例 +func (c Carbon) create(year, month, day, hour, minute, second, nanosecond int, timezone ...string) Carbon { + if len(timezone) > 0 { + c.loc, c.Error = getLocationByTimezone(timezone[0]) + } + if c.Error != nil { + return c + } + c.time = time.Date(year, time.Month(month), day, hour, minute, second, nanosecond, c.loc) + return c +} diff --git a/vendor/github.com/dromara/carbon/v2/database.go b/vendor/github.com/dromara/carbon/v2/database.go new file mode 100644 index 000000000..3069eb73c --- /dev/null +++ b/vendor/github.com/dromara/carbon/v2/database.go @@ -0,0 +1,890 @@ +package carbon + +import ( + "bytes" + "database/sql/driver" + "errors" + "fmt" + "strconv" + "time" +) + +// returns a failed scan error. +// 失败的扫描错误 +var failedScanError = func(src interface{}) error { + return errors.New(fmt.Sprintf("failed to scan value: %v", src)) +} + +// Scan an interface used by Scan in package database/sql for Scanning value from database to local golang variable. +func (c *Carbon) Scan(src interface{}) error { + switch v := src.(type) { + case []byte: + *c = Parse(string(v)) + case string: + *c = Parse(v) + case time.Time: + *c = CreateFromStdTime(v) + } + if c.Error == nil { + return nil + } + return failedScanError(src) +} + +// Value the interface providing the Value method for package database/sql/driver. +func (c Carbon) Value() (driver.Value, error) { + if c.IsZero() { + return nil, nil + } + return c.StdTime(), nil +} + +// MarshalJSON implements the interface json.Marshal for Carbon struct. +// 实现 json.Marshaler 接口 +func (c Carbon) MarshalJSON() ([]byte, error) { + return []byte(fmt.Sprintf(`"%s"`, c.Layout(c.layout))), nil +} + +// UnmarshalJSON implements the interface json.Unmarshal for Carbon struct. +// 实现 json.Unmarshaler 接口 +func (c *Carbon) UnmarshalJSON(b []byte) error { + value := fmt.Sprintf("%s", bytes.Trim(b, `"`)) + if value == "" || value == "null" { + return nil + } + *c = ParseByLayout(value, c.layout) + return c.Error +} + +// Scan an interface used by Scan in package database/sql for Scanning value from database to local golang variable. +func (t *DateTime) Scan(src interface{}) error { + switch v := src.(type) { + case []byte: + *t = NewDateTime(Parse(string(v))) + case string: + *t = NewDateTime(Parse(v)) + case time.Time: + *t = NewDateTime(CreateFromStdTime(v)) + } + if t.Error == nil { + return nil + } + return failedScanError(src) +} + +// Value the interface providing the Value method for package database/sql/driver. +func (t *DateTime) Value() (driver.Value, error) { + if t.IsZero() { + return nil, nil + } + return t.StdTime(), nil +} + +// MarshalJSON implements the interface json.Marshal for DateTime struct. +// 实现 MarshalJSON 接口 +func (t DateTime) MarshalJSON() ([]byte, error) { + return []byte(fmt.Sprintf(`"%s"`, t.ToDateTimeString())), nil +} + +// UnmarshalJSON implements the interface json.Unmarshal for DateTime struct. +// 实现 UnmarshalJSON 接口 +func (t *DateTime) UnmarshalJSON(b []byte) error { + value := fmt.Sprintf("%s", bytes.Trim(b, `"`)) + if value == "" || value == "null" { + return nil + } + c := ParseByLayout(value, DateTimeLayout) + if c.Error == nil { + *t = NewDateTime(c) + } + return c.Error +} + +// Scan an interface used by Scan in package database/sql for Scanning value from database to local golang variable. +func (t *DateTimeMilli) Scan(src interface{}) error { + switch v := src.(type) { + case []byte: + *t = NewDateTimeMilli(Parse(string(v))) + case string: + *t = NewDateTimeMilli(Parse(v)) + case time.Time: + *t = NewDateTimeMilli(CreateFromStdTime(v)) + } + if t.Error == nil { + return nil + } + return failedScanError(src) +} + +// Value the interface providing the Value method for package database/sql/driver. +func (t *DateTimeMilli) Value() (driver.Value, error) { + if t.IsZero() { + return nil, nil + } + return t.StdTime(), nil +} + +// MarshalJSON implements the interface json.Marshal for DateTimeMilli struct. +// 实现 MarshalJSON 接口 +func (t DateTimeMilli) MarshalJSON() ([]byte, error) { + return []byte(fmt.Sprintf(`"%s"`, t.ToDateTimeMilliString())), nil +} + +// UnmarshalJSON implements the interface json.Unmarshal for DateTimeMilli struct. +// 实现 UnmarshalJSON 接口 +func (t *DateTimeMilli) UnmarshalJSON(b []byte) error { + value := fmt.Sprintf("%s", bytes.Trim(b, `"`)) + if value == "" || value == "null" { + return nil + } + c := ParseByLayout(value, DateTimeMilliLayout) + if c.Error == nil { + *t = NewDateTimeMilli(c) + } + return c.Error +} + +// Scan an interface used by Scan in package database/sql for Scanning value from database to local golang variable. +func (t *DateTimeMicro) Scan(src interface{}) error { + switch v := src.(type) { + case []byte: + *t = NewDateTimeMicro(Parse(string(v))) + case string: + *t = NewDateTimeMicro(Parse(v)) + case time.Time: + *t = NewDateTimeMicro(CreateFromStdTime(v)) + } + if t.Error == nil { + return nil + } + return failedScanError(src) +} + +// Value the interface providing the Value method for package database/sql/driver. +func (t *DateTimeMicro) Value() (driver.Value, error) { + if t.IsZero() { + return nil, nil + } + return t.StdTime(), nil +} + +// MarshalJSON implements the interface json.Marshal for DateTimeMicro struct. +// 实现 MarshalJSON 接口 +func (t DateTimeMicro) MarshalJSON() ([]byte, error) { + return []byte(fmt.Sprintf(`"%s"`, t.ToDateTimeMicroString())), nil +} + +// UnmarshalJSON implements the interface json.Unmarshal for DateTimeMicro struct. +// 实现 UnmarshalJSON 接口 +func (t *DateTimeMicro) UnmarshalJSON(b []byte) error { + value := fmt.Sprintf("%s", bytes.Trim(b, `"`)) + if value == "" || value == "null" { + return nil + } + c := ParseByLayout(value, DateTimeMicroLayout) + if c.Error == nil { + *t = NewDateTimeMicro(c) + } + return c.Error +} + +// Scan an interface used by Scan in package database/sql for Scanning value from database to local golang variable. +func (t *DateTimeNano) Scan(src interface{}) error { + switch v := src.(type) { + case []byte: + *t = NewDateTimeNano(Parse(string(v))) + case string: + *t = NewDateTimeNano(Parse(v)) + case time.Time: + *t = NewDateTimeNano(CreateFromStdTime(v)) + } + if t.Error == nil { + return nil + } + return failedScanError(src) +} + +// Value the interface providing the Value method for package database/sql/driver. +func (t *DateTimeNano) Value() (driver.Value, error) { + if t.IsZero() { + return nil, nil + } + return t.StdTime(), nil +} + +// MarshalJSON implements the interface json.Marshal for DateTimeNano struct. +// 实现 MarshalJSON 接口 +func (t DateTimeNano) MarshalJSON() ([]byte, error) { + return []byte(fmt.Sprintf(`"%s"`, t.ToDateTimeNanoString())), nil +} + +// UnmarshalJSON implements the interface json.Unmarshal for DateTimeNano struct. +// 实现 UnmarshalJSON 接口 +func (t *DateTimeNano) UnmarshalJSON(b []byte) error { + value := fmt.Sprintf("%s", bytes.Trim(b, `"`)) + if value == "" || value == "null" { + return nil + } + c := ParseByLayout(value, DateTimeNanoLayout) + if c.Error == nil { + *t = NewDateTimeNano(c) + } + return c.Error +} + +// Scan an interface used by Scan in package database/sql for Scanning value from database to local golang variable. +func (t *Date) Scan(src interface{}) error { + switch v := src.(type) { + case []byte: + *t = NewDate(Parse(string(v))) + case string: + *t = NewDate(Parse(v)) + case time.Time: + *t = NewDate(CreateFromStdTime(v)) + } + if t.Error == nil { + return nil + } + return failedScanError(src) +} + +// Value the interface providing the Value method for package database/sql/driver. +func (t *Date) Value() (driver.Value, error) { + if t.IsZero() { + return nil, nil + } + return t.StdTime(), nil +} + +// MarshalJSON implements the interface json.Marshal for Date struct. +// 实现 MarshalJSON 接口 +func (t Date) MarshalJSON() ([]byte, error) { + return []byte(fmt.Sprintf(`"%s"`, t.ToDateString())), nil +} + +// UnmarshalJSON implements the interface json.Unmarshal for Date struct. +// 实现 UnmarshalJSON 接口 +func (t *Date) UnmarshalJSON(b []byte) error { + value := fmt.Sprintf("%s", bytes.Trim(b, `"`)) + if value == "" || value == "null" { + return nil + } + c := ParseByLayout(value, DateLayout) + if c.Error == nil { + *t = NewDate(c) + } + return c.Error +} + +// Scan an interface used by Scan in package database/sql for Scanning value from database to local golang variable. +func (t *DateMilli) Scan(src interface{}) error { + switch v := src.(type) { + case []byte: + *t = NewDateMilli(Parse(string(v))) + case string: + *t = NewDateMilli(Parse(v)) + case time.Time: + *t = NewDateMilli(CreateFromStdTime(v)) + } + if t.Error == nil { + return nil + } + return failedScanError(src) +} + +// Value the interface providing the Value method for package database/sql/driver. +func (t *DateMilli) Value() (driver.Value, error) { + if t.IsZero() { + return nil, nil + } + return t.StdTime(), nil +} + +// MarshalJSON implements the interface json.Marshal for DateMilli struct. +// 实现 MarshalJSON 接口 +func (t DateMilli) MarshalJSON() ([]byte, error) { + return []byte(fmt.Sprintf(`"%s"`, t.ToDateMilliString())), nil +} + +// UnmarshalJSON implements the interface json.Unmarshal for DateMilli struct. +// 实现 UnmarshalJSON 接口 +func (t *DateMilli) UnmarshalJSON(b []byte) error { + value := fmt.Sprintf("%s", bytes.Trim(b, `"`)) + if value == "" || value == "null" { + return nil + } + c := ParseByLayout(value, DateMilliLayout) + if c.Error == nil { + *t = NewDateMilli(c) + } + return c.Error +} + +// Scan an interface used by Scan in package database/sql for Scanning value from database to local golang variable. +func (t *DateMicro) Scan(src interface{}) error { + switch v := src.(type) { + case []byte: + *t = NewDateMicro(Parse(string(v))) + case string: + *t = NewDateMicro(Parse(v)) + case time.Time: + *t = NewDateMicro(CreateFromStdTime(v)) + } + if t.Error == nil { + return nil + } + return failedScanError(src) +} + +// Value the interface providing the Value method for package database/sql/driver. +func (t *DateMicro) Value() (driver.Value, error) { + if t.IsZero() { + return nil, nil + } + return t.StdTime(), nil +} + +// MarshalJSON implements the interface json.Marshal for DateMicro struct. +// 实现 MarshalJSON 接口 +func (t DateMicro) MarshalJSON() ([]byte, error) { + return []byte(fmt.Sprintf(`"%s"`, t.ToDateMicroString())), nil +} + +// UnmarshalJSON implements the interface json.Unmarshal for DateMicro struct. +// 实现 UnmarshalJSON 接口 +func (t *DateMicro) UnmarshalJSON(b []byte) error { + value := fmt.Sprintf("%s", bytes.Trim(b, `"`)) + if value == "" || value == "null" { + return nil + } + c := ParseByLayout(value, DateMicroLayout) + if c.Error == nil { + *t = NewDateMicro(c) + } + return c.Error +} + +// Scan an interface used by Scan in package database/sql for Scanning value from database to local golang variable. +func (t *DateNano) Scan(src interface{}) error { + switch v := src.(type) { + case []byte: + *t = NewDateNano(Parse(string(v))) + case string: + *t = NewDateNano(Parse(v)) + case time.Time: + *t = NewDateNano(CreateFromStdTime(v)) + } + if t.Error == nil { + return nil + } + return failedScanError(src) +} + +// Value the interface providing the Value method for package database/sql/driver. +func (t *DateNano) Value() (driver.Value, error) { + if t.IsZero() { + return nil, nil + } + return t.StdTime(), nil +} + +// MarshalJSON implements the interface json.Marshal for DateNano struct. +// 实现 MarshalJSON 接口 +func (t DateNano) MarshalJSON() ([]byte, error) { + return []byte(fmt.Sprintf(`"%s"`, t.ToDateNanoString())), nil +} + +// UnmarshalJSON implements the interface json.Unmarshal for DateNano struct. +// 实现 UnmarshalJSON 接口 +func (t *DateNano) UnmarshalJSON(b []byte) error { + value := fmt.Sprintf("%s", bytes.Trim(b, `"`)) + if value == "" || value == "null" { + return nil + } + c := ParseByLayout(value, DateNanoLayout) + if c.Error == nil { + *t = NewDateNano(c) + } + return c.Error +} + +// Scan an interface used by Scan in package database/sql for Scanning value from database to local golang variable. +func (t *Time) Scan(src interface{}) error { + switch v := src.(type) { + case []byte: + *t = NewTime(Parse(string(v))) + case string: + *t = NewTime(Parse(v)) + case time.Time: + *t = NewTime(CreateFromStdTime(v)) + } + if t.Error == nil { + return nil + } + return failedScanError(src) +} + +// Value the interface providing the Value method for package database/sql/driver. +func (t *Time) Value() (driver.Value, error) { + if t.IsZero() { + return nil, nil + } + return t.StdTime(), nil +} + +// MarshalJSON implements the interface json.Marshal for Time struct. +// 实现 MarshalJSON 接口 +func (t Time) MarshalJSON() ([]byte, error) { + return []byte(fmt.Sprintf(`"%s"`, t.ToTimeString())), nil +} + +// UnmarshalJSON implements the interface json.Unmarshal for Time struct. +// 实现 UnmarshalJSON 接口 +func (t *Time) UnmarshalJSON(b []byte) error { + value := fmt.Sprintf("%s", bytes.Trim(b, `"`)) + if value == "" || value == "null" { + return nil + } + year, month, day := Now().Date() + c := ParseByLayout(fmt.Sprintf("%d-%02d-%02d %s", year, month, day, value), DateTimeLayout) + fmt.Println("c", c) + if c.Error == nil { + *t = NewTime(c) + } + return c.Error +} + +// Scan an interface used by Scan in package database/sql for Scanning value from database to local golang variable. +func (t *TimeMilli) Scan(src interface{}) error { + switch v := src.(type) { + case []byte: + *t = NewTimeMilli(Parse(string(v))) + case string: + *t = NewTimeMilli(Parse(v)) + case time.Time: + *t = NewTimeMilli(CreateFromStdTime(v)) + } + if t.Error == nil { + return nil + } + return failedScanError(src) +} + +// Value the interface providing the Value method for package database/sql/driver. +func (t *TimeMilli) Value() (driver.Value, error) { + if t.IsZero() { + return nil, nil + } + return t.StdTime(), nil +} + +// MarshalJSON implements the interface json.Marshal for TimeMilli struct. +// 实现 MarshalJSON 接口 +func (t TimeMilli) MarshalJSON() ([]byte, error) { + return []byte(fmt.Sprintf(`"%s"`, t.ToTimeMilliString())), nil +} + +// UnmarshalJSON implements the interface json.Unmarshal for TimeMilli struct. +// 实现 UnmarshalJSON 接口 +func (t *TimeMilli) UnmarshalJSON(b []byte) error { + value := fmt.Sprintf("%s", bytes.Trim(b, `"`)) + if value == "" || value == "null" { + return nil + } + year, month, day := Now().Date() + c := ParseByLayout(fmt.Sprintf("%d-%02d-%02d %s", year, month, day, value), DateTimeMilliLayout) + if c.Error == nil { + *t = NewTimeMilli(c) + } + return c.Error +} + +// Scan an interface used by Scan in package database/sql for Scanning value from database to local golang variable. +func (t *TimeMicro) Scan(src interface{}) error { + switch v := src.(type) { + case []byte: + *t = NewTimeMicro(Parse(string(v))) + case string: + *t = NewTimeMicro(Parse(v)) + case time.Time: + *t = NewTimeMicro(CreateFromStdTime(v)) + } + if t.Error == nil { + return nil + } + return failedScanError(src) +} + +// Value the interface providing the Value method for package database/sql/driver. +func (t *TimeMicro) Value() (driver.Value, error) { + if t.IsZero() { + return nil, nil + } + return t.StdTime(), nil +} + +// MarshalJSON implements the interface json.Marshal for TimeMicro struct. +// 实现 MarshalJSON 接口 +func (t TimeMicro) MarshalJSON() ([]byte, error) { + return []byte(fmt.Sprintf(`"%s"`, t.ToTimeMicroString())), nil +} + +// UnmarshalJSON implements the interface json.Unmarshal for TimeMicro struct. +// 实现 UnmarshalJSON 接口 +func (t *TimeMicro) UnmarshalJSON(b []byte) error { + value := fmt.Sprintf("%s", bytes.Trim(b, `"`)) + if value == "" || value == "null" { + return nil + } + year, month, day := Now().Date() + c := ParseByLayout(fmt.Sprintf("%d-%02d-%02d %s", year, month, day, value), DateTimeMicroLayout) + if c.Error == nil { + *t = NewTimeMicro(c) + } + return c.Error +} + +// Scan an interface used by Scan in package database/sql for Scanning value from database to local golang variable. +func (t *TimeNano) Scan(src interface{}) error { + switch v := src.(type) { + case []byte: + *t = NewTimeNano(Parse(string(v))) + case string: + *t = NewTimeNano(Parse(v)) + case time.Time: + *t = NewTimeNano(CreateFromStdTime(v)) + } + if t.Error == nil { + return nil + } + return failedScanError(src) +} + +// Value the interface providing the Value method for package database/sql/driver. +func (t *TimeNano) Value() (driver.Value, error) { + if t.IsZero() { + return nil, nil + } + return t.StdTime(), nil +} + +// MarshalJSON implements the interface json.Marshal for TimeNano struct. +// 实现 MarshalJSON 接口 +func (t TimeNano) MarshalJSON() ([]byte, error) { + return []byte(fmt.Sprintf(`"%s"`, t.ToTimeNanoString())), nil +} + +// UnmarshalJSON implements the interface json.Unmarshal for TimeNano struct. +// 实现 UnmarshalJSON 接口 +func (t *TimeNano) UnmarshalJSON(b []byte) error { + value := fmt.Sprintf("%s", bytes.Trim(b, `"`)) + if value == "" || value == "null" { + return nil + } + year, month, day := Now().Date() + c := ParseByLayout(fmt.Sprintf("%d-%02d-%02d %s", year, month, day, value), DateTimeNanoLayout) + if c.Error == nil { + *t = NewTimeNano(c) + } + return c.Error +} + +// Scan an interface used by Scan in package database/sql for Scanning value from database to local golang variable. +func (t *Timestamp) Scan(src interface{}) error { + switch v := src.(type) { + case []byte: + *t = NewTimestamp(Parse(string(v))) + case string: + *t = NewTimestamp(Parse(v)) + case time.Time: + *t = NewTimestamp(CreateFromStdTime(v)) + } + if t.Error == nil { + return nil + } + return failedScanError(src) +} + +// Value the interface providing the Value method for package database/sql/driver. +func (t *Timestamp) Value() (driver.Value, error) { + if t.IsZero() { + return nil, nil + } + return t.StdTime(), nil +} + +// MarshalJSON implements the interface json.Marshal for Timestamp struct. +// 实现 MarshalJSON 接口 +func (t Timestamp) MarshalJSON() ([]byte, error) { + return []byte(fmt.Sprintf(`%d`, t.Timestamp())), nil +} + +// UnmarshalJSON implements the interface json.Unmarshal for Timestamp struct. +// 实现 UnmarshalJSON 接口 +func (t *Timestamp) UnmarshalJSON(b []byte) error { + value := fmt.Sprintf("%s", bytes.Trim(b, `"`)) + if value == "" || value == "null" { + return nil + } + ts, _ := strconv.ParseInt(value, 10, 64) + c := CreateFromTimestamp(ts) + if c.Error == nil { + *t = NewTimestamp(c) + } + return c.Error +} + +// Scan an interface used by Scan in package database/sql for Scanning value from database to local golang variable. +func (t *TimestampMilli) Scan(src interface{}) error { + switch v := src.(type) { + case []byte: + *t = NewTimestampMilli(Parse(string(v))) + case string: + *t = NewTimestampMilli(Parse(v)) + case time.Time: + *t = NewTimestampMilli(CreateFromStdTime(v)) + } + if t.Error == nil { + return nil + } + return failedScanError(src) +} + +// Value the interface providing the Value method for package database/sql/driver. +func (t *TimestampMilli) Value() (driver.Value, error) { + if t.IsZero() { + return nil, nil + } + return t.StdTime(), nil +} + +// MarshalJSON implements the interface json.Marshal for TimestampMilli struct. +// 实现 MarshalJSON 接口 +func (t TimestampMilli) MarshalJSON() ([]byte, error) { + return []byte(fmt.Sprintf(`%d`, t.TimestampMilli())), nil +} + +// UnmarshalJSON implements the interface json.Unmarshal for TimestampMilli struct. +// 实现 UnmarshalJSON 接口 +func (t *TimestampMilli) UnmarshalJSON(b []byte) error { + value := fmt.Sprintf("%s", bytes.Trim(b, `"`)) + if value == "" || value == "null" { + return nil + } + ts, _ := strconv.ParseInt(value, 10, 64) + c := CreateFromTimestampMilli(ts) + if c.Error == nil { + *t = NewTimestampMilli(c) + } + return c.Error +} + +// Scan an interface used by Scan in package database/sql for Scanning value from database to local golang variable. +func (t *TimestampMicro) Scan(src interface{}) error { + switch v := src.(type) { + case []byte: + *t = NewTimestampMicro(Parse(string(v))) + case string: + *t = NewTimestampMicro(Parse(v)) + case time.Time: + *t = NewTimestampMicro(CreateFromStdTime(v)) + } + if t.Error == nil { + return nil + } + return failedScanError(src) +} + +// Value the interface providing the Value method for package database/sql/driver. +func (t *TimestampMicro) Value() (driver.Value, error) { + if t.IsZero() { + return nil, nil + } + return t.StdTime(), nil +} + +// MarshalJSON implements the interface MarshalJSON for TimestampMicro struct. +// 实现 MarshalJSON 接口 +func (t TimestampMicro) MarshalJSON() ([]byte, error) { + return []byte(fmt.Sprintf(`%d`, t.TimestampMicro())), nil +} + +// UnmarshalJSON implements the interface json.Unmarshal for TimestampMicro struct. +// 实现 UnmarshalJSON 接口 +func (t *TimestampMicro) UnmarshalJSON(b []byte) error { + value := fmt.Sprintf("%s", bytes.Trim(b, `"`)) + if value == "" || value == "null" { + return nil + } + ts, _ := strconv.ParseInt(value, 10, 64) + c := CreateFromTimestampMicro(ts) + if c.Error == nil { + *t = NewTimestampMicro(c) + } + return c.Error +} + +// Scan an interface used by Scan in package database/sql for Scanning value from database to local golang variable. +func (t *TimestampNano) Scan(src interface{}) error { + switch v := src.(type) { + case []byte: + *t = NewTimestampNano(Parse(string(v))) + case string: + *t = NewTimestampNano(Parse(v)) + case time.Time: + *t = NewTimestampNano(CreateFromStdTime(v)) + } + if t.Error == nil { + return nil + } + return failedScanError(src) +} + +// Value the interface providing the Value method for package database/sql/driver. +func (t *TimestampNano) Value() (driver.Value, error) { + if t.IsZero() { + return nil, nil + } + return t.StdTime(), nil +} + +// MarshalJSON implements the interface json.Marshal for TimestampNano struct. +// 实现 MarshalJSON 接口 +func (t TimestampNano) MarshalJSON() ([]byte, error) { + return []byte(fmt.Sprintf(`%d`, t.TimestampNano())), nil +} + +// UnmarshalJSON implements the interface json.Unmarshal for TimestampNano struct. +// 实现 UnmarshalJSON 接口 +func (t *TimestampNano) UnmarshalJSON(b []byte) error { + value := fmt.Sprintf("%s", bytes.Trim(b, `"`)) + if value == "" || value == "null" { + return nil + } + ts, _ := strconv.ParseInt(value, 10, 64) + c := CreateFromTimestampNano(ts) + if c.Error == nil { + *t = NewTimestampNano(c) + } + return c.Error +} + +// Int64 outputs timestamp with second. +// 输出秒级时间戳 +func (t Timestamp) Int64() int64 { + return t.Timestamp() +} + +// Int64 outputs timestamp with millisecond. +// 输出豪秒级时间戳 +func (t TimestampMilli) Int64() int64 { + return t.TimestampMilli() +} + +// Int64 outputs timestamp with microsecond. +// 输出微秒级时间戳 +func (t TimestampMicro) Int64() int64 { + return t.TimestampMicro() +} + +// Int64 outputs timestamp with nanosecond. +// 输出纳秒级时间戳 +func (t TimestampNano) Int64() int64 { + return t.TimestampNano() +} + +// String implements the interface Stringer for DateTime struct. +// 实现 Stringer 接口 +func (t DateTime) String() string { + return t.ToDateTimeString() +} + +// String implements the interface Stringer for DateTimeMilli struct. +// 实现 Stringer 接口 +func (t DateTimeMilli) String() string { + return t.ToDateTimeMilliString() +} + +// String implements the interface Stringer for DateTimeMicro struct. +// 实现 Stringer 接口 +func (t DateTimeMicro) String() string { + return t.ToDateTimeMicroString() +} + +// String implements the interface Stringer for DateTimeNano struct. +// 实现 Stringer 接口 +func (t DateTimeNano) String() string { + return t.ToDateTimeNanoString() +} + +// String implements the interface Stringer for Date struct. +// 实现 Stringer 接口 +func (t Date) String() string { + return t.ToDateString() +} + +// String implements the interface Stringer for DateMilli struct. +// 实现 Stringer 接口 +func (t DateMilli) String() string { + return t.ToDateMilliString() +} + +// String implements the interface Stringer for DateMicro struct. +// 实现 Stringer 接口 +func (t DateMicro) String() string { + return t.ToDateMicroString() +} + +// String implements the interface Stringer for DateNano struct. +// 实现 Stringer 接口 +func (t DateNano) String() string { + return t.ToDateNanoString() +} + +// String implements the interface Stringer for Time struct. +// 实现 Stringer 接口 +func (t Time) String() string { + return t.ToTimeString() +} + +// String implements the interface Stringer for TimeMilli struct. +// 实现 Stringer 接口 +func (t TimeMilli) String() string { + return t.ToTimeMilliString() +} + +// String implements the interface Stringer for TimeMicro struct. +// 实现 Stringer 接口 +func (t TimeMicro) String() string { + return t.ToTimeMicroString() +} + +// String implements the interface Stringer for TimeNano struct. +// 实现 Stringer 接口 +func (t TimeNano) String() string { + return t.ToTimeNanoString() +} + +// String implements the interface Stringer for Timestamp struct. +// 实现 Stringer 接口 +func (t Timestamp) String() string { + return strconv.FormatInt(t.Timestamp(), 10) +} + +// String implements the interface Stringer for TimestampMilli struct. +// 实现 Stringer 接口 +func (t TimestampMilli) String() string { + return strconv.FormatInt(t.TimestampMilli(), 10) +} + +// String implements the interface Stringer for TimestampMicro struct. +// 实现 Stringer 接口 +func (t TimestampMicro) String() string { + return strconv.FormatInt(t.TimestampMicro(), 10) +} + +// String implements the interface Stringer for TimestampNano struct. +// 实现 Stringer 接口 +func (t TimestampNano) String() string { + return strconv.FormatInt(t.TimestampNano(), 10) +} diff --git a/vendor/github.com/dromara/carbon/v2/default.go b/vendor/github.com/dromara/carbon/v2/default.go new file mode 100644 index 000000000..aab8ca609 --- /dev/null +++ b/vendor/github.com/dromara/carbon/v2/default.go @@ -0,0 +1,45 @@ +package carbon + +var ( + // default layout + // 默认布局模板 + defaultLayout = DateTimeLayout + + // default timezone + // 默认时区 + defaultTimezone = Local + + // default week start date + // 默认一周开始日期 + defaultWeekStartsAt = Sunday + + // default language locale + // 默认语言区域 + defaultLocale = "en" +) + +// Default defines a Default struct. +// 定义 Default 结构体 +type Default struct { + Layout string + Timezone string + WeekStartsAt string + Locale string +} + +// SetDefault sets default. +// 设置全局默认值 +func SetDefault(d Default) { + if d.Layout != "" { + defaultLayout = d.Layout + } + if d.Timezone != "" { + defaultTimezone = d.Timezone + } + if d.WeekStartsAt != "" { + defaultWeekStartsAt = d.WeekStartsAt + } + if d.Locale != "" { + defaultLocale = d.Locale + } +} diff --git a/vendor/github.com/dromara/carbon/v2/difference.go b/vendor/github.com/dromara/carbon/v2/difference.go new file mode 100644 index 000000000..414be9713 --- /dev/null +++ b/vendor/github.com/dromara/carbon/v2/difference.go @@ -0,0 +1,292 @@ +package carbon + +import ( + "math" + "strings" + "time" +) + +const ( + minDuration time.Duration = -1 << 63 + maxDuration time.Duration = 1<<63 - 1 +) + +// DiffInYears gets the difference in years. +// 相差多少年 +func (c Carbon) DiffInYears(carbon ...Carbon) int64 { + start, end := c, c.Now() + if c.IsSetTestNow() { + end = CreateFromTimestampNano(c.testNow, c.Location()) + } + if len(carbon) > 0 { + end = carbon[0] + } + dy, dm, dd := end.Year()-start.Year(), end.Month()-start.Month(), end.Day()-start.Day() + if dm < 0 || (dm == 0 && dd < 0) { + dy-- + } + if dy < 0 && (dd != 0 || dm != 0) { + dy++ + } + return int64(dy) +} + +// DiffAbsInYears gets the difference in years with absolute value. +// 相差多少年(绝对值) +func (c Carbon) DiffAbsInYears(carbon ...Carbon) int64 { + return getAbsValue(c.DiffInYears(carbon...)) +} + +// DiffInMonths gets the difference in months. +// 相差多少月 +func (c Carbon) DiffInMonths(carbon ...Carbon) int64 { + start, end := c, c.Now() + if start.IsSetTestNow() { + end = CreateFromTimestampNano(c.testNow, c.Location()) + } + if len(carbon) > 0 { + end = carbon[0] + } + if start.Month() == end.Month() && start.Year() == end.Year() { + return 0 + } + dd := start.DiffInDays(end) + sign := 1 + if dd <= 0 { + start, end = end, start + sign = -1 + } + months := getDiffInMonths(start, end, 0) + return months * int64(sign) +} + +// DiffAbsInMonths gets the difference in months with absolute value. +// 相差多少月(绝对值) +func (c Carbon) DiffAbsInMonths(carbon ...Carbon) int64 { + return getAbsValue(c.DiffInMonths(carbon...)) +} + +// DiffInWeeks gets the difference in weeks. +// 相差多少周 +func (c Carbon) DiffInWeeks(carbon ...Carbon) int64 { + start, end := c, c.Now() + if c.IsSetTestNow() { + end = CreateFromTimestampNano(c.testNow, c.Location()) + } + if len(carbon) > 0 { + end = carbon[0] + } + return int64(math.Floor(float64((end.Timestamp() - start.Timestamp()) / (7 * 24 * 3600)))) +} + +// DiffAbsInWeeks gets the difference in weeks with absolute value. +// 相差多少周(绝对值) +func (c Carbon) DiffAbsInWeeks(carbon ...Carbon) int64 { + return getAbsValue(c.DiffInWeeks(carbon...)) +} + +// DiffInDays gets the difference in days. +// 相差多少天 +func (c Carbon) DiffInDays(carbon ...Carbon) int64 { + start, end := c, c.Now() + if c.IsSetTestNow() { + end = CreateFromTimestampNano(c.testNow, c.Location()) + } + if len(carbon) > 0 { + end = carbon[0] + } + return int64(math.Floor(float64((end.Timestamp() - start.Timestamp()) / (24 * 3600)))) +} + +// DiffAbsInDays gets the difference in days with absolute value. +// 相差多少天(绝对值) +func (c Carbon) DiffAbsInDays(carbon ...Carbon) int64 { + return getAbsValue(c.DiffInDays(carbon...)) +} + +// DiffInHours gets the difference in hours. +// 相差多少小时 +func (c Carbon) DiffInHours(carbon ...Carbon) int64 { + end := c.Now() + if c.IsSetTestNow() { + end = CreateFromTimestampNano(c.testNow, c.Location()) + } + if len(carbon) > 0 { + end = carbon[0] + } + return c.DiffInSeconds(end) / SecondsPerHour +} + +// DiffAbsInHours gets the difference in hours with absolute value. +// 相差多少小时(绝对值) +func (c Carbon) DiffAbsInHours(carbon ...Carbon) int64 { + return getAbsValue(c.DiffInHours(carbon...)) +} + +// DiffInMinutes gets the difference in minutes. +// 相差多少分钟 +func (c Carbon) DiffInMinutes(carbon ...Carbon) int64 { + end := c.Now() + if c.IsSetTestNow() { + end = CreateFromTimestampNano(c.testNow, c.Location()) + } + if len(carbon) > 0 { + end = carbon[0] + } + return c.DiffInSeconds(end) / SecondsPerMinute +} + +// DiffAbsInMinutes gets the difference in minutes with absolute value. +// 相差多少分钟(绝对值) +func (c Carbon) DiffAbsInMinutes(carbon ...Carbon) int64 { + return getAbsValue(c.DiffInMinutes(carbon...)) +} + +// DiffInSeconds gets the difference in seconds. +// 相差多少秒 +func (c Carbon) DiffInSeconds(carbon ...Carbon) int64 { + end := c.Now() + if c.IsSetTestNow() { + end = CreateFromTimestampNano(c.testNow, c.Location()) + } + if len(carbon) > 0 { + end = carbon[0] + } + return end.Timestamp() - c.Timestamp() +} + +// DiffAbsInSeconds gets the difference in seconds with absolute value. +// 相差多少秒(绝对值) +func (c Carbon) DiffAbsInSeconds(carbon ...Carbon) int64 { + return getAbsValue(c.DiffInSeconds(carbon...)) +} + +// DiffInString gets the difference in string, i18n is supported. +// 相差字符串,支持i18n +func (c Carbon) DiffInString(carbon ...Carbon) string { + end := c.Now() + if c.IsSetTestNow() { + end = CreateFromTimestampNano(c.testNow, c.Location()) + } + if len(carbon) > 0 { + end = carbon[0] + } + if c.Error != nil || end.Error != nil { + return "" + } + unit, value := c.diff(end) + return c.lang.translate(unit, value) +} + +// DiffAbsInString gets the difference in string with absolute value, i18n is supported. +// 相差字符串,支持i18n(绝对值) +func (c Carbon) DiffAbsInString(carbon ...Carbon) string { + end := c.Now() + if c.IsSetTestNow() { + end = CreateFromTimestampNano(c.testNow, c.Location()) + } + if len(carbon) > 0 { + end = carbon[0] + } + if c.Error != nil || end.Error != nil { + return "" + } + unit, value := c.diff(end) + return c.lang.translate(unit, getAbsValue(value)) +} + +// DiffInDuration gets the difference in duration. +// 相差时长 +func (c Carbon) DiffInDuration(carbon ...Carbon) time.Duration { + end := c.Now() + if c.IsSetTestNow() { + end = CreateFromTimestampNano(c.testNow, c.Location()) + } + if len(carbon) > 0 { + end = carbon[0] + } + return end.StdTime().Sub(c.StdTime()) +} + +// DiffAbsInDuration gets the difference in duration with absolute value. +// 相差时长(绝对值) +func (c Carbon) DiffAbsInDuration(carbon ...Carbon) time.Duration { + d := c.DiffInDuration(carbon...) + if d >= 0 { + return d + } + return -d +} + +// DiffForHumans gets the difference in a human-readable format, i18n is supported. +// 获取对人类友好的可读格式时间差,支持i18n +func (c Carbon) DiffForHumans(carbon ...Carbon) string { + end := c.Now() + if c.IsSetTestNow() { + end = CreateFromTimestampNano(c.testNow, c.Location()) + } + if len(carbon) > 0 { + end = carbon[0] + } + if c.Error != nil || end.Error != nil { + return "" + } + unit, value := c.diff(end) + translation := c.lang.translate(unit, getAbsValue(value)) + if unit == "now" { + return translation + } + if c.Lt(end) && len(carbon) == 0 { + return strings.Replace(c.lang.resources["ago"], "%s", translation, 1) + } + if c.Lt(end) && len(carbon) > 0 { + return strings.Replace(c.lang.resources["before"], "%s", translation, 1) + } + if c.Gt(end) && len(carbon) == 0 { + return strings.Replace(c.lang.resources["from_now"], "%s", translation, 1) + } + return strings.Replace(c.lang.resources["after"], "%s", translation, 1) +} + +// gets the difference for unit and value. +// 获取相差单位和差值 +func (c Carbon) diff(end Carbon) (unit string, value int64) { + switch true { + case c.DiffAbsInYears(end) > 0: + unit = "year" + value = c.DiffInYears(end) + case c.DiffAbsInMonths(end) > 0: + unit = "month" + value = c.DiffInMonths(end) + case c.DiffAbsInWeeks(end) > 0: + unit = "week" + value = c.DiffInWeeks(end) + case c.DiffAbsInDays(end) > 0: + unit = "day" + value = c.DiffInDays(end) + case c.DiffAbsInHours(end) > 0: + unit = "hour" + value = c.DiffInHours(end) + case c.DiffAbsInMinutes(end) > 0: + unit = "minute" + value = c.DiffInMinutes(end) + case c.DiffAbsInSeconds(end) > 0: + unit = "second" + value = c.DiffInSeconds(end) + case c.DiffAbsInSeconds(end) == 0: + unit = "now" + value = 0 + } + return +} + +func getDiffInMonths(start, end Carbon, months int64) int64 { + next := start.AddDays(start.DaysInMonth()) + days := next.DiffInDays(end) + seconds := next.DiffInSeconds(end) + if days < 0 || (days == 0 && seconds < 0) { + return months + } + months += 1 + return getDiffInMonths(next, end, months) +} diff --git a/vendor/github.com/dromara/carbon/v2/errors.go b/vendor/github.com/dromara/carbon/v2/errors.go new file mode 100644 index 000000000..0f2ca0b5c --- /dev/null +++ b/vendor/github.com/dromara/carbon/v2/errors.go @@ -0,0 +1,41 @@ +package carbon + +import ( + "fmt" +) + +// returns an invalid timezone error. +// 无效的时区错误 +var invalidTimezoneError = func(timezone string) error { + return fmt.Errorf("invalid timezone %q, please see the file %q for all valid timezones", timezone, "$GOROOT/lib/time/zoneinfo.zip") +} + +// returns an invalid location error. +// 无效的地区错误 +var invalidLocationError = func() error { + return fmt.Errorf("invalid location, please make sure the location is valid") +} + +// returns an invalid duration error. +// 无效的时长错误 +var invalidDurationError = func(duration string) error { + return fmt.Errorf("invalid duration %q, please make sure the duration is valid", duration) +} + +// returns an invalid value error. +// 无效的时间字符串错误 +var invalidValueError = func(value string) error { + return fmt.Errorf("cannot parse string %q as carbon, please make sure the value is valid", value) +} + +// returns an invalid layout error. +// 无效的布局模板错误 +var invalidLayoutError = func(value, layout string) error { + return fmt.Errorf("cannot parse string %q as carbon by layout %q, please make sure the value and layout match", value, layout) +} + +// returns an invalid format error. +// 无效的格式模板错误 +var invalidFormatError = func(value, format string) error { + return fmt.Errorf("cannot parse string %q as carbon by format %q, please make sure the value and format match", value, format) +} diff --git a/vendor/github.com/dromara/carbon/v2/extremum.go b/vendor/github.com/dromara/carbon/v2/extremum.go new file mode 100644 index 000000000..22a39a78f --- /dev/null +++ b/vendor/github.com/dromara/carbon/v2/extremum.go @@ -0,0 +1,67 @@ +package carbon + +// MaxValue returns a Carbon instance for the greatest supported date. +// 返回 Carbon 的最大值 +func MaxValue() Carbon { + return NewCarbon().create(9999, 12, 31, 23, 59, 59, 999999999, UTC) +} + +// MinValue returns a Carbon instance for the lowest supported date. +// 返回 Carbon 的最小值 +func MinValue() Carbon { + return NewCarbon().create(-9998, 1, 1, 0, 0, 0, 0, UTC) +} + +// Closest returns the closest Carbon instance from the given Carbon instance. +// 返回离给定 carbon 实例最近的 Carbon 实例 +func (c Carbon) Closest(c1 Carbon, c2 Carbon) Carbon { + if c1.Error != nil { + return c2 + } + if c2.Error != nil { + return c1 + } + if c.DiffAbsInSeconds(c1) < c.DiffAbsInSeconds(c2) { + return c1 + } + return c2 +} + +// Farthest returns the farthest Carbon instance from the given Carbon instance. +// 返回离给定 carbon 实例最远的 Carbon 实例 +func (c Carbon) Farthest(c1 Carbon, c2 Carbon) Carbon { + if c1.IsZero() || c1.IsInvalid() { + return c2 + } + if c2.IsZero() || c2.IsInvalid() { + return c1 + } + if c.DiffAbsInSeconds(c1) > c.DiffAbsInSeconds(c2) { + return c1 + } + return c2 +} + +// Max returns the maximum Carbon instance from the given Carbon instance (second-precision). +// 返回最大的 Carbon 实例 +func Max(c1 Carbon, c2 ...Carbon) (c Carbon) { + c = c1 + for i := range c2 { + if c2[i].Gte(c) { + c = c2[i] + } + } + return +} + +// Min returns the minimum Carbon instance from the given Carbon instance (second-precision). +// 返回最小的 Carbon 实例 +func Min(c1 Carbon, c2 ...Carbon) (c Carbon) { + c = c1 + for i := range c2 { + if c2[i].Lte(c) { + c = c2[i] + } + } + return +} diff --git a/vendor/github.com/dromara/carbon/v2/getter.go b/vendor/github.com/dromara/carbon/v2/getter.go new file mode 100644 index 000000000..112848c8a --- /dev/null +++ b/vendor/github.com/dromara/carbon/v2/getter.go @@ -0,0 +1,433 @@ +package carbon + +import ( + "time" +) + +// StdTime gets standard time.Time. +// 获取标准 time.Time +func (c Carbon) StdTime() time.Time { + if c.time.IsZero() { + return c.time + } + return c.time.In(c.loc) +} + +// DaysInYear gets total days in year like 365. +// 获取本年的总天数 +func (c Carbon) DaysInYear() int { + if c.Error != nil { + return 0 + } + if c.IsLeapYear() { + return DaysPerLeapYear + } + return DaysPerNormalYear +} + +// DaysInMonth gets total days in month like 30. +// 获取本月的总天数 +func (c Carbon) DaysInMonth() int { + if c.Error != nil { + return 0 + } + return c.EndOfMonth().StdTime().Day() +} + +// MonthOfYear gets month of year like 12. +// 获取本年的第几月 +func (c Carbon) MonthOfYear() int { + if c.Error != nil { + return 0 + } + return int(c.StdTime().Month()) +} + +// DayOfYear gets day of year like 365. +// 获取本年的第几天 +func (c Carbon) DayOfYear() int { + if c.Error != nil { + return 0 + } + return c.StdTime().YearDay() +} + +// DayOfMonth gets day of month like 30. +// 获取本月的第几天 +func (c Carbon) DayOfMonth() int { + if c.Error != nil { + return 0 + } + return c.StdTime().Day() +} + +// DayOfWeek gets day of week like 6. +// 获取本周的第几天 +func (c Carbon) DayOfWeek() int { + if c.Error != nil { + return 0 + } + day := int(c.StdTime().Weekday()) + if day == 0 { + return DaysPerWeek + } + return day +} + +// WeekOfYear gets week of year like 1, see https://en.wikipedia.org/wiki/ISO_8601#Week_dates. +// 获取本年的第几周 +func (c Carbon) WeekOfYear() int { + if c.Error != nil { + return 0 + } + _, week := c.StdTime().ISOWeek() + return week +} + +// WeekOfMonth gets week of month like 1. +// 获取本月的第几周 +func (c Carbon) WeekOfMonth() int { + if c.Error != nil { + return 0 + } + days := c.Day() + c.StartOfMonth().DayOfWeek() - 1 + if days%DaysPerWeek == 0 { + return days / DaysPerWeek + } + return days/DaysPerWeek + 1 +} + +// DateTime gets current year, month, day, hour, minute, and second like 2020, 8, 5, 13, 14, 15. +// 获取当前年、月、日、时、分、秒 +func (c Carbon) DateTime() (year, month, day, hour, minute, second int) { + if c.Error != nil { + return + } + year, month, day = c.Date() + hour, minute, second = c.Time() + return year, month, day, hour, minute, second +} + +// DateTimeMilli gets current year, month, day, hour, minute, second and millisecond like 2020, 8, 5, 13, 14, 15, 999. +// 获取当前年、月、日、时、分、秒、毫秒 +func (c Carbon) DateTimeMilli() (year, month, day, hour, minute, second, millisecond int) { + if c.Error != nil { + return + } + year, month, day, hour, minute, second = c.DateTime() + return year, month, day, hour, minute, second, c.Millisecond() +} + +// DateTimeMicro gets current year, month, day, hour, minute, second and microsecond like 2020, 8, 5, 13, 14, 15, 999999. +// 获取当前年、月、日、时、分、秒、微秒 +func (c Carbon) DateTimeMicro() (year, month, day, hour, minute, second, microsecond int) { + if c.Error != nil { + return + } + year, month, day, hour, minute, second = c.DateTime() + return year, month, day, hour, minute, second, c.Microsecond() +} + +// DateTimeNano gets current year, month, day, hour, minute, second and nanosecond like 2020, 8, 5, 13, 14, 15, 999999999. +// 获取当前年、月、日、时、分、秒、纳秒 +func (c Carbon) DateTimeNano() (year, month, day, hour, minute, second, nanosecond int) { + if c.Error != nil { + return + } + year, month, day, hour, minute, second = c.DateTime() + return year, month, day, hour, minute, second, c.Nanosecond() +} + +// Date gets current year, month, and day like 2020, 8, 5. +// 获取当前年、月、日 +func (c Carbon) Date() (year, month, day int) { + if c.Error != nil { + return + } + var tm time.Month + year, tm, day = c.StdTime().Date() + return year, int(tm), day +} + +// DateMilli gets current year, month, day and millisecond like 2020, 8, 5, 999. +// 获取当前年、月、日、毫秒 +func (c Carbon) DateMilli() (year, month, day, millisecond int) { + if c.Error != nil { + return + } + year, month, day = c.Date() + return year, month, day, c.Millisecond() +} + +// DateMicro gets current year, month, day and microsecond like 2020, 8, 5, 999999. +// 获取当前年、月、日、微秒 +func (c Carbon) DateMicro() (year, month, day, microsecond int) { + if c.Error != nil { + return + } + year, month, day = c.Date() + return year, month, day, c.Microsecond() +} + +// DateNano gets current year, month, day and nanosecond like 2020, 8, 5, 999999999. +// 获取当前年、月、日、纳秒 +func (c Carbon) DateNano() (year, month, day, nanosecond int) { + if c.Error != nil { + return + } + year, month, day = c.Date() + return year, month, day, c.Nanosecond() +} + +// Time gets current hour, minute, and second like 13, 14, 15. +// 获取当前时、分、秒 +func (c Carbon) Time() (hour, minute, second int) { + if c.Error != nil { + return + } + return c.StdTime().Clock() +} + +// TimeMilli gets current hour, minute, second and millisecond like 13, 14, 15, 999. +// 获取当前时、分、秒、毫秒 +func (c Carbon) TimeMilli() (hour, minute, second, millisecond int) { + if c.Error != nil { + return + } + hour, minute, second = c.Time() + return hour, minute, second, c.Millisecond() +} + +// TimeMicro gets current hour, minute, second and microsecond like 13, 14, 15, 999999. +// 获取当前时、分、秒、微秒 +func (c Carbon) TimeMicro() (hour, minute, second, microsecond int) { + if c.Error != nil { + return + } + hour, minute, second = c.Time() + return hour, minute, second, c.Microsecond() +} + +// TimeNano gets current hour, minute, second and nanosecond like 13, 14, 15, 999999999. +// 获取当前时、分、秒、纳秒 +func (c Carbon) TimeNano() (hour, minute, second, nanosecond int) { + if c.Error != nil { + return + } + hour, minute, second = c.Time() + return hour, minute, second, c.Nanosecond() +} + +// Century gets current century like 21. +// 获取当前世纪 +func (c Carbon) Century() int { + if c.Error != nil { + return 0 + } + return c.Year()/YearsPerCentury + 1 +} + +// Decade gets current decade like 20. +// 获取当前年代 +func (c Carbon) Decade() int { + if c.Error != nil { + return 0 + } + return c.Year() % YearsPerCentury / YearsPerDecade * YearsPerDecade +} + +// Year gets current year like 2020. +// 获取当前年 +func (c Carbon) Year() int { + if c.Error != nil { + return 0 + } + return c.StdTime().Year() +} + +// Quarter gets current quarter like 3. +// 获取当前季度 +func (c Carbon) Quarter() (quarter int) { + if c.Error != nil { + return + } + month := c.Month() + switch { + case month >= 10: + quarter = 4 + case month >= 7: + quarter = 3 + case month >= 4: + quarter = 2 + case month >= 1: + quarter = 1 + } + return +} + +// Month gets current month like 8. +// 获取当前月 +func (c Carbon) Month() int { + return c.MonthOfYear() +} + +// Week gets current week like 6, start from 0. +// 获取当前周(从0开始) +func (c Carbon) Week() int { + if c.Error != nil { + return -1 + } + return (c.DayOfWeek() + DaysPerWeek - int(c.weekStartsAt)) % DaysPerWeek +} + +// Day gets current day like 5. +// 获取当前日 +func (c Carbon) Day() int { + return c.DayOfMonth() +} + +// Hour gets current hour like 13. +// 获取当前小时 +func (c Carbon) Hour() int { + if c.Error != nil { + return 0 + } + return c.StdTime().Hour() +} + +// Minute gets current minute like 14. +// 获取当前分钟数 +func (c Carbon) Minute() int { + if c.Error != nil { + return 0 + } + return c.StdTime().Minute() +} + +// Second gets current second like 15. +// 获取当前秒数 +func (c Carbon) Second() int { + if c.Error != nil { + return 0 + } + return c.StdTime().Second() +} + +// Millisecond gets current millisecond like 999. +// 获取当前毫秒数 +func (c Carbon) Millisecond() int { + if c.Error != nil { + return 0 + } + return c.StdTime().Nanosecond() / 1e6 +} + +// Microsecond gets current microsecond like 999999. +// 获取当前微秒数 +func (c Carbon) Microsecond() int { + if c.Error != nil { + return 0 + } + return c.StdTime().Nanosecond() / 1e3 +} + +// Nanosecond gets current nanosecond like 999999999. +// 获取当前纳秒数 +func (c Carbon) Nanosecond() int { + if c.Error != nil { + return 0 + } + return c.StdTime().Nanosecond() +} + +// Timestamp gets timestamp with second like 1596604455. +// 输出秒级时间戳 +func (c Carbon) Timestamp() int64 { + if c.Error != nil { + return 0 + } + return c.StdTime().Unix() +} + +// TimestampMilli gets timestamp with millisecond like 1596604455000. +// 获取毫秒级时间戳 +func (c Carbon) TimestampMilli() int64 { + if c.Error != nil { + return 0 + } + t := c.StdTime() + return t.Unix()*1e3 + int64(t.Nanosecond())/1e6 +} + +// TimestampMicro gets timestamp with microsecond like 1596604455000000. +// 获取微秒级时间戳 +func (c Carbon) TimestampMicro() int64 { + if c.Error != nil { + return 0 + } + t := c.StdTime() + return t.Unix()*1e6 + int64(t.Nanosecond())/1e3 +} + +// TimestampNano gets timestamp with nanosecond like 1596604455000000000. +// 获取纳秒级时间戳 +func (c Carbon) TimestampNano() int64 { + if c.Error != nil { + return 0 + } + return c.StdTime().UnixNano() +} + +// Location gets location name like "PRC". +// 获取位置 +func (c Carbon) Location() string { + if c.Error != nil { + return "" + } + return c.loc.String() +} + +// Timezone gets timezone name like "CST". +// 获取时区 +func (c Carbon) Timezone() string { + if c.Error != nil { + return "" + } + name, _ := c.StdTime().Zone() + return name +} + +// Offset gets offset seconds from the UTC timezone like 28800. +// 获取距离UTC时区的偏移量,单位秒 +func (c Carbon) Offset() int { + if c.Error != nil { + return 0 + } + _, offset := c.StdTime().Zone() + return offset +} + +// Locale gets locale name like "zh-CN". +// 获取语言区域 +func (c Carbon) Locale() string { + if c.Error != nil { + return "" + } + return c.lang.locale +} + +// Age gets age like 18. +// 获取年龄 +func (c Carbon) Age() int { + if c.Error != nil { + return 0 + } + now := c.Now() + if c.IsSetTestNow() { + now = CreateFromTimestampNano(c.testNow, c.Location()) + } + if c.TimestampNano() > now.TimestampNano() { + return 0 + } + return int(c.DiffInYears(now)) +} diff --git a/vendor/github.com/dromara/carbon/v2/helper.go b/vendor/github.com/dromara/carbon/v2/helper.go new file mode 100644 index 000000000..92d8e8b8d --- /dev/null +++ b/vendor/github.com/dromara/carbon/v2/helper.go @@ -0,0 +1,127 @@ +package carbon + +import ( + "bytes" + "time" +) + +// week days +// 工作日 +var weekdays = map[string]time.Weekday{ + Monday: time.Monday, + Tuesday: time.Tuesday, + Wednesday: time.Wednesday, + Thursday: time.Thursday, + Friday: time.Friday, + Saturday: time.Saturday, + Sunday: time.Sunday, +} + +// common formatting symbols +// 常规格式化符号 +var formats = map[byte]string{ + 'd': "02", // Day: Day of the month, 2 digits with leading zeros. Eg: 01 to 31. + 'D': "Mon", // Day: A textual representation of a day, three letters. Eg: Mon through Sun. + 'j': "2", // Day: Day of the month without leading zeros. Eg: 1 to 31. + 'l': "Monday", // Day: A full textual representation of the day of the week. Eg: Sunday through Saturday. + 'F': "January", // Month: A full textual representation of a month, such as January or March. Eg: January through December. + 'm': "01", // Month: Numeric representation of a month, with leading zeros. Eg: 01 through 12. + 'M': "Jan", // Month: A short textual representation of a month, three letters. Eg: Jan through Dec. + 'n': "1", // Month: Numeric representation of a month, without leading zeros. Eg: 1 through 12. + 'Y': "2006", // Year: A full numeric representation of a year, 4 digits. Eg: 1999 or 2003. + 'y': "06", // Year: A two digit representation of a year. Eg: 99 or 03. + 'a': "pm", // Time: Lowercase morning or afternoon sign. Eg: am or pm. + 'A': "PM", // Time: Uppercase morning or afternoon sign. Eg: AM or PM. + 'g': "3", // Time: 12-hour format of an hour without leading zeros. Eg: 1 through 12. + 'h': "03", // Time: 12-hour format of an hour with leading zeros. Eg: 01 through 12. + 'H': "15", // Time: 24-hour format of an hour with leading zeros. Eg: 00 through 23. + 'i': "04", // Time: Minutes with leading zeros. Eg: 00 to 59. + 's': "05", // Time: Seconds with leading zeros. Eg: 00 through 59. + 'O': "-0700", // Zone: Difference to Greenwich time (GMT) in hours. Eg: +0200. + 'P': "-07:00", // Zone: Difference to Greenwich time (GMT) with colon between hours and minutes. Eg: +02:00. + 'T': "MST", // Zone: Timezone abbreviation. Eg: UTC, EST, MDT ... + + 'U': "timestamp", // Timestamp with second. Eg: 1699677240. + 'V': "timestampMilli", // TimestampMilli with second. Eg: 1596604455666. + 'X': "timestampMicro", // TimestampMicro with second. Eg: 1596604455666666. + 'Z': "timestampNano", // TimestampNano with second. Eg: 1596604455666666666. +} + +// common layout symbols +// 常规布局模板符号 +var layouts = []string{ + DayDateTimeLayout, + DateTimeLayout, DateTimeNanoLayout, ShortDateTimeLayout, ShortDateTimeNanoLayout, + DateLayout, DateNanoLayout, ShortDateLayout, ShortDateNanoLayout, + ISO8601Layout, ISO8601NanoLayout, + RFC822Layout, RFC822ZLayout, RFC850Layout, RFC1123Layout, RFC1123ZLayout, RFC3339Layout, RFC3339NanoLayout, RFC1036Layout, RFC7231Layout, + KitchenLayout, + CookieLayout, + ANSICLayout, + UnixDateLayout, + RubyDateLayout, + "2006", + "2006-1", "2006-1-2", "2006-1-2 15", "2006-1-2 15:4", "2006-1-2 15:4:5", "2006-1-2 15:4:5.999999999", + "2006.1", "2006.1.2", "2006.1.2 15", "2006.1.2 15:4", "2006.1.2 15:4:5", "2006.1.2 15:4:5.999999999", + "2006/1", "2006/1/2", "2006/1/2 15", "2006/1/2 15:4", "2006/1/2 15:4:5", "2006/1/2 15:4:5.999999999", + "2006-01-02 15:04:05 -0700 MST", + "2006-01-02 15:04:05PM MST", "2006-01-02 15:04:05.999999999PM MST", "2006-1-2 15:4:5PM MST", "2006-1-2 15:4:5.999999999PM MST", + "2006-01-02 15:04:05 PM MST", "2006-01-02 15:04:05.999999999 PM MST", "2006-1-2 15:4:5 PM MST", "2006-1-2 15:4:5.999999999 PM MST", + "1/2/2006", "1/2/2006 15", "1/2/2006 15:4", "1/2/2006 15:4:5", "1/2/2006 15:4:5.999999999", + "2006-1-2 15:4:5 -0700 MST", "2006-1-2 15:4:5.999999999 -0700 MST", "2006-1-2 15:04:05 -0700 MST", "2006-1-2 15:04:05.999999999 -0700 MST", + "2006-01-02T15:04:05", "2006-01-02T15:04:05.999999999", "2006-1-2T3:4:5", "2006-1-2T3:4:5.999999999", + "2006-01-02T15:04:05Z07", "2006-01-02T15:04:05.999999999Z07", "2006-1-2T15:4:5Z07", "2006-1-2T15:4:5.999999999Z07", + "2006-01-02T15:04:05Z07:00", "2006-01-02T15:04:05.999999999Z07:00", "2006-1-2T15:4:5Z07:00", "2006-1-2T15:4:5.999999999Z07:00", + "2006-01-02T15:04:05-07:00", "2006-01-02T15:04:05.999999999-07:00", "2006-1-2T15:4:5-07:00", "2006-1-2T15:4:5.999999999-07:00", + "2006-01-02T15:04:05-0700", "2006-01-02T15:04:05.999999999-0700", "2006-1-2T3:4:5-0700", "2006-1-2T3:4:5.999999999-0700", + "20060102150405-07:00", "20060102150405.999999999-07:00", + "20060102150405Z07", "20060102150405.999999999Z07", + "20060102150405Z07:00", "20060102150405.999999999Z07:00", +} + +// converts format to layout. +// format 转 layout +func format2layout(format string) string { + buffer := bytes.NewBuffer(nil) + for i := 0; i < len(format); i++ { + if layout, ok := formats[format[i]]; ok { + buffer.WriteString(layout) + } else { + switch format[i] { + case '\\': // raw output, no parse + buffer.WriteByte(format[i+1]) + i++ + continue + default: + buffer.WriteByte(format[i]) + } + } + } + return buffer.String() +} + +// gets a Location instance by a timezone string. +// 通过时区获取 Location 实例 +func getLocationByTimezone(timezone string) (*time.Location, error) { + loc, err := time.LoadLocation(timezone) + if err != nil { + err = invalidTimezoneError(timezone) + } + return loc, err +} + +// parses as a Duration instance by a duration string. +// 通过时长解析 +func parseByDuration(duration string) (time.Duration, error) { + td, err := time.ParseDuration(duration) + if err != nil { + err = invalidDurationError(duration) + } + return td, err +} + +// gets absolute value. +// 获取绝对值 +func getAbsValue(value int64) int64 { + return (value ^ value>>31) - value>>31 +} diff --git a/vendor/github.com/dromara/carbon/v2/lang/ar.json b/vendor/github.com/dromara/carbon/v2/lang/ar.json new file mode 100644 index 000000000..26d78f5fa --- /dev/null +++ b/vendor/github.com/dromara/carbon/v2/lang/ar.json @@ -0,0 +1,21 @@ +{ + "name": "Arabic", + "months": "يناير|فبراير|مارس|أبريل|مايو|يونيو|يوليو|أغسطس|سبتمبر|أكتوبر|نوفمبر|ديسمبر", + "short_months": "يناير|فبراير|مارس|أبريل|مايو|يونيو|يوليو|أغسطس|سبتمبر|أكتوبر|نوفمبر|ديسمبر", + "weeks": "الأحد|الإثنين|الثلاثاء|الأربعاء|الخميس|الجمعة|السبت", + "short_weeks": "أحد|إثنين|ثلاثاء|أربعاء|خميس|جمعة|سبت", + "seasons": "الربيع|الصيف|الخريف|الشتاء", + "constellations": "الحمل|الثور|الجوزاء|السرطان|الأسد|العذراء|الميزان|العقرب|القوس|الجدي|الدلو|الحوت", + "year": "1 سنة|%d سنوات", + "month": "1 شهر|%d أشهر", + "week": "1 أسبوع|%d أسابيع", + "day": "1 يوم|%d أيام", + "hour": "1 ساعة|%d ساعات", + "minute": "1 دقيقة|%d دقائق", + "second": "1 ثانية|%d ثواني", + "now": "الآن", + "ago": "%s مضت", + "from_now": "من %s", + "before": "%s قبل", + "after": "%s بعد" +} diff --git a/vendor/github.com/dromara/carbon/v2/lang/bg.json b/vendor/github.com/dromara/carbon/v2/lang/bg.json new file mode 100644 index 000000000..8bd3fa7f3 --- /dev/null +++ b/vendor/github.com/dromara/carbon/v2/lang/bg.json @@ -0,0 +1,21 @@ +{ + "name": "Български", + "months": "Януари|Февруари|Март|Април|Май|Юни|Юли|Август|Септември|Октомври|Ноември|Декември", + "short_months": "Ян|Фев|Март|Апр|Май|Юни|Юли|Авг|Сеп|Окт|Ноем|Дек", + "weeks": "Неделя|Понеделник|Вторник|Сряда|Четвъртък|Петък|Събота", + "short_weeks": "Нд|Пн|Вт|Ср|Чт|Пт|Сб", + "seasons": "Пролет|Лято|Есен|Зима", + "constellations": "Овен|Телец|Близнаци|Рак|Лъв|Дева|Везни|Скорпион|Стрелец|Козирог|Водолей|Риби", + "year": "1 година|%d години", + "month": "1 месец|%d месеца", + "week": "1 седмица|%d седмици", + "day": "1 ден|%d дни", + "hour": "1 час|%d часа", + "minute": "1 минута|%d минути", + "second": "1 секунда|%d секунди", + "now": "в момента", + "ago": "%s преди", + "from_now": "%s от сега", + "before": "%s преди", + "after": "%s след" +} diff --git a/vendor/github.com/dromara/carbon/v2/lang/de.json b/vendor/github.com/dromara/carbon/v2/lang/de.json new file mode 100644 index 000000000..fa5d809ba --- /dev/null +++ b/vendor/github.com/dromara/carbon/v2/lang/de.json @@ -0,0 +1,21 @@ +{ + "name": "German", + "months": "Januar|Februar|März|April|Mai|Juni|Juli|August|September|Oktober|November|Dezember", + "short_months": "Jan|Feb|Mär|Apr|Mai|Jun|Jul|Aug|Sep|Okt|Nov|Dez", + "weeks": "Sonntag|Montag|Dienstag|Mittwoch|Donnerstag|Freitag|Samstag", + "short_weeks": "So|Mo|Di|Mi|Do|Fr|Sa", + "seasons": "Frühling|Sommer|Herbst|Winter", + "constellations": "Widder|Stier|Zwilling|Krebs|Löwe|Jungfrau|Waage|Skorpion|Schütze|Steinbock|Wassermann|Fisch", + "year": "1 Jahr|%d Jahre", + "month": "1 Monat|%d Monate", + "week": "1 Woche|%d Wochen", + "day": "1 Tag|%d Tage", + "hour": "1 Stunde|%d Stunden", + "minute": "1 Minute|%d Minuten", + "second": "1 Sekunde|%d Sekunden", + "now": "gerade eben", + "ago": "vor %s", + "from_now": "%s ab jetzt", + "before": "%s davor", + "after": "%s danach" +} \ No newline at end of file diff --git a/vendor/github.com/dromara/carbon/v2/lang/dk.json b/vendor/github.com/dromara/carbon/v2/lang/dk.json new file mode 100644 index 000000000..a42303164 --- /dev/null +++ b/vendor/github.com/dromara/carbon/v2/lang/dk.json @@ -0,0 +1,21 @@ +{ + "name": "Dansk", + "months": "januar|februar|marts|april|maj|juni|juli|august|september|oktober|november|december", + "short_months": "jan|feb|mar|apr|maj|jun|jul|aug|sep|okt|nov|dec", + "weeks": "søndag|mandag|tirsdag|onsdag|torsdag|fredag|lørdag", + "short_weeks": "søn|man|tir|ons|tor|fre|lør", + "seasons": "forår|sommer|efterår|vinter", + "constellations": "vædder|tyr|tvilling|krebs|løve|jomfru|vægt|skorpion|skytte|stenbuk|vandmand|fisk", + "year": "1 år|%d år", + "month": "1 måned|%d måneder", + "week": "1 uge|%d uger", + "day": "1 dag|%d dage", + "hour": "1 time|%d timer", + "minute": "1 minut|%d minutter", + "second": "1 sekund|%d sekunder", + "now": "lige nu", + "ago": "%s siden", + "from_now": "om %s", + "before": "%s før", + "after": "%s efter" +} diff --git a/vendor/github.com/dromara/carbon/v2/lang/en.json b/vendor/github.com/dromara/carbon/v2/lang/en.json new file mode 100644 index 000000000..6dbc46a26 --- /dev/null +++ b/vendor/github.com/dromara/carbon/v2/lang/en.json @@ -0,0 +1,21 @@ +{ + "name": "English", + "months": "January|February|March|April|May|June|July|August|September|October|November|December", + "short_months": "Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec", + "weeks": "Sunday|Monday|Tuesday|Wednesday|Thursday|Friday|Saturday", + "short_weeks": "Sun|Mon|Tue|Wed|Thu|Fri|Sat", + "seasons": "Spring|Summer|Autumn|Winter", + "constellations": "Aries|Taurus|Gemini|Cancer|Leo|Virgo|Libra|Scorpio|Sagittarius|Capricorn|Aquarius|Pisces", + "year": "1 year|%d years", + "month": "1 month|%d months", + "week": "1 week|%d weeks", + "day": "1 day|%d days", + "hour": "1 hour|%d hours", + "minute": "1 minute|%d minutes", + "second": "1 second|%d seconds", + "now": "just now", + "ago": "%s ago", + "from_now": "%s from now", + "before": "%s before", + "after": "%s after" +} \ No newline at end of file diff --git a/vendor/github.com/dromara/carbon/v2/lang/es.json b/vendor/github.com/dromara/carbon/v2/lang/es.json new file mode 100644 index 000000000..3b8ac7d26 --- /dev/null +++ b/vendor/github.com/dromara/carbon/v2/lang/es.json @@ -0,0 +1,21 @@ +{ + "name": "Spanish", + "months": "Enero|Febrero|Marzo|Abril|Mayo|Junio|Julio|Agosto|Septiembre|Octubre|Noviembre|Diciembre", + "short_months": "Ene|Feb|Mar|Abr|May|Jun|Jul|Ago|Sep|Oct|Nov|Dic", + "weeks": "Domingo|Lunes|Martes|Miércoles|Jueves|Viernes|Sábado", + "short_weeks": "Dom|Lun|Mar|Mie|Jue|Vie|Sab", + "seasons": "Primavera|Verano|Otoño|Invierno", + "constellations": "Aries|Tauro|Geminis|Cancer|Leo|Virgo|Libra|Escorpio|Sagitario|Capricornio|Acuario|Piscis", + "year": "1 año|%d años", + "month": "1 mes|%d meses", + "week": "1 semana|%d semanas", + "day": "1 día|%d días", + "hour": "1 hora|%d horas", + "minute": "1 minuto|%d minutos", + "second": "1 segundo|%d segundos", + "now": "ahora", + "ago": "hace %s", + "from_now": "%s desde ahora", + "before": "%s antes", + "after": "%s después" +} diff --git a/vendor/github.com/dromara/carbon/v2/lang/fa.json b/vendor/github.com/dromara/carbon/v2/lang/fa.json new file mode 100644 index 000000000..7d10d9d21 --- /dev/null +++ b/vendor/github.com/dromara/carbon/v2/lang/fa.json @@ -0,0 +1,21 @@ +{ + "name": "Farsi", + "months": "ژانویه|فوریه|مارس|آوریل|مه|ژوئن|ژوئیه|اوت|سپتامبر|اکتبر|نوامبر|دسامبر", + "short_months": "ژانویه|فوریه|مارس|آوریل|مه|ژوئن|ژوئیه|اوت|سپتامبر|اکتبر|نوامبر|دسامبر", + "weeks": "یکشنبه|دوشنبه|سه‌شنبه|چهارشنبه|پنجشنبه|جمعه|شنبه", + "short_weeks": "یکشنبه|دوشنبه|سه‌شنبه|چهارشنبه|پنجشنبه|جمعه|شنبه", + "seasons": "بهار|تابستان|پاییز|زمستان", + "constellations": "قوچ|گاو نر|دو پیکر|خرچنگ|شیر|خوشه|ترازو|عقرب|کماندار|بز|آبریز|ماهی", + "year": "1 سال|%d سال", + "month": "1 ماه|%d ماه", + "week": "1 هفته|%d هفته", + "day": "1 روز|%d روز", + "hour": "1 ساعت|%d ساعت", + "minute": "1 دقیقه|%d دقیقه", + "second": "1 ثانیه|%d ثانیه", + "now": "همین الان", + "ago": "%s پیش", + "from_now": "در %s", + "before": "%s قبل", + "after": "%s بعد" +} diff --git a/vendor/github.com/dromara/carbon/v2/lang/fr.json b/vendor/github.com/dromara/carbon/v2/lang/fr.json new file mode 100644 index 000000000..4fd0f57bf --- /dev/null +++ b/vendor/github.com/dromara/carbon/v2/lang/fr.json @@ -0,0 +1,21 @@ +{ + "name": "French", + "months": "Janvier|Février|Mars|Avril|Mai|Juin|Juillet|Août|Septembre|Octobre|Novembre|Décembre", + "short_months": "Janv|Févr|Mars|Avril|Mai|Juin|Juil|Août|Sept|Oct|Nov|Déc", + "weeks": "Dimanche|Lundi|Mardi|Mercredi|Jeudi|Vendredi|Samedi", + "short_weeks": "Dim|Lun|Mar|Mer|Jeu|Ven|Sam", + "seasons": "Le Printemps|L’été|L’Automne|L’Hiver", + "constellations": "Bélier|Taureau|Gémeaux|Cancer|Lion|Vierge|Balance|Scorpion|Sagittaire|Capricorne|Verseau|Poissons", + "year": "1 an|%d ans", + "month": "1 mois|%d mois", + "week": "1 semaine|%d semaines", + "day": "1 jour|%d jours", + "hour": "1 heure|%d heures", + "minute": "1 minute|%d minutes", + "second": "1 seconde|%d secondes", + "now": "maintenant", + "ago": "il y a %s", + "from_now": "%s à partir de maintenant", + "before": "avant %s", + "after": "après %s" +} diff --git a/vendor/github.com/dromara/carbon/v2/lang/hi.json b/vendor/github.com/dromara/carbon/v2/lang/hi.json new file mode 100644 index 000000000..72b44bad1 --- /dev/null +++ b/vendor/github.com/dromara/carbon/v2/lang/hi.json @@ -0,0 +1,21 @@ +{ + "name": "Hindi", + "months": "जनवरी|फ़रवरी|मार्च|अप्रैल|मई|जून|जुलाई|अगस्त|सितंबर|अक्टूबर|नवंबर|दिसंबर", + "short_months": "जन|फ़र|मार्च|अप्रैल|मई|जून|जुलाई|अगस्त|सितंबर|अक्टूबर|नवंबर|दिसंबर", + "weeks": "रविवार|सोमवार|मंगलवार|बुधवार|गुरुवार|शुक्रवार|शनिवार", + "short_weeks": "रवि|सोम|मंगल|बुध|गुरु|शुक्र|शनि", + "seasons": "वसंत|ग्रीष्म|पतझड़|शीत", + "constellations": "मेष|वृषभ|मिथुन|कर्क|सिंह|कन्या|तुला|वृश्चिक|धनु|मकर|कुंभ|मीन", + "year": "1 वर्ष|%d वर्ष", + "month": "1 महीना|%d महीने", + "week": "1 सप्ताह|%d सप्ताह", + "day": "1 दिन|%d दिन", + "hour": "1 घंटा|%d घंटे", + "minute": "1 मिनट|%d मिनट", + "second": "1 सेकंड|%d सेकंड", + "now": "अभी", + "ago": "%s पहले", + "from_now": "%s बाद", + "before": "%s पहले", + "after": "%s बाद" +} diff --git a/vendor/github.com/dromara/carbon/v2/lang/hu.json b/vendor/github.com/dromara/carbon/v2/lang/hu.json new file mode 100644 index 000000000..edcf23f1f --- /dev/null +++ b/vendor/github.com/dromara/carbon/v2/lang/hu.json @@ -0,0 +1,21 @@ +{ + "name": "Hungarian", + "months": "január|február|március|április|május|június|július|augusztus|szeptember|október|november|december", + "short_months": "jan.|febr.|márc.|ápr.|máj.|jún.|júl.|aug.|szept.|okt.|nov.|dec.", + "weeks": "Vasárnap|Hétfő|Kedd|Szerda|Csütörtök|Péntek|Szombat", + "short_weeks": "Vas|Hét|Ke|Sze|Csü|Pé|Szo", + "seasons": "Tavasz|Nyár|Ősz|Tél", + "constellations": "Kos|Bika|Ikrek|Rák|Oroszlán|Szűz|Mérleg|Skorpió|Nyilas|Bak|Vízöntő|Halak", + "year": "1 év|%d év", + "month": "1 hónap|%d hónap", + "week": "1 hét|%d hét", + "day": "1 nap|%d nap", + "hour": "1 óra|%d óra", + "minute": "1 perc|%d perc", + "second": "1 másodperc|%d másodperc", + "now": "most", + "ago": "%s", + "from_now": "%s múlva", + "before": "%s korábban", + "after": "%s később" +} diff --git a/vendor/github.com/dromara/carbon/v2/lang/id.json b/vendor/github.com/dromara/carbon/v2/lang/id.json new file mode 100644 index 000000000..e57fdfce0 --- /dev/null +++ b/vendor/github.com/dromara/carbon/v2/lang/id.json @@ -0,0 +1,21 @@ +{ + "name": "Indonesian", + "months": "Januari|Februari|Maret|April|Mei|Juni|Juli|Agustus|September|Oktober|November|Desember", + "short_months": "Jan|Feb|Mar|Apr|Mei|Jun|Jul|Agt|Sep|Okt|Nov|Des", + "weeks": "Minggu|Senin|Selasa|Rabu|Kamis|Jumaat|Sabtu", + "short_weeks": "Min|Sen|Sel|Rab|Kam|Jum|Sab", + "seasons": "Musim Semi|Musim Panas|Musim Gugur|Musim Salju", + "constellations": "Aries|Taurus|Gemini|Cancer|Leo|Virgo|Libra|Scorpio|Sagitarius|Capricorn|Aquarius|Pisces", + "year": "1 tahun|%d tahun", + "month": "1 bulan|%d bulan", + "week": "1 minggu|%d minggu", + "day": "1 hari|%d hari", + "hour": "1 jam|%d jam", + "minute": "1 menit|%d menit", + "second": "1 detik|%d detik", + "now": "baru saja", + "ago": "%s yang lalu", + "from_now": "%s dari sekarang", + "before": "%s sebelum", + "after": "%s sesudah" +} diff --git a/vendor/github.com/dromara/carbon/v2/lang/it.json b/vendor/github.com/dromara/carbon/v2/lang/it.json new file mode 100644 index 000000000..a2164f451 --- /dev/null +++ b/vendor/github.com/dromara/carbon/v2/lang/it.json @@ -0,0 +1,20 @@ +{ + "name": "Italian", + "months": "Gennaio|Febbraio|Marzo|Aprile|Maggio|Giugno|Luglio|Agosto|Settembre|Ottobre|Novembre|Dicembre", + "short_months": "Gen|Feb|Mar|Apr|Mag|Giu|Lug|Ago|Set|Ott|Nov|Dic", + "weeks": "Domenica|Lunedí|Martedí|Mercoledí|Giovedí|Venerdí|Sabato", + "short_weeks": "Dom|Lun|Mar|Mer|Gio|Ven|Sab", + "seasons": "Primavera|Estate|Autunno|Inverno", + "year": "1 anno|%d anni", + "month": "1 mese|%d mesi", + "week": "1 settimana|%d settimane", + "day": "1 giorno|%d giorni", + "hour": "1 ora|%d ore", + "minute": "1 minuto|%d minuti", + "second": "1 secondo|%d secondi", + "now": "proprio ora", + "ago": "%s fa", + "from_now": "%s da adesso", + "before": "%s prima", + "after": "%s dopo" +} diff --git a/vendor/github.com/dromara/carbon/v2/lang/jp.json b/vendor/github.com/dromara/carbon/v2/lang/jp.json new file mode 100644 index 000000000..e5808401a --- /dev/null +++ b/vendor/github.com/dromara/carbon/v2/lang/jp.json @@ -0,0 +1,21 @@ +{ + "name": "Japanese", + "months": "1月|2月|3月|4月|5月|6月|7月|8月|9月|10月|11月|12月", + "short_months": "1月|2月|3月|4月|5月|6月|7月|8月|9月|10月|11月|12月", + "weeks": "日曜日|月曜日|火曜日|水曜日|木曜日|金曜日|土曜日", + "short_weeks": "日|月|火|水|木|金|土", + "seasons": "春|夏|秋|冬", + "constellations": "おひつじ座|おうし座|ふたご座|かに座|しし座|おとめ座|てんびん座|さそり座|いて座|やぎ座|みずがめ座|うお座", + "year": "%d 年", + "month": "%d ヶ月", + "week": "%d 週間", + "day": "%d 日", + "hour": "%d 時間", + "minute": "%d 分", + "second": "%d 秒", + "now": "現在", + "ago": "%s前", + "from_now": "%s後", + "before": "%s前", + "after": "%s後" +} diff --git a/vendor/github.com/dromara/carbon/v2/lang/kr.json b/vendor/github.com/dromara/carbon/v2/lang/kr.json new file mode 100644 index 000000000..978d3a88d --- /dev/null +++ b/vendor/github.com/dromara/carbon/v2/lang/kr.json @@ -0,0 +1,21 @@ +{ + "name": "Korean", + "months": "일월|이월|삼월|사월|오월|유월|칠월|팔월|구월|시월|십일월|십이월", + "short_months": "1월|2월|3월|4월|5월|6월|7월|8월|9월|10월|11월|12월", + "weeks": "일요일|월요일|화요일|수요일|목요일|금요일|토요일", + "short_weeks": "일요일|월요일|화요일|수요일|목요일|금요일|토요일", + "seasons": "봄|여름|가을|겨울", + "constellations": "양자리|황소자리|쌍둥이자리|게자리|사자자리|처녀자리|천칭자리|전갈자리|사수자리|염소자리|물병자리|물고기자리", + "year": "%d 년", + "month": "%d 개월", + "week": "%d 주", + "day": "%d 일", + "hour": "%d 시간", + "minute": "%d 분", + "second": "%d 초", + "now": "방금", + "ago": "%s앞", + "from_now": "%s후", + "before": "%s전", + "after": "%s후" +} diff --git a/vendor/github.com/dromara/carbon/v2/lang/ms-MY.json b/vendor/github.com/dromara/carbon/v2/lang/ms-MY.json new file mode 100644 index 000000000..49b2922d9 --- /dev/null +++ b/vendor/github.com/dromara/carbon/v2/lang/ms-MY.json @@ -0,0 +1,21 @@ +{ + "name": "Bahasa Malaysia", + "months": "Januari|Februari|Mac|April|Mei|Jun|Julai|Ogos|September|Oktober|November|Disember", + "short_months": "Jan|Feb|Mac|Apr|Mei|Jun|Jul|Ogs|Sep|Okt|Nov|Dis", + "weeks": "Ahad|Isnin|Selasa|Rabu|Khamis|Jumaat|Sabtu", + "short_weeks": "Ahd|Isn|Sel|Rab|Kha|Jum|Sab", + "seasons": "Musim Bunga|Musim Panas|Musim Luruh|Musim Sejuk", + "constellations": "Aries|Taurus|Gemini|Cancer|Leo|Virgo|Libra|Scorpio|Sagittarius|Capricorn|Aquarius|Pisces", + "year": "1 tahun|%d tahun", + "month": "1 bulan|%d bulan", + "week": "1 minggu|%d minggu", + "day": "1 hari|%d hari", + "hour": "1 jam|%d jam", + "minute": "1 minit|%d minit", + "second": "1 saat|%d saat", + "now": "baru tadi", + "ago": "%s lalu", + "from_now": "%s dari sekarang", + "before": "sebelum %s", + "after": "selepas %s" +} diff --git a/vendor/github.com/dromara/carbon/v2/lang/nl.json b/vendor/github.com/dromara/carbon/v2/lang/nl.json new file mode 100644 index 000000000..d49ea2d26 --- /dev/null +++ b/vendor/github.com/dromara/carbon/v2/lang/nl.json @@ -0,0 +1,21 @@ +{ + "name": "Dutch", + "months": "januari|februari|maart|april|mei|juni|juli|augustus|september|oktober|november|december", + "short_months": "jan|feb|mrt|apr|mei|jun|jul|aug|sep|okt|nov|dec", + "weeks": "Zondag|Maandag|Dinsdag|Woensdag|Donderdag|Vrijdag|Zaterdag|Zondag", + "short_weeks": "zo|ma|di|wo|do|vr|za", + "seasons": "Lente|Zomer|Herfst|Winter", + "constellations": "Ram|Stier|Tweelingen|Kreeft|Leeuw|Maagd|Weegschaal|Schorpioen|Boogschutter|Steenbok|Waterman|Vissen", + "year": "1 jaar|%d jaren", + "month": "1 maand|%d maanden", + "week": "1 week|%d weken", + "day": "1 dag|%d dagen", + "hour": "1 uur|%d uren", + "minute": "1 minuut|%d minuten", + "second": "1 seconde|%d seconden", + "now": "zojuist", + "ago": "%s geleden", + "from_now": "%s vanaf nu", + "before": "%s voor", + "after": "%s na" +} diff --git a/vendor/github.com/dromara/carbon/v2/lang/pl.json b/vendor/github.com/dromara/carbon/v2/lang/pl.json new file mode 100644 index 000000000..03ba9d988 --- /dev/null +++ b/vendor/github.com/dromara/carbon/v2/lang/pl.json @@ -0,0 +1,21 @@ +{ + "name": "Polish", + "months": "stycznia|lutego|marca|kwietnia|maja|czerwca|lipca|sierpnia|września|października|listopada|grudnia", + "short_months": "sty|lut|mar|kwi|maj|cze|lip|sie|wrz|paź|lis|gru", + "weeks": "niedziela|poniedziałek|wtorek|środa|czwartek|piątek|sobota", + "short_weeks": "ndz|pon|wt|śr|czw|pt|sob", + "seasons": "sprężyna|lato|jesień|zima", + "constellations": "baran|byk|bliźnięta|rak|lew|dziewica|waga|skorpion|strzelec|koziorożec|wodnik|ryby", + "year": "1 rok|2 lata|%d lat", + "month": "1 miesiąc|2 miesiące|%d miesięcy", + "week": "1 tydzień|2 tygodnie|%d tygodni", + "day": "1 dzień|%d dni", + "hour": "1 godzina|2 godziny|%d godzin", + "minute": "1 minuta|2 minuty|%d minut", + "second": "1 sekunda|2 sekundy|%d sekund", + "now": "teraz", + "ago": "%s temu", + "from_now": "%s po", + "before": "%s przed", + "after": "%s po" +} \ No newline at end of file diff --git a/vendor/github.com/dromara/carbon/v2/lang/pt.json b/vendor/github.com/dromara/carbon/v2/lang/pt.json new file mode 100644 index 000000000..1602eead6 --- /dev/null +++ b/vendor/github.com/dromara/carbon/v2/lang/pt.json @@ -0,0 +1,21 @@ +{ + "name": "Portuguese", + "months": "Janeiro|Fevereiro|Março|Abril|Maio|Junho|Julho|Agosto|Setembro|Outubro|Novembro|Dezembro", + "short_months": "Jan|Fev|Mar|Abr|Maio|Jun|Jul|Ago|Set|Out|Nov|Dez", + "weeks": "Domingo|Segunda-feira|Terça-feira|Quarta-feira|Quinta-feira|Sexta-feira|Sábado", + "short_weeks": "Dom|Seg|Ter|Qua|Qui|Sex|Sab", + "seasons": "Primavera|Verão|Outono|Inverno", + "constellations": "Áries|Touro|Gêmeos|Câncer|Leão|Virgem|Libra|Escorpião|Sagitário|Capricórnio|Aquário|Peixes", + "year": "1 ano|%d anos", + "month": "1 mês|%d meses", + "week": "1 semana|%d semanas", + "day": "1 dia|%d dias", + "hour": "1 hora|%d horas", + "minute": "1 minuto|%d minutos", + "second": "1 segundo|%d segundos", + "now": "agora", + "ago": "%s atrás", + "from_now": "%s a partir de agora", + "before": "%s antes", + "after": "%s depois" +} diff --git a/vendor/github.com/dromara/carbon/v2/lang/ro.json b/vendor/github.com/dromara/carbon/v2/lang/ro.json new file mode 100644 index 000000000..a11bc4b6b --- /dev/null +++ b/vendor/github.com/dromara/carbon/v2/lang/ro.json @@ -0,0 +1,21 @@ +{ + "name": "Romanian", + "months": "Ianuarie|Februarie|Martie|Aprilie|Mai|Iunie|Iulie|August|Septembrie|Octombrie|Noiembrie|Decembrie", + "short_months": "Ian|Feb|Mar|Apr|Mai|Iun|Iul|Aug|Sep|Oct|Noi|Dec", + "weeks": "Duminică|Luni|Marți|Miercuri|Joi|Vineri|Sîmbătă", + "short_weeks": "Dum|Lun|Mar|Mie|Joi|Vin|Sîm", + "seasons": "Primăvara|Vara|Toamna|Iarna", + "constellations": "Berbec|Taur|Gemeni|Rac|Leu|Fecioară|Balanță|Scorpion|Săgetător|Capricorn|Vărsător|Pești", + "year": "1 an|%d ani", + "month": "1 lună|%d luni", + "week": "1 săptămînă|%d săptămîni", + "day": "1 zi|%d zile", + "hour": "1 oră|%d ore", + "minute": "1 minută|%d minute", + "second": "1 secundă|%d secunde", + "now": "chiar acum", + "ago": "%s în urmă", + "from_now": "%s de acum", + "before": "%s înainte", + "after": "%s după" +} diff --git a/vendor/github.com/dromara/carbon/v2/lang/ru.json b/vendor/github.com/dromara/carbon/v2/lang/ru.json new file mode 100644 index 000000000..744397443 --- /dev/null +++ b/vendor/github.com/dromara/carbon/v2/lang/ru.json @@ -0,0 +1,21 @@ +{ + "name": "Russian", + "months": "Январь|Февраль|Март|Апрель|Май|Июнь|Июль|Август|Сентябрь|Октябрь|Ноябрь|Декабрь", + "short_months": "Янв|Фев|Мар|Апр|Май|Июн|Июл|Авг|Сен|Окт|Ноя|Дек", + "weeks": "Воскресенье|Понедельник|Вторник|Среда|Четверг|Пятница|Суббота", + "short_weeks": "Вс|Пн|Вт|Ср|Чт|Пт|Сб", + "seasons": "Весна|Лето|Осень|Зима", + "constellations": "Овен|Телец|Близнецы|Рак|Лев|Дева|Весы|Скорпион|Стрелец|Козерог|Водолей|Рыбы", + "year": "1 год|2 года|3 года|4 года|%d лет", + "month": "1 месяц|2 месяца|3 месяца|4 месяца|%d месяцев", + "week": "1 неделя|2 недели|3 недели|4 недели|%d недель", + "day": "1 день|2 дня|3 дня|4 дня|%d дней", + "hour": "1 час|2 часа|3 часа|4 часа|%d часов", + "minute": "1 минуту|2 минуты|3 минуты|4 минуты|%d минут", + "second": "1 секунда|2 секунды|3 секунды|4 секунды|%d секунд", + "now": "сейчас", + "ago": "%s назад", + "from_now": "через %s", + "before": "за %s до", + "after": "через %s после" +} diff --git a/vendor/github.com/dromara/carbon/v2/lang/se.json b/vendor/github.com/dromara/carbon/v2/lang/se.json new file mode 100644 index 000000000..5b210026c --- /dev/null +++ b/vendor/github.com/dromara/carbon/v2/lang/se.json @@ -0,0 +1,21 @@ +{ + "name": "Swedish", + "months": "Januari|Februari|Mars|April|Maj|Juni|Juli|Augusti|September|Oktober|November|December", + "short_months": "Jan|Feb|Mars|April|Maj|Juni|Juli|Aug|Sep|Okt|Nov|Dec", + "weeks": "Söndag|Måndag|Tisdag|Onsdag|Torsdag|Fredag|Lördag", + "short_weeks": "Sön|Mån|Tis|Ons|Tors|Fre|Lör", + "seasons": "Vår|Sommar|Höst|Vinter", + "constellations": "Väduren|Oxen|Tvillingarna|Kräftan|Lejonet|Jungfrun|Vågen|Skorpionen|Skytten|Stenbocken|Vattumannen|Fiskarna", + "year": "1 år|%d år", + "month": "1 månad|%d månader", + "week": "1 vecka|%d veckor", + "day": "1 dag|%d dagar", + "hour": "1 timme|%d timmar", + "minute": "1 minut|%d minuter", + "second": "1 sekund|%d sekunder", + "now": "just nu", + "ago": "%s sedan", + "from_now": "%s fr.o.m. nu", + "before": "%s innan", + "after": "%s efter" +} \ No newline at end of file diff --git a/vendor/github.com/dromara/carbon/v2/lang/th.json b/vendor/github.com/dromara/carbon/v2/lang/th.json new file mode 100644 index 000000000..4ca378f41 --- /dev/null +++ b/vendor/github.com/dromara/carbon/v2/lang/th.json @@ -0,0 +1,21 @@ +{ + "name": "Thailand", + "months": "มกราคม|กุมภาพันธ์|มีนาคม|เมษายน|พฤษภาคม|มิถุนายน|กรกฎาคม|สิงหาคม|กันยายน|ตุลาคม|พฤศจิกายน|ธันวาคม", + "short_months": "ม.ค.|ก.พ.|มี.ค.|เม.ย.|พ.ค.|มิ.ย.|ก.ค.|ส.ค.|ก.ย.|ต.ค.|พ.ย.|ธ.ค.", + "weeks": "อาทิตย์|จันทร์|อังคาร|พุธ|พฤหัสบดี|ศุกร์|เสาร์", + "short_weeks": "อา.|จ.|อัง.|พ.|พฤ.|ศ.|ส.", + "seasons": "ฤดูใบไม้ผลิ|ฤดูร้อน|ฤดูใบไม้ร่วง|ฤดูหนาว", + "constellations": "เมษ|พฤษภ|เมถุน|กรกฎ|สิงห์|กันย์|ตุลย์|พิจิก|ธนู|มังกร|กุมภ์|มีน", + "year": "1 ปี|%d ปี", + "month": "1 เดือน|%d เดือน", + "week": "1 สัปดาห์|%d สัปดาห์", + "day": "1 วัน|%d วัน", + "hour": "1 ชั่วโมง|%d ชั่วโมง", + "minute": "1 นาที|%d นาที", + "second": "1 วินาที|%d วินาที", + "now": "ไม่กี่วินาทีที่แล้ว", + "ago": "%s ที่แล้ว", + "from_now": "อีก %s", + "before": "%s ก่อน", + "after": "%s หลังจากนี้" +} \ No newline at end of file diff --git a/vendor/github.com/dromara/carbon/v2/lang/tr.json b/vendor/github.com/dromara/carbon/v2/lang/tr.json new file mode 100644 index 000000000..c2bcddc83 --- /dev/null +++ b/vendor/github.com/dromara/carbon/v2/lang/tr.json @@ -0,0 +1,21 @@ +{ + "name": "Turkish", + "months": "Ocak|Şubat|Mart|Nisan|Mayıs|Haziran|Temmuz|Ağustos|Eylül|Ekim|Kasım|Aralık", + "short_months": "Oca|Şub|Mar|Nis|May|Haz|Tem|Ağu|Eyl|Eki|Kas|Ara", + "weeks": "Pazar|Pazartesi|Salı|Çarşamba|Perşembe|Cuma|Cumartesi", + "short_weeks": "Paz|Pts|Sal|Çrş|Per|Cum|Cts", + "seasons": "İlkbahar|Yaz|Sonbahar|Kış", + "constellations": "Koç|Boğa|İkizler|Yengeç|Aslan|Başak|Terazi|Akrep|Yay|Oğlak|Kova|Balık", + "year": "bir yıl|%d yıl", + "month": "bir ay|%d ay", + "week": "bir hafta|%d hafta", + "day": "bir gün|%d gün", + "hour": "bir saat|%d saat", + "minute": "bir dakika|%d dakika", + "second": "bir saniye|%d saniye", + "now": "az önce", + "ago": "%s evvel", + "from_now": "şu andan itibaren %s sonra", + "before": "%s önce", + "after": "%s sonra" +} diff --git a/vendor/github.com/dromara/carbon/v2/lang/uk.json b/vendor/github.com/dromara/carbon/v2/lang/uk.json new file mode 100644 index 000000000..e97915857 --- /dev/null +++ b/vendor/github.com/dromara/carbon/v2/lang/uk.json @@ -0,0 +1,21 @@ +{ + "name": "Ukrainian", + "months": "січня|лютого|березня|квітня|травня|червня|липня|серпня|вересня|жовтня|листопада|грудня", + "short_months": "січ|лют|бер|квіт|трав|черв|лип|серп|вер|жовт|лист|груд", + "weeks": "неділя|понеділок|вівторок|середа|четвер|п’ятниця|субота", + "short_weeks": "ндл|пнд|втр|срд|чтв|птн|сбт", + "seasons": "Весна|Літо|Осінь|Зима", + "constellations": "Овен|Телець|Близнюки|Рак|Лев|Діва|Терези|Скорпіон|Стрілець|Козоріг|Водолій|Риби", + "year": "рік|2 роки|3 роки|4 роки|%d років", + "month": "місяць|2 місяці|3 місяці|4 місяці|%d місяців", + "week": "tиждень|2 тижні|3 тижні|4 тижні|%d тижнів", + "day": "день|2 дні|3 дні|4 дні|%d днів", + "hour": "1 година|2 години|3 години|4 години|%d годин", + "minute": "1 хвилина|2 хвилини|3 хвилини|4 хвилини|%d хвилин", + "second": "1 секунда|2 секунди|3 секунди|4 секунди|%d секунд", + "now": "зараз", + "ago": "%s тому", + "from_now": "за %s", + "before": "%s до", + "after": "%s після" +} \ No newline at end of file diff --git a/vendor/github.com/dromara/carbon/v2/lang/vi.json b/vendor/github.com/dromara/carbon/v2/lang/vi.json new file mode 100644 index 000000000..87a8ee9cf --- /dev/null +++ b/vendor/github.com/dromara/carbon/v2/lang/vi.json @@ -0,0 +1,21 @@ +{ + "name": "VietNamese", + "months": "Tháng Một|Tháng Hai|Tháng Ba|Tháng Tư|Tháng Năm|Tháng Sáu|Tháng Bảy|Tháng Tám|Tháng Chín|Tháng Mười|Tháng Mười Một|Tháng Mười Hai", + "short_months": "Giêng|Hai|Ba|Bốn|Năm|Sáu|Bảy|Tám|Chìn|Mười|Một|Chạp", + "weeks": "Chủ Nhật|Thứ Hai|Thứ Ba|Thứ Tư|Thứ Năm|Thứ Sáu|Thứ Bảy", + "short_weeks": "CN|Hai|Ba|Tư|Năm|Sáu|Bảy", + "seasons": "Xuân|Hè|Thu|Đông", + "constellations": "Bạch Dương|Kim Ngưu|Song Tử|Cự Giải|Sư Tử|Xử Nữ|Thiên Bình|Bọ Cạp|Nhân Mã|Ma Kết|Bảo Bình|Song Ngư", + "year": "%d năm", + "month": "%d tháng", + "week": "%d tuần", + "day": "%d ngày", + "hour": "%d giờ", + "minute": "%d phút", + "second": "%d giây", + "now": "vừa xong", + "ago": "%s trước", + "from_now": "%s từ bây giờ", + "before": "%s trước", + "after": "%s sau" +} diff --git a/vendor/github.com/dromara/carbon/v2/lang/zh-CN.json b/vendor/github.com/dromara/carbon/v2/lang/zh-CN.json new file mode 100644 index 000000000..89036c563 --- /dev/null +++ b/vendor/github.com/dromara/carbon/v2/lang/zh-CN.json @@ -0,0 +1,21 @@ +{ + "name": "Simplified Chinese", + "months": "一月|二月|三月|四月|五月|六月|七月|八月|九月|十月|十一月|十二月", + "short_months": "1月|2月|3月|4月|5月|6月|7月|8月|9月|10月|11月|12月", + "weeks": "星期日|星期一|星期二|星期三|星期四|星期五|星期六", + "short_weeks": "周日|周一|周二|周三|周四|周五|周六", + "seasons": "春季|夏季|秋季|冬季", + "constellations": "白羊座|金牛座|双子座|巨蟹座|狮子座|处女座|天秤座|天蝎座|射手座|摩羯座|水瓶座|双鱼座", + "year": "%d 年", + "month": "%d 个月", + "week": "%d 周", + "day": "%d 天", + "hour": "%d 小时", + "minute": "%d 分钟", + "second": "%d 秒", + "now": "刚刚", + "ago": "%s前", + "from_now": "%s后", + "before": "%s前", + "after": "%s后" +} diff --git a/vendor/github.com/dromara/carbon/v2/lang/zh-TW.json b/vendor/github.com/dromara/carbon/v2/lang/zh-TW.json new file mode 100644 index 000000000..6e9c1f2c9 --- /dev/null +++ b/vendor/github.com/dromara/carbon/v2/lang/zh-TW.json @@ -0,0 +1,21 @@ +{ + "name": "Traditional Chinese", + "months": "一月|二月|三月|四月|五月|六月|七月|八月|九月|十月|十一月|十二月", + "short_months": "1月|2月|3月|4月|5月|6月|7月|8月|9月|10月|11月|12月", + "weeks": "星期日|星期一|星期二|星期三|星期四|星期五|星期六", + "short_weeks": "週日|週一|週二|週三|週四|週五|週六", + "seasons": "春季|夏季|秋季|冬季", + "constellations": "白羊座|金牛座|雙子座|巨蟹座|獅子座|處女座|天秤座|天蠍座|射手座|摩羯座|水瓶座|雙魚座", + "year": "%d 年", + "month": "%d 個月", + "week": "%d 週", + "day": "%d 天", + "hour": "%d 小時", + "minute": "%d 分鐘", + "second": "%d 秒", + "now": "剛剛", + "ago": "%s前", + "from_now": "%s後", + "before": "%s前", + "after": "%s後" +} diff --git a/vendor/github.com/dromara/carbon/v2/language.go b/vendor/github.com/dromara/carbon/v2/language.go new file mode 100644 index 000000000..e16e45225 --- /dev/null +++ b/vendor/github.com/dromara/carbon/v2/language.go @@ -0,0 +1,109 @@ +package carbon + +import ( + "embed" + "encoding/json" + "fmt" + "strconv" + "strings" + "sync" +) + +//go:embed lang +var fs embed.FS + +var ( + // invalid locale error + // 无效的区域错误 + invalidLocaleError = func(locale string) error { + return fmt.Errorf("invalid locale file %q, please make sure the json file exists and is valid", locale) + } +) + +// Language defines a Language struct. +// 定义 Language 结构体 +type Language struct { + dir string + locale string + resources map[string]string + Error error + rw *sync.RWMutex +} + +// NewLanguage returns a new Language instance. +// 初始化 Language 结构体 +func NewLanguage() *Language { + return &Language{ + dir: "lang/", + locale: defaultLocale, + resources: make(map[string]string), + rw: new(sync.RWMutex), + } +} + +// SetLanguage sets language. +// 设置语言对象 +func SetLanguage(lang *Language) Carbon { + c := NewCarbon() + lang.SetLocale(lang.locale) + c.lang, c.Error = lang, lang.Error + return c +} + +// SetLocale sets language locale. +// 设置区域 +func (lang *Language) SetLocale(locale string) *Language { + lang.rw.Lock() + defer lang.rw.Unlock() + + if len(lang.resources) != 0 { + return lang + } + lang.locale = locale + fileName := lang.dir + locale + ".json" + bytes, err := fs.ReadFile(fileName) + if err != nil { + lang.Error = invalidLocaleError(fileName) + return lang + } + _ = json.Unmarshal(bytes, &lang.resources) + return lang +} + +// SetResources sets language resources. +// 设置资源 +func (lang *Language) SetResources(resources map[string]string) *Language { + lang.rw.Lock() + defer lang.rw.Unlock() + + if len(lang.resources) == 0 { + lang.resources = resources + return lang + } + for k, v := range resources { + if _, ok := lang.resources[k]; ok { + lang.resources[k] = v + } + } + return lang +} + +// returns a translated string. +// 翻译转换 +func (lang *Language) translate(unit string, value int64) string { + if len(lang.resources) == 0 { + lang.SetLocale(defaultLocale) + } + slice := strings.Split(lang.resources[unit], "|") + number := getAbsValue(value) + if len(slice) == 1 { + return strings.Replace(slice[0], "%d", strconv.FormatInt(value, 10), 1) + } + if int64(len(slice)) <= number { + return strings.Replace(slice[len(slice)-1], "%d", strconv.FormatInt(value, 10), 1) + } + if !strings.Contains(slice[number-1], "%d") && value < 0 { + return "-" + slice[number-1] + } + return strings.Replace(slice[number-1], "%d", strconv.FormatInt(value, 10), 1) +} diff --git a/vendor/github.com/dromara/carbon/v2/outputer.go b/vendor/github.com/dromara/carbon/v2/outputer.go new file mode 100644 index 000000000..ebad07ad0 --- /dev/null +++ b/vendor/github.com/dromara/carbon/v2/outputer.go @@ -0,0 +1,892 @@ +package carbon + +import ( + "bytes" + "fmt" + "strconv" + "strings" +) + +// String implements the interface Stringer for Carbon struct. +// 实现 Stringer 接口 +func (c Carbon) String() string { + return c.Layout(c.layout, c.Location()) +} + +// GoString implements fmt.GoStringer and formats c to be printed in Go source code. +// 实现 fmt.GoStringer 接口,并格式化 c 以在 Go 源代码中打印 +func (c Carbon) GoString() string { + if c.IsInvalid() { + return "" + } + return c.StdTime().GoString() +} + +// ToString outputs a string in "2006-01-02 15:04:05.999999999 -0700 MST" layout. +// 输出 "2006-01-02 15:04:05.999999999 -0700 MST" 格式字符串 +func (c Carbon) ToString(timezone ...string) string { + if c.IsInvalid() { + return "" + } + if len(timezone) > 0 { + c.loc, c.Error = getLocationByTimezone(timezone[0]) + } + return c.StdTime().String() +} + +// ToMonthString outputs a string in month layout like "January", i18n is supported. +// 输出完整月份字符串,支持i18n +func (c Carbon) ToMonthString(timezone ...string) string { + if c.IsInvalid() { + return "" + } + if len(timezone) > 0 { + c.loc, c.Error = getLocationByTimezone(timezone[0]) + } + if len(c.lang.resources) == 0 { + c.lang.SetLocale(defaultLocale) + } + c.lang.rw.RLock() + defer c.lang.rw.RUnlock() + if resources, ok := c.lang.resources["months"]; ok { + slice := strings.Split(resources, "|") + if len(slice) == MonthsPerYear { + return slice[c.Month()-1] + } + } + return "" +} + +// ToShortMonthString outputs a string in short month layout like "Jan", i18n is supported. +// 输出缩写月份字符串,支持i18n +func (c Carbon) ToShortMonthString(timezone ...string) string { + if c.IsInvalid() { + return "" + } + if len(timezone) > 0 { + c.loc, c.Error = getLocationByTimezone(timezone[0]) + } + if len(c.lang.resources) == 0 { + c.lang.SetLocale(defaultLocale) + } + c.lang.rw.RLock() + defer c.lang.rw.RUnlock() + if resources, ok := c.lang.resources["short_months"]; ok { + slice := strings.Split(resources, "|") + if len(slice) == MonthsPerYear { + return slice[c.Month()-1] + } + } + return "" +} + +// ToWeekString outputs a string in week layout like "Sunday", i18n is supported. +// 输出完整星期字符串,支持i18n +func (c Carbon) ToWeekString(timezone ...string) string { + if c.IsInvalid() { + return "" + } + if len(timezone) > 0 { + c.loc, c.Error = getLocationByTimezone(timezone[0]) + } + if len(c.lang.resources) == 0 { + c.lang.SetLocale(defaultLocale) + } + c.lang.rw.RLock() + defer c.lang.rw.RUnlock() + if resources, ok := c.lang.resources["weeks"]; ok { + slice := strings.Split(resources, "|") + if len(slice) == DaysPerWeek { + return slice[c.DayOfWeek()%DaysPerWeek] + } + } + return "" +} + +// ToShortWeekString outputs a string in short week layout like "Sun", i18n is supported. +// 输出缩写星期字符串,支持i18n +func (c Carbon) ToShortWeekString(timezone ...string) string { + if c.IsInvalid() { + return "" + } + if len(timezone) > 0 { + c.loc, c.Error = getLocationByTimezone(timezone[0]) + } + if len(c.lang.resources) == 0 { + c.lang.SetLocale(defaultLocale) + } + c.lang.rw.RLock() + defer c.lang.rw.RUnlock() + if resources, ok := c.lang.resources["short_weeks"]; ok { + slice := strings.Split(resources, "|") + if len(slice) == DaysPerWeek { + return slice[c.DayOfWeek()%DaysPerWeek] + } + } + return "" +} + +// ToDayDateTimeString outputs a string in "Mon, Jan 2, 2006 3:04 PM" layout. +// 输出 "Mon, Jan 2, 2006 3:04 PM" 格式字符串 +func (c Carbon) ToDayDateTimeString(timezone ...string) string { + if c.IsInvalid() { + return "" + } + if len(timezone) > 0 { + c.loc, c.Error = getLocationByTimezone(timezone[0]) + } + return c.StdTime().Format(DayDateTimeLayout) +} + +// ToDateTimeString outputs a string in "2006-01-02 15:04:05" layout. +// 输出 "2006-01-02 15:04:05" 格式字符串 +func (c Carbon) ToDateTimeString(timezone ...string) string { + if c.IsInvalid() { + return "" + } + if len(timezone) > 0 { + c.loc, c.Error = getLocationByTimezone(timezone[0]) + } + return c.StdTime().Format(DateTimeLayout) +} + +// ToDateTimeMilliString outputs a string in "2006-01-02 15:04:05.999" layout. +// 输出 "2006-01-02 15:04:05.999" 格式字符串 +func (c Carbon) ToDateTimeMilliString(timezone ...string) string { + if c.IsInvalid() { + return "" + } + if len(timezone) > 0 { + c.loc, c.Error = getLocationByTimezone(timezone[0]) + } + return c.StdTime().Format(DateTimeMilliLayout) +} + +// ToDateTimeMicroString outputs a string in "2006-01-02 15:04:05.999999" layout. +// 输出 "2006-01-02 15:04:05.999999" 格式字符串 +func (c Carbon) ToDateTimeMicroString(timezone ...string) string { + if c.IsInvalid() { + return "" + } + if len(timezone) > 0 { + c.loc, c.Error = getLocationByTimezone(timezone[0]) + } + return c.StdTime().Format(DateTimeMicroLayout) +} + +// ToDateTimeNanoString outputs a string in "2006-01-02 15:04:05.999999999" layout. +// 输出 "2006-01-02 15:04:05.999999999" 格式字符串 +func (c Carbon) ToDateTimeNanoString(timezone ...string) string { + if c.IsInvalid() { + return "" + } + if len(timezone) > 0 { + c.loc, c.Error = getLocationByTimezone(timezone[0]) + } + return c.StdTime().Format(DateTimeNanoLayout) +} + +// ToShortDateTimeString outputs a string in "20060102150405" layout. +// 输出 "20060102150405" 格式字符串 +func (c Carbon) ToShortDateTimeString(timezone ...string) string { + if c.IsInvalid() { + return "" + } + if len(timezone) > 0 { + c.loc, c.Error = getLocationByTimezone(timezone[0]) + } + return c.StdTime().Format(ShortDateTimeLayout) +} + +// ToShortDateTimeMilliString outputs a string in "20060102150405.999" layout. +// 输出 "20060102150405.999" 格式字符串 +func (c Carbon) ToShortDateTimeMilliString(timezone ...string) string { + if c.IsInvalid() { + return "" + } + if len(timezone) > 0 { + c.loc, c.Error = getLocationByTimezone(timezone[0]) + } + return c.StdTime().Format(ShortDateTimeMilliLayout) +} + +// ToShortDateTimeMicroString outputs a string in "20060102150405.999999" layout. +// 输出 "20060102150405.999999" 格式字符串 +func (c Carbon) ToShortDateTimeMicroString(timezone ...string) string { + if c.IsInvalid() { + return "" + } + if len(timezone) > 0 { + c.loc, c.Error = getLocationByTimezone(timezone[0]) + } + return c.StdTime().Format(ShortDateTimeMicroLayout) +} + +// ToShortDateTimeNanoString outputs a string in "20060102150405.999999999" layout. +// 输出 "20060102150405.999999999" 格式字符串 +func (c Carbon) ToShortDateTimeNanoString(timezone ...string) string { + if c.IsInvalid() { + return "" + } + if len(timezone) > 0 { + c.loc, c.Error = getLocationByTimezone(timezone[0]) + } + return c.StdTime().Format(ShortDateTimeNanoLayout) +} + +// ToDateString outputs a string in "2006-01-02" layout. +// 输出 "2006-01-02" 格式字符串 +func (c Carbon) ToDateString(timezone ...string) string { + if c.IsInvalid() { + return "" + } + if len(timezone) > 0 { + c.loc, c.Error = getLocationByTimezone(timezone[0]) + } + return c.StdTime().Format(DateLayout) +} + +// ToDateMilliString outputs a string in "2006-01-02.999" layout. +// 输出 "2006-01-02.999" 格式字符串 +func (c Carbon) ToDateMilliString(timezone ...string) string { + if c.IsInvalid() { + return "" + } + if len(timezone) > 0 { + c.loc, c.Error = getLocationByTimezone(timezone[0]) + } + return c.StdTime().Format(DateMilliLayout) +} + +// ToDateMicroString outputs a string in "2006-01-02.999999" layout. +// 输出 "2006-01-02.999999" 格式字符串 +func (c Carbon) ToDateMicroString(timezone ...string) string { + if c.IsInvalid() { + return "" + } + if len(timezone) > 0 { + c.loc, c.Error = getLocationByTimezone(timezone[0]) + } + return c.StdTime().Format(DateMicroLayout) +} + +// ToDateNanoString outputs a string in "2006-01-02.999999999" layout. +// 输出 "2006-01-02.999999999" 格式字符串 +func (c Carbon) ToDateNanoString(timezone ...string) string { + if c.IsInvalid() { + return "" + } + if len(timezone) > 0 { + c.loc, c.Error = getLocationByTimezone(timezone[0]) + } + return c.StdTime().Format(DateNanoLayout) +} + +// ToShortDateString outputs a string in "20060102" layout. +// 输出 "20060102" 格式字符串 +func (c Carbon) ToShortDateString(timezone ...string) string { + if c.IsInvalid() { + return "" + } + if len(timezone) > 0 { + c.loc, c.Error = getLocationByTimezone(timezone[0]) + } + return c.StdTime().Format(ShortDateLayout) +} + +// ToShortDateMilliString outputs a string in "20060102.999" layout. +// 输出 "20060102.999" 格式字符串 +func (c Carbon) ToShortDateMilliString(timezone ...string) string { + if c.IsInvalid() { + return "" + } + if len(timezone) > 0 { + c.loc, c.Error = getLocationByTimezone(timezone[0]) + } + return c.StdTime().Format(ShortDateMilliLayout) +} + +// ToShortDateMicroString outputs a string in "20060102.999999" layout. +// 输出 "20060102.999999" 格式字符串 +func (c Carbon) ToShortDateMicroString(timezone ...string) string { + if c.IsInvalid() { + return "" + } + if len(timezone) > 0 { + c.loc, c.Error = getLocationByTimezone(timezone[0]) + } + return c.StdTime().Format(ShortDateMicroLayout) +} + +// ToShortDateNanoString outputs a string in "20060102.999999999" layout. +// 输出 "20060102.999999999" 格式字符串 +func (c Carbon) ToShortDateNanoString(timezone ...string) string { + if c.IsInvalid() { + return "" + } + if len(timezone) > 0 { + c.loc, c.Error = getLocationByTimezone(timezone[0]) + } + return c.StdTime().Format(ShortDateNanoLayout) +} + +// ToTimeString outputs a string in "15:04:05" layout. +// 输出 "15:04:05" 格式字符串 +func (c Carbon) ToTimeString(timezone ...string) string { + if c.IsInvalid() { + return "" + } + if len(timezone) > 0 { + c.loc, c.Error = getLocationByTimezone(timezone[0]) + } + return c.StdTime().Format(TimeLayout) +} + +// ToTimeMilliString outputs a string in "15:04:05.999" layout. +// 输出 "15:04:05.999" 格式字符串 +func (c Carbon) ToTimeMilliString(timezone ...string) string { + if c.IsInvalid() { + return "" + } + if len(timezone) > 0 { + c.loc, c.Error = getLocationByTimezone(timezone[0]) + } + return c.StdTime().Format(TimeMilliLayout) +} + +// ToTimeMicroString outputs a string in "15:04:05.999999" layout. +// 输出 "15:04:05.999999" 格式字符串 +func (c Carbon) ToTimeMicroString(timezone ...string) string { + if c.IsInvalid() { + return "" + } + if len(timezone) > 0 { + c.loc, c.Error = getLocationByTimezone(timezone[0]) + } + return c.StdTime().Format(TimeMicroLayout) +} + +// ToTimeNanoString outputs a string in "15:04:05.999999999" layout. +// 输出 "15:04:05.999999999" 格式字符串 +func (c Carbon) ToTimeNanoString(timezone ...string) string { + if c.IsInvalid() { + return "" + } + if len(timezone) > 0 { + c.loc, c.Error = getLocationByTimezone(timezone[0]) + } + return c.StdTime().Format(TimeNanoLayout) +} + +// ToShortTimeString outputs a string in "150405" layout. +// 输出 "150405" 格式字符串 +func (c Carbon) ToShortTimeString(timezone ...string) string { + if c.IsInvalid() { + return "" + } + if len(timezone) > 0 { + c.loc, c.Error = getLocationByTimezone(timezone[0]) + } + return c.StdTime().Format(ShortTimeLayout) +} + +// ToShortTimeMilliString outputs a string in "150405.999" layout. +// 输出 "150405.999" 格式字符串 +func (c Carbon) ToShortTimeMilliString(timezone ...string) string { + if c.IsInvalid() { + return "" + } + if len(timezone) > 0 { + c.loc, c.Error = getLocationByTimezone(timezone[0]) + } + return c.StdTime().Format(ShortTimeMilliLayout) +} + +// ToShortTimeMicroString outputs a string in "150405.999999" layout. +// 输出 "150405.999999" 格式字符串 +func (c Carbon) ToShortTimeMicroString(timezone ...string) string { + if c.IsInvalid() { + return "" + } + if len(timezone) > 0 { + c.loc, c.Error = getLocationByTimezone(timezone[0]) + } + return c.StdTime().Format(ShortTimeMicroLayout) +} + +// ToShortTimeNanoString outputs a string in "150405.999999999" layout. +// 输出 "150405.999999999" 格式字符串 +func (c Carbon) ToShortTimeNanoString(timezone ...string) string { + if c.IsInvalid() { + return "" + } + if len(timezone) > 0 { + c.loc, c.Error = getLocationByTimezone(timezone[0]) + } + return c.StdTime().Format(ShortTimeNanoLayout) +} + +// ToAtomString outputs a string in "2006-01-02T15:04:05Z07:00" layout. +// 输出 "2006-01-02T15:04:05Z07:00" 格式字符串 +func (c Carbon) ToAtomString(timezone ...string) string { + if c.IsInvalid() { + return "" + } + if len(timezone) > 0 { + c.loc, c.Error = getLocationByTimezone(timezone[0]) + } + return c.StdTime().Format(AtomLayout) +} + +// ToAnsicString outputs a string in "Mon Jan _2 15:04:05 2006" layout. +// 输出 "Mon Jan _2 15:04:05 2006" 格式字符串 +func (c Carbon) ToAnsicString(timezone ...string) string { + if c.IsInvalid() { + return "" + } + if len(timezone) > 0 { + c.loc, c.Error = getLocationByTimezone(timezone[0]) + } + return c.StdTime().Format(ANSICLayout) +} + +// ToCookieString outputs a string in "Monday, 02-Jan-2006 15:04:05 MST" layout. +// 输出 "Monday, 02-Jan-2006 15:04:05 MST" 格式字符串 +func (c Carbon) ToCookieString(timezone ...string) string { + if c.IsInvalid() { + return "" + } + if len(timezone) > 0 { + c.loc, c.Error = getLocationByTimezone(timezone[0]) + } + return c.StdTime().Format(CookieLayout) +} + +// ToRssString outputs a string in "Mon, 02 Jan 2006 15:04:05 -0700" format. +// 输出 "Mon, 02 Jan 2006 15:04:05 -0700" 格式字符串 +func (c Carbon) ToRssString(timezone ...string) string { + if c.IsInvalid() { + return "" + } + if len(timezone) > 0 { + c.loc, c.Error = getLocationByTimezone(timezone[0]) + } + return c.StdTime().Format(RssLayout) +} + +// ToW3cString outputs a string in "2006-01-02T15:04:05Z07:00" layout. +// 输出 "2006-01-02T15:04:05Z07:00" 格式字符串 +func (c Carbon) ToW3cString(timezone ...string) string { + if c.IsInvalid() { + return "" + } + if len(timezone) > 0 { + c.loc, c.Error = getLocationByTimezone(timezone[0]) + } + return c.StdTime().Format(W3cLayout) +} + +// ToUnixDateString outputs a string in "Mon Jan _2 15:04:05 MST 2006" layout. +// 输出 "Mon Jan _2 15:04:05 MST 2006" 格式字符串 +func (c Carbon) ToUnixDateString(timezone ...string) string { + if c.IsInvalid() { + return "" + } + if len(timezone) > 0 { + c.loc, c.Error = getLocationByTimezone(timezone[0]) + } + return c.StdTime().Format(UnixDateLayout) +} + +// ToRubyDateString outputs a string in "Mon Jan 02 15:04:05 -0700 2006" layout. +// 输出 "Mon Jan 02 15:04:05 -0700 2006" 格式字符串 +func (c Carbon) ToRubyDateString(timezone ...string) string { + if c.IsInvalid() { + return "" + } + if len(timezone) > 0 { + c.loc, c.Error = getLocationByTimezone(timezone[0]) + } + return c.StdTime().Format(RubyDateLayout) +} + +// ToKitchenString outputs a string in "3:04PM" layout. +// 输出 "3:04PM" 格式字符串 +func (c Carbon) ToKitchenString(timezone ...string) string { + if c.IsInvalid() { + return "" + } + if len(timezone) > 0 { + c.loc, c.Error = getLocationByTimezone(timezone[0]) + } + return c.StdTime().Format(KitchenLayout) +} + +// ToIso8601String outputs a string in "2006-01-02T15:04:05-07:00" layout. +// 输出 "2006-01-02T15:04:05-07:00" 格式字符串 +func (c Carbon) ToIso8601String(timezone ...string) string { + if c.IsInvalid() { + return "" + } + if len(timezone) > 0 { + c.loc, c.Error = getLocationByTimezone(timezone[0]) + } + return c.StdTime().Format(ISO8601Layout) +} + +// ToIso8601MilliString outputs a string in "2006-01-02T15:04:05.999-07:00" layout. +// 输出 "2006-01-02T15:04:05.999-07:00" 格式字符串 +func (c Carbon) ToIso8601MilliString(timezone ...string) string { + if c.IsInvalid() { + return "" + } + if len(timezone) > 0 { + c.loc, c.Error = getLocationByTimezone(timezone[0]) + } + return c.StdTime().Format(ISO8601MilliLayout) +} + +// ToIso8601MicroString outputs a string in "2006-01-02T15:04:05.999999-07:00" layout. +// 输出 "2006-01-02T15:04:05.999999-07:00" 格式字符串 +func (c Carbon) ToIso8601MicroString(timezone ...string) string { + if c.IsInvalid() { + return "" + } + if len(timezone) > 0 { + c.loc, c.Error = getLocationByTimezone(timezone[0]) + } + return c.StdTime().Format(ISO8601MicroLayout) +} + +// ToIso8601NanoString outputs a string in "2006-01-02T15:04:05.999999999-07:00" layout. +// 输出 "2006-01-02T15:04:05.999999999-07:00" 格式字符串 +func (c Carbon) ToIso8601NanoString(timezone ...string) string { + if c.IsInvalid() { + return "" + } + if len(timezone) > 0 { + c.loc, c.Error = getLocationByTimezone(timezone[0]) + } + return c.StdTime().Format(ISO8601NanoLayout) +} + +// ToIso8601ZuluString outputs a string in "2006-01-02T15:04:05Z" layout. +// 输出 "2006-01-02T15:04:05Z" 格式字符串 +func (c Carbon) ToIso8601ZuluString(timezone ...string) string { + if c.IsInvalid() { + return "" + } + if len(timezone) > 0 { + c.loc, c.Error = getLocationByTimezone(timezone[0]) + } + return c.StdTime().Format(ISO8601ZuluLayout) +} + +// ToIso8601ZuluMilliString outputs a string in "2006-01-02T15:04:05.999Z" layout. +// 输出 "2006-01-02T15:04:05.999Z" 格式字符串 +func (c Carbon) ToIso8601ZuluMilliString(timezone ...string) string { + if c.IsInvalid() { + return "" + } + if len(timezone) > 0 { + c.loc, c.Error = getLocationByTimezone(timezone[0]) + } + return c.StdTime().Format(ISO8601ZuluMilliLayout) +} + +// ToIso8601ZuluMicroString outputs a string in "2006-01-02T15:04:05.999999Z" layout. +// 输出 "2006-01-02T15:04:05.999999Z" 格式字符串 +func (c Carbon) ToIso8601ZuluMicroString(timezone ...string) string { + if c.IsInvalid() { + return "" + } + if len(timezone) > 0 { + c.loc, c.Error = getLocationByTimezone(timezone[0]) + } + return c.StdTime().Format(ISO8601ZuluMicroLayout) +} + +// ToIso8601ZuluNanoString outputs a string in "2006-01-02T15:04:05.999999999Z" layout. +// 输出 "2006-01-02T15:04:05.999999999Z" 格式字符串 +func (c Carbon) ToIso8601ZuluNanoString(timezone ...string) string { + if c.IsInvalid() { + return "" + } + if len(timezone) > 0 { + c.loc, c.Error = getLocationByTimezone(timezone[0]) + } + return c.StdTime().Format(ISO8601ZuluNanoLayout) +} + +// ToRfc822String outputs a string in "02 Jan 06 15:04 MST" layout. +// 输出 "02 Jan 06 15:04 MST" 格式字符串 +func (c Carbon) ToRfc822String(timezone ...string) string { + if c.IsInvalid() { + return "" + } + if len(timezone) > 0 { + c.loc, c.Error = getLocationByTimezone(timezone[0]) + } + return c.StdTime().Format(RFC822Layout) +} + +// ToRfc822zString outputs a string in "02 Jan 06 15:04 -0700" layout. +// 输出 "02 Jan 06 15:04 -0700" 格式字符串 +func (c Carbon) ToRfc822zString(timezone ...string) string { + if c.IsInvalid() { + return "" + } + if len(timezone) > 0 { + c.loc, c.Error = getLocationByTimezone(timezone[0]) + } + return c.StdTime().Format(RFC822ZLayout) +} + +// ToRfc850String outputs a string in "Monday, 02-Jan-06 15:04:05 MST" layout. +// 输出 "Monday, 02-Jan-06 15:04:05 MST" 格式字符串 +func (c Carbon) ToRfc850String(timezone ...string) string { + if c.IsInvalid() { + return "" + } + if len(timezone) > 0 { + c.loc, c.Error = getLocationByTimezone(timezone[0]) + } + return c.StdTime().Format(RFC850Layout) +} + +// ToRfc1036String outputs a string in "Mon, 02 Jan 06 15:04:05 -0700" layout. +// 输出 "Mon, 02 Jan 06 15:04:05 -0700" 格式字符串 +func (c Carbon) ToRfc1036String(timezone ...string) string { + if c.IsInvalid() { + return "" + } + if len(timezone) > 0 { + c.loc, c.Error = getLocationByTimezone(timezone[0]) + } + return c.StdTime().Format(RFC1036Layout) +} + +// ToRfc1123String outputs a string in "Mon, 02 Jan 2006 15:04:05 MST" layout. +// 输出 "Mon, 02 Jan 2006 15:04:05 MST" 格式字符串 +func (c Carbon) ToRfc1123String(timezone ...string) string { + if c.IsInvalid() { + return "" + } + if len(timezone) > 0 { + c.loc, c.Error = getLocationByTimezone(timezone[0]) + } + return c.StdTime().Format(RFC1123Layout) +} + +// ToRfc1123zString outputs a string in "Mon, 02 Jan 2006 15:04:05 -0700" layout. +// 输出 "Mon, 02 Jan 2006 15:04:05 -0700" 格式字符串 +func (c Carbon) ToRfc1123zString(timezone ...string) string { + if c.IsInvalid() { + return "" + } + if len(timezone) > 0 { + c.loc, c.Error = getLocationByTimezone(timezone[0]) + } + return c.StdTime().Format(RFC1123ZLayout) +} + +// ToRfc2822String outputs a string in "Mon, 02 Jan 2006 15:04:05 -0700" layout. +// 输出 "Mon, 02 Jan 2006 15:04:05 -0700" 格式字符串 +func (c Carbon) ToRfc2822String(timezone ...string) string { + if c.IsInvalid() { + return "" + } + if len(timezone) > 0 { + c.loc, c.Error = getLocationByTimezone(timezone[0]) + } + return c.StdTime().Format(RFC2822Layout) +} + +// ToRfc3339String outputs a string in "2006-01-02T15:04:05Z07:00" layout. +// 输出 "2006-01-02T15:04:05Z07:00" 格式字符串 +func (c Carbon) ToRfc3339String(timezone ...string) string { + if c.IsInvalid() { + return "" + } + if len(timezone) > 0 { + c.loc, c.Error = getLocationByTimezone(timezone[0]) + } + return c.StdTime().Format(RFC3339Layout) +} + +// ToRfc3339MilliString outputs a string in "2006-01-02T15:04:05.999Z07:00" layout. +// 输出 "2006-01-02T15:04:05.999Z07:00" 格式字符串 +func (c Carbon) ToRfc3339MilliString(timezone ...string) string { + if c.IsInvalid() { + return "" + } + if len(timezone) > 0 { + c.loc, c.Error = getLocationByTimezone(timezone[0]) + } + return c.StdTime().Format(RFC3339MilliLayout) +} + +// ToRfc3339MicroString outputs a string in "2006-01-02T15:04:05.999999Z07:00" layout. +// 输出 "2006-01-02T15:04:05.999999Z07:00" 格式字符串 +func (c Carbon) ToRfc3339MicroString(timezone ...string) string { + if c.IsInvalid() { + return "" + } + if len(timezone) > 0 { + c.loc, c.Error = getLocationByTimezone(timezone[0]) + } + return c.StdTime().Format(RFC3339MicroLayout) +} + +// ToRfc3339NanoString outputs a string in "2006-01-02T15:04:05.999999999Z07:00" layout. +// 输出 "2006-01-02T15:04:05.999999999Z07:00" 格式字符串 +func (c Carbon) ToRfc3339NanoString(timezone ...string) string { + if c.IsInvalid() { + return "" + } + if len(timezone) > 0 { + c.loc, c.Error = getLocationByTimezone(timezone[0]) + } + return c.StdTime().Format(RFC3339NanoLayout) +} + +// ToRfc7231String outputs a string in "Mon, 02 Jan 2006 15:04:05 GMT" layout. +// 输出 "Mon, 02 Jan 2006 15:04:05 GMT" 格式字符串 +func (c Carbon) ToRfc7231String(timezone ...string) string { + if c.IsInvalid() { + return "" + } + if len(timezone) > 0 { + c.loc, c.Error = getLocationByTimezone(timezone[0]) + } + return c.StdTime().Format(RFC7231Layout) +} + +// ToFormattedDateString outputs a string in "Jan 2, 2006" layout. +// 输出 "Jan 2, 2006" 格式字符串 +func (c Carbon) ToFormattedDateString(timezone ...string) string { + if c.IsInvalid() { + return "" + } + if len(timezone) > 0 { + c.loc, c.Error = getLocationByTimezone(timezone[0]) + } + return c.StdTime().Format(FormattedDateLayout) +} + +// ToFormattedDayDateString outputs a string in "Mon, Jan 2, 2006" layout. +// 输出 "Jan 2, 2006" 格式字符串 +func (c Carbon) ToFormattedDayDateString(timezone ...string) string { + if c.IsInvalid() { + return "" + } + if len(timezone) > 0 { + c.loc, c.Error = getLocationByTimezone(timezone[0]) + } + return c.StdTime().Format(FormattedDayDateLayout) +} + +// Layout outputs a string by layout. +// 输出指定布局模板的时间字符串 +func (c Carbon) Layout(layout string, timezone ...string) string { + if c.IsInvalid() { + return "" + } + if len(timezone) > 0 { + c.loc, c.Error = getLocationByTimezone(timezone[0]) + } + return c.StdTime().Format(layout) +} + +// Format outputs a string by format. +// 输出指定格式模板的时间字符串 +func (c Carbon) Format(format string, timezone ...string) string { + if c.IsInvalid() { + return "" + } + if len(timezone) > 0 { + c.loc, c.Error = getLocationByTimezone(timezone[0]) + } + buffer := bytes.NewBuffer(nil) + for i := 0; i < len(format); i++ { + if layout, ok := formats[format[i]]; ok { + // support for i18n specific symbols + switch format[i] { + case 'l': // week, such as Monday + buffer.WriteString(c.ToWeekString()) + case 'D': // short week, such as Mon + buffer.WriteString(c.ToShortWeekString()) + case 'F': // month, such as January + buffer.WriteString(c.ToMonthString()) + case 'M': // short month, such as Jan + buffer.WriteString(c.ToShortMonthString()) + case 'U': // timestamp with second, such as 1596604455 + buffer.WriteString(strconv.FormatInt(c.Timestamp(), 10)) + case 'V': // timestamp with millisecond, such as 1596604455000 + buffer.WriteString(strconv.FormatInt(c.TimestampMilli(), 10)) + case 'X': // timestamp with microsecond, such as 1596604455000000 + buffer.WriteString(strconv.FormatInt(c.TimestampMicro(), 10)) + case 'Z': // timestamp with nanoseconds, such as 1596604455000000000 + buffer.WriteString(strconv.FormatInt(c.TimestampNano(), 10)) + default: // common symbols + buffer.WriteString(c.StdTime().Format(layout)) + } + } else { + switch format[i] { + case '\\': // raw output, no parse + buffer.WriteByte(format[i+1]) + i++ + continue + case 'W': // week number of the year in ISO-8601 format, ranging from 01-52 + week := fmt.Sprintf("%02d", c.WeekOfYear()) + buffer.WriteString(week) + case 'N': // day of the week as a number in ISO-8601 format, ranging from 01-7 + week := fmt.Sprintf("%02d", c.DayOfWeek()) + buffer.WriteString(week) + case 'S': // abbreviated suffix for the day of the month, such as st, nd, rd, th + suffix := "th" + switch c.Day() { + case 1, 21, 31: + suffix = "st" + case 2, 22: + suffix = "nd" + case 3, 23: + suffix = "rd" + } + buffer.WriteString(suffix) + case 'L': // whether it is a leap year, if it is a leap year, it is 1, otherwise it is 0 + if c.IsLeapYear() { + buffer.WriteString("1") + } else { + buffer.WriteString("0") + } + case 'G': // 24-hour format, no padding, ranging from 0-23 + buffer.WriteString(strconv.Itoa(c.Hour())) + case 'v': // current millisecond, such as 999 + s := c.Layout(".999") + buffer.WriteString(strings.Trim(s, ".")) + case 'u': // current microsecond, such as 999999 + s := c.Layout(".999999") + buffer.WriteString(strings.Trim(s, ".")) + case 'x': // current nanosecond, such as 999999999 + s := c.Layout(".999999999") + buffer.WriteString(strings.Trim(s, ".")) + case 'w': // day of the week represented by the number, ranging from 0-6 + buffer.WriteString(strconv.Itoa(c.DayOfWeek() - 1)) + case 't': // number of days in the month, ranging from 28-31 + buffer.WriteString(strconv.Itoa(c.DaysInMonth())) + case 'z': // day of the year, ranging from 0-365 + buffer.WriteString(strconv.Itoa(c.DayOfYear() - 1)) + case 'e': // current location, such as UTC,GMT,Atlantic/Azores + buffer.WriteString(c.Location()) + case 'Q': // current quarter, ranging from 1-4 + buffer.WriteString(strconv.Itoa(c.Quarter())) + case 'C': // current century, ranging from 0-99 + buffer.WriteString(strconv.Itoa(c.Century())) + default: + buffer.WriteByte(format[i]) + } + } + } + return buffer.String() +} diff --git a/vendor/github.com/dromara/carbon/v2/parser.go b/vendor/github.com/dromara/carbon/v2/parser.go new file mode 100644 index 000000000..86517f590 --- /dev/null +++ b/vendor/github.com/dromara/carbon/v2/parser.go @@ -0,0 +1,104 @@ +package carbon + +import ( + "strconv" + "time" +) + +// Parse parses a standard time string as a Carbon instance. +// 将标准格式时间字符串解析成 Carbon 实例 +func (c Carbon) Parse(value string, timezone ...string) Carbon { + if len(value) == 0 { + c.Error = invalidValueError(value) + return c + } + if len(timezone) > 0 { + c.loc, c.Error = getLocationByTimezone(timezone[0]) + } + switch value { + case "now": + return c.Now(timezone...) + case "yesterday": + return c.Yesterday(timezone...) + case "tomorrow": + return c.Tomorrow(timezone...) + } + for _, layout := range layouts { + t, err := time.ParseInLocation(layout, value, c.loc) + if err == nil { + c.time = t + return c + } + } + c.Error = invalidValueError(value) + return c +} + +// Parse parses a standard time string as a Carbon instance. +// 将标准时间字符串解析成 Carbon 实例 +func Parse(value string, timezone ...string) Carbon { + return NewCarbon().Parse(value, timezone...) +} + +// ParseByFormat parses a time string as a Carbon instance by format. +// 通过格式模板将时间字符串解析成 Carbon 实例 +func (c Carbon) ParseByFormat(value, format string, timezone ...string) Carbon { + carbon := c.ParseByLayout(value, format2layout(format), timezone...) + if carbon.Error != nil { + carbon.Error = invalidFormatError(value, format) + } + return carbon +} + +// ParseByFormat parses a time string as a Carbon instance by format. +// 通过格式模板将时间字符串解析成 Carbon 实例 +func ParseByFormat(value, format string, timezone ...string) Carbon { + return NewCarbon().ParseByFormat(value, format, timezone...) +} + +// ParseByLayout parses a time string as a Carbon instance by layout. +// 通过布局模板将时间字符串解析成 Carbon 实例 +func (c Carbon) ParseByLayout(value, layout string, timezone ...string) Carbon { + if len(value) == 0 { + c.Error = invalidValueError(value) + return c + } + if len(timezone) > 0 { + c.loc, c.Error = getLocationByTimezone(timezone[0]) + } + if c.Error != nil { + return c + } + if len(layout) == 0 { + layout = defaultLayout + } + if layout == "timestamp" { + timestamp, _ := strconv.ParseInt(value, 10, 64) + return c.CreateFromTimestamp(timestamp) + } + if layout == "timestampMilli" { + timestamp, _ := strconv.ParseInt(value, 10, 64) + return c.CreateFromTimestampMilli(timestamp) + } + if layout == "timestampMicro" { + timestamp, _ := strconv.ParseInt(value, 10, 64) + return c.CreateFromTimestampMicro(timestamp) + } + if layout == "timestampNano" { + timestamp, _ := strconv.ParseInt(value, 10, 64) + return c.CreateFromTimestampNano(timestamp) + } + tt, err := time.ParseInLocation(layout, value, c.loc) + if err != nil { + c.Error = invalidLayoutError(value, layout) + return c + } + c.time = tt + return c +} + +// ParseByLayout parses a time string as a Carbon instance by layout. +// 通过布局模板将时间字符串解析成 Carbon 实例 +func ParseByLayout(value, layout string, timezone ...string) Carbon { + return NewCarbon().ParseByLayout(value, layout, timezone...) +} diff --git a/vendor/github.com/dromara/carbon/v2/season.go b/vendor/github.com/dromara/carbon/v2/season.go new file mode 100644 index 000000000..76402c75d --- /dev/null +++ b/vendor/github.com/dromara/carbon/v2/season.go @@ -0,0 +1,131 @@ +package carbon + +import ( + "strings" +) + +var seasons = []struct { + month, index int +}{ + {3, 0}, // spring + {4, 0}, // spring + {5, 0}, // spring + {6, 1}, // summer + {7, 1}, // summer + {8, 1}, // summer + {9, 2}, // autumn + {10, 2}, // autumn + {11, 2}, // autumn + {12, 3}, // winter + {1, 3}, // winter + {2, 3}, // winter +} + +// Season gets season name according to the meteorological division method like "Spring", i18n is supported. +// 获取当前季节(以气象划分),支持i18n +func (c Carbon) Season() string { + if c.Error != nil { + return "" + } + if len(c.lang.resources) == 0 { + c.lang.SetLocale(defaultLocale) + } + index := -1 + month := c.Month() + for i := 0; i < len(seasons); i++ { + season := seasons[i] + if month == season.month { + index = season.index + } + } + c.lang.rw.RLock() + defer c.lang.rw.RUnlock() + if resources, ok := c.lang.resources["seasons"]; ok { + slice := strings.Split(resources, "|") + if len(slice) == QuartersPerYear { + return slice[index] + } + } + return "" +} + +// StartOfSeason returns a Carbon instance for start of the season. +// 本季节开始时间 +func (c Carbon) StartOfSeason() Carbon { + if c.Error != nil { + return c + } + year, month, _ := c.Date() + if month == 1 || month == 2 { + return c.create(year-1, 12, 1, 0, 0, 0, 0) + } + return c.create(year, month/3*3, 1, 0, 0, 0, 0) +} + +// EndOfSeason returns a Carbon instance for end of the season. +// 本季节结束时间 +func (c Carbon) EndOfSeason() Carbon { + if c.Error != nil { + return c + } + year, month, _ := c.Date() + if month == 1 || month == 2 { + return c.create(year, 3, 0, 23, 59, 59, 999999999) + } + if month == 12 { + return c.create(year+1, 3, 0, 23, 59, 59, 999999999) + } + return c.create(year, month/3*3+3, 0, 23, 59, 59, 999999999) +} + +// IsSpring reports whether is spring. +// 是否是春季 +func (c Carbon) IsSpring() bool { + if c.Error != nil { + return false + } + month := c.Month() + if month == 3 || month == 4 || month == 5 { + return true + } + return false +} + +// IsSummer reports whether is summer. +// 是否是夏季 +func (c Carbon) IsSummer() bool { + if c.Error != nil { + return false + } + month := c.Month() + if month == 6 || month == 7 || month == 8 { + return true + } + return false +} + +// IsAutumn reports whether is autumn. +// 是否是秋季 +func (c Carbon) IsAutumn() bool { + if c.Error != nil { + return false + } + month := c.Month() + if month == 9 || month == 10 || month == 11 { + return true + } + return false +} + +// IsWinter reports whether is winter. +// 是否是冬季 +func (c Carbon) IsWinter() bool { + if c.Error != nil { + return false + } + month := c.Month() + if month == 12 || month == 1 || month == 2 { + return true + } + return false +} diff --git a/vendor/github.com/dromara/carbon/v2/setter.go b/vendor/github.com/dromara/carbon/v2/setter.go new file mode 100644 index 000000000..6ecbf7638 --- /dev/null +++ b/vendor/github.com/dromara/carbon/v2/setter.go @@ -0,0 +1,302 @@ +package carbon + +import ( + "time" +) + +// SetWeekStartsAt sets start day of the week. +// 设置一周的开始日期 +func (c Carbon) SetWeekStartsAt(day string) Carbon { + if c.Error != nil { + return c + } + if weekday, ok := weekdays[day]; ok { + c.weekStartsAt = weekday + } + return c +} + +// SetWeekStartsAt sets start day of the week. +// 设置一周的开始日期 +func SetWeekStartsAt(day string) Carbon { + return NewCarbon().SetWeekStartsAt(day) +} + +// SetTimezone sets timezone. +// 设置时区 +func (c Carbon) SetTimezone(name string) Carbon { + if c.Error != nil { + return c + } + c.loc, c.Error = getLocationByTimezone(name) + return c +} + +// SetTimezone sets timezone. +// 设置时区 +func SetTimezone(name string) Carbon { + return NewCarbon().SetTimezone(name) +} + +// SetLocation sets location. +// 设置地区 +func (c Carbon) SetLocation(loc *time.Location) Carbon { + if c.Error != nil { + return c + } + if loc == nil { + c.Error = invalidLocationError() + } + c.loc = loc + return c +} + +// SetLocation sets location. +// 设置地区 +func SetLocation(loc *time.Location) Carbon { + return NewCarbon().SetLocation(loc) +} + +// SetLocale sets locale. +// 设置语言区域 +func (c Carbon) SetLocale(locale string) Carbon { + if c.Error != nil { + return c + } + c.lang.SetLocale(locale) + c.Error = c.lang.Error + return c +} + +// SetLocale sets locale. +// 设置语言区域 +func SetLocale(locale string) Carbon { + c := NewCarbon() + c.lang.SetLocale(locale) + c.Error = c.lang.Error + return c +} + +// SetDateTime sets year, month, day, hour, minute and second. +// 设置年、月、日、时、分、秒 +func (c Carbon) SetDateTime(year, month, day, hour, minute, second int) Carbon { + if c.Error != nil { + return c + } + return c.create(year, month, day, hour, minute, second, c.Nanosecond()) +} + +// SetDateTimeMilli sets year, month, day, hour, minute, second and millisecond. +// 设置年、月、日、时、分、秒、毫秒 +func (c Carbon) SetDateTimeMilli(year, month, day, hour, minute, second, millisecond int) Carbon { + if c.Error != nil { + return c + } + return c.create(year, month, day, hour, minute, second, millisecond*1e6) +} + +// SetDateTimeMicro sets year, month, day, hour, minute, second and microsecond. +// 设置年、月、日、时、分、秒、微秒 +func (c Carbon) SetDateTimeMicro(year, month, day, hour, minute, second, microsecond int) Carbon { + if c.Error != nil { + return c + } + return c.create(year, month, day, hour, minute, second, microsecond*1e3) +} + +// SetDateTimeNano sets year, month, day, hour, minute, second and nanosecond. +// 设置年、月、日、时、分、秒、纳秒 +func (c Carbon) SetDateTimeNano(year, month, day, hour, minute, second, nanosecond int) Carbon { + if c.Error != nil { + return c + } + return c.create(year, month, day, hour, minute, second, nanosecond) +} + +// SetDate sets year, month and day. +// 设置年、月、日 +func (c Carbon) SetDate(year, month, day int) Carbon { + if c.Error != nil { + return c + } + hour, minute, second := c.Time() + return c.create(year, month, day, hour, minute, second, c.Nanosecond()) +} + +// SetDateMilli sets year, month, day and millisecond. +// 设置年、月、日、毫秒 +func (c Carbon) SetDateMilli(year, month, day, millisecond int) Carbon { + if c.Error != nil { + return c + } + hour, minute, second := c.Time() + return c.create(year, month, day, hour, minute, second, millisecond*1e6) +} + +// SetDateMicro sets year, month, day and microsecond. +// 设置年、月、日、微秒 +func (c Carbon) SetDateMicro(year, month, day, microsecond int) Carbon { + if c.Error != nil { + return c + } + hour, minute, second := c.Time() + return c.create(year, month, day, hour, minute, second, microsecond*1e3) +} + +// SetDateNano sets year, month, day and nanosecond. +// 设置年、月、日、纳秒 +func (c Carbon) SetDateNano(year, month, day, nanosecond int) Carbon { + if c.Error != nil { + return c + } + hour, minute, second := c.Time() + return c.create(year, month, day, hour, minute, second, nanosecond) +} + +// SetTime sets hour, minute and second. +// 设置时、分、秒 +func (c Carbon) SetTime(hour, minute, second int) Carbon { + if c.Error != nil { + return c + } + year, month, day := c.Date() + return c.create(year, month, day, hour, minute, second, c.Nanosecond()) +} + +// SetTimeMilli sets hour, minute, second and millisecond. +// 设置时、分、秒、毫秒 +func (c Carbon) SetTimeMilli(hour, minute, second, millisecond int) Carbon { + if c.Error != nil { + return c + } + year, month, day := c.Date() + return c.create(year, month, day, hour, minute, second, millisecond*1e6) +} + +// SetTimeMicro sets hour, minute, second and microsecond. +// 设置时、分、秒、微秒 +func (c Carbon) SetTimeMicro(hour, minute, second, microsecond int) Carbon { + if c.Error != nil { + return c + } + year, month, day := c.Date() + return c.create(year, month, day, hour, minute, second, microsecond*1e3) +} + +// SetTimeNano sets hour, minute, second and nanosecond. +// 设置、时、分、秒、纳秒 +func (c Carbon) SetTimeNano(hour, minute, second, nanosecond int) Carbon { + if c.Error != nil { + return c + } + year, month, day := c.Date() + return c.create(year, month, day, hour, minute, second, nanosecond) +} + +// SetYear sets year. +// 设置年份 +func (c Carbon) SetYear(year int) Carbon { + if c.Error != nil { + return c + } + _, month, day, hour, minute, second := c.DateTime() + return c.create(year, month, day, hour, minute, second, c.Nanosecond()) +} + +// SetYearNoOverflow sets year without overflowing month. +// 设置年份(月份不溢出) +func (c Carbon) SetYearNoOverflow(year int) Carbon { + if c.Error != nil { + return c + } + return c.AddYearsNoOverflow(year - c.Year()) +} + +// SetMonth sets month. +// 设置月份 +func (c Carbon) SetMonth(month int) Carbon { + if c.Error != nil { + return c + } + year, _, day, hour, minute, second := c.DateTime() + return c.create(year, month, day, hour, minute, second, c.Nanosecond()) +} + +// SetMonthNoOverflow sets month without overflowing month. +// 设置月份(月份不溢出) +func (c Carbon) SetMonthNoOverflow(month int) Carbon { + if c.Error != nil { + return c + } + return c.AddMonthsNoOverflow(month - c.Month()) +} + +// SetDay sets day. +// 设置日期 +func (c Carbon) SetDay(day int) Carbon { + if c.Error != nil { + return c + } + year, month, _, hour, minute, second := c.DateTime() + return c.create(year, month, day, hour, minute, second, c.Nanosecond()) +} + +// SetHour sets hour. +// 设置小时 +func (c Carbon) SetHour(hour int) Carbon { + if c.Error != nil { + return c + } + year, month, day, _, minute, second := c.DateTime() + return c.create(year, month, day, hour, minute, second, c.Nanosecond()) +} + +// SetMinute sets minute. +// 设置分钟 +func (c Carbon) SetMinute(minute int) Carbon { + if c.Error != nil { + return c + } + year, month, day, hour, _, second := c.DateTime() + return c.create(year, month, day, hour, minute, second, c.Nanosecond()) +} + +// SetSecond sets second. +// 设置秒数 +func (c Carbon) SetSecond(second int) Carbon { + if c.Error != nil { + return c + } + year, month, day, hour, minute, _ := c.DateTime() + return c.create(year, month, day, hour, minute, second, c.Nanosecond()) +} + +// SetMillisecond sets millisecond. +// 设置毫秒 +func (c Carbon) SetMillisecond(millisecond int) Carbon { + if c.Error != nil { + return c + } + year, month, day, hour, minute, second := c.DateTime() + return c.create(year, month, day, hour, minute, second, millisecond*1e6) +} + +// SetMicrosecond sets microsecond. +// 设置微秒 +func (c Carbon) SetMicrosecond(microsecond int) Carbon { + if c.Error != nil { + return c + } + year, month, day, hour, minute, second := c.DateTime() + return c.create(year, month, day, hour, minute, second, microsecond*1e3) +} + +// SetNanosecond sets nanosecond. +// 设置纳秒 +func (c Carbon) SetNanosecond(nanosecond int) Carbon { + if c.Error != nil { + return c + } + year, month, day, hour, minute, second := c.DateTime() + return c.create(year, month, day, hour, minute, second, nanosecond) +} diff --git a/vendor/github.com/dromara/carbon/v2/test.go b/vendor/github.com/dromara/carbon/v2/test.go new file mode 100644 index 000000000..c4481d020 --- /dev/null +++ b/vendor/github.com/dromara/carbon/v2/test.go @@ -0,0 +1,19 @@ +package carbon + +// SetTestNow sets a test Carbon instance (real or mock) to be returned when a "now" instance is created. +// 设置当前测试时间 +func (c *Carbon) SetTestNow(carbon Carbon) { + c.testNow, c.loc = carbon.TimestampNano(), carbon.loc +} + +// UnSetTestNow clears a test Carbon instance (real or mock) to be returned when a "now" instance is created. +// 清除当前测试时间 +func (c *Carbon) UnSetTestNow() { + c.testNow = 0 +} + +// IsSetTestNow report whether there is testing time now. +// 是否设置过当前测试时间 +func (c Carbon) IsSetTestNow() bool { + return c.testNow > 0 +} diff --git a/vendor/github.com/dromara/carbon/v2/traveler.go b/vendor/github.com/dromara/carbon/v2/traveler.go new file mode 100644 index 000000000..fc1fa33db --- /dev/null +++ b/vendor/github.com/dromara/carbon/v2/traveler.go @@ -0,0 +1,585 @@ +package carbon + +import ( + "time" +) + +// Now returns a Carbon instance for now. +// 当前 +func (c Carbon) Now(timezone ...string) Carbon { + if len(timezone) > 0 { + c.loc, c.Error = getLocationByTimezone(timezone[0]) + } + if c.Error != nil { + return c + } + if c.IsSetTestNow() { + now := CreateFromTimestampNano(c.testNow, c.Location()) + now.testNow = c.testNow + return now + } + c.time = time.Now().In(c.loc) + return c +} + +// Now returns a Carbon instance for now. +// 当前 +func Now(timezone ...string) Carbon { + return NewCarbon().Now(timezone...) +} + +// Tomorrow returns a Carbon instance for tomorrow. +// 明天 +func (c Carbon) Tomorrow(timezone ...string) Carbon { + if len(timezone) > 0 { + c.loc, c.Error = getLocationByTimezone(timezone[0]) + } + if c.Error != nil { + return c + } + if !c.IsZero() { + return c.AddDay() + } + return c.Now().AddDay() +} + +// Tomorrow returns a Carbon instance for tomorrow. +// 明天 +func Tomorrow(timezone ...string) Carbon { + return NewCarbon().Tomorrow(timezone...) +} + +// Yesterday returns a Carbon instance for yesterday. +// 昨天 +func (c Carbon) Yesterday(timezone ...string) Carbon { + if len(timezone) > 0 { + c.loc, c.Error = getLocationByTimezone(timezone[0]) + } + if c.Error != nil { + return c + } + if !c.IsZero() { + return c.SubDay() + } + return c.Now().SubDay() +} + +// Yesterday returns a Carbon instance for yesterday. +// 昨天 +func Yesterday(timezone ...string) Carbon { + return NewCarbon().Yesterday(timezone...) +} + +// AddDuration adds one duration. +// 按照时长增加时间,支持整数/浮点数和符号ns(纳秒)、us(微妙)、ms(毫秒)、s(秒)、m(分钟)、h(小时)的组合 +func (c Carbon) AddDuration(duration string) Carbon { + if c.IsInvalid() { + return c + } + td, err := parseByDuration(duration) + c.time, c.Error = c.StdTime().Add(td), err + return c +} + +// SubDuration subtracts one duration. +// 按照时长减少时间,支持整数/浮点数和符号ns(纳秒)、us(微妙)、ms(毫秒)、s(秒)、m(分钟)、h(小时)的组合 +func (c Carbon) SubDuration(duration string) Carbon { + return c.AddDuration("-" + duration) +} + +// AddCenturies adds some centuries. +// N个世纪后 +func (c Carbon) AddCenturies(centuries int) Carbon { + return c.AddYears(centuries * YearsPerCentury) +} + +// AddCenturiesNoOverflow adds some centuries without overflowing month. +// N个世纪后(月份不溢出) +func (c Carbon) AddCenturiesNoOverflow(centuries int) Carbon { + return c.AddYearsNoOverflow(centuries * YearsPerCentury) +} + +// AddCentury adds one century. +// 1个世纪后 +func (c Carbon) AddCentury() Carbon { + return c.AddCenturies(1) +} + +// AddCenturyNoOverflow adds one century without overflowing month. +// 1个世纪后(月份不溢出) +func (c Carbon) AddCenturyNoOverflow() Carbon { + return c.AddCenturiesNoOverflow(1) +} + +// SubCenturies subtracts some centuries. +// N个世纪前 +func (c Carbon) SubCenturies(centuries int) Carbon { + return c.SubYears(centuries * YearsPerCentury) +} + +// SubCenturiesNoOverflow subtracts some centuries without overflowing month. +// N个世纪前(月份不溢出) +func (c Carbon) SubCenturiesNoOverflow(centuries int) Carbon { + return c.SubYearsNoOverflow(centuries * YearsPerCentury) +} + +// SubCentury subtracts one century. +// 1个世纪前 +func (c Carbon) SubCentury() Carbon { + return c.SubCenturies(1) +} + +// SubCenturyNoOverflow subtracts one century without overflowing month. +// 1个世纪前(月份不溢出) +func (c Carbon) SubCenturyNoOverflow() Carbon { + return c.SubCenturiesNoOverflow(1) +} + +// AddDecades adds some decades. +// N个年代后 +func (c Carbon) AddDecades(decades int) Carbon { + return c.AddYears(decades * YearsPerDecade) +} + +// AddDecadesNoOverflow adds some decades without overflowing month. +// N个年代后(月份不溢出) +func (c Carbon) AddDecadesNoOverflow(decades int) Carbon { + return c.AddYearsNoOverflow(decades * YearsPerDecade) +} + +// AddDecade adds one decade. +// 1个年代后 +func (c Carbon) AddDecade() Carbon { + return c.AddDecades(1) +} + +// AddDecadeNoOverflow adds one decade without overflowing month. +// 1个年代后(月份不溢出) +func (c Carbon) AddDecadeNoOverflow() Carbon { + return c.AddDecadesNoOverflow(1) +} + +// SubDecades subtracts some decades. +// N个年代后 +func (c Carbon) SubDecades(decades int) Carbon { + return c.SubYears(decades * YearsPerDecade) +} + +// SubDecadesNoOverflow subtracts some decades without overflowing month. +// N个年代后(月份不溢出) +func (c Carbon) SubDecadesNoOverflow(decades int) Carbon { + return c.SubYearsNoOverflow(decades * YearsPerDecade) +} + +// SubDecade subtracts one decade. +// 1个年代后 +func (c Carbon) SubDecade() Carbon { + return c.SubDecades(1) +} + +// SubDecadeNoOverflow subtracts one decade without overflowing month. +// 1个年代后(月份不溢出) +func (c Carbon) SubDecadeNoOverflow() Carbon { + return c.SubDecadesNoOverflow(1) +} + +// AddYears adds some years. +// N年后 +func (c Carbon) AddYears(years int) Carbon { + if c.IsInvalid() { + return c + } + c.time = c.StdTime().AddDate(years, 0, 0) + return c +} + +// AddYearsNoOverflow adds some years without overflowing month. +// N年后(月份不溢出) +func (c Carbon) AddYearsNoOverflow(years int) Carbon { + if c.IsInvalid() { + return c + } + nanosecond := c.Nanosecond() + year, month, day, hour, minute, second := c.DateTime() + // 获取N年后本月的最后一天 + lastYear, lastMonth, lastDay := c.create(year+years, month+1, 0, hour, minute, second, nanosecond).Date() + if day > lastDay { + day = lastDay + } + return c.create(lastYear, lastMonth, day, hour, minute, second, nanosecond) +} + +// AddYear adds one year. +// 1年后 +func (c Carbon) AddYear() Carbon { + return c.AddYears(1) +} + +// AddYearNoOverflow adds one year without overflowing month. +// 1年后(月份不溢出) +func (c Carbon) AddYearNoOverflow() Carbon { + return c.AddYearsNoOverflow(1) +} + +// SubYears subtracts some years. +// N年前 +func (c Carbon) SubYears(years int) Carbon { + if c.IsInvalid() { + return c + } + return c.AddYears(-years) +} + +// SubYearsNoOverflow subtracts some years without overflowing month. +// N年前(月份不溢出) +func (c Carbon) SubYearsNoOverflow(years int) Carbon { + return c.AddYearsNoOverflow(-years) +} + +// SubYear subtracts one year. +// 1年前 +func (c Carbon) SubYear() Carbon { + return c.SubYears(1) +} + +// SubYearNoOverflow subtracts one year without overflowing month. +// 1年前(月份不溢出) +func (c Carbon) SubYearNoOverflow() Carbon { + return c.SubYearsNoOverflow(1) +} + +// AddQuarters adds some quarters +// N个季度后 +func (c Carbon) AddQuarters(quarters int) Carbon { + return c.AddMonths(quarters * MonthsPerQuarter) +} + +// AddQuartersNoOverflow adds quarters without overflowing month. +// N个季度后(月份不溢出) +func (c Carbon) AddQuartersNoOverflow(quarters int) Carbon { + return c.AddMonthsNoOverflow(quarters * MonthsPerQuarter) +} + +// AddQuarter adds one quarter +// 1个季度后 +func (c Carbon) AddQuarter() Carbon { + return c.AddQuarters(1) +} + +// AddQuarterNoOverflow adds one quarter without overflowing month. +// 1个季度后(月份不溢出) +func (c Carbon) AddQuarterNoOverflow() Carbon { + return c.AddQuartersNoOverflow(1) +} + +// SubQuarters subtracts some quarters. +// N个季度前 +func (c Carbon) SubQuarters(quarters int) Carbon { + return c.AddQuarters(-quarters) +} + +// SubQuartersNoOverflow subtracts some quarters without overflowing month. +// N个季度前(月份不溢出) +func (c Carbon) SubQuartersNoOverflow(quarters int) Carbon { + return c.AddMonthsNoOverflow(-quarters * MonthsPerQuarter) +} + +// SubQuarter subtracts one quarter. +// 1个季度前 +func (c Carbon) SubQuarter() Carbon { + return c.SubQuarters(1) +} + +// SubQuarterNoOverflow subtracts one quarter without overflowing month. +// 1个季度前(月份不溢出) +func (c Carbon) SubQuarterNoOverflow() Carbon { + return c.SubQuartersNoOverflow(1) +} + +// AddMonths adds some months. +// N个月后 +func (c Carbon) AddMonths(months int) Carbon { + if c.IsInvalid() { + return c + } + c.time = c.StdTime().AddDate(0, months, 0) + return c +} + +// AddMonthsNoOverflow adds some months without overflowing month. +// N个月后(月份不溢出) +func (c Carbon) AddMonthsNoOverflow(months int) Carbon { + if c.IsInvalid() { + return c + } + nanosecond := c.Nanosecond() + year, month, day, hour, minute, second := c.DateTime() + // 获取N月后的最后一天 + lastYear, lastMonth, lastDay := c.create(year, month+months+1, 0, hour, minute, second, nanosecond).Date() + if day > lastDay { + day = lastDay + } + return c.create(lastYear, lastMonth, day, hour, minute, second, nanosecond) +} + +// AddMonth adds one month. +// 1个月后 +func (c Carbon) AddMonth() Carbon { + return c.AddMonths(1) +} + +// AddMonthNoOverflow adds one month without overflowing month. +// 1个月后(月份不溢出) +func (c Carbon) AddMonthNoOverflow() Carbon { + return c.AddMonthsNoOverflow(1) +} + +// SubMonths subtracts some months. +// N个月前 +func (c Carbon) SubMonths(months int) Carbon { + return c.AddMonths(-months) +} + +// SubMonthsNoOverflow subtracts some months without overflowing month. +// N个月前(月份不溢出) +func (c Carbon) SubMonthsNoOverflow(months int) Carbon { + return c.AddMonthsNoOverflow(-months) +} + +// SubMonth subtracts one month. +// 1个月前 +func (c Carbon) SubMonth() Carbon { + return c.SubMonths(1) +} + +// SubMonthNoOverflow subtracts one month without overflowing month. +// 1个月前(月份不溢出) +func (c Carbon) SubMonthNoOverflow() Carbon { + return c.SubMonthsNoOverflow(1) +} + +// AddWeeks adds some weeks. +// N周后 +func (c Carbon) AddWeeks(weeks int) Carbon { + return c.AddDays(weeks * DaysPerWeek) +} + +// AddWeek adds one week. +// 1周后 +func (c Carbon) AddWeek() Carbon { + return c.AddWeeks(1) +} + +// SubWeeks subtracts some weeks. +// N周前 +func (c Carbon) SubWeeks(weeks int) Carbon { + return c.SubDays(weeks * DaysPerWeek) +} + +// SubWeek subtracts one week. +// 1周前 +func (c Carbon) SubWeek() Carbon { + return c.SubWeeks(1) +} + +// AddDays adds some days. +// N天后 +func (c Carbon) AddDays(days int) Carbon { + if c.IsInvalid() { + return c + } + c.time = c.StdTime().AddDate(0, 0, days) + return c +} + +// AddDay adds one day. +// 1天后 +func (c Carbon) AddDay() Carbon { + return c.AddDays(1) +} + +// SubDays subtracts some days. +// N天前 +func (c Carbon) SubDays(days int) Carbon { + return c.AddDays(-days) +} + +// SubDay subtracts one day. +// 1天前 +func (c Carbon) SubDay() Carbon { + return c.SubDays(1) +} + +// AddHours adds some hours. +// N小时后 +func (c Carbon) AddHours(hours int) Carbon { + if c.IsInvalid() { + return c + } + td := time.Duration(hours) * time.Hour + c.time = c.StdTime().Add(td) + return c +} + +// AddHour adds one hour. +// 1小时后 +func (c Carbon) AddHour() Carbon { + return c.AddHours(1) +} + +// SubHours subtracts some hours. +// N小时前 +func (c Carbon) SubHours(hours int) Carbon { + return c.AddHours(-hours) +} + +// SubHour subtracts one hour. +// 1小时前 +func (c Carbon) SubHour() Carbon { + return c.SubHours(1) +} + +// AddMinutes adds some minutes. +// N分钟后 +func (c Carbon) AddMinutes(minutes int) Carbon { + if c.IsInvalid() { + return c + } + td := time.Duration(minutes) * time.Minute + c.time = c.StdTime().Add(td) + return c +} + +// AddMinute adds one minute. +// 1分钟后 +func (c Carbon) AddMinute() Carbon { + return c.AddMinutes(1) +} + +// SubMinutes subtracts some minutes. +// N分钟前 +func (c Carbon) SubMinutes(minutes int) Carbon { + return c.AddMinutes(-minutes) +} + +// SubMinute subtracts one minute. +// 1分钟前 +func (c Carbon) SubMinute() Carbon { + return c.SubMinutes(1) +} + +// AddSeconds adds some seconds. +// N秒钟后 +func (c Carbon) AddSeconds(seconds int) Carbon { + if c.IsInvalid() { + return c + } + td := time.Duration(seconds) * time.Second + c.time = c.StdTime().Add(td) + return c +} + +// AddSecond adds one second. +// 1秒钟后 +func (c Carbon) AddSecond() Carbon { + return c.AddSeconds(1) +} + +// SubSeconds subtracts some seconds. +// N秒钟前 +func (c Carbon) SubSeconds(seconds int) Carbon { + return c.AddSeconds(-seconds) +} + +// SubSecond subtracts one second. +// 1秒钟前 +func (c Carbon) SubSecond() Carbon { + return c.SubSeconds(1) +} + +// AddMilliseconds adds some milliseconds. +// N毫秒后 +func (c Carbon) AddMilliseconds(milliseconds int) Carbon { + if c.IsInvalid() { + return c + } + td := time.Duration(milliseconds) * time.Millisecond + c.time = c.StdTime().Add(td) + return c +} + +// AddMillisecond adds one millisecond. +// 1毫秒后 +func (c Carbon) AddMillisecond() Carbon { + return c.AddMilliseconds(1) +} + +// SubMilliseconds subtracts some milliseconds. +// N毫秒前 +func (c Carbon) SubMilliseconds(milliseconds int) Carbon { + return c.AddMilliseconds(-milliseconds) +} + +// SubMillisecond subtracts one millisecond. +// 1毫秒前 +func (c Carbon) SubMillisecond() Carbon { + return c.SubMilliseconds(1) +} + +// AddMicroseconds adds some microseconds. +// N微秒后 +func (c Carbon) AddMicroseconds(microseconds int) Carbon { + if c.IsInvalid() { + return c + } + td := time.Duration(microseconds) * time.Microsecond + c.time = c.StdTime().Add(td) + return c +} + +// AddMicrosecond adds one microsecond. +// 1微秒后 +func (c Carbon) AddMicrosecond() Carbon { + return c.AddMicroseconds(1) +} + +// SubMicroseconds subtracts some microseconds. +// N微秒前 +func (c Carbon) SubMicroseconds(microseconds int) Carbon { + return c.AddMicroseconds(-microseconds) +} + +// SubMicrosecond subtracts one microsecond. +// 1微秒前 +func (c Carbon) SubMicrosecond() Carbon { + return c.SubMicroseconds(1) +} + +// AddNanoseconds adds some nanoseconds. +// N纳秒后 +func (c Carbon) AddNanoseconds(nanoseconds int) Carbon { + if c.IsInvalid() { + return c + } + td := time.Duration(nanoseconds) * time.Nanosecond + c.time = c.StdTime().Add(td) + return c +} + +// AddNanosecond adds one nanosecond. +// 1纳秒后 +func (c Carbon) AddNanosecond() Carbon { + return c.AddNanoseconds(1) +} + +// SubNanoseconds subtracts some nanoseconds. +// N纳秒前 +func (c Carbon) SubNanoseconds(nanoseconds int) Carbon { + return c.AddNanoseconds(-nanoseconds) +} + +// SubNanosecond subtracts one nanosecond. +// 1纳秒前 +func (c Carbon) SubNanosecond() Carbon { + return c.SubNanoseconds(1) +} diff --git a/vendor/github.com/hako/durafmt/.gitignore b/vendor/github.com/hako/durafmt/.gitignore deleted file mode 100644 index daf913b1b..000000000 --- a/vendor/github.com/hako/durafmt/.gitignore +++ /dev/null @@ -1,24 +0,0 @@ -# Compiled Object files, Static and Dynamic libs (Shared Objects) -*.o -*.a -*.so - -# Folders -_obj -_test - -# Architecture specific extensions/prefixes -*.[568vq] -[568vq].out - -*.cgo1.go -*.cgo2.c -_cgo_defun.c -_cgo_gotypes.go -_cgo_export.* - -_testmain.go - -*.exe -*.test -*.prof diff --git a/vendor/github.com/hako/durafmt/.travis.yml b/vendor/github.com/hako/durafmt/.travis.yml deleted file mode 100644 index 77f8c12ca..000000000 --- a/vendor/github.com/hako/durafmt/.travis.yml +++ /dev/null @@ -1,21 +0,0 @@ -language: go - -go: - - 1.5 - - 1.6 - - 1.7 - - 1.8 - - 1.9 - - tip - -before_install: - - go get golang.org/x/tools/cmd/cover - -script: - - GOARCH=386 go test # test 32bit architectures. - - go test -coverprofile=coverage.txt -covermode=atomic - -after_success: - - bash <(curl -s https://codecov.io/bash) - -sudo: false diff --git a/vendor/github.com/hako/durafmt/CODE_OF_CONDUCT.md b/vendor/github.com/hako/durafmt/CODE_OF_CONDUCT.md deleted file mode 100644 index 19a95e513..000000000 --- a/vendor/github.com/hako/durafmt/CODE_OF_CONDUCT.md +++ /dev/null @@ -1,46 +0,0 @@ -# Contributor Covenant Code of Conduct - -## Our Pledge - -In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. - -## Our Standards - -Examples of behavior that contributes to creating a positive environment include: - -* Using welcoming and inclusive language -* Being respectful of differing viewpoints and experiences -* Gracefully accepting constructive criticism -* Focusing on what is best for the community -* Showing empathy towards other community members - -Examples of unacceptable behavior by participants include: - -* The use of sexualized language or imagery and unwelcome sexual attention or advances -* Trolling, insulting/derogatory comments, and personal or political attacks -* Public or private harassment -* Publishing others' private information, such as a physical or electronic address, without explicit permission -* Other conduct which could reasonably be considered inappropriate in a professional setting - -## Our Responsibilities - -Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. - -Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. - -## Scope - -This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. - -## Enforcement - -Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at wesley@hakobaito.co.uk. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. - -Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. - -## Attribution - -This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] - -[homepage]: http://contributor-covenant.org -[version]: http://contributor-covenant.org/version/1/4/ diff --git a/vendor/github.com/hako/durafmt/CONTRIBUTING.md b/vendor/github.com/hako/durafmt/CONTRIBUTING.md deleted file mode 100644 index bdfb376fc..000000000 --- a/vendor/github.com/hako/durafmt/CONTRIBUTING.md +++ /dev/null @@ -1,9 +0,0 @@ -# Contributing - -Contributions are welcome! Fork this repo and add your changes and submit a PR. - -If you would like to fix a bug, add a feature or provide feedback you can do so in the issues section. - -You can run tests by runnning `go test`. Running `go test; go vet; golint` is recommended. - -durafmt is also tested against `gometalinter`. diff --git a/vendor/github.com/hako/durafmt/README.md b/vendor/github.com/hako/durafmt/README.md deleted file mode 100644 index 45448f514..000000000 --- a/vendor/github.com/hako/durafmt/README.md +++ /dev/null @@ -1,154 +0,0 @@ -# durafmt - -[![Build Status](https://travis-ci.org/hako/durafmt.svg?branch=master)](https://travis-ci.org/hako/durafmt) [![Go Report Card](https://goreportcard.com/badge/github.com/hako/durafmt)](https://goreportcard.com/report/github.com/hako/durafmt) [![codecov](https://codecov.io/gh/hako/durafmt/branch/master/graph/badge.svg)](https://codecov.io/gh/hako/durafmt) [![GoDoc](https://godoc.org/github.com/hako/durafmt?status.svg)](https://godoc.org/github.com/hako/durafmt) -[![Open Source Helpers](https://www.codetriage.com/hako/durafmt/badges/users.svg)](https://www.codetriage.com/hako/durafmt) - - - -durafmt is a tiny Go library that formats `time.Duration` strings (and types) into a human readable format. - -``` -go get github.com/hako/durafmt -``` - -# Why - -If you've worked with `time.Duration` in Go, you most likely have come across this: - -``` -53m28.587093086s // :) -``` - -The above seems very easy to read, unless your duration looks like this: - -``` -354h22m3.24s // :S -``` - -# Usage - -### durafmt.ParseString() - -```go -package main - -import ( - "fmt" - "github.com/hako/durafmt" -) - -func main() { - duration, err := durafmt.ParseString("354h22m3.24s") - if err != nil { - fmt.Println(err) - } - fmt.Println(duration) // 2 weeks 18 hours 22 minutes 3 seconds - // duration.String() // String representation. "2 weeks 18 hours 22 minutes 3 seconds" -} -``` - -### durafmt.ParseStringShort() - -Version of `durafmt.ParseString()` that only returns the first part of the duration string. - -```go -package main - -import ( - "fmt" - "github.com/hako/durafmt" -) - -func main() { - duration, err := durafmt.ParseStringShort("354h22m3.24s") - if err != nil { - fmt.Println(err) - } - fmt.Println(duration) // 2 weeks - // duration.String() // String short representation. "2 weeks" -} -``` - -### durafmt.Parse() - -```go -package main - -import ( - "fmt" - "time" - "github.com/hako/durafmt" -) - -func main() { - timeduration := (354 * time.Hour) + (22 * time.Minute) + (3 * time.Second) - duration := durafmt.Parse(timeduration).String() - fmt.Println(duration) // 2 weeks 18 hours 22 minutes 3 seconds -} -``` - -#### LimitFirstN() - -Like `durafmt.ParseStringShort()` but for limiting the first N parts of the duration string. - -```go -package main - -import ( - "fmt" - "time" - "github.com/hako/durafmt" -) - -func main() { - timeduration := (354 * time.Hour) + (22 * time.Minute) + (3 * time.Second) - duration := durafmt.Parse(timeduration).LimitFirstN(2) // // limit first two parts. - fmt.Println(duration) // 2 weeks 18 hours -} -``` - -#### Custom Units - -Like `durafmt.Units{}` and `durafmt.Durafmt.Format(units)` to stringify duration with custom units. - -```go -package main - -import ( - "fmt" - "time" - "github.com/hako/durafmt" -) - -func main() { - timeduration := (354 * time.Hour) + (22 * time.Minute) + (1 * time.Second) + (100*time.Microsecond) - duration := durafmt.Parse(timeduration) - // units in portuguese - units, err := durafmt.DefaultUnitsCoder.Decode("ano,semana,dia,hora,minuto,segundo,milissegundo,microssegundo") - if err != nil { - panic(err) - } - fmt.Println(duration.Format(units)) // 2 semanas 18 horas 22 minutos 1 segundo 100 microssegundos - - // custom plural (singular:plural) - units, err = durafmt.DefaultUnitsCoder.Decode("ano,semana:SEMANAS,dia,hora,minuto,segundo,milissegundo,microssegundo") - if err != nil { - panic(err) - } - fmt.Println(duration.Format(units)) // 2 SEMANAS 18 horas 22 minutos 1 segundo 100 microssegundos -} -``` - -# Contributing - -Contributions are welcome! Fork this repo, add your changes and submit a PR. - -If you would like to fix a bug, add a feature or provide feedback you can do so in the issues section. - -durafmt is tested against `golangci-lint` and you can run tests with `go test`. - -When contributing, running `go test; go vet; golint` or `golangci-lint` is recommended. - -# License - -MIT diff --git a/vendor/github.com/hako/durafmt/durafmt.go b/vendor/github.com/hako/durafmt/durafmt.go deleted file mode 100644 index 128726ed2..000000000 --- a/vendor/github.com/hako/durafmt/durafmt.go +++ /dev/null @@ -1,330 +0,0 @@ -// Package durafmt formats time.Duration into a human readable format. -package durafmt - -import ( - "errors" - "fmt" - "regexp" - "strconv" - "strings" - "time" -) - -var ( - units, _ = DefaultUnitsCoder.Decode("year,week,day,hour,minute,second,millisecond,microsecond") - unitsShort = []string{"y", "w", "d", "h", "m", "s", "ms", "µs"} -) - -// Durafmt holds the parsed duration and the original input duration. -type Durafmt struct { - duration time.Duration - input string // Used as reference. - limitN int // Non-zero to limit only first N elements to output. - limitUnit string // Non-empty to limit max unit -} - -// LimitToUnit sets the output format, you will not have unit bigger than the UNIT specified. UNIT = "" means no restriction. -func (d *Durafmt) LimitToUnit(unit string) *Durafmt { - d.limitUnit = unit - return d -} - -// LimitFirstN sets the output format, outputing only first N elements. n == 0 means no limit. -func (d *Durafmt) LimitFirstN(n int) *Durafmt { - d.limitN = n - return d -} - -func (d *Durafmt) Duration() time.Duration { - return d.duration -} - -// Parse creates a new *Durafmt struct, returns error if input is invalid. -func Parse(dinput time.Duration) *Durafmt { - input := dinput.String() - return &Durafmt{dinput, input, 0, ""} -} - -// ParseShort creates a new *Durafmt struct, short form, returns error if input is invalid. -// It's shortcut for `Parse(dur).LimitFirstN(1)` -func ParseShort(dinput time.Duration) *Durafmt { - input := dinput.String() - return &Durafmt{dinput, input, 1, ""} -} - -// ParseString creates a new *Durafmt struct from a string. -// returns an error if input is invalid. -func ParseString(input string) (*Durafmt, error) { - if input == "0" || input == "-0" { - return nil, errors.New("durafmt: missing unit in duration " + input) - } - duration, err := time.ParseDuration(input) - if err != nil { - return nil, err - } - return &Durafmt{duration, input, 0, ""}, nil -} - -// ParseStringShort creates a new *Durafmt struct from a string, short form -// returns an error if input is invalid. -// It's shortcut for `ParseString(durStr)` and then calling `LimitFirstN(1)` -func ParseStringShort(input string) (*Durafmt, error) { - if input == "0" || input == "-0" { - return nil, errors.New("durafmt: missing unit in duration " + input) - } - duration, err := time.ParseDuration(input) - if err != nil { - return nil, err - } - return &Durafmt{duration, input, 1, ""}, nil -} - -// String parses d *Durafmt into a human readable duration with default units. -func (d *Durafmt) String() string { - return d.Format(units) -} - -// Format parses d *Durafmt into a human readable duration with units. -func (d *Durafmt) Format(units Units) string { - var duration string - - // Check for minus durations. - if string(d.input[0]) == "-" { - duration += "-" - d.duration = -d.duration - } - - var microseconds int64 - var milliseconds int64 - var seconds int64 - var minutes int64 - var hours int64 - var days int64 - var weeks int64 - var years int64 - var shouldConvert = false - - remainingSecondsToConvert := int64(d.duration / time.Microsecond) - - // Convert duration. - if d.limitUnit == "" { - shouldConvert = true - } - - if d.limitUnit == "years" || shouldConvert { - years = remainingSecondsToConvert / (365 * 24 * 3600 * 1000000) - remainingSecondsToConvert -= years * 365 * 24 * 3600 * 1000000 - shouldConvert = true - } - - if d.limitUnit == "weeks" || shouldConvert { - weeks = remainingSecondsToConvert / (7 * 24 * 3600 * 1000000) - remainingSecondsToConvert -= weeks * 7 * 24 * 3600 * 1000000 - shouldConvert = true - } - - if d.limitUnit == "days" || shouldConvert { - days = remainingSecondsToConvert / (24 * 3600 * 1000000) - remainingSecondsToConvert -= days * 24 * 3600 * 1000000 - shouldConvert = true - } - - if d.limitUnit == "hours" || shouldConvert { - hours = remainingSecondsToConvert / (3600 * 1000000) - remainingSecondsToConvert -= hours * 3600 * 1000000 - shouldConvert = true - } - - if d.limitUnit == "minutes" || shouldConvert { - minutes = remainingSecondsToConvert / (60 * 1000000) - remainingSecondsToConvert -= minutes * 60 * 1000000 - shouldConvert = true - } - - if d.limitUnit == "seconds" || shouldConvert { - seconds = remainingSecondsToConvert / 1000000 - remainingSecondsToConvert -= seconds * 1000000 - shouldConvert = true - } - - if d.limitUnit == "milliseconds" || shouldConvert { - milliseconds = remainingSecondsToConvert / 1000 - remainingSecondsToConvert -= milliseconds * 1000 - } - - microseconds = remainingSecondsToConvert - - // Create a map of the converted duration time. - durationMap := []int64{ - microseconds, - milliseconds, - seconds, - minutes, - hours, - days, - weeks, - years, - } - - // Construct duration string. - for i, u := range units.Units() { - v := durationMap[7-i] - strval := strconv.FormatInt(v, 10) - switch { - // add to the duration string if v > 1. - case v > 1: - duration += strval + " " + u.Plural + " " - // remove the plural 's', if v is 1. - case v == 1: - duration += strval + " " + u.Singular + " " - // omit any value with 0s or 0. - case d.duration.String() == "0" || d.duration.String() == "0s": - pattern := fmt.Sprintf("^-?0%s$", unitsShort[i]) - isMatch, err := regexp.MatchString(pattern, d.input) - if err != nil { - return "" - } - if isMatch { - duration += strval + " " + u.Plural - } - - // omit any value with 0. - case v == 0: - continue - } - } - // trim any remaining spaces. - duration = strings.TrimSpace(duration) - - // if more than 2 spaces present return the first 2 strings - // if short version is requested - if d.limitN > 0 { - parts := strings.Split(duration, " ") - if len(parts) > d.limitN*2 { - duration = strings.Join(parts[:d.limitN*2], " ") - } - } - - return duration -} - -func (d *Durafmt) InternationalString() string { - var duration string - - // Check for minus durations. - if string(d.input[0]) == "-" { - duration += "-" - d.duration = -d.duration - } - - var microseconds int64 - var milliseconds int64 - var seconds int64 - var minutes int64 - var hours int64 - var days int64 - var weeks int64 - var years int64 - var shouldConvert = false - - remainingSecondsToConvert := int64(d.duration / time.Microsecond) - - // Convert duration. - if d.limitUnit == "" { - shouldConvert = true - } - - if d.limitUnit == "years" || shouldConvert { - years = remainingSecondsToConvert / (365 * 24 * 3600 * 1000000) - remainingSecondsToConvert -= years * 365 * 24 * 3600 * 1000000 - shouldConvert = true - } - - if d.limitUnit == "weeks" || shouldConvert { - weeks = remainingSecondsToConvert / (7 * 24 * 3600 * 1000000) - remainingSecondsToConvert -= weeks * 7 * 24 * 3600 * 1000000 - shouldConvert = true - } - - if d.limitUnit == "days" || shouldConvert { - days = remainingSecondsToConvert / (24 * 3600 * 1000000) - remainingSecondsToConvert -= days * 24 * 3600 * 1000000 - shouldConvert = true - } - - if d.limitUnit == "hours" || shouldConvert { - hours = remainingSecondsToConvert / (3600 * 1000000) - remainingSecondsToConvert -= hours * 3600 * 1000000 - shouldConvert = true - } - - if d.limitUnit == "minutes" || shouldConvert { - minutes = remainingSecondsToConvert / (60 * 1000000) - remainingSecondsToConvert -= minutes * 60 * 1000000 - shouldConvert = true - } - - if d.limitUnit == "seconds" || shouldConvert { - seconds = remainingSecondsToConvert / 1000000 - remainingSecondsToConvert -= seconds * 1000000 - shouldConvert = true - } - - if d.limitUnit == "milliseconds" || shouldConvert { - milliseconds = remainingSecondsToConvert / 1000 - remainingSecondsToConvert -= milliseconds * 1000 - } - - microseconds = remainingSecondsToConvert - - // Create a map of the converted duration time. - durationMap := map[string]int64{ - "µs": microseconds, - "ms": milliseconds, - "s": seconds, - "m": minutes, - "h": hours, - "d": days, - "w": weeks, - "y": years, - } - - // Construct duration string. - for i := range units.Units() { - u := unitsShort[i] - v := durationMap[u] - strval := strconv.FormatInt(v, 10) - switch { - // add to the duration string if v > 0. - case v > 0: - duration += strval + " " + u + " " - // omit any value with 0. - case d.duration.String() == "0": - pattern := fmt.Sprintf("^-?0%s$", unitsShort[i]) - isMatch, err := regexp.MatchString(pattern, d.input) - if err != nil { - return "" - } - if isMatch { - duration += strval + " " + u - } - - // omit any value with 0. - case v == 0: - continue - } - } - // trim any remaining spaces. - duration = strings.TrimSpace(duration) - - // if more than 2 spaces present return the first 2 strings - // if short version is requested - if d.limitN > 0 { - parts := strings.Split(duration, " ") - if len(parts) > d.limitN*2 { - duration = strings.Join(parts[:d.limitN*2], " ") - } - } - - return duration -} diff --git a/vendor/github.com/hako/durafmt/unit.go b/vendor/github.com/hako/durafmt/unit.go deleted file mode 100644 index 041f0b1b5..000000000 --- a/vendor/github.com/hako/durafmt/unit.go +++ /dev/null @@ -1,108 +0,0 @@ -package durafmt - -import ( - "fmt" - "strings" -) - -// DefaultUnitsCoder default units coder using `":"` as PluralSep and `","` as UnitsSep -var DefaultUnitsCoder = UnitsCoder{":", ","} - -// Unit the pair of singular and plural units -type Unit struct { - Singular, Plural string -} - -// Units duration units -type Units struct { - Year, Week, Day, Hour, Minute, - Second, Millisecond, Microsecond Unit -} - -// Units return a slice of units -func (u Units) Units() []Unit { - return []Unit{u.Year, u.Week, u.Day, u.Hour, u.Minute, - u.Second, u.Millisecond, u.Microsecond} -} - -// UnitsCoder the units encoder and decoder -type UnitsCoder struct { - // PluralSep char to sep singular and plural pair. - // Example with char `":"`: `"year:year"` (english) or `"mês:meses"` (portuguese) - PluralSep, - // UnitsSep char to sep units (singular and plural pairs). - // Example with char `","`: `"year:year,week:weeks"` (english) or `"mês:meses,semana:semanas"` (portuguese) - UnitsSep string -} - -// Encode encodes input Units to string -// Examples with `UnitsCoder{PluralSep: ":", UnitsSep = ","}` -// - singular and plural pair units: `"year:wers,week:weeks,day:days,hour:hours,minute:minutes,second:seconds,millisecond:millliseconds,microsecond:microsseconds"` -func (coder UnitsCoder) Encode(units Units) string { - var pairs = make([]string, 8) - for i, u := range units.Units() { - pairs[i] = u.Singular + coder.PluralSep + u.Plural - } - return strings.Join(pairs, coder.UnitsSep) -} - -// Decode decodes input string to Units. -// The input must follow the following formats: -// - Unit format (singular and plural pair) -// - must singular (the plural receives 's' character as suffix) -// - singular and plural: separated by `PluralSep` char -// Example with char `":"`: `"year:year"` (english) or `"mês:meses"` (portuguese) -// - Units format (pairs of Year, Week, Day, Hour, Minute, -// Second, Millisecond and Microsecond units) separated by `UnitsSep` char -// - Examples with `UnitsCoder{PluralSep: ":", UnitsSep = ","}` -// - must singular units: `"year,week,day,hour,minute,second,millisecond,microsecond"` -// - mixed units: `"year,week:weeks,day,hour,minute:minutes,second,millisecond,microsecond"` -// - singular and plural pair units: `"year:wers,week:weeks,day:days,hour:hours,minute:minutes,second:seconds,millisecond:millliseconds,microsecond:microsseconds"` -func (coder UnitsCoder) Decode(s string) (units Units, err error) { - parts := strings.Split(s, coder.UnitsSep) - if len(parts) != 8 { - err = fmt.Errorf("bad parts length") - return units, err - } - - var parse = func(name, part string, u *Unit) bool { - ps := strings.Split(part, coder.PluralSep) - switch len(ps) { - case 1: - // create plural form with sigular + 's' suffix - u.Singular, u.Plural = ps[0], ps[0]+"s" - case 2: - u.Singular, u.Plural = ps[0], ps[1] - default: - err = fmt.Errorf("bad unit %q pair length", name) - return false - } - return true - } - - if !parse("Year", parts[0], &units.Year) { - return units, err - } - if !parse("Week", parts[1], &units.Week) { - return units, err - } - if !parse("Day", parts[2], &units.Day) { - return units, err - } - if !parse("Hour", parts[3], &units.Hour) { - return units, err - } - if !parse("Minute", parts[4], &units.Minute) { - return units, err - } - if !parse("Second", parts[5], &units.Second) { - return units, err - } - if !parse("Millisecond", parts[6], &units.Millisecond) { - return units, err - } - if !parse("Microsecond", parts[7], &units.Microsecond) { - return units, err - } - return units, err -} diff --git a/vendor/modules.txt b/vendor/modules.txt index b7864bba4..b9022b538 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -174,6 +174,13 @@ github.com/docker/go-connections/tlsconfig # github.com/docker/go-units v0.5.0 ## explicit github.com/docker/go-units +# github.com/dromara/carbon/v2 v2.5.2 +## explicit; go 1.17 +github.com/dromara/carbon/v2 +github.com/dromara/carbon/v2/calendar +github.com/dromara/carbon/v2/calendar/julian +github.com/dromara/carbon/v2/calendar/lunar +github.com/dromara/carbon/v2/calendar/persian # github.com/eclipse/paho.mqtt.golang v1.5.0 ## explicit; go 1.20 github.com/eclipse/paho.mqtt.golang @@ -274,9 +281,6 @@ github.com/gorilla/websocket # github.com/gregdel/pushover v1.3.1 ## explicit; go 1.14 github.com/gregdel/pushover -# github.com/hako/durafmt v0.0.0-20210608085754-5c1018a4e16b -## explicit; go 1.11 -github.com/hako/durafmt # github.com/hashicorp/cronexpr v1.1.2 ## explicit github.com/hashicorp/cronexpr