mirror of
https://github.com/crazy-max/diun.git
synced 2025-12-21 13:23:09 +01:00
Merge pull request #1435 from crazy-max/dependabot/go_modules/github.com/dromara/carbon/v2-2.6.8
chore(deps): bump github.com/dromara/carbon/v2 from 2.5.2 to 2.6.8
This commit is contained in:
10
vendor/github.com/dromara/carbon/v2/.editorconfig
generated
vendored
10
vendor/github.com/dromara/carbon/v2/.editorconfig
generated
vendored
@@ -2,13 +2,11 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
indent_style = tab
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
|
||||
[*.md]
|
||||
indent_size = 4
|
||||
trim_trailing_whitespace = false
|
||||
|
||||
[lang/*.json]
|
||||
indent_size = 4
|
||||
trim_trailing_whitespace = false
|
||||
5
vendor/github.com/dromara/carbon/v2/.gitignore
generated
vendored
Normal file
5
vendor/github.com/dromara/carbon/v2/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
# IntelliJ project files
|
||||
.idea
|
||||
*.iml
|
||||
out
|
||||
gen
|
||||
177
vendor/github.com/dromara/carbon/v2/.golangci.yml
generated
vendored
Normal file
177
vendor/github.com/dromara/carbon/v2/.golangci.yml
generated
vendored
Normal file
@@ -0,0 +1,177 @@
|
||||
---
|
||||
# golangci-lint configuration file made by @ccoVeille
|
||||
# Source: https://github.com/ccoVeille/golangci-lint-config-examples/
|
||||
# Author: @ccoVeille
|
||||
# License: MIT
|
||||
# Variant: 03-safe
|
||||
# Version: v1.2.0
|
||||
#
|
||||
linters:
|
||||
# some linters are enabled by default
|
||||
# https://golangci-lint.run/usage/linters/
|
||||
#
|
||||
# enable some extra linters
|
||||
enable:
|
||||
# Errcheck is a program for checking for unchecked errors in Go code.
|
||||
- errcheck
|
||||
|
||||
# Linter for Go source code that specializes in simplifying code.
|
||||
- gosimple
|
||||
|
||||
# Vet examines Go source code and reports suspicious constructs.
|
||||
- govet
|
||||
|
||||
# Detects when assignments to existing variables are not used.
|
||||
- ineffassign
|
||||
|
||||
# It's a set of rules from staticcheck. See https://staticcheck.io/
|
||||
- staticcheck
|
||||
|
||||
# Fast, configurable, extensible, flexible, and beautiful linter for Go.
|
||||
# Drop-in replacement of golint.
|
||||
- revive
|
||||
|
||||
# check imports order and makes it always deterministic.
|
||||
- gci
|
||||
|
||||
# make sure to use t.Helper() when needed
|
||||
- thelper
|
||||
|
||||
# mirror suggests rewrites to avoid unnecessary []byte/string conversion
|
||||
- mirror
|
||||
|
||||
# detect the possibility to use variables/constants from the Go standard library.
|
||||
- usestdlibvars
|
||||
|
||||
# Finds commonly misspelled English words.
|
||||
- misspell
|
||||
|
||||
# Checks for duplicate words in the source code.
|
||||
- dupword
|
||||
|
||||
# linter to detect errors invalid key values count
|
||||
- loggercheck
|
||||
|
||||
# detects nested contexts in loops or function literals
|
||||
- fatcontext
|
||||
|
||||
# Checks usage of github.com/stretchr/testify/require
|
||||
- testifylint
|
||||
|
||||
linters-settings:
|
||||
gci: # define the section orders for imports
|
||||
sections:
|
||||
# Standard section: captures all standard packages.
|
||||
- standard
|
||||
# Default section: catchall that is not standard or custom
|
||||
- default
|
||||
# linters that related to local tool, so they should be separated
|
||||
- localmodule
|
||||
|
||||
revive:
|
||||
rules:
|
||||
# Check for commonly mistaken usages of the sync/atomic package
|
||||
- name: atomic
|
||||
|
||||
# Blank import should be only in a main or test package, or have a comment justifying it.
|
||||
- name: blank-imports
|
||||
|
||||
# Spots comments not starting with a space
|
||||
- name: comment-spacings
|
||||
|
||||
# context.Context() should be the first parameter of a function when provided as argument.
|
||||
- name: context-as-argument
|
||||
arguments:
|
||||
- allowTypesBefore: "*testing.T"
|
||||
|
||||
# Basic types should not be used as a key in `context.WithValue`
|
||||
- name: context-keys-type
|
||||
|
||||
# warns on some common mistakes when using defer statement.
|
||||
- name: defer
|
||||
|
||||
# Importing with `.` makes the programs much harder to understand
|
||||
- name: dot-imports
|
||||
|
||||
# suggest to simplify if-then-else constructions when possible
|
||||
- name: early-return
|
||||
|
||||
# Empty blocks make code less readable and could be a symptom of a bug or unfinished refactoring.
|
||||
- name: empty-block
|
||||
|
||||
# for better readability, variables of type `error` must be named with the prefix `err`.
|
||||
- name: error-naming
|
||||
|
||||
# for better readability, the errors should be last in the list of returned values by a function.
|
||||
- name: error-return
|
||||
|
||||
# for better readability, error messages should not be capitalized or end with punctuation or a newline.
|
||||
- name: error-strings
|
||||
|
||||
# report when replacing `errors.New(fmt.Sprintf())` with `fmt.Errorf()` is possible
|
||||
- name: errorf
|
||||
|
||||
# Checking if an error is nil to just after return the error or nil is redundant.
|
||||
- name: if-return
|
||||
|
||||
# incrementing an integer variable by 1 is recommended to be done using the `++` operator
|
||||
- name: increment-decrement
|
||||
|
||||
# highlights redundant else-blocks that can be eliminated from the code
|
||||
- name: indent-error-flow
|
||||
|
||||
# This rule suggests a shorter way of writing ranges that do not use the second value.
|
||||
- name: range
|
||||
|
||||
# receiver names in a method should reflect the struct name (p for Person, for example)
|
||||
- name: receiver-naming
|
||||
|
||||
# redefining built in names (true, false, append, make) can lead to bugs very difficult to detect.
|
||||
- name: redefines-builtin-id
|
||||
|
||||
# redundant else-blocks that can be eliminated from the code.
|
||||
- name: superfluous-else
|
||||
|
||||
# prevent confusing name for variables when using `time` package
|
||||
- name: time-naming
|
||||
|
||||
# warns when an exported function or method returns a value of an un-exported type.
|
||||
- name: unexported-return
|
||||
|
||||
# spots and proposes to remove unreachable code. also helps to spot errors
|
||||
- name: unreachable-code
|
||||
|
||||
# Functions or methods with unused parameters can be a symptom of an unfinished refactoring or a bug.
|
||||
- name: unused-parameter
|
||||
|
||||
# warns on useless break statements in case clauses of switch and select statements
|
||||
- name: useless-break
|
||||
|
||||
# report when a variable declaration can be simplified
|
||||
- name: var-declaration
|
||||
|
||||
# warns when initialism, variable or package naming conventions are not followed.
|
||||
- name: var-naming
|
||||
|
||||
dupword:
|
||||
# Keywords used to ignore detection.
|
||||
# Default: []
|
||||
ignore:
|
||||
# - "blah" # this will accept "blah blah …" as a valid duplicate word
|
||||
|
||||
misspell:
|
||||
# Correct spellings using locale preferences for US or UK.
|
||||
# Setting locale to US will correct the British spelling of 'colour' to 'color'.
|
||||
# Default ("") is to use a neutral variety of English.
|
||||
locale: US
|
||||
|
||||
# List of words to ignore
|
||||
# among the one defined in https://github.com/golangci/misspell/blob/master/words.go
|
||||
ignore-words:
|
||||
# - valor
|
||||
# - and
|
||||
|
||||
# Extra word corrections.
|
||||
extra-words:
|
||||
# - typo: "whattever"
|
||||
# correction: "whatever"
|
||||
1552
vendor/github.com/dromara/carbon/v2/README.cn.md
generated
vendored
1552
vendor/github.com/dromara/carbon/v2/README.cn.md
generated
vendored
File diff suppressed because it is too large
Load Diff
1521
vendor/github.com/dromara/carbon/v2/README.jp.md
generated
vendored
1521
vendor/github.com/dromara/carbon/v2/README.jp.md
generated
vendored
File diff suppressed because it is too large
Load Diff
1528
vendor/github.com/dromara/carbon/v2/README.md
generated
vendored
1528
vendor/github.com/dromara/carbon/v2/README.md
generated
vendored
File diff suppressed because it is too large
Load Diff
114
vendor/github.com/dromara/carbon/v2/boundary.go
generated
vendored
114
vendor/github.com/dromara/carbon/v2/boundary.go
generated
vendored
@@ -1,63 +1,56 @@
|
||||
package carbon
|
||||
|
||||
// StartOfCentury returns a Carbon instance for start of the century.
|
||||
// 本世纪开始时间
|
||||
func (c Carbon) StartOfCentury() Carbon {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) StartOfCentury() *Carbon {
|
||||
if c.IsInvalid() {
|
||||
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 {
|
||||
func (c *Carbon) EndOfCentury() *Carbon {
|
||||
if c.IsInvalid() {
|
||||
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 {
|
||||
func (c *Carbon) StartOfDecade() *Carbon {
|
||||
if c.IsInvalid() {
|
||||
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 {
|
||||
func (c *Carbon) EndOfDecade() *Carbon {
|
||||
if c.IsInvalid() {
|
||||
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 {
|
||||
func (c *Carbon) StartOfYear() *Carbon {
|
||||
if c.IsInvalid() {
|
||||
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 {
|
||||
func (c *Carbon) EndOfYear() *Carbon {
|
||||
if c.IsInvalid() {
|
||||
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 {
|
||||
func (c *Carbon) StartOfQuarter() *Carbon {
|
||||
if c.IsInvalid() {
|
||||
return c
|
||||
}
|
||||
year, quarter, day := c.Year(), c.Quarter(), 1
|
||||
@@ -65,9 +58,8 @@ func (c Carbon) StartOfQuarter() Carbon {
|
||||
}
|
||||
|
||||
// EndOfQuarter returns a Carbon instance for end of the quarter.
|
||||
// 本季度结束时间
|
||||
func (c Carbon) EndOfQuarter() Carbon {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) EndOfQuarter() *Carbon {
|
||||
if c.IsInvalid() {
|
||||
return c
|
||||
}
|
||||
year, quarter, day := c.Year(), c.Quarter(), 30
|
||||
@@ -81,9 +73,8 @@ func (c Carbon) EndOfQuarter() Carbon {
|
||||
}
|
||||
|
||||
// StartOfMonth returns a Carbon instance for start of the month.
|
||||
// 本月开始时间
|
||||
func (c Carbon) StartOfMonth() Carbon {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) StartOfMonth() *Carbon {
|
||||
if c.IsInvalid() {
|
||||
return c
|
||||
}
|
||||
year, month, _ := c.Date()
|
||||
@@ -91,9 +82,8 @@ func (c Carbon) StartOfMonth() Carbon {
|
||||
}
|
||||
|
||||
// EndOfMonth returns a Carbon instance for end of the month.
|
||||
// 本月结束时间
|
||||
func (c Carbon) EndOfMonth() Carbon {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) EndOfMonth() *Carbon {
|
||||
if c.IsInvalid() {
|
||||
return c
|
||||
}
|
||||
year, month, _ := c.Date()
|
||||
@@ -101,29 +91,32 @@ func (c Carbon) EndOfMonth() Carbon {
|
||||
}
|
||||
|
||||
// StartOfWeek returns a Carbon instance for start of the week.
|
||||
// 本周开始时间
|
||||
func (c Carbon) StartOfWeek() Carbon {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) StartOfWeek() *Carbon {
|
||||
if c.IsInvalid() {
|
||||
return c
|
||||
}
|
||||
dayOfWeek, weekStartsAt := c.DayOfWeek(), int(c.weekStartsAt)
|
||||
return c.SubDays((DaysPerWeek + dayOfWeek - weekStartsAt) % DaysPerWeek).StartOfDay()
|
||||
dayOfWeek, weekStartsAt := c.StdTime().Weekday(), c.WeekStartsAt()
|
||||
if dayOfWeek == weekStartsAt {
|
||||
return c.StartOfDay()
|
||||
}
|
||||
return c.Copy().SubDays(int(DaysPerWeek+dayOfWeek-weekStartsAt) % DaysPerWeek).StartOfDay()
|
||||
}
|
||||
|
||||
// EndOfWeek returns a Carbon instance for end of the week.
|
||||
// 本周结束时间
|
||||
func (c Carbon) EndOfWeek() Carbon {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) EndOfWeek() *Carbon {
|
||||
if c.IsInvalid() {
|
||||
return c
|
||||
}
|
||||
dayOfWeek, weekEndsAt := c.DayOfWeek(), int(c.weekStartsAt)+DaysPerWeek-1
|
||||
return c.AddDays((DaysPerWeek - dayOfWeek + weekEndsAt) % DaysPerWeek).EndOfDay()
|
||||
dayOfWeek, weekEndsAt := c.StdTime().Weekday(), c.WeekEndsAt()
|
||||
if dayOfWeek == weekEndsAt {
|
||||
return c.EndOfDay()
|
||||
}
|
||||
return c.Copy().AddDays(int(DaysPerWeek-dayOfWeek+weekEndsAt) % DaysPerWeek).EndOfDay()
|
||||
}
|
||||
|
||||
// StartOfDay returns a Carbon instance for start of the day.
|
||||
// 本日开始时间
|
||||
func (c Carbon) StartOfDay() Carbon {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) StartOfDay() *Carbon {
|
||||
if c.IsInvalid() {
|
||||
return c
|
||||
}
|
||||
year, month, day := c.Date()
|
||||
@@ -131,9 +124,8 @@ func (c Carbon) StartOfDay() Carbon {
|
||||
}
|
||||
|
||||
// EndOfDay returns a Carbon instance for end of the day.
|
||||
// 本日结束时间
|
||||
func (c Carbon) EndOfDay() Carbon {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) EndOfDay() *Carbon {
|
||||
if c.IsInvalid() {
|
||||
return c
|
||||
}
|
||||
year, month, day := c.Date()
|
||||
@@ -141,9 +133,8 @@ func (c Carbon) EndOfDay() Carbon {
|
||||
}
|
||||
|
||||
// StartOfHour returns a Carbon instance for start of the hour.
|
||||
// 小时开始时间
|
||||
func (c Carbon) StartOfHour() Carbon {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) StartOfHour() *Carbon {
|
||||
if c.IsInvalid() {
|
||||
return c
|
||||
}
|
||||
year, month, day := c.Date()
|
||||
@@ -151,9 +142,8 @@ func (c Carbon) StartOfHour() Carbon {
|
||||
}
|
||||
|
||||
// EndOfHour returns a Carbon instance for end of the hour.
|
||||
// 小时结束时间
|
||||
func (c Carbon) EndOfHour() Carbon {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) EndOfHour() *Carbon {
|
||||
if c.IsInvalid() {
|
||||
return c
|
||||
}
|
||||
year, month, day := c.Date()
|
||||
@@ -161,9 +151,8 @@ func (c Carbon) EndOfHour() Carbon {
|
||||
}
|
||||
|
||||
// StartOfMinute returns a Carbon instance for start of the minute.
|
||||
// 分钟开始时间
|
||||
func (c Carbon) StartOfMinute() Carbon {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) StartOfMinute() *Carbon {
|
||||
if c.IsInvalid() {
|
||||
return c
|
||||
}
|
||||
year, month, day, hour, minute, _ := c.DateTime()
|
||||
@@ -171,9 +160,8 @@ func (c Carbon) StartOfMinute() Carbon {
|
||||
}
|
||||
|
||||
// EndOfMinute returns a Carbon instance for end of the minute.
|
||||
// 分钟结束时间
|
||||
func (c Carbon) EndOfMinute() Carbon {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) EndOfMinute() *Carbon {
|
||||
if c.IsInvalid() {
|
||||
return c
|
||||
}
|
||||
year, month, day, hour, minute, _ := c.DateTime()
|
||||
@@ -181,9 +169,8 @@ func (c Carbon) EndOfMinute() Carbon {
|
||||
}
|
||||
|
||||
// StartOfSecond returns a Carbon instance for start of the second.
|
||||
// 秒开始时间
|
||||
func (c Carbon) StartOfSecond() Carbon {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) StartOfSecond() *Carbon {
|
||||
if c.IsInvalid() {
|
||||
return c
|
||||
}
|
||||
year, month, day, hour, minute, second := c.DateTime()
|
||||
@@ -191,9 +178,8 @@ func (c Carbon) StartOfSecond() Carbon {
|
||||
}
|
||||
|
||||
// EndOfSecond returns a Carbon instance for end of the second.
|
||||
// 秒结束时间
|
||||
func (c Carbon) EndOfSecond() Carbon {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) EndOfSecond() *Carbon {
|
||||
if c.IsInvalid() {
|
||||
return c
|
||||
}
|
||||
year, month, day, hour, minute, second := c.DateTime()
|
||||
|
||||
77
vendor/github.com/dromara/carbon/v2/calendar.go
generated
vendored
77
vendor/github.com/dromara/carbon/v2/calendar.go
generated
vendored
@@ -7,55 +7,66 @@ import (
|
||||
)
|
||||
|
||||
// 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
|
||||
func (c *Carbon) Lunar() *lunar.Lunar {
|
||||
if c.IsNil() {
|
||||
return nil
|
||||
}
|
||||
return lunar.FromGregorian(c.StdTime()).ToLunar()
|
||||
if c.IsZero() || c.IsEmpty() {
|
||||
return &lunar.Lunar{}
|
||||
}
|
||||
if c.HasError() {
|
||||
return &lunar.Lunar{Error: c.Error}
|
||||
}
|
||||
return lunar.FromStdTime(c.StdTime())
|
||||
}
|
||||
|
||||
// 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)
|
||||
// CreateFromLunar creates a Carbon instance from Lunar date.
|
||||
func CreateFromLunar(year, month, day int, isLeapMonth bool) *Carbon {
|
||||
l := lunar.NewLunar(year, month, day, isLeapMonth)
|
||||
if l.Error != nil {
|
||||
return &Carbon{Error: l.Error}
|
||||
}
|
||||
return NewCarbon(l.ToGregorian(DefaultTimezone).Time)
|
||||
}
|
||||
|
||||
// Julian converts Carbon instance to Julian instance.
|
||||
// 将 Carbon 实例转化为 Julian 实例
|
||||
func (c Carbon) Julian() (j julian.Julian) {
|
||||
if c.Error != nil {
|
||||
return
|
||||
func (c *Carbon) Julian() *julian.Julian {
|
||||
if c.IsNil() {
|
||||
return nil
|
||||
}
|
||||
return julian.FromGregorian(c.StdTime()).ToJulian()
|
||||
if c.IsEmpty() {
|
||||
return &julian.Julian{}
|
||||
}
|
||||
if c.HasError() {
|
||||
return &julian.Julian{}
|
||||
}
|
||||
return julian.FromStdTime(c.StdTime())
|
||||
}
|
||||
|
||||
// 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)
|
||||
func CreateFromJulian(f float64) *Carbon {
|
||||
return NewCarbon(julian.NewJulian(f).ToGregorian(DefaultTimezone).Time)
|
||||
}
|
||||
|
||||
// Persian converts Carbon instance to Persian instance.
|
||||
// 将 Carbon 实例转化为 Persian 实例
|
||||
func (c Carbon) Persian() (p persian.Persian) {
|
||||
if c.Error != nil {
|
||||
return
|
||||
func (c *Carbon) Persian() *persian.Persian {
|
||||
if c.IsNil() {
|
||||
return nil
|
||||
}
|
||||
return persian.FromGregorian(c.StdTime()).ToPersian()
|
||||
if c.IsZero() || c.IsEmpty() {
|
||||
return &persian.Persian{}
|
||||
}
|
||||
if c.HasError() {
|
||||
return &persian.Persian{Error: c.Error}
|
||||
}
|
||||
return persian.FromStdTime(c.StdTime())
|
||||
}
|
||||
|
||||
// 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)
|
||||
// CreateFromPersian creates a Carbon instance from Persian date.
|
||||
func CreateFromPersian(year, month, day int) *Carbon {
|
||||
p := persian.NewPersian(year, month, day)
|
||||
if p.Error != nil {
|
||||
c.Error = p.Error
|
||||
return
|
||||
return &Carbon{Error: p.Error}
|
||||
}
|
||||
t := p.ToGregorian().Time
|
||||
return CreateFromStdTime(t)
|
||||
return NewCarbon(p.ToGregorian(DefaultTimezone).Time)
|
||||
}
|
||||
|
||||
269
vendor/github.com/dromara/carbon/v2/calendar/gregorian.go
generated
vendored
269
vendor/github.com/dromara/carbon/v2/calendar/gregorian.go
generated
vendored
@@ -2,279 +2,22 @@
|
||||
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() {
|
||||
// String implements "Stringer" interface.
|
||||
func (g *Gregorian) String() string {
|
||||
if g == nil {
|
||||
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
|
||||
if g.Time.IsZero() {
|
||||
return ""
|
||||
}
|
||||
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
|
||||
return g.Time.String()
|
||||
}
|
||||
|
||||
97
vendor/github.com/dromara/carbon/v2/calendar/julian/julian.go
generated
vendored
97
vendor/github.com/dromara/carbon/v2/calendar/julian/julian.go
generated
vendored
@@ -11,39 +11,20 @@ import (
|
||||
|
||||
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) {
|
||||
// NewJulian returns a new Lunar instance.
|
||||
func NewJulian(f float64) (j *Julian) {
|
||||
j = new(Julian)
|
||||
// get length of the integer part
|
||||
l := len(strconv.Itoa(int(math.Ceil(f))))
|
||||
switch l {
|
||||
@@ -62,15 +43,17 @@ func FromJulian(f float64) (j Julian) {
|
||||
return
|
||||
}
|
||||
|
||||
// ToJulian converts Gregorian instance to Julian instance.
|
||||
// 将 Gregorian 实例转化为 Julian 实例
|
||||
func (g Gregorian) ToJulian() (j Julian) {
|
||||
if g.IsZero() {
|
||||
return
|
||||
// FromStdTime creates a Julian instance from standard time.Time.
|
||||
func FromStdTime(t time.Time) *Julian {
|
||||
j := new(Julian)
|
||||
if t.IsZero() {
|
||||
j.jd = 1721423.5
|
||||
j.mjd = -678577
|
||||
return j
|
||||
}
|
||||
y := g.Year()
|
||||
m := g.Month()
|
||||
d := float64(g.Day()) + ((float64(g.Second())/60+float64(g.Minute()))/60+float64(g.Hour()))/24
|
||||
y := t.Year()
|
||||
m := int(t.Month())
|
||||
d := float64(t.Day()) + ((float64(t.Second())/60+float64(t.Minute()))/60+float64(t.Hour()))/24
|
||||
n := 0
|
||||
f := false
|
||||
if y*372+m*31+int(d) >= 588829 {
|
||||
@@ -85,14 +68,21 @@ func (g Gregorian) ToJulian() (j Julian) {
|
||||
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)
|
||||
return NewJulian(jd)
|
||||
}
|
||||
|
||||
// ToGregorian converts Julian instance to Gregorian instance.
|
||||
// 将 Julian 实例转化为 Gregorian 实例
|
||||
func (j Julian) ToGregorian() (g Gregorian) {
|
||||
if j.IsZero() {
|
||||
return
|
||||
func (j *Julian) ToGregorian(timezone ...string) *calendar.Gregorian {
|
||||
g := new(calendar.Gregorian)
|
||||
if j == nil {
|
||||
return nil
|
||||
}
|
||||
loc := time.UTC
|
||||
if len(timezone) > 0 {
|
||||
loc, g.Error = time.LoadLocation(timezone[0])
|
||||
}
|
||||
if g.Error != nil {
|
||||
return g
|
||||
}
|
||||
d := int(j.jd + 0.5)
|
||||
f := j.jd + 0.5 - float64(d)
|
||||
@@ -123,38 +113,35 @@ func (j Julian) ToGregorian() (g Gregorian) {
|
||||
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))
|
||||
g.Time = time.Date(year, time.Month(month), day, hour, minute, second, 0, loc)
|
||||
return g
|
||||
}
|
||||
|
||||
// JD gets julian day like 2460332.5
|
||||
// 获取儒略日
|
||||
func (j Julian) JD(precision ...int) float64 {
|
||||
if len(precision) > 0 {
|
||||
decimalPrecision = precision[0]
|
||||
func (j *Julian) JD(precision ...int) float64 {
|
||||
if j == nil {
|
||||
return 0
|
||||
}
|
||||
return parseFloat64(j.jd, decimalPrecision)
|
||||
p := decimalPrecision
|
||||
if len(precision) > 0 {
|
||||
p = precision[0]
|
||||
}
|
||||
return parseFloat64(j.jd, p)
|
||||
}
|
||||
|
||||
// MJD gets modified julian day like 60332
|
||||
// 获取简化儒略日
|
||||
func (j Julian) MJD(precision ...int) float64 {
|
||||
func (j *Julian) MJD(precision ...int) float64 {
|
||||
if j == nil {
|
||||
return 0
|
||||
}
|
||||
p := decimalPrecision
|
||||
if len(precision) > 0 {
|
||||
decimalPrecision = precision[0]
|
||||
p = 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
|
||||
return parseFloat64(j.mjd, p)
|
||||
}
|
||||
|
||||
// parseFloat64 round to n decimal places
|
||||
// 四舍五入保留 n 位小数点
|
||||
func parseFloat64(f float64, n int) float64 {
|
||||
p10 := math.Pow10(n)
|
||||
return math.Round(f*p10) / p10
|
||||
|
||||
72
vendor/github.com/dromara/carbon/v2/calendar/lunar/README.cn.md
generated
vendored
72
vendor/github.com/dromara/carbon/v2/calendar/lunar/README.cn.md
generated
vendored
@@ -10,40 +10,40 @@
|
||||
|
||||
```go
|
||||
// 获取农历生肖
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().Animal() // 鼠
|
||||
carbon.Parse("2020-08-05").Lunar().Animal() // 鼠
|
||||
// 获取农历节日
|
||||
carbon.Parse("2021-02-12 13:14:15").Lunar().Festival() // 春节
|
||||
carbon.Parse("2021-02-12").Lunar().Festival() // 春节
|
||||
|
||||
// 获取农历年份
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().Year() // 2020
|
||||
carbon.Parse("2020-08-05").Lunar().Year() // 2020
|
||||
// 获取农历月份
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().Month() // 6
|
||||
carbon.Parse("2020-08-05").Lunar().Month() // 6
|
||||
// 获取农历闰月月份
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().LeapMonth() // 4
|
||||
carbon.Parse("2020-08-05").Lunar().LeapMonth() // 4
|
||||
// 获取农历日期
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().Day() // 16
|
||||
carbon.Parse("2020-08-05").Lunar().Day() // 16
|
||||
// 获取农历时辰
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().Hour() // 13
|
||||
carbon.Parse("2020-08-05").Lunar().Hour() // 13
|
||||
// 获取农历分钟
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().Minute() // 14
|
||||
carbon.Parse("2020-08-05").Lunar().Minute() // 14
|
||||
// 获取农历秒数
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().Second() // 15
|
||||
carbon.Parse("2020-08-05").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").Lunar().String() // 2020-06-16
|
||||
fmt.Printf("%s", carbon.Parse("2020-08-05").Lunar()) // 2020-06-16
|
||||
// 获取农历年字符串
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().ToYearString() // 二零二零
|
||||
carbon.Parse("2020-08-05").Lunar().ToYearString() // 二零二零
|
||||
// 获取农历月字符串
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().ToMonthString() // 六月
|
||||
carbon.Parse("2020-08-05").Lunar().ToMonthString() // 六月
|
||||
// 获取农历闰月字符串
|
||||
carbon.Parse("2020-04-23 13:14:15").Lunar().ToMonthString() // 闰四月
|
||||
carbon.Parse("2020-04-23").Lunar().ToMonthString() // 闰四月
|
||||
// 获取农历周字符串
|
||||
carbon.Parse("2020-04-23 13:14:15").Lunar().ToWeekString() // 周四
|
||||
carbon.Parse("2020-04-23").Lunar().ToWeekString() // 周四
|
||||
// 获取农历天字符串
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().ToDayString() // 十六
|
||||
carbon.Parse("2020-08-05").Lunar().ToDayString() // 十六
|
||||
// 获取农历日期字符串
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().ToDateString() // 二零二零年六月十六
|
||||
carbon.Parse("2020-08-05").Lunar().ToDateString() // 二零二零年六月十六
|
||||
|
||||
```
|
||||
|
||||
@@ -51,11 +51,11 @@ 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, 12, 11, 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, false).ToDateTimeString() // 2023-03-02 00:00:00
|
||||
// 将农历 二零二三年闰二月十一 转化为 公历
|
||||
carbon.CreateFromLunar(2023, 2, 11, 0, 0, 0, true).ToDateTimeString() // 2023-04-01 00:00:00
|
||||
carbon.CreateFromLunar(2023, 2, 11, true).ToDateTimeString() // 2023-04-01 00:00:00
|
||||
```
|
||||
|
||||
##### 日期判断
|
||||
@@ -63,36 +63,36 @@ carbon.CreateFromLunar(2023, 2, 11, 0, 0, 0, true).ToDateTimeString() // 2023-04
|
||||
```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("0000-00-00").Lunar().IsValid() // false
|
||||
carbon.Parse("2020-08-05").Lunar().IsValid() // true
|
||||
|
||||
// 是否是农历闰年
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsLeapYear() // true
|
||||
carbon.Parse("2020-08-05").Lunar().IsLeapYear() // true
|
||||
// 是否是农历闰月
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsLeapMonth() // false
|
||||
carbon.Parse("2020-08-05").Lunar().IsLeapMonth() // false
|
||||
|
||||
// 是否是鼠年
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsRatYear() // true
|
||||
carbon.Parse("2020-08-05").Lunar().IsRatYear() // true
|
||||
// 是否是牛年
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsOxYear() // false
|
||||
carbon.Parse("2020-08-05").Lunar().IsOxYear() // false
|
||||
// 是否是虎年
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsTigerYear() // false
|
||||
carbon.Parse("2020-08-05").Lunar().IsTigerYear() // false
|
||||
// 是否是兔年
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsRabbitYear() // false
|
||||
carbon.Parse("2020-08-05").Lunar().IsRabbitYear() // false
|
||||
// 是否是龙年
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsDragonYear() // false
|
||||
carbon.Parse("2020-08-05").Lunar().IsDragonYear() // false
|
||||
// 是否是蛇年
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsSnakeYear() // false
|
||||
carbon.Parse("2020-08-05").Lunar().IsSnakeYear() // false
|
||||
// 是否是马年
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsHorseYear() // false
|
||||
carbon.Parse("2020-08-05").Lunar().IsHorseYear() // false
|
||||
// 是否是羊年
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsGoatYear() // false
|
||||
carbon.Parse("2020-08-05").Lunar().IsGoatYear() // false
|
||||
// 是否是猴年
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsMonkeyYear() // false
|
||||
carbon.Parse("2020-08-05").Lunar().IsMonkeyYear() // false
|
||||
// 是否是鸡年
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsRoosterYear() // false
|
||||
carbon.Parse("2020-08-05").Lunar().IsRoosterYear() // false
|
||||
// 是否是狗年
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsDogYear() // false
|
||||
carbon.Parse("2020-08-05").Lunar().IsDogYear() // false
|
||||
// 是否是猪年
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsPigYear() // false
|
||||
carbon.Parse("2020-08-05").Lunar().IsPigYear() // false
|
||||
```
|
||||
66
vendor/github.com/dromara/carbon/v2/calendar/lunar/README.jp.md
generated
vendored
66
vendor/github.com/dromara/carbon/v2/calendar/lunar/README.jp.md
generated
vendored
@@ -10,40 +10,40 @@
|
||||
|
||||
```go
|
||||
// 旧暦の干支を手に入れる
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().Animal() // 鼠
|
||||
carbon.Parse("2020-08-05").Lunar().Animal() // 鼠
|
||||
// 旧暦の祝日を取得する
|
||||
carbon.Parse("2021-02-12 13:14:15").Lunar().Festival() // 春节
|
||||
carbon.Parse("2021-02-12").Lunar().Festival() // 春节
|
||||
|
||||
// 旧正月の取得
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().Year() // 2020
|
||||
carbon.Parse("2020-08-05").Lunar().Year() // 2020
|
||||
// 旧暦月の取得
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().Month() // 6
|
||||
carbon.Parse("2020-08-05").Lunar().Month() // 6
|
||||
// 旧暦うるう月の取得
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().LeapMonth() // 4
|
||||
carbon.Parse("2020-08-05").Lunar().LeapMonth() // 4
|
||||
// 旧暦日の取得
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().Day() // 16
|
||||
carbon.Parse("2020-08-05").Lunar().Day() // 16
|
||||
// 旧暦時刻の取得
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().Hour() // 13
|
||||
carbon.Parse("2020-08-05").Lunar().Hour() // 13
|
||||
// 旧暦分の取得
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().Minute() // 14
|
||||
carbon.Parse("2020-08-05").Lunar().Minute() // 14
|
||||
// 旧暦の取得秒数
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().Second() // 15
|
||||
carbon.Parse("2020-08-05").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").Lunar().String() // 2020-06-16
|
||||
fmt.Printf("%s", carbon.Parse("2020-08-05").Lunar()) // 2020-06-16
|
||||
// 旧正月文字列の取得
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().ToYearString() // 二零二零
|
||||
carbon.Parse("2020-08-05").Lunar().ToYearString() // 二零二零
|
||||
// 旧暦月文字列の取得
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().ToMonthString() // 六月
|
||||
carbon.Parse("2020-08-05").Lunar().ToMonthString() // 六月
|
||||
// 旧暦うるう月文字列の取得
|
||||
carbon.Parse("2020-04-23 13:14:15").Lunar().ToMonthString() // 闰四月
|
||||
carbon.Parse("2020-04-23").Lunar().ToMonthString() // 闰四月
|
||||
// 旧暦週文字列の取得
|
||||
carbon.Parse("2020-04-23 13:14:15").Lunar().ToWeekString() // 周四
|
||||
carbon.Parse("2020-04-23").Lunar().ToWeekString() // 周四
|
||||
// 旧暦日文字列の取得
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().ToDayString() // 十六
|
||||
carbon.Parse("2020-08-05").Lunar().ToDayString() // 十六
|
||||
// 旧暦日付文字列の取得
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().ToDateString() // 二零二零年六月十六
|
||||
carbon.Parse("2020-08-05").Lunar().ToDateString() // 二零二零年六月十六
|
||||
|
||||
```
|
||||
|
||||
@@ -61,37 +61,37 @@ carbon.CreateFromLunar(2023, 2, 11, 0, 0, 0, true).ToDateTimeString() // 2023-04
|
||||
##### 日付判断
|
||||
```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("0000-00-00").Lunar().IsValid() // false
|
||||
carbon.Parse("2020-08-05").Lunar().IsValid() // true
|
||||
|
||||
// 旧暦うるう年かどうか
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsLeapYear() // true
|
||||
carbon.Parse("2020-08-05").Lunar().IsLeapYear() // true
|
||||
// 旧暦うるう月かどうか
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsLeapMonth() // false
|
||||
carbon.Parse("2020-08-05").Lunar().IsLeapMonth() // false
|
||||
|
||||
// ねずみ年かどうか
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsRatYear() // true
|
||||
carbon.Parse("2020-08-05").Lunar().IsRatYear() // true
|
||||
// 牛年かどうか
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsOxYear() // false
|
||||
carbon.Parse("2020-08-05").Lunar().IsOxYear() // false
|
||||
// 寅年かどうか
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsTigerYear() // false
|
||||
carbon.Parse("2020-08-05").Lunar().IsTigerYear() // false
|
||||
// うさぎ年かどうか
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsRabbitYear() // false
|
||||
carbon.Parse("2020-08-05").Lunar().IsRabbitYear() // false
|
||||
// 龍年かどうか
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsDragonYear() // false
|
||||
carbon.Parse("2020-08-05").Lunar().IsDragonYear() // false
|
||||
// 蛇の年かどうか
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsSnakeYear() // false
|
||||
carbon.Parse("2020-08-05").Lunar().IsSnakeYear() // false
|
||||
// 馬年かどうか
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsHorseYear() // false
|
||||
carbon.Parse("2020-08-05").Lunar().IsHorseYear() // false
|
||||
// 羊年かどうか
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsGoatYear() // false
|
||||
carbon.Parse("2020-08-05").Lunar().IsGoatYear() // false
|
||||
// 申年かどうか
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsMonkeyYear() // false
|
||||
carbon.Parse("2020-08-05").Lunar().IsMonkeyYear() // false
|
||||
// 鶏の年かどうか
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsRoosterYear() // false
|
||||
carbon.Parse("2020-08-05").Lunar().IsRoosterYear() // false
|
||||
// 犬年かどうか
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsDogYear() // false
|
||||
carbon.Parse("2020-08-05").Lunar().IsDogYear() // false
|
||||
// 豚年かどうか
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsPigYear() // false
|
||||
carbon.Parse("2020-08-05").Lunar().IsPigYear() // false
|
||||
|
||||
```
|
||||
64
vendor/github.com/dromara/carbon/v2/calendar/lunar/README.md
generated
vendored
64
vendor/github.com/dromara/carbon/v2/calendar/lunar/README.md
generated
vendored
@@ -12,38 +12,38 @@ English | [简体中文](README.cn.md) | [日本語](README.jp.md)
|
||||
// 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() // 春节
|
||||
carbon.Parse("2021-02-12").Lunar().Festival() // 春节
|
||||
|
||||
// Get lunar year
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().Year() // 2020
|
||||
carbon.Parse("2020-08-05").Lunar().Year() // 2020
|
||||
// Get lunar month
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().Month() // 6
|
||||
carbon.Parse("2020-08-05").Lunar().Month() // 6
|
||||
// Get lunar leap month
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().LeapMonth() // 4
|
||||
carbon.Parse("2020-08-05").Lunar().LeapMonth() // 4
|
||||
// Get lunar day
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().Day() // 16
|
||||
carbon.Parse("2020-08-05").Lunar().Day() // 16
|
||||
// Get lunar hour
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().Hour() // 13
|
||||
carbon.Parse("2020-08-05").Lunar().Hour() // 13
|
||||
// Get lunar minute
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().Minute() // 14
|
||||
carbon.Parse("2020-08-05").Lunar().Minute() // 14
|
||||
// Get lunar second
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().Second() // 15
|
||||
carbon.Parse("2020-08-05").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
|
||||
carbon.Parse("2020-08-05").Lunar().String() // 2020-06-16
|
||||
fmt.Printf("%s", carbon.Parse("2020-08-05").Lunar()) // 2020-06-16
|
||||
// Get lunar year as string
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().ToYearString() // 二零二零
|
||||
carbon.Parse("2020-08-05").Lunar().ToYearString() // 二零二零
|
||||
// Get lunar month as string
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().ToMonthString() // 六月
|
||||
carbon.Parse("2020-08-05").Lunar().ToMonthString() // 六月
|
||||
// Get lunar leap month as string
|
||||
carbon.Parse("2020-04-23 13:14:15").Lunar().ToMonthString() // 闰四月
|
||||
carbon.Parse("2020-04-23").Lunar().ToMonthString() // 闰四月
|
||||
// Get lunar week as string
|
||||
carbon.Parse("2020-04-23 13:14:15").Lunar().ToWeekString() // 周四
|
||||
carbon.Parse("2020-04-23").Lunar().ToWeekString() // 周四
|
||||
// Get lunar day as string
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().ToDayString() // 十六
|
||||
carbon.Parse("2020-08-05").Lunar().ToDayString() // 十六
|
||||
// Get lunar date as string
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().ToDateString() // 二零二零年六月十六
|
||||
carbon.Parse("2020-08-05").Lunar().ToDateString() // 二零二零年六月十六
|
||||
|
||||
```
|
||||
|
||||
@@ -61,37 +61,37 @@ carbon.CreateFromLunar(2023, 2, 11, 0, 0, 0, true).ToDateTimeString() // 2023-04
|
||||
##### 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
|
||||
carbon.Parse("0000-00-00").Lunar().IsValid() // false
|
||||
carbon.Parse("2020-08-05").Lunar().IsValid() // true
|
||||
|
||||
// Whether is a lunar leap year
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsLeapYear() // true
|
||||
carbon.Parse("2020-08-05").Lunar().IsLeapYear() // true
|
||||
// Whether is a lunar leap month
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsLeapMonth() // false
|
||||
carbon.Parse("2020-08-05").Lunar().IsLeapMonth() // false
|
||||
|
||||
// Whether is a lunar year of the rat
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsRatYear() // true
|
||||
carbon.Parse("2020-08-05").Lunar().IsRatYear() // true
|
||||
// Whether is a lunar year of the ox
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsOxYear() // false
|
||||
carbon.Parse("2020-08-05").Lunar().IsOxYear() // false
|
||||
// Whether is a lunar year of the tiger
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsTigerYear() // false
|
||||
carbon.Parse("2020-08-05").Lunar().IsTigerYear() // false
|
||||
// Whether is a lunar year of the rabbit
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsRabbitYear() // false
|
||||
carbon.Parse("2020-08-05").Lunar().IsRabbitYear() // false
|
||||
// Whether is a lunar year of the dragon
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsDragonYear() // false
|
||||
carbon.Parse("2020-08-05").Lunar().IsDragonYear() // false
|
||||
// Whether is a lunar year of the snake
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsSnakeYear() // false
|
||||
carbon.Parse("2020-08-05").Lunar().IsSnakeYear() // false
|
||||
// Whether is a lunar year of the horse
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsHorseYear() // false
|
||||
carbon.Parse("2020-08-05").Lunar().IsHorseYear() // false
|
||||
// Whether is a lunar year of the goat
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsGoatYear() // false
|
||||
carbon.Parse("2020-08-05").Lunar().IsGoatYear() // false
|
||||
// Whether is a lunar year of the monkey
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsMonkeyYear() // false
|
||||
carbon.Parse("2020-08-05").Lunar().IsMonkeyYear() // false
|
||||
// Whether is a lunar year of the rooster
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsRoosterYear() // false
|
||||
carbon.Parse("2020-08-05").Lunar().IsRoosterYear() // false
|
||||
// Whether is a lunar year of the dog
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsDogYear() // false
|
||||
carbon.Parse("2020-08-05").Lunar().IsDogYear() // false
|
||||
// Whether is a lunar year of the dig
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsPigYear() // false
|
||||
carbon.Parse("2020-08-05").Lunar().IsPigYear() // false
|
||||
|
||||
```
|
||||
329
vendor/github.com/dromara/carbon/v2/calendar/lunar/lunar.go
generated
vendored
329
vendor/github.com/dromara/carbon/v2/calendar/lunar/lunar.go
generated
vendored
@@ -54,86 +54,58 @@ var (
|
||||
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
|
||||
// ErrInvalidLunar returns a invalid lunar date.
|
||||
var ErrInvalidLunar = func() error {
|
||||
return fmt.Errorf("invalid lunar date, please make sure the lunar date is valid")
|
||||
}
|
||||
|
||||
// Lunar defines a Lunar struct.
|
||||
// 定义 Lunar 结构体
|
||||
type Lunar struct {
|
||||
year, month, day, hour, minute, second int
|
||||
isLeapMonth bool
|
||||
Error error
|
||||
year, month, day int
|
||||
isLeapMonth bool
|
||||
Error error
|
||||
}
|
||||
|
||||
// NewLunar returns a new Lunar instance.
|
||||
func NewLunar(year, month, day int, isLeapMonth bool) *Lunar {
|
||||
l := new(Lunar)
|
||||
l.year, l.month, l.day, l.isLeapMonth = year, month, day, isLeapMonth
|
||||
if !l.IsValid() {
|
||||
l.Error = ErrInvalidLunar()
|
||||
}
|
||||
return l
|
||||
}
|
||||
|
||||
// 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,
|
||||
func MaxValue() *Lunar {
|
||||
return &Lunar{
|
||||
year: 2100,
|
||||
month: 12,
|
||||
day: 31,
|
||||
}
|
||||
}
|
||||
|
||||
// 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,
|
||||
func MinValue() *Lunar {
|
||||
return &Lunar{
|
||||
year: 1900,
|
||||
month: 1,
|
||||
day: 1,
|
||||
}
|
||||
}
|
||||
|
||||
// FromGregorian creates a Gregorian instance from time.Time.
|
||||
// 从标准 time.Time 创建 Gregorian 实例
|
||||
func FromGregorian(t time.Time) (g Gregorian) {
|
||||
// FromStdTime creates a Lunar instance from standard time.Time.
|
||||
func FromStdTime(t time.Time) *Lunar {
|
||||
l := new(Lunar)
|
||||
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
|
||||
return nil
|
||||
}
|
||||
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()))
|
||||
offset := int(t.Truncate(time.Hour).Sub(time.Date(minYear, 1, 31, 0, 0, 0, 0, t.Location())).Hours() / 24)
|
||||
for l.year = minYear; l.year <= maxYear && offset > 0; l.year++ {
|
||||
daysInYear = l.getDaysInYear()
|
||||
offset -= daysInYear
|
||||
@@ -156,7 +128,6 @@ func (g Gregorian) ToLunar() (l Lunar) {
|
||||
l.isLeapMonth = false
|
||||
}
|
||||
}
|
||||
// offset为0时,并且刚才计算的月份是闰月,要校正
|
||||
if offset == 0 && leapMonth > 0 && l.month == leapMonth+1 {
|
||||
if l.isLeapMonth {
|
||||
l.isLeapMonth = false
|
||||
@@ -165,51 +136,51 @@ func (g Gregorian) ToLunar() (l Lunar) {
|
||||
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
|
||||
return l
|
||||
}
|
||||
|
||||
// ToGregorian converts Lunar instance to Gregorian instance.
|
||||
// 将 Lunar 实例转化为 Gregorian 实例
|
||||
func (l Lunar) ToGregorian() (g Gregorian) {
|
||||
func (l *Lunar) ToGregorian(timezone ...string) *calendar.Gregorian {
|
||||
g := new(calendar.Gregorian)
|
||||
if !l.IsValid() {
|
||||
return
|
||||
return g
|
||||
}
|
||||
loc := time.UTC
|
||||
if len(timezone) > 0 {
|
||||
loc, g.Error = time.LoadLocation(timezone[0])
|
||||
}
|
||||
if g.Error != nil {
|
||||
return g
|
||||
}
|
||||
days := l.getDaysInMonth()
|
||||
offset := l.getOffsetInYear()
|
||||
offset += l.getOffsetInMonth()
|
||||
// 转换闰月农历 需补充该年闰月的前一个月的时差
|
||||
|
||||
// add the time difference of the month before the leap month
|
||||
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
|
||||
// https://github.com/dromara/carbon/issues/219
|
||||
ts := int64(offset+l.day)*86400 - int64(2206512000)
|
||||
g.Time = time.Unix(ts, 0).In(loc)
|
||||
return g
|
||||
}
|
||||
|
||||
// Animal gets lunar animal name like "猴".
|
||||
// 获取农历生肖
|
||||
func (l Lunar) Animal() string {
|
||||
func (l *Lunar) Animal() string {
|
||||
if !l.IsValid() {
|
||||
return ""
|
||||
}
|
||||
return animals[l.year%calendar.MonthsPerYear]
|
||||
return animals[l.year%12]
|
||||
}
|
||||
|
||||
// Festival gets lunar festival name like "春节".
|
||||
// 获取农历节日
|
||||
func (l Lunar) Festival() string {
|
||||
func (l *Lunar) Festival() string {
|
||||
if !l.IsValid() {
|
||||
return ""
|
||||
}
|
||||
@@ -217,97 +188,60 @@ func (l Lunar) Festival() string {
|
||||
}
|
||||
|
||||
// Year gets lunar year like 2020.
|
||||
// 获取农历年份
|
||||
func (l Lunar) Year() int {
|
||||
if l.Error != nil {
|
||||
func (l *Lunar) Year() int {
|
||||
if !l.IsValid() {
|
||||
return 0
|
||||
}
|
||||
return l.year
|
||||
}
|
||||
|
||||
// Month gets lunar month like 8.
|
||||
// 获取农历月份
|
||||
func (l Lunar) Month() int {
|
||||
if l.Error != nil {
|
||||
func (l *Lunar) Month() int {
|
||||
if !l.IsValid() {
|
||||
return 0
|
||||
}
|
||||
return l.month
|
||||
}
|
||||
|
||||
// Day gets lunar day like 5.
|
||||
// 获取农历日,如 5
|
||||
func (l Lunar) Day() int {
|
||||
if l.Error != nil {
|
||||
func (l *Lunar) Day() int {
|
||||
if !l.IsValid() {
|
||||
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 {
|
||||
func (l *Lunar) LeapMonth() int {
|
||||
if !l.IsValid() {
|
||||
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 {
|
||||
// String implements "Stringer" interface for Lunar.
|
||||
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)
|
||||
return fmt.Sprintf("%04d-%02d-%02d", l.year, l.month, l.day)
|
||||
}
|
||||
|
||||
// ToYearString outputs a string in lunar year format like "二零二零".
|
||||
// 获取农历年份字符串,如 "二零二零"
|
||||
func (l Lunar) ToYearString() (year string) {
|
||||
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)
|
||||
for i := range numbers {
|
||||
year = strings.Replace(year, fmt.Sprintf("%d", i), numbers[i], -1)
|
||||
}
|
||||
return year
|
||||
}
|
||||
|
||||
// ToMonthString outputs a string in lunar month format like "正月".
|
||||
// 获取农历月份字符串,如 "正月"
|
||||
func (l Lunar) ToMonthString() (month string) {
|
||||
func (l *Lunar) ToMonthString() (month string) {
|
||||
if !l.IsValid() {
|
||||
return ""
|
||||
}
|
||||
@@ -319,17 +253,15 @@ func (l Lunar) ToMonthString() (month string) {
|
||||
}
|
||||
|
||||
// ToWeekString outputs a string in week layout like "周一".
|
||||
// 输出完整农历星期字符串,如 "周一"
|
||||
func (l Lunar) ToWeekString() (month string) {
|
||||
func (l *Lunar) ToWeekString() (month string) {
|
||||
if !l.IsValid() {
|
||||
return ""
|
||||
}
|
||||
return weeks[l.ToGregorian().Week()]
|
||||
return weeks[l.ToGregorian().Time.Weekday()]
|
||||
}
|
||||
|
||||
// ToDayString outputs a string in lunar day format like "廿一".
|
||||
// 获取农历日字符串,如 "廿一"
|
||||
func (l Lunar) ToDayString() (day string) {
|
||||
func (l *Lunar) ToDayString() (day string) {
|
||||
if !l.IsValid() {
|
||||
return ""
|
||||
}
|
||||
@@ -353,7 +285,7 @@ func (l Lunar) ToDayString() (day string) {
|
||||
|
||||
// ToDateString outputs a string in lunar date format like "二零二零年腊月初五".
|
||||
// 获取农历日期字符串,如 "二零二零年腊月初五"
|
||||
func (l Lunar) ToDateString() string {
|
||||
func (l *Lunar) ToDateString() string {
|
||||
if !l.IsValid() {
|
||||
return ""
|
||||
}
|
||||
@@ -362,182 +294,167 @@ func (l Lunar) ToDateString() string {
|
||||
|
||||
// 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 {
|
||||
func (l *Lunar) IsValid() bool {
|
||||
if l == nil || l.Error != nil {
|
||||
return false
|
||||
}
|
||||
if l.year >= MinValue().year && l.year <= MaxValue().year {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// IsLeapYear reports whether is a lunar leap year.
|
||||
// 是否是农历闰年
|
||||
func (l Lunar) IsLeapYear() bool {
|
||||
if l.Error != nil {
|
||||
func (l *Lunar) IsLeapYear() bool {
|
||||
if !l.IsValid() {
|
||||
return false
|
||||
}
|
||||
return l.LeapMonth() != 0
|
||||
}
|
||||
|
||||
// IsLeapMonth reports whether is a lunar leap month.
|
||||
// 是否是农历闰月
|
||||
func (l Lunar) IsLeapMonth() bool {
|
||||
if l.Error != nil {
|
||||
func (l *Lunar) IsLeapMonth() bool {
|
||||
if !l.IsValid() {
|
||||
return false
|
||||
}
|
||||
return l.month == l.LeapMonth()
|
||||
return l.isLeapMonth
|
||||
}
|
||||
|
||||
// IsRatYear reports whether is lunar year of Rat.
|
||||
// 是否是鼠年
|
||||
func (l Lunar) IsRatYear() bool {
|
||||
if l.Error != nil {
|
||||
func (l *Lunar) IsRatYear() bool {
|
||||
if !l.IsValid() {
|
||||
return false
|
||||
}
|
||||
if l.year%calendar.MonthsPerYear == 4 {
|
||||
if l.year%12 == 4 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// IsOxYear reports whether is lunar year of Ox.
|
||||
// 是否是牛年
|
||||
func (l Lunar) IsOxYear() bool {
|
||||
if l.Error != nil {
|
||||
func (l *Lunar) IsOxYear() bool {
|
||||
if !l.IsValid() {
|
||||
return false
|
||||
}
|
||||
if l.year%calendar.MonthsPerYear == 5 {
|
||||
if l.year%12 == 5 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// IsTigerYear reports whether is lunar year of Tiger.
|
||||
// 是否是虎年
|
||||
func (l Lunar) IsTigerYear() bool {
|
||||
if l.Error != nil {
|
||||
func (l *Lunar) IsTigerYear() bool {
|
||||
if !l.IsValid() {
|
||||
return false
|
||||
}
|
||||
if l.year%calendar.MonthsPerYear == 6 {
|
||||
if l.year%12 == 6 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// IsRabbitYear reports whether is lunar year of Rabbit.
|
||||
// 是否是兔年
|
||||
func (l Lunar) IsRabbitYear() bool {
|
||||
if l.Error != nil {
|
||||
func (l *Lunar) IsRabbitYear() bool {
|
||||
if !l.IsValid() {
|
||||
return false
|
||||
}
|
||||
if l.year%calendar.MonthsPerYear == 7 {
|
||||
if l.year%12 == 7 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// IsDragonYear reports whether is lunar year of Dragon.
|
||||
// 是否是龙年
|
||||
func (l Lunar) IsDragonYear() bool {
|
||||
if l.Error != nil {
|
||||
func (l *Lunar) IsDragonYear() bool {
|
||||
if !l.IsValid() {
|
||||
return false
|
||||
}
|
||||
if l.year%calendar.MonthsPerYear == 8 {
|
||||
if l.year%12 == 8 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// IsSnakeYear reports whether is lunar year of Snake.
|
||||
// 是否是蛇年
|
||||
func (l Lunar) IsSnakeYear() bool {
|
||||
if l.Error != nil {
|
||||
func (l *Lunar) IsSnakeYear() bool {
|
||||
if !l.IsValid() {
|
||||
return false
|
||||
}
|
||||
if l.year%calendar.MonthsPerYear == 9 {
|
||||
if l.year%12 == 9 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// IsHorseYear reports whether is lunar year of Horse.
|
||||
// 是否是马年
|
||||
func (l Lunar) IsHorseYear() bool {
|
||||
if l.Error != nil {
|
||||
func (l *Lunar) IsHorseYear() bool {
|
||||
if !l.IsValid() {
|
||||
return false
|
||||
}
|
||||
if l.year%calendar.MonthsPerYear == 10 {
|
||||
if l.year%12 == 10 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// IsGoatYear reports whether is lunar year of Goat.
|
||||
// 是否是羊年
|
||||
func (l Lunar) IsGoatYear() bool {
|
||||
if l.Error != nil {
|
||||
func (l *Lunar) IsGoatYear() bool {
|
||||
if !l.IsValid() {
|
||||
return false
|
||||
}
|
||||
if l.year%calendar.MonthsPerYear == 11 {
|
||||
if l.year%12 == 11 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// IsMonkeyYear reports whether is lunar year of Monkey.
|
||||
// 是否是猴年
|
||||
func (l Lunar) IsMonkeyYear() bool {
|
||||
if l.Error != nil {
|
||||
func (l *Lunar) IsMonkeyYear() bool {
|
||||
if !l.IsValid() {
|
||||
return false
|
||||
}
|
||||
if l.year%calendar.MonthsPerYear == 0 {
|
||||
if l.year%12 == 0 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// IsRoosterYear reports whether is lunar year of Rooster.
|
||||
// 是否是鸡年
|
||||
func (l Lunar) IsRoosterYear() bool {
|
||||
if l.Error != nil {
|
||||
func (l *Lunar) IsRoosterYear() bool {
|
||||
if !l.IsValid() {
|
||||
return false
|
||||
}
|
||||
if l.year%calendar.MonthsPerYear == 1 {
|
||||
if l.year%12 == 1 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// IsDogYear reports whether is lunar year of Dog.
|
||||
// 是否是狗年
|
||||
func (l Lunar) IsDogYear() bool {
|
||||
if l.Error != nil {
|
||||
func (l *Lunar) IsDogYear() bool {
|
||||
if !l.IsValid() {
|
||||
return false
|
||||
}
|
||||
if l.year%calendar.MonthsPerYear == 2 {
|
||||
if l.year%12 == 2 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// IsPigYear reports whether is lunar year of Pig.
|
||||
// 是否是猪年
|
||||
func (l Lunar) IsPigYear() bool {
|
||||
if l.Error != nil {
|
||||
func (l *Lunar) IsPigYear() bool {
|
||||
if !l.IsValid() {
|
||||
return false
|
||||
}
|
||||
if l.year%calendar.MonthsPerYear == 3 {
|
||||
if l.year%12 == 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 {
|
||||
func (l *Lunar) getOffsetInYear() int {
|
||||
flag := false
|
||||
clone, month, offset := l, 0, 0
|
||||
clone, month, offset := *l, 0, 0
|
||||
for month = 1; month < l.month; month++ {
|
||||
leapMonth := l.LeapMonth()
|
||||
if !flag {
|
||||
@@ -553,8 +470,8 @@ func (l Lunar) getOffsetInYear() int {
|
||||
return offset
|
||||
}
|
||||
|
||||
func (l Lunar) getOffsetInMonth() int {
|
||||
clone, year, offset := l, 0, 0
|
||||
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()
|
||||
@@ -562,7 +479,7 @@ func (l Lunar) getOffsetInMonth() int {
|
||||
return offset
|
||||
}
|
||||
|
||||
func (l Lunar) getDaysInYear() int {
|
||||
func (l *Lunar) getDaysInYear() int {
|
||||
var days = 348
|
||||
for i := 0x8000; i > 0x8; i >>= 1 {
|
||||
if (years[l.year-MinValue().year] & i) != 0 {
|
||||
@@ -572,14 +489,14 @@ func (l Lunar) getDaysInYear() int {
|
||||
return days + l.getDaysInLeapMonth()
|
||||
}
|
||||
|
||||
func (l Lunar) getDaysInMonth() int {
|
||||
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 {
|
||||
func (l *Lunar) getDaysInLeapMonth() int {
|
||||
if l.LeapMonth() == 0 {
|
||||
return 0
|
||||
}
|
||||
|
||||
68
vendor/github.com/dromara/carbon/v2/calendar/persian/README.cn.md
generated
vendored
68
vendor/github.com/dromara/carbon/v2/calendar/persian/README.cn.md
generated
vendored
@@ -8,67 +8,67 @@
|
||||
|
||||
```go
|
||||
// 获取波斯历年份
|
||||
carbon.Parse("2020-08-05 13:14:15").Persian().Year() // 1399
|
||||
carbon.Parse("2020-08-05").Persian().Year() // 1399
|
||||
// 获取波斯历月份
|
||||
carbon.Parse("2020-08-05 13:14:15").Persian().Month() // 5
|
||||
carbon.Parse("2020-08-05").Persian().Month() // 5
|
||||
// 获取波斯历日期
|
||||
carbon.Parse("2020-08-05 13:14:15").Persian().Day() // 15
|
||||
carbon.Parse("2020-08-05").Persian().Day() // 15
|
||||
// 获取波斯历小时
|
||||
carbon.Parse("2020-08-05 13:14:15").Persian().Hour() // 13
|
||||
carbon.Parse("2020-08-05").Persian().Hour() // 13
|
||||
// 获取波斯历分钟
|
||||
carbon.Parse("2020-08-05 13:14:15").Persian().Minute() // 14
|
||||
carbon.Parse("2020-08-05").Persian().Minute() // 14
|
||||
// 获取波斯历秒数
|
||||
carbon.Parse("2020-08-05 13:14:15").Persian().Second() // 15
|
||||
carbon.Parse("2020-08-05").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").Persian().String() // 1399-05-15
|
||||
fmt.Printf("%s", carbon.Parse("2020-08-05").Persian()) // 1399-05-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").Persian().ToMonthString() // Mordad
|
||||
carbon.Parse("2020-08-05").Persian().ToMonthString("en") // Mordad
|
||||
carbon.Parse("2020-08-05").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").Persian().ToShortMonthString() // Mor
|
||||
carbon.Parse("2020-08-05").Persian().ToShortMonthString("en") // Mor
|
||||
carbon.Parse("2020-08-05").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").Persian().ToWeekString() // Chaharshanbeh
|
||||
carbon.Parse("2020-08-05").Persian().ToWeekString("en") // Chaharshanbeh
|
||||
carbon.Parse("2020-08-05").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") // د
|
||||
carbon.Parse("2020-08-05").Persian().ToShortWeekString() // Cha
|
||||
carbon.Parse("2020-08-05").Persian().ToShortWeekString("en") // Cha
|
||||
carbon.Parse("2020-08-05").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
|
||||
carbon.CreateFromPersian(1, 1, 1).ToDateTimeString() // 2016-03-20 00:00:00
|
||||
carbon.CreateFromPersian(622, 1, 1).ToDateTimeString() // 1243-03-21 00:00:00
|
||||
carbon.CreateFromPersian(1395, 1, 1).ToDateTimeString() // 2016-03-20 00:00:00
|
||||
carbon.CreateFromPersian(9377, 1, 1).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(1, 1, 1).IsValid() // true
|
||||
carbon.CreateFromPersian(622, 1, 1).IsValid() // true
|
||||
carbon.CreateFromPersian(9377, 1, 1).IsValid() // true
|
||||
carbon.CreateFromPersian(0, 0, 0, 0).IsValid() // false
|
||||
carbon.CreateFromPersian(2024, 0, 1).IsValid() // false
|
||||
carbon.CreateFromPersian(2024, 1, 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
|
||||
carbon.CreateFromPersian(1395, 1, 1).IsLeapYear() // true
|
||||
carbon.CreateFromPersian(9377, 1, 1).IsLeapYear() // true
|
||||
carbon.CreateFromPersian(622, 1, 1).IsLeapYear() // false
|
||||
carbon.CreateFromPersian(9999, 1, 1).IsLeapYear() // false
|
||||
|
||||
```
|
||||
68
vendor/github.com/dromara/carbon/v2/calendar/persian/README.jp.md
generated
vendored
68
vendor/github.com/dromara/carbon/v2/calendar/persian/README.jp.md
generated
vendored
@@ -8,66 +8,66 @@
|
||||
|
||||
```go
|
||||
// ペルシャ暦の取得
|
||||
carbon.Parse("2020-08-05 13:14:15").Persian().Year() // 1399
|
||||
carbon.Parse("2020-08-05").Persian().Year() // 1399
|
||||
// ペルシャ暦月の取得
|
||||
carbon.Parse("2020-08-05 13:14:15").Persian().Month() // 5
|
||||
carbon.Parse("2020-08-05").Persian().Month() // 5
|
||||
// ペルシャ暦の取得日
|
||||
carbon.Parse("2020-08-05 13:14:15").Persian().Day() // 15
|
||||
carbon.Parse("2020-08-05").Persian().Day() // 15
|
||||
// ペルシャ暦時間の取得
|
||||
carbon.Parse("2020-08-05 13:14:15").Persian().Hour() // 13
|
||||
carbon.Parse("2020-08-05").Persian().Hour() // 13
|
||||
// ペルシャ暦分の取得
|
||||
carbon.Parse("2020-08-05 13:14:15").Persian().Minute() // 14
|
||||
carbon.Parse("2020-08-05").Persian().Minute() // 14
|
||||
// ペルシャ暦秒の取得
|
||||
carbon.Parse("2020-08-05 13:14:15").Persian().Second() // 15
|
||||
carbon.Parse("2020-08-05").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").Persian().String() // 1399-05-15
|
||||
fmt.Printf("%s", carbon.Parse("2020-08-05").Persian()) // 1399-05-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").Persian().ToMonthString() // Mordad
|
||||
carbon.Parse("2020-08-05").Persian().ToMonthString("en") // Mordad
|
||||
carbon.Parse("2020-08-05").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").Persian().ToShortMonthString() // Mor
|
||||
carbon.Parse("2020-08-05").Persian().ToShortMonthString("en") // Mor
|
||||
carbon.Parse("2020-08-05").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").Persian().ToWeekString() // Chaharshanbeh
|
||||
carbon.Parse("2020-08-05").Persian().ToWeekString("en") // Chaharshanbeh
|
||||
carbon.Parse("2020-08-05").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") // د
|
||||
carbon.Parse("2020-08-05").Persian().ToShortWeekString() // Cha
|
||||
carbon.Parse("2020-08-05").Persian().ToShortWeekString("en") // Cha
|
||||
carbon.Parse("2020-08-05").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
|
||||
carbon.CreateFromPersian(1, 1, 1).ToDateTimeString() // 2016-03-20 00:00:00
|
||||
carbon.CreateFromPersian(622, 1, 1).ToDateTimeString() // 1243-03-21 00:00:00
|
||||
carbon.CreateFromPersian(1395, 1, 1).ToDateTimeString() // 2016-03-20 00:00:00
|
||||
carbon.CreateFromPersian(9377, 1, 1).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(1, 1, 1).IsValid() // true
|
||||
carbon.CreateFromPersian(622, 1, 1).IsValid() // true
|
||||
carbon.CreateFromPersian(9377, 1, 1).IsValid() // true
|
||||
carbon.CreateFromPersian(0, 0, 0, 0).IsValid() // false
|
||||
carbon.CreateFromPersian(2024, 0, 1).IsValid() // false
|
||||
carbon.CreateFromPersian(2024, 1, 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
|
||||
carbon.CreateFromPersian(1395, 1, 1).IsLeapYear() // true
|
||||
carbon.CreateFromPersian(9377, 1, 1).IsLeapYear() // true
|
||||
carbon.CreateFromPersian(622, 1, 1).IsLeapYear() // false
|
||||
carbon.CreateFromPersian(9999, 1, 1).IsLeapYear() // false
|
||||
|
||||
```
|
||||
68
vendor/github.com/dromara/carbon/v2/calendar/persian/README.md
generated
vendored
68
vendor/github.com/dromara/carbon/v2/calendar/persian/README.md
generated
vendored
@@ -8,67 +8,67 @@ English | [简体中文](README.cn.md) | [日本語](README.jp.md)
|
||||
|
||||
```go
|
||||
// Get persian year
|
||||
carbon.Parse("2020-08-05 13:14:15").Persian().Year() // 1399
|
||||
carbon.Parse("2020-08-05").Persian().Year() // 1399
|
||||
// Get persian month
|
||||
carbon.Parse("2020-08-05 13:14:15").Persian().Month() // 5
|
||||
carbon.Parse("2020-08-05").Persian().Month() // 5
|
||||
// Get persian day
|
||||
carbon.Parse("2020-08-05 13:14:15").Persian().Day() // 15
|
||||
carbon.Parse("2020-08-05").Persian().Day() // 15
|
||||
// Get persian hour
|
||||
carbon.Parse("2020-08-05 13:14:15").Persian().Hour() // 13
|
||||
carbon.Parse("2020-08-05").Persian().Hour() // 13
|
||||
// Get persian minute
|
||||
carbon.Parse("2020-08-05 13:14:15").Persian().Minute() // 14
|
||||
carbon.Parse("2020-08-05").Persian().Minute() // 14
|
||||
// Get persian second
|
||||
carbon.Parse("2020-08-05 13:14:15").Persian().Second() // 15
|
||||
carbon.Parse("2020-08-05").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
|
||||
carbon.Parse("2020-08-05").Persian().String() // 1399-05-15
|
||||
fmt.Printf("%s", carbon.Parse("2020-08-05").Persian()) // 1399-05-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") // مرداد
|
||||
carbon.Parse("2020-08-05").Persian().ToMonthString() // Mordad
|
||||
carbon.Parse("2020-08-05").Persian().ToMonthString("en") // Mordad
|
||||
carbon.Parse("2020-08-05").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") // مرد
|
||||
carbon.Parse("2020-08-05").Persian().ToShortMonthString() // Mor
|
||||
carbon.Parse("2020-08-05").Persian().ToShortMonthString("en") // Mor
|
||||
carbon.Parse("2020-08-05").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") // چهارشنبه
|
||||
carbon.Parse("2020-08-05").Persian().ToWeekString() // Chaharshanbeh
|
||||
carbon.Parse("2020-08-05").Persian().ToWeekString("en") // Chaharshanbeh
|
||||
carbon.Parse("2020-08-05").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") // د
|
||||
carbon.Parse("2020-08-05").Persian().ToShortWeekString() // Cha
|
||||
carbon.Parse("2020-08-05").Persian().ToShortWeekString("en") // Cha
|
||||
carbon.Parse("2020-08-05").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
|
||||
carbon.CreateFromPersian(1, 1, 1).ToDateTimeString() // 2016-03-20 00:00:00
|
||||
carbon.CreateFromPersian(622, 1, 1).ToDateTimeString() // 1243-03-21 00:00:00
|
||||
carbon.CreateFromPersian(1395, 1, 1).ToDateTimeString() // 2016-03-20 00:00:00
|
||||
carbon.CreateFromPersian(9377, 1, 1).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
|
||||
carbon.CreateFromPersian(1, 1, 1).IsValid() // true
|
||||
carbon.CreateFromPersian(622, 1, 1).IsValid() // true
|
||||
carbon.CreateFromPersian(9377, 1, 1).IsValid() // true
|
||||
carbon.CreateFromPersian(0, 0, 0, 0).IsValid() // false
|
||||
carbon.CreateFromPersian(2024, 0, 1).IsValid() // false
|
||||
carbon.CreateFromPersian(2024, 1, 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
|
||||
carbon.CreateFromPersian(1395, 1, 1).IsLeapYear() // true
|
||||
carbon.CreateFromPersian(9377, 1, 1).IsLeapYear() // true
|
||||
carbon.CreateFromPersian(622, 1, 1).IsLeapYear() // false
|
||||
carbon.CreateFromPersian(9999, 1, 1).IsLeapYear() // false
|
||||
|
||||
```
|
||||
229
vendor/github.com/dromara/carbon/v2/calendar/persian/persian.go
generated
vendored
229
vendor/github.com/dromara/carbon/v2/calendar/persian/persian.go
generated
vendored
@@ -10,6 +10,13 @@ import (
|
||||
"github.com/dromara/carbon/v2/calendar/julian"
|
||||
)
|
||||
|
||||
type Locale string
|
||||
|
||||
const EnLocale Locale = "en"
|
||||
const FaLocale Locale = "fa"
|
||||
|
||||
const defaultLocale = EnLocale
|
||||
|
||||
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"}
|
||||
@@ -22,78 +29,54 @@ var (
|
||||
|
||||
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
|
||||
// ErrInvalidPersian returns a invalid persian date.
|
||||
var ErrInvalidPersian = func() error {
|
||||
return fmt.Errorf("invalid persian date, please make sure the persian date is valid")
|
||||
}
|
||||
|
||||
// Persian defines a Persian struct.
|
||||
// 定义 Persian 结构体
|
||||
type Persian struct {
|
||||
year, month, day, hour, minute, second int
|
||||
Error error
|
||||
year, month, day int
|
||||
Error error
|
||||
}
|
||||
|
||||
// NewPersian returns a new Persian instance.
|
||||
func NewPersian(year, month, day int) *Persian {
|
||||
p := new(Persian)
|
||||
p.year, p.month, p.day = year, month, day
|
||||
if !p.IsValid() {
|
||||
p.Error = ErrInvalidPersian()
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
// 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,
|
||||
func MaxValue() *Persian {
|
||||
return &Persian{
|
||||
year: 9377,
|
||||
month: 12,
|
||||
day: 31,
|
||||
}
|
||||
}
|
||||
|
||||
// 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,
|
||||
func MinValue() *Persian {
|
||||
return &Persian{
|
||||
year: 1,
|
||||
month: 1,
|
||||
day: 1,
|
||||
}
|
||||
}
|
||||
|
||||
// FromGregorian creates a Gregorian instance from time.Time.
|
||||
// 从标准 time.Time 创建 Gregorian 实例
|
||||
func FromGregorian(t time.Time) (g Gregorian) {
|
||||
// FromStdTime creates a Persian instance from standard time.Time.
|
||||
func FromStdTime(t time.Time) *Persian {
|
||||
p := new(Persian)
|
||||
if t.IsZero() {
|
||||
return
|
||||
return nil
|
||||
}
|
||||
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())
|
||||
gjdn := int(julian.FromStdTime(time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, 0, t.Location())).JD(0))
|
||||
pjdn := getPersianJdn(475, 1, 1)
|
||||
|
||||
diff := gjdn - pjdn
|
||||
@@ -109,21 +92,23 @@ func (g Gregorian) ToPersian() (p Persian) {
|
||||
}
|
||||
pjdn = getPersianJdn(p.year, p.month, 1)
|
||||
p.day = gjdn - pjdn + 1
|
||||
if !p.IsValid() {
|
||||
p.Error = InvalidDateError()
|
||||
return
|
||||
}
|
||||
return
|
||||
return p
|
||||
}
|
||||
|
||||
// ToGregorian converts Persian instance to Gregorian instance.
|
||||
// 将 Persian 实例转化为 Gregorian 实例
|
||||
func (p Persian) ToGregorian() (g Gregorian) {
|
||||
func (p *Persian) ToGregorian(timezone ...string) *calendar.Gregorian {
|
||||
g := new(calendar.Gregorian)
|
||||
if !p.IsValid() {
|
||||
return
|
||||
return g
|
||||
}
|
||||
loc := time.UTC
|
||||
if len(timezone) > 0 {
|
||||
loc, g.Error = time.LoadLocation(timezone[0])
|
||||
}
|
||||
if g.Error != nil {
|
||||
return g
|
||||
}
|
||||
jdn := getPersianJdn(p.year, p.month, p.day)
|
||||
|
||||
l := jdn + 68569
|
||||
n := 4 * l / 146097
|
||||
l = l - (146097*n+3)/4
|
||||
@@ -135,161 +120,129 @@ func (p Persian) ToGregorian() (g Gregorian) {
|
||||
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
|
||||
g.Time = time.Date(y, time.Month(m), d, 0, 0, 0, 0, loc)
|
||||
return g
|
||||
}
|
||||
|
||||
// Year gets lunar year like 2020.
|
||||
// 获取年份,如 2020
|
||||
func (p Persian) Year() int {
|
||||
if p.Error != nil {
|
||||
func (p *Persian) Year() int {
|
||||
if !p.IsValid() {
|
||||
return 0
|
||||
}
|
||||
return p.year
|
||||
}
|
||||
|
||||
// Month gets lunar month like 8.
|
||||
// 获取月份,如 8
|
||||
func (p Persian) Month() int {
|
||||
if p.Error != nil {
|
||||
func (p *Persian) Month() int {
|
||||
if !p.IsValid() {
|
||||
return 0
|
||||
}
|
||||
return p.month
|
||||
}
|
||||
|
||||
// Day gets lunar day like 5.
|
||||
// 获取日,如 5
|
||||
func (p Persian) Day() int {
|
||||
if p.Error != nil {
|
||||
func (p *Persian) Day() int {
|
||||
if !p.IsValid() {
|
||||
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 {
|
||||
// String implements "Stringer" interface for Persian.
|
||||
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)
|
||||
return fmt.Sprintf("%04d-%02d-%02d", p.year, p.month, p.day)
|
||||
}
|
||||
|
||||
// ToMonthString outputs a string in persian month format like "فروردین".
|
||||
// 获取完整月份字符串,如 "فروردین"
|
||||
func (p Persian) ToMonthString(locale ...string) (month string) {
|
||||
func (p *Persian) ToMonthString(locale ...Locale) (month string) {
|
||||
if !p.IsValid() {
|
||||
return ""
|
||||
}
|
||||
loc := "en"
|
||||
loc := defaultLocale
|
||||
if len(locale) > 0 {
|
||||
loc = locale[0]
|
||||
}
|
||||
switch loc {
|
||||
case "en":
|
||||
case EnLocale:
|
||||
return EnMonths[p.month-1]
|
||||
case "fa":
|
||||
case FaLocale:
|
||||
return FaMonths[p.month-1]
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// ToShortMonthString outputs a short string in persian month format like "فروردین".
|
||||
// 获取缩写月份字符串,如 "فروردین"
|
||||
func (p Persian) ToShortMonthString(locale ...string) (month string) {
|
||||
func (p *Persian) ToShortMonthString(locale ...Locale) (month string) {
|
||||
if !p.IsValid() {
|
||||
return ""
|
||||
}
|
||||
loc := "en"
|
||||
loc := defaultLocale
|
||||
if len(locale) > 0 {
|
||||
loc = locale[0]
|
||||
}
|
||||
switch loc {
|
||||
case "en":
|
||||
case EnLocale:
|
||||
return ShortEnMonths[p.month-1]
|
||||
case "fa":
|
||||
case FaLocale:
|
||||
return ShortFaMonths[p.month-1]
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// ToWeekString outputs a string in week layout like "چهارشنبه".
|
||||
// 输出完整星期字符串,如 "چهارشنبه"
|
||||
func (p Persian) ToWeekString(locale ...string) (month string) {
|
||||
func (p *Persian) ToWeekString(locale ...Locale) (month string) {
|
||||
if !p.IsValid() {
|
||||
return ""
|
||||
}
|
||||
loc := "en"
|
||||
loc := defaultLocale
|
||||
if len(locale) > 0 {
|
||||
loc = locale[0]
|
||||
}
|
||||
week := p.ToGregorian().Time.Weekday()
|
||||
switch loc {
|
||||
case "en":
|
||||
return EnWeeks[p.ToGregorian().Week()]
|
||||
case "fa":
|
||||
return FaWeeks[p.ToGregorian().Week()]
|
||||
case EnLocale:
|
||||
return EnWeeks[week]
|
||||
case FaLocale:
|
||||
return FaWeeks[week]
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// ToShortWeekString outputs a short string in week layout like "چهارشنبه".
|
||||
// 输出缩写星期字符串,如 "چهارشنبه"
|
||||
func (p Persian) ToShortWeekString(locale ...string) (month string) {
|
||||
func (p *Persian) ToShortWeekString(locale ...Locale) (month string) {
|
||||
if !p.IsValid() {
|
||||
return ""
|
||||
}
|
||||
loc := "en"
|
||||
loc := defaultLocale
|
||||
if len(locale) > 0 {
|
||||
loc = locale[0]
|
||||
}
|
||||
week := p.ToGregorian().Time.Weekday()
|
||||
switch loc {
|
||||
case "en":
|
||||
return ShortEnWeeks[p.ToGregorian().Week()]
|
||||
case "fa":
|
||||
return ShortFaWeeks[p.ToGregorian().Week()]
|
||||
case EnLocale:
|
||||
return ShortEnWeeks[week]
|
||||
case FaLocale:
|
||||
return ShortFaWeeks[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 {
|
||||
func (p *Persian) IsValid() bool {
|
||||
if p == nil || p.Error != nil {
|
||||
return false
|
||||
}
|
||||
if p.year >= MinValue().year && p.year <= MaxValue().year {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// IsLeapYear reports whether is a persian leap year.
|
||||
// 是否是闰年
|
||||
func (p Persian) IsLeapYear() bool {
|
||||
func (p *Persian) IsLeapYear() bool {
|
||||
if !p.IsValid() {
|
||||
return false
|
||||
}
|
||||
@@ -297,7 +250,6 @@ func (p Persian) IsLeapYear() bool {
|
||||
}
|
||||
|
||||
// gets Julian day number in Persian calendar
|
||||
// 获取波斯历儒略日计数
|
||||
func getPersianJdn(year, month, day int) int {
|
||||
year = year - 473
|
||||
if year >= 0 {
|
||||
@@ -312,10 +264,3 @@ func getPersianJdn(year, month, day int) int {
|
||||
}
|
||||
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)
|
||||
}
|
||||
|
||||
500
vendor/github.com/dromara/carbon/v2/carbon.go
generated
vendored
500
vendor/github.com/dromara/carbon/v2/carbon.go
generated
vendored
@@ -1,483 +1,63 @@
|
||||
// @Package carbon
|
||||
// @Description a simple, semantic and developer-friendly golang package for datetime
|
||||
// @Description a simple, semantic and developer-friendly time package for golang
|
||||
// @Page github.com/dromara/carbon
|
||||
// @Developer gouguoyin
|
||||
// @Blog www.gouguoyin.com
|
||||
// @Email 245629560@qq.com
|
||||
|
||||
// Package carbon is a simple, semantic and developer-friendly golang package for datetime.
|
||||
// Package carbon is a simple, semantic and developer-friendly time package for golang.
|
||||
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"
|
||||
)
|
||||
type StdTime = time.Time
|
||||
type Weekday = time.Weekday
|
||||
type Location = time.Location
|
||||
type Duration = time.Duration
|
||||
|
||||
// Carbon defines a Carbon struct.
|
||||
// 定义 Carbon 结构体
|
||||
type Carbon struct {
|
||||
time time.Time
|
||||
testNow int64 // nanosecond timestamp of test now time
|
||||
layout string
|
||||
weekStartsAt time.Weekday
|
||||
loc *time.Location
|
||||
lang *Language
|
||||
Error error
|
||||
time StdTime
|
||||
weekStartsAt Weekday
|
||||
weekendDays []Weekday
|
||||
loc *Location
|
||||
lang *Language
|
||||
currentLayout string
|
||||
isEmpty bool
|
||||
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
|
||||
func NewCarbon(stdTime ...StdTime) *Carbon {
|
||||
c := new(Carbon)
|
||||
c.lang = NewLanguage().SetLocale(DefaultLocale)
|
||||
c.weekStartsAt = DefaultWeekStartsAt
|
||||
c.weekendDays = DefaultWeekendDays
|
||||
c.currentLayout = DefaultLayout
|
||||
if len(stdTime) > 0 {
|
||||
c.time = stdTime[0]
|
||||
c.loc = c.time.Location()
|
||||
return c
|
||||
}
|
||||
c.layout = defaultLayout
|
||||
c.loc, c.Error = parseTimezone(DefaultTimezone)
|
||||
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}
|
||||
// Copy returns a copy of the Carbon instance.
|
||||
func (c *Carbon) Copy() *Carbon {
|
||||
if c.IsNil() {
|
||||
return nil
|
||||
}
|
||||
return &Carbon{
|
||||
time: time.Date(c.Year(), time.Month(c.Month()), c.Day(), c.Hour(), c.Minute(), c.Second(), c.Nanosecond(), c.loc),
|
||||
weekStartsAt: c.weekStartsAt,
|
||||
weekendDays: c.weekendDays,
|
||||
loc: c.loc,
|
||||
lang: c.lang.Copy(),
|
||||
currentLayout: c.currentLayout,
|
||||
isEmpty: c.isEmpty,
|
||||
Error: c.Error,
|
||||
}
|
||||
}
|
||||
|
||||
411
vendor/github.com/dromara/carbon/v2/comparer.go
generated
vendored
411
vendor/github.com/dromara/carbon/v2/comparer.go
generated
vendored
@@ -4,79 +4,83 @@ 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() {
|
||||
// HasError reports whether has error.
|
||||
func (c *Carbon) HasError() bool {
|
||||
if c.IsNil() {
|
||||
return false
|
||||
}
|
||||
if c.Year() >= MinValue().Year() && c.Year() <= MaxValue().Year() && c.Month() > 0 && c.Day() > 0 {
|
||||
return c.Error != nil
|
||||
}
|
||||
|
||||
// IsNil reports whether is nil pointer.
|
||||
func (c *Carbon) IsNil() bool {
|
||||
return c == nil
|
||||
}
|
||||
|
||||
// IsEmpty reports whether is empty value.
|
||||
func (c *Carbon) IsEmpty() bool {
|
||||
if c.IsNil() || c.HasError() {
|
||||
return false
|
||||
}
|
||||
return c.isEmpty
|
||||
}
|
||||
|
||||
// IsZero reports whether is a zero time(0001-01-01 00:00:00 +0000 UTC).
|
||||
func (c *Carbon) IsZero() bool {
|
||||
if c.IsNil() || c.IsEmpty() || c.HasError() {
|
||||
return false
|
||||
}
|
||||
return c.StdTime().IsZero()
|
||||
}
|
||||
|
||||
// IsEpoch reports whether is a unix epoch time(1970-01-01 00:00:00 +0000 UTC).
|
||||
func (c *Carbon) IsEpoch() bool {
|
||||
if c.IsInvalid() {
|
||||
return false
|
||||
}
|
||||
return c.Eq(EpochValue())
|
||||
}
|
||||
|
||||
// IsValid reports whether is a valid time.
|
||||
func (c *Carbon) IsValid() bool {
|
||||
if !c.IsNil() && !c.HasError() && !c.IsEmpty() {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// IsInvalid reports whether is invalid time.
|
||||
// 是否是无效时间
|
||||
func (c Carbon) IsInvalid() bool {
|
||||
// IsInvalid reports whether is an invalid time.
|
||||
func (c *Carbon) IsInvalid() bool {
|
||||
return !c.IsValid()
|
||||
}
|
||||
|
||||
// IsDST reports whether is a daylight saving time.
|
||||
func (c *Carbon) IsDST() bool {
|
||||
if c.IsInvalid() {
|
||||
return false
|
||||
}
|
||||
return c.StdTime().IsDST()
|
||||
}
|
||||
|
||||
// IsAM reports whether is before noon.
|
||||
// 是否是上午
|
||||
func (c Carbon) IsAM() bool {
|
||||
func (c *Carbon) IsAM() bool {
|
||||
if c.IsInvalid() {
|
||||
return false
|
||||
}
|
||||
return c.Format("a") == "am"
|
||||
}
|
||||
|
||||
// IsPM reports whether is after noon.
|
||||
// 是否是下午
|
||||
func (c Carbon) IsPM() bool {
|
||||
func (c *Carbon) IsPM() bool {
|
||||
if c.IsInvalid() {
|
||||
return false
|
||||
}
|
||||
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 {
|
||||
func (c *Carbon) IsLeapYear() bool {
|
||||
if c.IsInvalid() {
|
||||
return false
|
||||
}
|
||||
year := c.Year()
|
||||
@@ -86,308 +90,310 @@ func (c Carbon) IsLeapYear() bool {
|
||||
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 {
|
||||
// IsLongYear reports whether is a long year, refer to https://en.wikipedia.org/wiki/ISO_8601#Week_dates.
|
||||
func (c *Carbon) IsLongYear() bool {
|
||||
if c.IsInvalid() {
|
||||
return false
|
||||
}
|
||||
_, w := time.Date(c.Year(), 12, 31, 0, 0, 0, 0, c.loc).ISOWeek()
|
||||
return w == weeksPerLongYear
|
||||
return w == WeeksPerLongYear
|
||||
}
|
||||
|
||||
// IsJanuary reports whether is January.
|
||||
// 是否是一月
|
||||
func (c Carbon) IsJanuary() bool {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) IsJanuary() bool {
|
||||
if c.IsInvalid() {
|
||||
return false
|
||||
}
|
||||
return c.Month() == int(time.January)
|
||||
}
|
||||
|
||||
// IsFebruary reports whether is February.
|
||||
// 是否是二月
|
||||
func (c Carbon) IsFebruary() bool {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) IsFebruary() bool {
|
||||
if c.IsInvalid() {
|
||||
return false
|
||||
}
|
||||
return c.Month() == int(time.February)
|
||||
}
|
||||
|
||||
// IsMarch reports whether is March.
|
||||
// 是否是三月
|
||||
func (c Carbon) IsMarch() bool {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) IsMarch() bool {
|
||||
if c.IsInvalid() {
|
||||
return false
|
||||
}
|
||||
return c.Month() == int(time.March)
|
||||
}
|
||||
|
||||
// IsApril reports whether is April.
|
||||
// 是否是四月
|
||||
func (c Carbon) IsApril() bool {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) IsApril() bool {
|
||||
if c.IsInvalid() {
|
||||
return false
|
||||
}
|
||||
return c.Month() == int(time.April)
|
||||
}
|
||||
|
||||
// IsMay reports whether is May.
|
||||
// 是否是五月
|
||||
func (c Carbon) IsMay() bool {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) IsMay() bool {
|
||||
if c.IsInvalid() {
|
||||
return false
|
||||
}
|
||||
return c.Month() == int(time.May)
|
||||
}
|
||||
|
||||
// IsJune reports whether is June.
|
||||
// 是否是六月
|
||||
func (c Carbon) IsJune() bool {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) IsJune() bool {
|
||||
if c.IsInvalid() {
|
||||
return false
|
||||
}
|
||||
return c.Month() == int(time.June)
|
||||
}
|
||||
|
||||
// IsJuly reports whether is July.
|
||||
// 是否是七月
|
||||
func (c Carbon) IsJuly() bool {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) IsJuly() bool {
|
||||
if c.IsInvalid() {
|
||||
return false
|
||||
}
|
||||
return c.Month() == int(time.July)
|
||||
}
|
||||
|
||||
// IsAugust reports whether is August.
|
||||
// 是否是八月
|
||||
func (c Carbon) IsAugust() bool {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) IsAugust() bool {
|
||||
if c.IsInvalid() {
|
||||
return false
|
||||
}
|
||||
return c.Month() == int(time.August)
|
||||
}
|
||||
|
||||
// IsSeptember reports whether is September.
|
||||
// 是否是九月
|
||||
func (c Carbon) IsSeptember() bool {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) IsSeptember() bool {
|
||||
if c.IsInvalid() {
|
||||
return false
|
||||
}
|
||||
return c.Month() == int(time.September)
|
||||
}
|
||||
|
||||
// IsOctober reports whether is October.
|
||||
// 是否是十月
|
||||
func (c Carbon) IsOctober() bool {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) IsOctober() bool {
|
||||
if c.IsInvalid() {
|
||||
return false
|
||||
}
|
||||
return c.Month() == int(time.October)
|
||||
}
|
||||
|
||||
// IsNovember reports whether is November.
|
||||
// 是否是十一月
|
||||
func (c Carbon) IsNovember() bool {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) IsNovember() bool {
|
||||
if c.IsInvalid() {
|
||||
return false
|
||||
}
|
||||
return c.Month() == int(time.November)
|
||||
}
|
||||
|
||||
// IsDecember reports whether is December.
|
||||
// 是否是十二月
|
||||
func (c Carbon) IsDecember() bool {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) IsDecember() bool {
|
||||
if c.IsInvalid() {
|
||||
return false
|
||||
}
|
||||
return c.Month() == int(time.December)
|
||||
}
|
||||
|
||||
// IsMonday reports whether is Monday.
|
||||
// 是否是周一
|
||||
func (c Carbon) IsMonday() bool {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) IsMonday() bool {
|
||||
if c.IsInvalid() {
|
||||
return false
|
||||
}
|
||||
return c.StdTime().Weekday() == time.Monday
|
||||
}
|
||||
|
||||
// IsTuesday reports whether is Tuesday.
|
||||
// 是否是周二
|
||||
func (c Carbon) IsTuesday() bool {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) IsTuesday() bool {
|
||||
if c.IsInvalid() {
|
||||
return false
|
||||
}
|
||||
return c.StdTime().Weekday() == time.Tuesday
|
||||
}
|
||||
|
||||
// IsWednesday reports whether is Wednesday.
|
||||
// 是否是周三
|
||||
func (c Carbon) IsWednesday() bool {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) IsWednesday() bool {
|
||||
if c.IsInvalid() {
|
||||
return false
|
||||
}
|
||||
return c.StdTime().Weekday() == time.Wednesday
|
||||
}
|
||||
|
||||
// IsThursday reports whether is Thursday.
|
||||
// 是否是周四
|
||||
func (c Carbon) IsThursday() bool {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) IsThursday() bool {
|
||||
if c.IsInvalid() {
|
||||
return false
|
||||
}
|
||||
return c.StdTime().Weekday() == time.Thursday
|
||||
}
|
||||
|
||||
// IsFriday reports whether is Friday.
|
||||
// 是否是周五
|
||||
func (c Carbon) IsFriday() bool {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) IsFriday() bool {
|
||||
if c.IsInvalid() {
|
||||
return false
|
||||
}
|
||||
return c.StdTime().Weekday() == time.Friday
|
||||
}
|
||||
|
||||
// IsSaturday reports whether is Saturday.
|
||||
// 是否是周六
|
||||
func (c Carbon) IsSaturday() bool {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) IsSaturday() bool {
|
||||
if c.IsInvalid() {
|
||||
return false
|
||||
}
|
||||
return c.StdTime().Weekday() == time.Saturday
|
||||
}
|
||||
|
||||
// IsSunday reports whether is Sunday.
|
||||
// 是否是周日
|
||||
func (c Carbon) IsSunday() bool {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) IsSunday() bool {
|
||||
if c.IsInvalid() {
|
||||
return false
|
||||
}
|
||||
return c.StdTime().Weekday() == time.Sunday
|
||||
}
|
||||
|
||||
// IsWeekday reports whether is weekday.
|
||||
// 是否是工作日
|
||||
func (c Carbon) IsWeekday() bool {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) IsWeekday() bool {
|
||||
if c.IsInvalid() {
|
||||
return false
|
||||
}
|
||||
return !c.IsSaturday() && !c.IsSunday()
|
||||
return !c.IsWeekend()
|
||||
}
|
||||
|
||||
// IsWeekend reports whether is weekend.
|
||||
// 是否是周末
|
||||
func (c Carbon) IsWeekend() bool {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) IsWeekend() bool {
|
||||
if c.IsInvalid() {
|
||||
return false
|
||||
}
|
||||
return c.IsSaturday() || c.IsSunday()
|
||||
d := c.StdTime().Weekday()
|
||||
for i := range c.weekendDays {
|
||||
if d == c.weekendDays[i] {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// IsNow reports whether is now time.
|
||||
func (c *Carbon) IsNow() bool {
|
||||
if c.IsInvalid() {
|
||||
return false
|
||||
}
|
||||
return c.Timestamp() == Now().SetLocation(c.loc).Timestamp()
|
||||
}
|
||||
|
||||
// IsFuture reports whether is future time.
|
||||
func (c *Carbon) IsFuture() bool {
|
||||
if c.IsInvalid() {
|
||||
return false
|
||||
}
|
||||
if c.IsZero() {
|
||||
return false
|
||||
}
|
||||
return c.Timestamp() > Now().SetLocation(c.loc).Timestamp()
|
||||
}
|
||||
|
||||
// IsPast reports whether is past time.
|
||||
func (c *Carbon) IsPast() bool {
|
||||
if c.IsInvalid() {
|
||||
return false
|
||||
}
|
||||
if c.IsZero() {
|
||||
return true
|
||||
}
|
||||
return c.Timestamp() < Now().SetLocation(c.loc).Timestamp()
|
||||
}
|
||||
|
||||
// IsYesterday reports whether is yesterday.
|
||||
// 是否是昨天
|
||||
func (c Carbon) IsYesterday() bool {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) IsYesterday() bool {
|
||||
if c.IsInvalid() {
|
||||
return false
|
||||
}
|
||||
return c.ToDateString() == Yesterday().ToDateString()
|
||||
return c.ToDateString() == Yesterday().SetLocation(c.loc).ToDateString()
|
||||
}
|
||||
|
||||
// IsToday reports whether is today.
|
||||
// 是否是今天
|
||||
func (c Carbon) IsToday() bool {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) IsToday() bool {
|
||||
if c.IsInvalid() {
|
||||
return false
|
||||
}
|
||||
return c.ToDateString() == Now().ToDateString()
|
||||
return c.ToDateString() == Now().SetLocation(c.loc).ToDateString()
|
||||
}
|
||||
|
||||
// IsTomorrow reports whether is tomorrow.
|
||||
// 是否是明天
|
||||
func (c Carbon) IsTomorrow() bool {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) IsTomorrow() bool {
|
||||
if c.IsInvalid() {
|
||||
return false
|
||||
}
|
||||
return c.ToDateString() == Tomorrow().ToDateString()
|
||||
return c.ToDateString() == Tomorrow().SetLocation(c.loc).ToDateString()
|
||||
}
|
||||
|
||||
// IsSameCentury reports whether is same century.
|
||||
// 是否是同一世纪
|
||||
func (c Carbon) IsSameCentury(t Carbon) bool {
|
||||
if c.Error != nil || t.Error != nil {
|
||||
func (c *Carbon) IsSameCentury(t *Carbon) bool {
|
||||
if c.IsInvalid() || t.IsInvalid() {
|
||||
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 {
|
||||
func (c *Carbon) IsSameDecade(t *Carbon) bool {
|
||||
if c.IsInvalid() || t.IsInvalid() {
|
||||
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 {
|
||||
func (c *Carbon) IsSameYear(t *Carbon) bool {
|
||||
if c.IsInvalid() || t.IsInvalid() {
|
||||
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 {
|
||||
func (c *Carbon) IsSameQuarter(t *Carbon) bool {
|
||||
if c.IsInvalid() || t.IsInvalid() {
|
||||
return false
|
||||
}
|
||||
return c.Quarter() == t.Quarter()
|
||||
return c.Year() == t.Year() && c.Quarter() == t.Quarter()
|
||||
}
|
||||
|
||||
// IsSameMonth reports whether is same month.
|
||||
// 是否是同一月
|
||||
func (c Carbon) IsSameMonth(t Carbon) bool {
|
||||
if c.Error != nil || t.Error != nil {
|
||||
func (c *Carbon) IsSameMonth(t *Carbon) bool {
|
||||
if c.IsInvalid() || t.IsInvalid() {
|
||||
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 {
|
||||
func (c *Carbon) IsSameDay(t *Carbon) bool {
|
||||
if c.IsInvalid() || t.IsInvalid() {
|
||||
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 {
|
||||
func (c *Carbon) IsSameHour(t *Carbon) bool {
|
||||
if c.IsInvalid() || t.IsInvalid() {
|
||||
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 {
|
||||
func (c *Carbon) IsSameMinute(t *Carbon) bool {
|
||||
if c.IsInvalid() || t.IsInvalid() {
|
||||
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 {
|
||||
func (c *Carbon) IsSameSecond(t *Carbon) bool {
|
||||
if c.IsInvalid() || t.IsInvalid() {
|
||||
return false
|
||||
}
|
||||
return c.Format("YmdHis") == t.Format("YmdHis")
|
||||
@@ -395,9 +401,8 @@ func (c Carbon) IsSameSecond(t Carbon) bool {
|
||||
}
|
||||
|
||||
// Compare compares by an operator.
|
||||
// 时间比较
|
||||
func (c Carbon) Compare(operator string, t Carbon) bool {
|
||||
if c.Error != nil || t.Error != nil {
|
||||
func (c *Carbon) Compare(operator string, t *Carbon) bool {
|
||||
if c.IsInvalid() || t.IsInvalid() {
|
||||
return false
|
||||
}
|
||||
switch operator {
|
||||
@@ -418,60 +423,59 @@ func (c Carbon) Compare(operator string, t Carbon) bool {
|
||||
}
|
||||
|
||||
// Gt reports whether greater than.
|
||||
// 是否大于
|
||||
func (c Carbon) Gt(t Carbon) bool {
|
||||
if c.Error != nil || t.Error != nil {
|
||||
func (c *Carbon) Gt(t *Carbon) bool {
|
||||
if c.IsInvalid() || t.IsInvalid() {
|
||||
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 {
|
||||
func (c *Carbon) Lt(t *Carbon) bool {
|
||||
if c.IsInvalid() || t.IsInvalid() {
|
||||
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 {
|
||||
func (c *Carbon) Eq(t *Carbon) bool {
|
||||
if c.IsInvalid() || t.IsInvalid() {
|
||||
return false
|
||||
}
|
||||
return c.time.Equal(t.time)
|
||||
}
|
||||
|
||||
// Ne reports whether not equal.
|
||||
// 是否不等于
|
||||
func (c Carbon) Ne(t Carbon) bool {
|
||||
func (c *Carbon) Ne(t *Carbon) bool {
|
||||
if c.IsInvalid() || t.IsInvalid() {
|
||||
return false
|
||||
}
|
||||
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 {
|
||||
func (c *Carbon) Gte(t *Carbon) bool {
|
||||
if c.IsInvalid() || t.IsInvalid() {
|
||||
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 {
|
||||
func (c *Carbon) Lte(t *Carbon) bool {
|
||||
if c.IsInvalid() || t.IsInvalid() {
|
||||
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 {
|
||||
func (c *Carbon) Between(start *Carbon, end *Carbon) bool {
|
||||
if start.Gt(end) {
|
||||
return false
|
||||
}
|
||||
if c.IsInvalid() || start.IsInvalid() || end.IsInvalid() {
|
||||
return false
|
||||
}
|
||||
if c.Gt(start) && c.Lt(end) {
|
||||
@@ -481,9 +485,14 @@ func (c Carbon) Between(start Carbon, end Carbon) bool {
|
||||
}
|
||||
|
||||
// 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 {
|
||||
func (c *Carbon) BetweenIncludedStart(start *Carbon, end *Carbon) bool {
|
||||
if start.Gt(end) {
|
||||
return false
|
||||
}
|
||||
if c.IsZero() && start.IsZero() {
|
||||
return true
|
||||
}
|
||||
if c.IsInvalid() || start.IsInvalid() || end.IsInvalid() {
|
||||
return false
|
||||
}
|
||||
if c.Gte(start) && c.Lt(end) {
|
||||
@@ -493,9 +502,14 @@ func (c Carbon) BetweenIncludedStart(start Carbon, end Carbon) bool {
|
||||
}
|
||||
|
||||
// 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 {
|
||||
func (c *Carbon) BetweenIncludedEnd(start *Carbon, end *Carbon) bool {
|
||||
if start.Gt(end) {
|
||||
return false
|
||||
}
|
||||
if c.IsZero() && end.IsZero() {
|
||||
return true
|
||||
}
|
||||
if c.IsInvalid() || start.IsInvalid() || end.IsInvalid() {
|
||||
return false
|
||||
}
|
||||
if c.Gt(start) && c.Lte(end) {
|
||||
@@ -505,9 +519,14 @@ func (c Carbon) BetweenIncludedEnd(start Carbon, end Carbon) bool {
|
||||
}
|
||||
|
||||
// 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 {
|
||||
func (c *Carbon) BetweenIncludedBoth(start *Carbon, end *Carbon) bool {
|
||||
if start.Gt(end) {
|
||||
return false
|
||||
}
|
||||
if (c.IsZero() && start.IsZero()) || (c.IsZero() && end.IsZero()) {
|
||||
return true
|
||||
}
|
||||
if c.IsInvalid() || start.IsInvalid() || end.IsInvalid() {
|
||||
return false
|
||||
}
|
||||
if c.Gte(start) && c.Lte(end) {
|
||||
|
||||
290
vendor/github.com/dromara/carbon/v2/constants.go
generated
vendored
Normal file
290
vendor/github.com/dromara/carbon/v2/constants.go
generated
vendored
Normal file
@@ -0,0 +1,290 @@
|
||||
package carbon
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// Version current version
|
||||
const Version = "2.6.7"
|
||||
|
||||
// timezone constants
|
||||
const (
|
||||
Local = "Local"
|
||||
UTC = "UTC"
|
||||
|
||||
CET = "CET"
|
||||
EET = "EET"
|
||||
EST = "EST"
|
||||
GMT = "GMT"
|
||||
MET = "MET"
|
||||
MST = "MST"
|
||||
UCT = "MST"
|
||||
WET = "WET"
|
||||
Zulu = "Zulu"
|
||||
|
||||
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 = time.January
|
||||
February = time.February
|
||||
March = time.March
|
||||
April = time.April
|
||||
May = time.May
|
||||
June = time.June
|
||||
July = time.July
|
||||
August = time.August
|
||||
September = time.September
|
||||
October = time.October
|
||||
November = time.November
|
||||
December = time.December
|
||||
)
|
||||
|
||||
// constellation constants
|
||||
const (
|
||||
Aries = "Aries"
|
||||
Taurus = "Taurus"
|
||||
Gemini = "Gemini"
|
||||
Cancer = "Cancer"
|
||||
Leo = "Leo"
|
||||
Virgo = "Virgo"
|
||||
Libra = "Libra"
|
||||
Scorpio = "Scorpio"
|
||||
Sagittarius = "Sagittarius"
|
||||
Capricorn = "Capricorn"
|
||||
Aquarius = "Aquarius"
|
||||
Pisces = "Pisces"
|
||||
)
|
||||
|
||||
// week constants
|
||||
const (
|
||||
Monday = time.Monday
|
||||
Tuesday = time.Tuesday
|
||||
Wednesday = time.Wednesday
|
||||
Thursday = time.Thursday
|
||||
Friday = time.Friday
|
||||
Saturday = time.Saturday
|
||||
Sunday = time.Sunday
|
||||
)
|
||||
|
||||
// season constants
|
||||
const (
|
||||
Spring = "Spring"
|
||||
Summer = "Summer"
|
||||
Autumn = "Autumn"
|
||||
Winter = "Winter"
|
||||
)
|
||||
|
||||
// number constants
|
||||
const (
|
||||
EpochYear = 1970
|
||||
YearsPerMillennium = 1000
|
||||
YearsPerCentury = 100
|
||||
YearsPerDecade = 10
|
||||
QuartersPerYear = 4
|
||||
MonthsPerYear = 12
|
||||
MonthsPerQuarter = 3
|
||||
WeeksPerNormalYear = 52
|
||||
WeeksPerLongYear = 53
|
||||
WeeksPerMonth = 4
|
||||
DaysPerLeapYear = 366
|
||||
DaysPerNormalYear = 365
|
||||
DaysPerWeek = 7
|
||||
HoursPerWeek = 168
|
||||
HoursPerDay = 24
|
||||
MinutesPerDay = 1440
|
||||
MinutesPerHour = 60
|
||||
SecondsPerWeek = 604800
|
||||
SecondsPerDay = 86400
|
||||
SecondsPerHour = 3600
|
||||
SecondsPerMinute = 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"
|
||||
|
||||
TimestampLayout = "unix"
|
||||
TimestampMilliLayout = "unixMilli"
|
||||
TimestampMicroLayout = "unixMicro"
|
||||
TimestampNanoLayout = "unixNano"
|
||||
)
|
||||
|
||||
// format constants
|
||||
const (
|
||||
AtomFormat = "Y-m-d\\TH:i:sR"
|
||||
ANSICFormat = "D M j H:i:s Y"
|
||||
CookieFormat = "l, d-M-Y H:i:s Z"
|
||||
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 Z Y"
|
||||
|
||||
RFC1036Format = "D, d M y H:i:s O"
|
||||
RFC1123Format = "D, d M Y H:i:s Z"
|
||||
RFC1123ZFormat = "D, d M Y H:i:s O"
|
||||
RFC2822Format = "D, d M Y H:i:s O"
|
||||
RFC3339Format = "Y-m-d\\TH:i:sR"
|
||||
RFC3339MilliFormat = "Y-m-d\\TH:i:s.uR"
|
||||
RFC3339MicroFormat = "Y-m-d\\TH:i:s.vR"
|
||||
RFC3339NanoFormat = "Y-m-d\\TH:i:s.xR"
|
||||
RFC7231Format = "D, d M Y H:i:s Z"
|
||||
RFC822Format = "d M y H:i Z"
|
||||
RFC822ZFormat = "d M y H:i O"
|
||||
RFC850Format = "l, d-M-y H:i:s Z"
|
||||
|
||||
ISO8601Format = "Y-m-d\\TH:i:sP"
|
||||
ISO8601MilliFormat = "Y-m-d\\TH:i:s.uP"
|
||||
ISO8601MicroFormat = "Y-m-d\\TH:i:s.vP"
|
||||
ISO8601NanoFormat = "Y-m-d\\TH:i:s.xP"
|
||||
|
||||
ISO8601ZuluFormat = "Y-m-d\\TH:i:s\\Z"
|
||||
ISO8601ZuluMilliFormat = "Y-m-d\\TH:i:s.u\\Z"
|
||||
ISO8601ZuluMicroFormat = "Y-m-d\\TH:i:s.v\\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.u"
|
||||
DateTimeMicroFormat = "Y-m-d H:i:s.v"
|
||||
DateTimeNanoFormat = "Y-m-d H:i:s.x"
|
||||
ShortDateTimeFormat = "YmdHis"
|
||||
ShortDateTimeMilliFormat = "YmdHis.u"
|
||||
ShortDateTimeMicroFormat = "YmdHis.v"
|
||||
ShortDateTimeNanoFormat = "YmdHis.x"
|
||||
|
||||
DateFormat = "Y-m-d"
|
||||
DateMilliFormat = "Y-m-d.u"
|
||||
DateMicroFormat = "Y-m-d.v"
|
||||
DateNanoFormat = "Y-m-d.x"
|
||||
ShortDateFormat = "Ymd"
|
||||
ShortDateMilliFormat = "Ymd.u"
|
||||
ShortDateMicroFormat = "Ymd.v"
|
||||
ShortDateNanoFormat = "Ymd.x"
|
||||
|
||||
TimeFormat = "H:i:s"
|
||||
TimeMilliFormat = "H:i:s.u"
|
||||
TimeMicroFormat = "H:i:s.v"
|
||||
TimeNanoFormat = "H:i:s.x"
|
||||
ShortTimeFormat = "His"
|
||||
ShortTimeMilliFormat = "His.u"
|
||||
ShortTimeMicroFormat = "His.v"
|
||||
ShortTimeNanoFormat = "His.x"
|
||||
|
||||
TimestampFormat = "S"
|
||||
TimestampMilliFormat = "U"
|
||||
TimestampMicroFormat = "V"
|
||||
TimestampNanoFormat = "X"
|
||||
)
|
||||
44
vendor/github.com/dromara/carbon/v2/constellation.go
generated
vendored
44
vendor/github.com/dromara/carbon/v2/constellation.go
generated
vendored
@@ -23,14 +23,10 @@ var constellations = []struct {
|
||||
}
|
||||
|
||||
// Constellation gets constellation name like "Aries", i18n is supported.
|
||||
// 获取星座,支持i18n
|
||||
func (c Carbon) Constellation() string {
|
||||
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++ {
|
||||
@@ -42,8 +38,10 @@ func (c Carbon) Constellation() string {
|
||||
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 {
|
||||
@@ -54,8 +52,7 @@ func (c Carbon) Constellation() string {
|
||||
}
|
||||
|
||||
// IsAries reports whether is Aries.
|
||||
// 是否是白羊座
|
||||
func (c Carbon) IsAries() bool {
|
||||
func (c *Carbon) IsAries() bool {
|
||||
if c.IsInvalid() {
|
||||
return false
|
||||
}
|
||||
@@ -70,8 +67,7 @@ func (c Carbon) IsAries() bool {
|
||||
}
|
||||
|
||||
// IsTaurus reports whether is Taurus.
|
||||
// 是否是金牛座
|
||||
func (c Carbon) IsTaurus() bool {
|
||||
func (c *Carbon) IsTaurus() bool {
|
||||
if c.IsInvalid() {
|
||||
return false
|
||||
}
|
||||
@@ -86,8 +82,7 @@ func (c Carbon) IsTaurus() bool {
|
||||
}
|
||||
|
||||
// IsGemini reports whether is Gemini.
|
||||
// 是否是双子座
|
||||
func (c Carbon) IsGemini() bool {
|
||||
func (c *Carbon) IsGemini() bool {
|
||||
if c.IsInvalid() {
|
||||
return false
|
||||
}
|
||||
@@ -102,8 +97,7 @@ func (c Carbon) IsGemini() bool {
|
||||
}
|
||||
|
||||
// IsCancer reports whether is Cancer.
|
||||
// 是否是巨蟹座
|
||||
func (c Carbon) IsCancer() bool {
|
||||
func (c *Carbon) IsCancer() bool {
|
||||
if c.IsInvalid() {
|
||||
return false
|
||||
}
|
||||
@@ -118,8 +112,7 @@ func (c Carbon) IsCancer() bool {
|
||||
}
|
||||
|
||||
// IsLeo reports whether is Leo.
|
||||
// 是否是狮子座
|
||||
func (c Carbon) IsLeo() bool {
|
||||
func (c *Carbon) IsLeo() bool {
|
||||
if c.IsInvalid() {
|
||||
return false
|
||||
}
|
||||
@@ -134,8 +127,7 @@ func (c Carbon) IsLeo() bool {
|
||||
}
|
||||
|
||||
// IsVirgo reports whether is Virgo.
|
||||
// 是否是处女座
|
||||
func (c Carbon) IsVirgo() bool {
|
||||
func (c *Carbon) IsVirgo() bool {
|
||||
if c.IsInvalid() {
|
||||
return false
|
||||
}
|
||||
@@ -150,8 +142,7 @@ func (c Carbon) IsVirgo() bool {
|
||||
}
|
||||
|
||||
// IsLibra reports whether is Libra.
|
||||
// 是否是天秤座
|
||||
func (c Carbon) IsLibra() bool {
|
||||
func (c *Carbon) IsLibra() bool {
|
||||
if c.IsInvalid() {
|
||||
return false
|
||||
}
|
||||
@@ -166,8 +157,7 @@ func (c Carbon) IsLibra() bool {
|
||||
}
|
||||
|
||||
// IsScorpio reports whether is Scorpio.
|
||||
// 是否是天蝎座
|
||||
func (c Carbon) IsScorpio() bool {
|
||||
func (c *Carbon) IsScorpio() bool {
|
||||
if c.IsInvalid() {
|
||||
return false
|
||||
}
|
||||
@@ -182,8 +172,7 @@ func (c Carbon) IsScorpio() bool {
|
||||
}
|
||||
|
||||
// IsSagittarius reports whether is Sagittarius.
|
||||
// 是否是射手座
|
||||
func (c Carbon) IsSagittarius() bool {
|
||||
func (c *Carbon) IsSagittarius() bool {
|
||||
if c.IsInvalid() {
|
||||
return false
|
||||
}
|
||||
@@ -198,8 +187,7 @@ func (c Carbon) IsSagittarius() bool {
|
||||
}
|
||||
|
||||
// IsCapricorn reports whether is Capricorn.
|
||||
// 是否是摩羯座
|
||||
func (c Carbon) IsCapricorn() bool {
|
||||
func (c *Carbon) IsCapricorn() bool {
|
||||
if c.IsInvalid() {
|
||||
return false
|
||||
}
|
||||
@@ -214,8 +202,7 @@ func (c Carbon) IsCapricorn() bool {
|
||||
}
|
||||
|
||||
// IsAquarius reports whether is Aquarius.
|
||||
// 是否是水瓶座
|
||||
func (c Carbon) IsAquarius() bool {
|
||||
func (c *Carbon) IsAquarius() bool {
|
||||
if c.IsInvalid() {
|
||||
return false
|
||||
}
|
||||
@@ -230,8 +217,7 @@ func (c Carbon) IsAquarius() bool {
|
||||
}
|
||||
|
||||
// IsPisces reports whether is Pisces.
|
||||
// 是否是双鱼座
|
||||
func (c Carbon) IsPisces() bool {
|
||||
func (c *Carbon) IsPisces() bool {
|
||||
if c.IsInvalid() {
|
||||
return false
|
||||
}
|
||||
|
||||
310
vendor/github.com/dromara/carbon/v2/creator.go
generated
vendored
310
vendor/github.com/dromara/carbon/v2/creator.go
generated
vendored
@@ -5,250 +5,184 @@ import (
|
||||
)
|
||||
|
||||
// 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()
|
||||
func CreateFromStdTime(stdTime StdTime, timezone ...string) *Carbon {
|
||||
if len(timezone) == 0 {
|
||||
return NewCarbon(stdTime)
|
||||
}
|
||||
var (
|
||||
loc *Location
|
||||
err error
|
||||
)
|
||||
if loc, err = parseTimezone(timezone[0]); err != nil {
|
||||
return &Carbon{Error: err}
|
||||
}
|
||||
return NewCarbon(stdTime.In(loc))
|
||||
}
|
||||
|
||||
// CreateFromTimestamp creates a Carbon instance from a given timestamp with second precision.
|
||||
func CreateFromTimestamp(timestamp int64, timezone ...string) *Carbon {
|
||||
var (
|
||||
tz string
|
||||
loc *Location
|
||||
err error
|
||||
)
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
tz = timezone[0]
|
||||
} else {
|
||||
tz = DefaultTimezone
|
||||
}
|
||||
c.time = tt
|
||||
return c
|
||||
if loc, err = parseTimezone(tz); err != nil {
|
||||
return &Carbon{Error: err}
|
||||
}
|
||||
return NewCarbon(time.Unix(timestamp, 0).In(loc))
|
||||
}
|
||||
|
||||
// CreateFromTimestamp creates a Carbon instance from a given timestamp with second.
|
||||
// 从给定的秒级时间戳创建 Carbon 实例
|
||||
func (c Carbon) CreateFromTimestamp(timestamp int64, timezone ...string) Carbon {
|
||||
// CreateFromTimestampMilli creates a Carbon instance from a given timestamp with millisecond precision.
|
||||
func CreateFromTimestampMilli(timestampMilli int64, timezone ...string) *Carbon {
|
||||
var (
|
||||
tz string
|
||||
loc *Location
|
||||
err error
|
||||
)
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
tz = timezone[0]
|
||||
} else {
|
||||
tz = DefaultTimezone
|
||||
}
|
||||
if c.Error != nil {
|
||||
return c
|
||||
if loc, err = parseTimezone(tz); err != nil {
|
||||
return &Carbon{Error: err}
|
||||
}
|
||||
c.time = time.Unix(timestamp, 0)
|
||||
return c
|
||||
return NewCarbon(time.Unix(timestampMilli/1e3, (timestampMilli%1e3)*1e6).In(loc))
|
||||
}
|
||||
|
||||
// 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 {
|
||||
// CreateFromTimestampMicro creates a Carbon instance from a given timestamp with microsecond precision.
|
||||
func CreateFromTimestampMicro(timestampMicro int64, timezone ...string) *Carbon {
|
||||
var (
|
||||
tz string
|
||||
loc *Location
|
||||
err error
|
||||
)
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
tz = timezone[0]
|
||||
} else {
|
||||
tz = DefaultTimezone
|
||||
}
|
||||
if c.Error != nil {
|
||||
return c
|
||||
if loc, err = parseTimezone(tz); err != nil {
|
||||
return &Carbon{Error: err}
|
||||
}
|
||||
c.time = time.Unix(timestamp/1e3, (timestamp%1e3)*1e6)
|
||||
return c
|
||||
return NewCarbon(time.Unix(timestampMicro/1e6, (timestampMicro%1e6)*1e3).In(loc))
|
||||
}
|
||||
|
||||
// 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 {
|
||||
// CreateFromTimestampNano creates a Carbon instance from a given timestamp with nanosecond precision.
|
||||
func CreateFromTimestampNano(timestampNano int64, timezone ...string) *Carbon {
|
||||
var (
|
||||
tz string
|
||||
loc *Location
|
||||
err error
|
||||
)
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
tz = timezone[0]
|
||||
} else {
|
||||
tz = DefaultTimezone
|
||||
}
|
||||
if c.Error != nil {
|
||||
return c
|
||||
if loc, err = parseTimezone(tz); err != nil {
|
||||
return &Carbon{Error: err}
|
||||
}
|
||||
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...)
|
||||
return NewCarbon(time.Unix(timestampNano/1e9, timestampNano%1e9).In(loc))
|
||||
}
|
||||
|
||||
// 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...)
|
||||
func CreateFromDateTime(year, month, day, hour, minute, second int, timezone ...string) *Carbon {
|
||||
return create(year, month, day, hour, minute, second, 0, 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...)
|
||||
func CreateFromDateTimeMilli(year, month, day, hour, minute, second, millisecond int, timezone ...string) *Carbon {
|
||||
return create(year, month, day, hour, minute, second, millisecond*1e6, 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...)
|
||||
func CreateFromDateTimeMicro(year, month, day, hour, minute, second, microsecond int, timezone ...string) *Carbon {
|
||||
return create(year, month, day, hour, minute, second, microsecond*1e3, 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...)
|
||||
func CreateFromDateTimeNano(year, month, day, hour, minute, second, nanosecond int, timezone ...string) *Carbon {
|
||||
return create(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...)
|
||||
func CreateFromDate(year, month, day int, timezone ...string) *Carbon {
|
||||
return create(year, month, day, 0, 0, 0, 0, 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...)
|
||||
func CreateFromDateMilli(year, month, day, millisecond int, timezone ...string) *Carbon {
|
||||
return create(year, month, day, 0, 0, 0, millisecond*1e6, 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...)
|
||||
func CreateFromDateMicro(year, month, day, microsecond int, timezone ...string) *Carbon {
|
||||
return create(year, month, day, 0, 0, 0, microsecond*1e3, 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...)
|
||||
func CreateFromDateNano(year, month, day, nanosecond int, timezone ...string) *Carbon {
|
||||
return create(year, month, day, 0, 0, 0, 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...)
|
||||
func CreateFromTime(hour, minute, second int, timezone ...string) *Carbon {
|
||||
year, month, day := Now(timezone...).Date()
|
||||
return create(year, month, day, hour, minute, second, 0, 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...)
|
||||
func CreateFromTimeMilli(hour, minute, second, millisecond int, timezone ...string) *Carbon {
|
||||
year, month, day := Now(timezone...).Date()
|
||||
return create(year, month, day, hour, minute, second, millisecond*1e6, 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...)
|
||||
func CreateFromTimeMicro(hour, minute, second, microsecond int, timezone ...string) *Carbon {
|
||||
year, month, day := Now(timezone...).Date()
|
||||
return create(year, month, day, hour, minute, second, microsecond*1e3, 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...)
|
||||
func CreateFromTimeNano(hour, minute, second, nanosecond int, timezone ...string) *Carbon {
|
||||
year, month, day := Now(timezone...).Date()
|
||||
return 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 {
|
||||
// creates a new Carbon instance from a given date, time and nanosecond.
|
||||
func create(year, month, day, hour, minute, second, nanosecond int, timezone ...string) *Carbon {
|
||||
var (
|
||||
tz string
|
||||
loc *Location
|
||||
err error
|
||||
)
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
tz = timezone[0]
|
||||
} else {
|
||||
tz = DefaultTimezone
|
||||
}
|
||||
if c.Error != nil {
|
||||
return c
|
||||
if loc, err = parseTimezone(tz); err != nil {
|
||||
return &Carbon{Error: err}
|
||||
}
|
||||
return NewCarbon(time.Date(year, time.Month(month), day, hour, minute, second, nanosecond, loc))
|
||||
}
|
||||
|
||||
// creates a new Carbon instance from a given date, time and nanosecond based on the existing Carbon.
|
||||
func (c *Carbon) create(year, month, day, hour, minute, second, nanosecond int) *Carbon {
|
||||
return &Carbon{
|
||||
time: time.Date(year, time.Month(month), day, hour, minute, second, nanosecond, c.loc),
|
||||
weekStartsAt: c.weekStartsAt,
|
||||
weekendDays: c.weekendDays,
|
||||
loc: c.loc,
|
||||
lang: c.lang.Copy(),
|
||||
currentLayout: c.currentLayout,
|
||||
isEmpty: c.isEmpty,
|
||||
Error: c.Error,
|
||||
}
|
||||
c.time = time.Date(year, time.Month(month), day, hour, minute, second, nanosecond, c.loc)
|
||||
return c
|
||||
}
|
||||
|
||||
890
vendor/github.com/dromara/carbon/v2/database.go
generated
vendored
890
vendor/github.com/dromara/carbon/v2/database.go
generated
vendored
@@ -1,890 +0,0 @@
|
||||
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)
|
||||
}
|
||||
57
vendor/github.com/dromara/carbon/v2/default.go
generated
vendored
57
vendor/github.com/dromara/carbon/v2/default.go
generated
vendored
@@ -1,45 +1,58 @@
|
||||
package carbon
|
||||
|
||||
var (
|
||||
// default layout
|
||||
// 默认布局模板
|
||||
defaultLayout = DateTimeLayout
|
||||
// DefaultLayout default layout
|
||||
DefaultLayout = DateTimeLayout
|
||||
|
||||
// default timezone
|
||||
// 默认时区
|
||||
defaultTimezone = Local
|
||||
// DefaultTimezone default timezone
|
||||
DefaultTimezone = UTC
|
||||
|
||||
// default week start date
|
||||
// 默认一周开始日期
|
||||
defaultWeekStartsAt = Sunday
|
||||
// DefaultLocale default language locale
|
||||
DefaultLocale = "en"
|
||||
|
||||
// default language locale
|
||||
// 默认语言区域
|
||||
defaultLocale = "en"
|
||||
// DefaultWeekStartsAt default start date of the week
|
||||
DefaultWeekStartsAt = Monday
|
||||
|
||||
// DefaultWeekendDays default weekend days of the week
|
||||
DefaultWeekendDays = []Weekday{
|
||||
Saturday, Sunday,
|
||||
}
|
||||
)
|
||||
|
||||
// Default defines a Default struct.
|
||||
// 定义 Default 结构体
|
||||
type Default struct {
|
||||
Layout string
|
||||
Timezone string
|
||||
WeekStartsAt string
|
||||
Locale string
|
||||
WeekStartsAt Weekday
|
||||
WeekendDays []Weekday
|
||||
}
|
||||
|
||||
// SetDefault sets default.
|
||||
// 设置全局默认值
|
||||
func SetDefault(d Default) {
|
||||
if d.Layout != "" {
|
||||
defaultLayout = d.Layout
|
||||
DefaultLayout = d.Layout
|
||||
}
|
||||
if d.Timezone != "" {
|
||||
defaultTimezone = d.Timezone
|
||||
}
|
||||
if d.WeekStartsAt != "" {
|
||||
defaultWeekStartsAt = d.WeekStartsAt
|
||||
DefaultTimezone = d.Timezone
|
||||
}
|
||||
if d.Locale != "" {
|
||||
defaultLocale = d.Locale
|
||||
DefaultLocale = d.Locale
|
||||
}
|
||||
if d.WeekStartsAt.String() != "" {
|
||||
DefaultWeekStartsAt = d.WeekStartsAt
|
||||
}
|
||||
if len(d.WeekendDays) > 0 {
|
||||
DefaultWeekendDays = d.WeekendDays
|
||||
}
|
||||
}
|
||||
|
||||
// ResetDefault resets default.
|
||||
func ResetDefault() {
|
||||
DefaultLayout = DateTimeLayout
|
||||
DefaultTimezone = UTC
|
||||
DefaultLocale = "en"
|
||||
DefaultWeekStartsAt = Monday
|
||||
DefaultWeekendDays = []Weekday{
|
||||
Saturday, Sunday,
|
||||
}
|
||||
}
|
||||
|
||||
258
vendor/github.com/dromara/carbon/v2/difference.go
generated
vendored
258
vendor/github.com/dromara/carbon/v2/difference.go
generated
vendored
@@ -6,20 +6,20 @@ import (
|
||||
"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())
|
||||
func (c *Carbon) DiffInYears(carbon ...*Carbon) int64 {
|
||||
start := c
|
||||
if start.IsInvalid() {
|
||||
return 0
|
||||
}
|
||||
var end *Carbon
|
||||
if len(carbon) > 0 {
|
||||
end = carbon[0]
|
||||
} else {
|
||||
end = Now().SetLocation(c.loc)
|
||||
}
|
||||
if end.IsInvalid() {
|
||||
return 0
|
||||
}
|
||||
dy, dm, dd := end.Year()-start.Year(), end.Month()-start.Month(), end.Day()-start.Day()
|
||||
if dm < 0 || (dm == 0 && dd < 0) {
|
||||
@@ -32,20 +32,24 @@ func (c Carbon) DiffInYears(carbon ...Carbon) int64 {
|
||||
}
|
||||
|
||||
// DiffAbsInYears gets the difference in years with absolute value.
|
||||
// 相差多少年(绝对值)
|
||||
func (c Carbon) DiffAbsInYears(carbon ...Carbon) int64 {
|
||||
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())
|
||||
func (c *Carbon) DiffInMonths(carbon ...*Carbon) int64 {
|
||||
start := c
|
||||
if start.IsInvalid() {
|
||||
return 0
|
||||
}
|
||||
var end *Carbon
|
||||
if len(carbon) > 0 {
|
||||
end = carbon[0]
|
||||
} else {
|
||||
end = Now().SetLocation(c.loc)
|
||||
}
|
||||
if end.IsInvalid() {
|
||||
return 0
|
||||
}
|
||||
if start.Month() == end.Month() && start.Year() == end.Year() {
|
||||
return 0
|
||||
@@ -56,182 +60,207 @@ func (c Carbon) DiffInMonths(carbon ...Carbon) int64 {
|
||||
start, end = end, start
|
||||
sign = -1
|
||||
}
|
||||
months := getDiffInMonths(start, end, 0)
|
||||
months := getDiffInMonths(start, end)
|
||||
return months * int64(sign)
|
||||
}
|
||||
|
||||
// DiffAbsInMonths gets the difference in months with absolute value.
|
||||
// 相差多少月(绝对值)
|
||||
func (c Carbon) DiffAbsInMonths(carbon ...Carbon) int64 {
|
||||
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())
|
||||
func (c *Carbon) DiffInWeeks(carbon ...*Carbon) int64 {
|
||||
start := c
|
||||
if start.IsInvalid() {
|
||||
return 0
|
||||
}
|
||||
var end *Carbon
|
||||
if len(carbon) > 0 {
|
||||
end = carbon[0]
|
||||
} else {
|
||||
end = Now().SetLocation(c.loc)
|
||||
}
|
||||
if end.IsInvalid() {
|
||||
return 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 {
|
||||
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())
|
||||
func (c *Carbon) DiffInDays(carbon ...*Carbon) int64 {
|
||||
start := c
|
||||
if start.IsInvalid() {
|
||||
return 0
|
||||
}
|
||||
var end *Carbon
|
||||
if len(carbon) > 0 {
|
||||
end = carbon[0]
|
||||
} else {
|
||||
end = Now().SetLocation(c.loc)
|
||||
}
|
||||
if end.IsInvalid() {
|
||||
return 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 {
|
||||
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())
|
||||
func (c *Carbon) DiffInHours(carbon ...*Carbon) int64 {
|
||||
start := c
|
||||
if start.IsInvalid() {
|
||||
return 0
|
||||
}
|
||||
var end *Carbon
|
||||
if len(carbon) > 0 {
|
||||
end = carbon[0]
|
||||
} else {
|
||||
end = Now().SetLocation(c.loc)
|
||||
}
|
||||
return c.DiffInSeconds(end) / SecondsPerHour
|
||||
if end.IsInvalid() {
|
||||
return 0
|
||||
}
|
||||
return start.DiffInSeconds(end) / SecondsPerHour
|
||||
}
|
||||
|
||||
// DiffAbsInHours gets the difference in hours with absolute value.
|
||||
// 相差多少小时(绝对值)
|
||||
func (c Carbon) DiffAbsInHours(carbon ...Carbon) int64 {
|
||||
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())
|
||||
func (c *Carbon) DiffInMinutes(carbon ...*Carbon) int64 {
|
||||
start := c
|
||||
if start.IsInvalid() {
|
||||
return 0
|
||||
}
|
||||
var end *Carbon
|
||||
if len(carbon) > 0 {
|
||||
end = carbon[0]
|
||||
} else {
|
||||
end = Now().SetLocation(c.loc)
|
||||
}
|
||||
return c.DiffInSeconds(end) / SecondsPerMinute
|
||||
if end.IsInvalid() {
|
||||
return 0
|
||||
}
|
||||
return start.DiffInSeconds(end) / SecondsPerMinute
|
||||
}
|
||||
|
||||
// DiffAbsInMinutes gets the difference in minutes with absolute value.
|
||||
// 相差多少分钟(绝对值)
|
||||
func (c Carbon) DiffAbsInMinutes(carbon ...Carbon) int64 {
|
||||
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())
|
||||
func (c *Carbon) DiffInSeconds(carbon ...*Carbon) int64 {
|
||||
start := c
|
||||
if start.IsInvalid() {
|
||||
return 0
|
||||
}
|
||||
var end *Carbon
|
||||
if len(carbon) > 0 {
|
||||
end = carbon[0]
|
||||
} else {
|
||||
end = Now().SetLocation(c.loc)
|
||||
}
|
||||
return end.Timestamp() - c.Timestamp()
|
||||
if end.IsInvalid() {
|
||||
return 0
|
||||
}
|
||||
return end.Timestamp() - start.Timestamp()
|
||||
}
|
||||
|
||||
// DiffAbsInSeconds gets the difference in seconds with absolute value.
|
||||
// 相差多少秒(绝对值)
|
||||
func (c Carbon) DiffAbsInSeconds(carbon ...Carbon) int64 {
|
||||
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 {
|
||||
func (c *Carbon) DiffInString(carbon ...*Carbon) string {
|
||||
start := c
|
||||
if start.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
unit, value := c.diff(end)
|
||||
var end *Carbon
|
||||
if len(carbon) > 0 {
|
||||
end = carbon[0]
|
||||
} else {
|
||||
end = Now().SetLocation(c.loc)
|
||||
}
|
||||
if end.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
unit, value := start.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 {
|
||||
func (c *Carbon) DiffAbsInString(carbon ...*Carbon) string {
|
||||
start := c
|
||||
if start.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
unit, value := c.diff(end)
|
||||
var end *Carbon
|
||||
if len(carbon) > 0 {
|
||||
end = carbon[0]
|
||||
} else {
|
||||
end = Now().SetLocation(c.loc)
|
||||
}
|
||||
if end.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
unit, value := start.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())
|
||||
func (c *Carbon) DiffInDuration(carbon ...*Carbon) Duration {
|
||||
start := c
|
||||
if start.IsInvalid() {
|
||||
return 0
|
||||
}
|
||||
var end *Carbon
|
||||
if len(carbon) > 0 {
|
||||
end = carbon[0]
|
||||
} else {
|
||||
end = Now().SetLocation(c.loc)
|
||||
}
|
||||
return end.StdTime().Sub(c.StdTime())
|
||||
if end.IsInvalid() {
|
||||
return 0
|
||||
}
|
||||
return end.StdTime().Sub(start.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
|
||||
func (c *Carbon) DiffAbsInDuration(carbon ...*Carbon) Duration {
|
||||
return c.DiffInDuration(carbon...).Abs()
|
||||
}
|
||||
|
||||
// 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 {
|
||||
func (c *Carbon) DiffForHumans(carbon ...*Carbon) string {
|
||||
start := c
|
||||
if start.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
unit, value := c.diff(end)
|
||||
var end *Carbon
|
||||
if len(carbon) > 0 {
|
||||
end = carbon[0]
|
||||
} else {
|
||||
end = Now().SetLocation(c.loc)
|
||||
}
|
||||
if end.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
unit, value := start.diff(end)
|
||||
translation := c.lang.translate(unit, getAbsValue(value))
|
||||
if unit == "now" {
|
||||
return translation
|
||||
@@ -249,8 +278,7 @@ func (c Carbon) DiffForHumans(carbon ...Carbon) string {
|
||||
}
|
||||
|
||||
// gets the difference for unit and value.
|
||||
// 获取相差单位和差值
|
||||
func (c Carbon) diff(end Carbon) (unit string, value int64) {
|
||||
func (c *Carbon) diff(end *Carbon) (unit string, value int64) {
|
||||
switch true {
|
||||
case c.DiffAbsInYears(end) > 0:
|
||||
unit = "year"
|
||||
@@ -280,13 +308,15 @@ func (c Carbon) diff(end Carbon) (unit string, value int64) {
|
||||
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
|
||||
func getDiffInMonths(start, end *Carbon) int64 {
|
||||
if start.IsInvalid() || end.IsInvalid() {
|
||||
return 0
|
||||
}
|
||||
months += 1
|
||||
return getDiffInMonths(next, end, months)
|
||||
sy, sm, d, h, i, s, ns := start.DateTimeNano()
|
||||
ey, em, _ := end.Date()
|
||||
dm := (ey-sy)*12 + (em - sm)
|
||||
if time.Date(sy, time.Month(sm+dm), d, h, i, s, ns, start.StdTime().Location()).After(end.StdTime()) {
|
||||
return int64(dm - 1)
|
||||
}
|
||||
return int64(dm)
|
||||
}
|
||||
|
||||
116
vendor/github.com/dromara/carbon/v2/errors.go
generated
vendored
116
vendor/github.com/dromara/carbon/v2/errors.go
generated
vendored
@@ -4,38 +4,94 @@ 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")
|
||||
}
|
||||
var (
|
||||
// ErrFailedParse failed to parse error.
|
||||
ErrFailedParse = func(value any) error {
|
||||
return fmt.Errorf("failed to parse %v as carbon", value)
|
||||
}
|
||||
|
||||
// returns an invalid location error.
|
||||
// 无效的地区错误
|
||||
var invalidLocationError = func() error {
|
||||
return fmt.Errorf("invalid location, please make sure the location is valid")
|
||||
}
|
||||
// ErrFailedScan failed to scan error.
|
||||
ErrFailedScan = func(value any) error {
|
||||
return fmt.Errorf("failed to scan %v as carbon", value)
|
||||
}
|
||||
|
||||
// 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)
|
||||
}
|
||||
// ErrInvalidTimestamp invalid timestamp error.
|
||||
ErrInvalidTimestamp = func(value string) error {
|
||||
return fmt.Errorf("invalid timestamp %v", value)
|
||||
}
|
||||
|
||||
// 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)
|
||||
}
|
||||
// ErrNilLocation nil location error.
|
||||
ErrNilLocation = func() error {
|
||||
return fmt.Errorf("location cannot be nil")
|
||||
}
|
||||
|
||||
// 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)
|
||||
}
|
||||
// ErrNilLanguage nil language error.
|
||||
ErrNilLanguage = func() error {
|
||||
return fmt.Errorf("language cannot be nil")
|
||||
}
|
||||
|
||||
// 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)
|
||||
}
|
||||
// ErrInvalidLanguage invalid language error.
|
||||
ErrInvalidLanguage = func(lang *Language) error {
|
||||
return fmt.Errorf("invalid Language %v", lang)
|
||||
}
|
||||
|
||||
// ErrEmptyLocale empty locale error.
|
||||
ErrEmptyLocale = func() error {
|
||||
return fmt.Errorf("locale cannot be empty")
|
||||
}
|
||||
|
||||
// ErrNotExistLocale not exist locale error.
|
||||
ErrNotExistLocale = func(locale string) error {
|
||||
return fmt.Errorf("locale %q doesn't exist", locale)
|
||||
}
|
||||
|
||||
// ErrEmptyResources empty resources error.
|
||||
ErrEmptyResources = func() error {
|
||||
return fmt.Errorf("resources cannot be empty")
|
||||
}
|
||||
|
||||
// ErrInvalidResourcesError invalid resources error.
|
||||
ErrInvalidResourcesError = func(resources map[string]string) error {
|
||||
return fmt.Errorf("invalid resources %v", resources)
|
||||
}
|
||||
|
||||
// ErrEmptyTimezone empty timezone error.
|
||||
ErrEmptyTimezone = func() error {
|
||||
return fmt.Errorf("timezone cannot be empty")
|
||||
}
|
||||
|
||||
// ErrInvalidTimezone invalid timezone error.
|
||||
ErrInvalidTimezone = 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")
|
||||
}
|
||||
|
||||
// ErrEmptyDuration empty duration error.
|
||||
ErrEmptyDuration = func() error {
|
||||
return fmt.Errorf("duration cannot be empty")
|
||||
}
|
||||
|
||||
// ErrInvalidDuration invalid duration error.
|
||||
ErrInvalidDuration = func(duration string) error {
|
||||
return fmt.Errorf("invalid duration %q", duration)
|
||||
}
|
||||
|
||||
// ErrEmptyLayout empty layout error.
|
||||
ErrEmptyLayout = func() error {
|
||||
return fmt.Errorf("layout cannot be empty")
|
||||
}
|
||||
|
||||
// ErrMismatchedLayout mismatched layout error.
|
||||
ErrMismatchedLayout = func(value, layout string) error {
|
||||
return fmt.Errorf("value %q and layout %q are mismatched", value, layout)
|
||||
}
|
||||
|
||||
// ErrEmptyFormat empty format error.
|
||||
ErrEmptyFormat = func() error {
|
||||
return fmt.Errorf("format cannot be empty")
|
||||
}
|
||||
|
||||
// ErrMismatchedFormat mismatched format error.
|
||||
ErrMismatchedFormat = func(value, format string) error {
|
||||
return fmt.Errorf("value %q and format %q are mismatched", value, format)
|
||||
}
|
||||
)
|
||||
|
||||
151
vendor/github.com/dromara/carbon/v2/extremum.go
generated
vendored
151
vendor/github.com/dromara/carbon/v2/extremum.go
generated
vendored
@@ -1,52 +1,55 @@
|
||||
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)
|
||||
import "time"
|
||||
|
||||
const (
|
||||
minDuration Duration = -1 << 63
|
||||
maxDuration Duration = 1<<63 - 1
|
||||
)
|
||||
|
||||
// ZeroValue returns the zero value of Carbon instance.
|
||||
func ZeroValue() *Carbon {
|
||||
return MinValue()
|
||||
}
|
||||
|
||||
// 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)
|
||||
// EpochValue returns the unix epoch value of Carbon instance.
|
||||
func EpochValue() *Carbon {
|
||||
return NewCarbon(time.Date(EpochYear, time.January, 1, 0, 0, 0, 0, time.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
|
||||
// MaxValue returns the maximum value of Carbon instance.
|
||||
func MaxValue() *Carbon {
|
||||
return NewCarbon(time.Date(9999, time.December, 31, 23, 59, 59, 999999999, time.UTC))
|
||||
}
|
||||
|
||||
// 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
|
||||
// MinValue returns the minimum value of Carbon instance.
|
||||
func MinValue() *Carbon {
|
||||
return NewCarbon(time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC))
|
||||
}
|
||||
|
||||
// Max returns the maximum Carbon instance from the given Carbon instance (second-precision).
|
||||
// 返回最大的 Carbon 实例
|
||||
func Max(c1 Carbon, c2 ...Carbon) (c Carbon) {
|
||||
// MaxDuration returns the maximum value of duration instance.
|
||||
func MaxDuration() Duration {
|
||||
return maxDuration
|
||||
}
|
||||
|
||||
// MinDuration returns the minimum value of duration instance.
|
||||
func MinDuration() Duration {
|
||||
return minDuration
|
||||
}
|
||||
|
||||
// Max returns the maximum Carbon instance from some given Carbon instances.
|
||||
func Max(c1 *Carbon, c2 ...*Carbon) (c *Carbon) {
|
||||
c = c1
|
||||
if c.IsInvalid() {
|
||||
return
|
||||
}
|
||||
if len(c2) == 0 {
|
||||
return
|
||||
}
|
||||
for i := range c2 {
|
||||
if c2[i].IsInvalid() {
|
||||
return c2[i]
|
||||
}
|
||||
if c2[i].Gte(c) {
|
||||
c = c2[i]
|
||||
}
|
||||
@@ -54,14 +57,82 @@ func Max(c1 Carbon, c2 ...Carbon) (c Carbon) {
|
||||
return
|
||||
}
|
||||
|
||||
// Min returns the minimum Carbon instance from the given Carbon instance (second-precision).
|
||||
// 返回最小的 Carbon 实例
|
||||
func Min(c1 Carbon, c2 ...Carbon) (c Carbon) {
|
||||
// Min returns the minimum Carbon instance from some given Carbon instances.
|
||||
func Min(c1 *Carbon, c2 ...*Carbon) (c *Carbon) {
|
||||
c = c1
|
||||
if c.IsInvalid() {
|
||||
return
|
||||
}
|
||||
if len(c2) == 0 {
|
||||
return
|
||||
}
|
||||
for i := range c2 {
|
||||
if c2[i].IsInvalid() {
|
||||
return c2[i]
|
||||
}
|
||||
if c2[i].Lte(c) {
|
||||
c = c2[i]
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Closest returns the closest Carbon instance from some given Carbon instances.
|
||||
func (c *Carbon) Closest(c1 *Carbon, c2 ...*Carbon) *Carbon {
|
||||
if c.IsInvalid() {
|
||||
return c
|
||||
}
|
||||
if c1.IsInvalid() {
|
||||
return c1
|
||||
}
|
||||
if len(c2) == 0 {
|
||||
return c1
|
||||
}
|
||||
args := append([]*Carbon{c1}, c2...)
|
||||
for i := range args {
|
||||
if args[i].IsInvalid() {
|
||||
return args[i]
|
||||
}
|
||||
}
|
||||
closest := args[0]
|
||||
minDiff := c.DiffAbsInSeconds(closest)
|
||||
for i := range args[1:] {
|
||||
arg := args[1:][i]
|
||||
diff := c.DiffAbsInSeconds(arg)
|
||||
if diff < minDiff {
|
||||
minDiff = diff
|
||||
closest = arg
|
||||
}
|
||||
}
|
||||
return closest
|
||||
}
|
||||
|
||||
// Farthest returns the farthest Carbon instance from some given Carbon instances.
|
||||
func (c *Carbon) Farthest(c1 *Carbon, c2 ...*Carbon) *Carbon {
|
||||
if c.IsInvalid() {
|
||||
return c
|
||||
}
|
||||
if c1.IsInvalid() {
|
||||
return c1
|
||||
}
|
||||
if len(c2) == 0 {
|
||||
return c1
|
||||
}
|
||||
args := append([]*Carbon{c1}, c2...)
|
||||
for i := range args {
|
||||
if args[i].IsInvalid() {
|
||||
return args[i]
|
||||
}
|
||||
}
|
||||
farthest := args[0]
|
||||
maxDiff := c.DiffAbsInSeconds(farthest)
|
||||
for i := range args[1:] {
|
||||
arg := args[1:][i]
|
||||
diff := c.DiffAbsInSeconds(arg)
|
||||
if diff > maxDiff {
|
||||
maxDiff = diff
|
||||
farthest = arg
|
||||
}
|
||||
}
|
||||
return farthest
|
||||
}
|
||||
|
||||
46
vendor/github.com/dromara/carbon/v2/frozen.go
generated
vendored
Normal file
46
vendor/github.com/dromara/carbon/v2/frozen.go
generated
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
package carbon
|
||||
|
||||
import "sync"
|
||||
|
||||
// FrozenNow defines a FrozenNow struct.
|
||||
type FrozenNow struct {
|
||||
isFrozen bool
|
||||
testNow *Carbon
|
||||
rw *sync.RWMutex
|
||||
}
|
||||
|
||||
var frozenNow = &FrozenNow{
|
||||
rw: new(sync.RWMutex),
|
||||
}
|
||||
|
||||
// SetTestNow sets a test Carbon instance for now.
|
||||
func SetTestNow(c *Carbon) {
|
||||
frozenNow.rw.Lock()
|
||||
defer frozenNow.rw.Unlock()
|
||||
|
||||
frozenNow.isFrozen = true
|
||||
frozenNow.testNow = c
|
||||
}
|
||||
|
||||
// CleanTestNow clears the test Carbon instance for now.
|
||||
//
|
||||
// Deprecated: it will be removed in the future, use "ClearTestNow" instead.
|
||||
func CleanTestNow() {
|
||||
ClearTestNow()
|
||||
}
|
||||
|
||||
// ClearTestNow clears the test Carbon instance for now.
|
||||
func ClearTestNow() {
|
||||
frozenNow.rw.Lock()
|
||||
defer frozenNow.rw.Unlock()
|
||||
|
||||
frozenNow.isFrozen = false
|
||||
}
|
||||
|
||||
// IsTestNow reports whether is testing time.
|
||||
func IsTestNow() bool {
|
||||
frozenNow.rw.Lock()
|
||||
defer frozenNow.rw.Unlock()
|
||||
|
||||
return frozenNow.isFrozen
|
||||
}
|
||||
279
vendor/github.com/dromara/carbon/v2/getter.go
generated
vendored
279
vendor/github.com/dromara/carbon/v2/getter.go
generated
vendored
@@ -5,18 +5,19 @@ import (
|
||||
)
|
||||
|
||||
// StdTime gets standard time.Time.
|
||||
// 获取标准 time.Time
|
||||
func (c Carbon) StdTime() time.Time {
|
||||
if c.time.IsZero() {
|
||||
func (c *Carbon) StdTime() StdTime {
|
||||
if c.IsInvalid() {
|
||||
return StdTime{}
|
||||
}
|
||||
if c.loc == nil {
|
||||
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 {
|
||||
func (c *Carbon) DaysInYear() int {
|
||||
if c.IsInvalid() {
|
||||
return 0
|
||||
}
|
||||
if c.IsLeapYear() {
|
||||
@@ -26,58 +27,48 @@ func (c Carbon) DaysInYear() int {
|
||||
}
|
||||
|
||||
// DaysInMonth gets total days in month like 30.
|
||||
// 获取本月的总天数
|
||||
func (c Carbon) DaysInMonth() int {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) DaysInMonth() int {
|
||||
if c.IsInvalid() {
|
||||
return 0
|
||||
}
|
||||
return c.EndOfMonth().StdTime().Day()
|
||||
}
|
||||
|
||||
// MonthOfYear gets month of year like 12.
|
||||
// 获取本年的第几月
|
||||
func (c Carbon) MonthOfYear() int {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) MonthOfYear() int {
|
||||
if c.IsInvalid() {
|
||||
return 0
|
||||
}
|
||||
return int(c.StdTime().Month())
|
||||
}
|
||||
|
||||
// DayOfYear gets day of year like 365.
|
||||
// 获取本年的第几天
|
||||
func (c Carbon) DayOfYear() int {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) DayOfYear() int {
|
||||
if c.IsInvalid() {
|
||||
return 0
|
||||
}
|
||||
return c.StdTime().YearDay()
|
||||
}
|
||||
|
||||
// DayOfMonth gets day of month like 30.
|
||||
// 获取本月的第几天
|
||||
func (c Carbon) DayOfMonth() int {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) DayOfMonth() int {
|
||||
if c.IsInvalid() {
|
||||
return 0
|
||||
}
|
||||
return c.StdTime().Day()
|
||||
}
|
||||
|
||||
// DayOfWeek gets day of week like 6.
|
||||
// 获取本周的第几天
|
||||
func (c Carbon) DayOfWeek() int {
|
||||
if c.Error != nil {
|
||||
// DayOfWeek gets day of week like 6, start from 1.
|
||||
func (c *Carbon) DayOfWeek() int {
|
||||
if c.IsInvalid() {
|
||||
return 0
|
||||
}
|
||||
day := int(c.StdTime().Weekday())
|
||||
if day == 0 {
|
||||
return DaysPerWeek
|
||||
}
|
||||
return day
|
||||
return (int(c.StdTime().Weekday())+DaysPerWeek-int(c.weekStartsAt))%DaysPerWeek + 1
|
||||
}
|
||||
|
||||
// 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 {
|
||||
// WeekOfYear gets week of year like 1, refer to https://en.wikipedia.org/wiki/ISO_8601#Week_dates.
|
||||
func (c *Carbon) WeekOfYear() int {
|
||||
if c.IsInvalid() {
|
||||
return 0
|
||||
}
|
||||
_, week := c.StdTime().ISOWeek()
|
||||
@@ -85,9 +76,8 @@ func (c Carbon) WeekOfYear() int {
|
||||
}
|
||||
|
||||
// WeekOfMonth gets week of month like 1.
|
||||
// 获取本月的第几周
|
||||
func (c Carbon) WeekOfMonth() int {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) WeekOfMonth() int {
|
||||
if c.IsInvalid() {
|
||||
return 0
|
||||
}
|
||||
days := c.Day() + c.StartOfMonth().DayOfWeek() - 1
|
||||
@@ -98,9 +88,8 @@ func (c Carbon) WeekOfMonth() int {
|
||||
}
|
||||
|
||||
// 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 {
|
||||
func (c *Carbon) DateTime() (year, month, day, hour, minute, second int) {
|
||||
if c.IsInvalid() {
|
||||
return
|
||||
}
|
||||
year, month, day = c.Date()
|
||||
@@ -109,9 +98,8 @@ func (c Carbon) DateTime() (year, month, day, hour, minute, second int) {
|
||||
}
|
||||
|
||||
// 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 {
|
||||
func (c *Carbon) DateTimeMilli() (year, month, day, hour, minute, second, millisecond int) {
|
||||
if c.IsInvalid() {
|
||||
return
|
||||
}
|
||||
year, month, day, hour, minute, second = c.DateTime()
|
||||
@@ -119,9 +107,8 @@ func (c Carbon) DateTimeMilli() (year, month, day, hour, minute, second, millise
|
||||
}
|
||||
|
||||
// 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 {
|
||||
func (c *Carbon) DateTimeMicro() (year, month, day, hour, minute, second, microsecond int) {
|
||||
if c.IsInvalid() {
|
||||
return
|
||||
}
|
||||
year, month, day, hour, minute, second = c.DateTime()
|
||||
@@ -129,9 +116,8 @@ func (c Carbon) DateTimeMicro() (year, month, day, hour, minute, second, microse
|
||||
}
|
||||
|
||||
// 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 {
|
||||
func (c *Carbon) DateTimeNano() (year, month, day, hour, minute, second, nanosecond int) {
|
||||
if c.IsInvalid() {
|
||||
return
|
||||
}
|
||||
year, month, day, hour, minute, second = c.DateTime()
|
||||
@@ -139,9 +125,8 @@ func (c Carbon) DateTimeNano() (year, month, day, hour, minute, second, nanoseco
|
||||
}
|
||||
|
||||
// Date gets current year, month, and day like 2020, 8, 5.
|
||||
// 获取当前年、月、日
|
||||
func (c Carbon) Date() (year, month, day int) {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) Date() (year, month, day int) {
|
||||
if c.IsInvalid() {
|
||||
return
|
||||
}
|
||||
var tm time.Month
|
||||
@@ -150,9 +135,8 @@ func (c Carbon) Date() (year, month, day int) {
|
||||
}
|
||||
|
||||
// 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 {
|
||||
func (c *Carbon) DateMilli() (year, month, day, millisecond int) {
|
||||
if c.IsInvalid() {
|
||||
return
|
||||
}
|
||||
year, month, day = c.Date()
|
||||
@@ -160,9 +144,8 @@ func (c Carbon) DateMilli() (year, month, day, millisecond int) {
|
||||
}
|
||||
|
||||
// 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 {
|
||||
func (c *Carbon) DateMicro() (year, month, day, microsecond int) {
|
||||
if c.IsInvalid() {
|
||||
return
|
||||
}
|
||||
year, month, day = c.Date()
|
||||
@@ -170,9 +153,8 @@ func (c Carbon) DateMicro() (year, month, day, microsecond int) {
|
||||
}
|
||||
|
||||
// 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 {
|
||||
func (c *Carbon) DateNano() (year, month, day, nanosecond int) {
|
||||
if c.IsInvalid() {
|
||||
return
|
||||
}
|
||||
year, month, day = c.Date()
|
||||
@@ -180,18 +162,16 @@ func (c Carbon) DateNano() (year, month, day, nanosecond int) {
|
||||
}
|
||||
|
||||
// Time gets current hour, minute, and second like 13, 14, 15.
|
||||
// 获取当前时、分、秒
|
||||
func (c Carbon) Time() (hour, minute, second int) {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) Time() (hour, minute, second int) {
|
||||
if c.IsInvalid() {
|
||||
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 {
|
||||
func (c *Carbon) TimeMilli() (hour, minute, second, millisecond int) {
|
||||
if c.IsInvalid() {
|
||||
return
|
||||
}
|
||||
hour, minute, second = c.Time()
|
||||
@@ -199,9 +179,8 @@ func (c Carbon) TimeMilli() (hour, minute, second, millisecond int) {
|
||||
}
|
||||
|
||||
// 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 {
|
||||
func (c *Carbon) TimeMicro() (hour, minute, second, microsecond int) {
|
||||
if c.IsInvalid() {
|
||||
return
|
||||
}
|
||||
hour, minute, second = c.Time()
|
||||
@@ -209,9 +188,8 @@ func (c Carbon) TimeMicro() (hour, minute, second, microsecond int) {
|
||||
}
|
||||
|
||||
// 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 {
|
||||
func (c *Carbon) TimeNano() (hour, minute, second, nanosecond int) {
|
||||
if c.IsInvalid() {
|
||||
return
|
||||
}
|
||||
hour, minute, second = c.Time()
|
||||
@@ -219,36 +197,32 @@ func (c Carbon) TimeNano() (hour, minute, second, nanosecond int) {
|
||||
}
|
||||
|
||||
// Century gets current century like 21.
|
||||
// 获取当前世纪
|
||||
func (c Carbon) Century() int {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) Century() int {
|
||||
if c.IsInvalid() {
|
||||
return 0
|
||||
}
|
||||
return c.Year()/YearsPerCentury + 1
|
||||
}
|
||||
|
||||
// Decade gets current decade like 20.
|
||||
// 获取当前年代
|
||||
func (c Carbon) Decade() int {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) Decade() int {
|
||||
if c.IsInvalid() {
|
||||
return 0
|
||||
}
|
||||
return c.Year() % YearsPerCentury / YearsPerDecade * YearsPerDecade
|
||||
}
|
||||
|
||||
// Year gets current year like 2020.
|
||||
// 获取当前年
|
||||
func (c Carbon) Year() int {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) Year() int {
|
||||
if c.IsInvalid() {
|
||||
return 0
|
||||
}
|
||||
return c.StdTime().Year()
|
||||
}
|
||||
|
||||
// Quarter gets current quarter like 3.
|
||||
// 获取当前季度
|
||||
func (c Carbon) Quarter() (quarter int) {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) Quarter() (quarter int) {
|
||||
if c.IsInvalid() {
|
||||
return
|
||||
}
|
||||
month := c.Month()
|
||||
@@ -266,141 +240,123 @@ func (c Carbon) Quarter() (quarter int) {
|
||||
}
|
||||
|
||||
// Month gets current month like 8.
|
||||
// 获取当前月
|
||||
func (c Carbon) Month() int {
|
||||
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 {
|
||||
func (c *Carbon) Week() int {
|
||||
if c.IsInvalid() {
|
||||
return -1
|
||||
}
|
||||
return (c.DayOfWeek() + DaysPerWeek - int(c.weekStartsAt)) % DaysPerWeek
|
||||
return c.DayOfWeek() - 1
|
||||
}
|
||||
|
||||
// Day gets current day like 5.
|
||||
// 获取当前日
|
||||
func (c Carbon) Day() int {
|
||||
func (c *Carbon) Day() int {
|
||||
return c.DayOfMonth()
|
||||
}
|
||||
|
||||
// Hour gets current hour like 13.
|
||||
// 获取当前小时
|
||||
func (c Carbon) Hour() int {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) Hour() int {
|
||||
if c.IsInvalid() {
|
||||
return 0
|
||||
}
|
||||
return c.StdTime().Hour()
|
||||
}
|
||||
|
||||
// Minute gets current minute like 14.
|
||||
// 获取当前分钟数
|
||||
func (c Carbon) Minute() int {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) Minute() int {
|
||||
if c.IsInvalid() {
|
||||
return 0
|
||||
}
|
||||
return c.StdTime().Minute()
|
||||
}
|
||||
|
||||
// Second gets current second like 15.
|
||||
// 获取当前秒数
|
||||
func (c Carbon) Second() int {
|
||||
if c.Error != nil {
|
||||
// Second gets current second like 9.
|
||||
func (c *Carbon) Second() int {
|
||||
if c.IsInvalid() {
|
||||
return 0
|
||||
}
|
||||
return c.StdTime().Second()
|
||||
}
|
||||
|
||||
// Millisecond gets current millisecond like 999.
|
||||
// 获取当前毫秒数
|
||||
func (c Carbon) Millisecond() int {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) Millisecond() int {
|
||||
if c.IsInvalid() {
|
||||
return 0
|
||||
}
|
||||
return c.StdTime().Nanosecond() / 1e6
|
||||
}
|
||||
|
||||
// Microsecond gets current microsecond like 999999.
|
||||
// 获取当前微秒数
|
||||
func (c Carbon) Microsecond() int {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) Microsecond() int {
|
||||
if c.IsInvalid() {
|
||||
return 0
|
||||
}
|
||||
return c.StdTime().Nanosecond() / 1e3
|
||||
}
|
||||
|
||||
// Nanosecond gets current nanosecond like 999999999.
|
||||
// 获取当前纳秒数
|
||||
func (c Carbon) Nanosecond() int {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) Nanosecond() int {
|
||||
if c.IsInvalid() {
|
||||
return 0
|
||||
}
|
||||
return c.StdTime().Nanosecond()
|
||||
}
|
||||
|
||||
// Timestamp gets timestamp with second like 1596604455.
|
||||
// 输出秒级时间戳
|
||||
func (c Carbon) Timestamp() int64 {
|
||||
if c.Error != nil {
|
||||
// Timestamp gets timestamp with second precision like 1596604455.
|
||||
func (c *Carbon) Timestamp() int64 {
|
||||
if c.IsInvalid() {
|
||||
return 0
|
||||
}
|
||||
return c.StdTime().Unix()
|
||||
}
|
||||
|
||||
// TimestampMilli gets timestamp with millisecond like 1596604455000.
|
||||
// 获取毫秒级时间戳
|
||||
func (c Carbon) TimestampMilli() int64 {
|
||||
if c.Error != nil {
|
||||
// TimestampMilli gets timestamp with millisecond precision like 1596604455000.
|
||||
func (c *Carbon) TimestampMilli() int64 {
|
||||
if c.IsInvalid() {
|
||||
return 0
|
||||
}
|
||||
t := c.StdTime()
|
||||
return t.Unix()*1e3 + int64(t.Nanosecond())/1e6
|
||||
return c.StdTime().UnixMilli()
|
||||
}
|
||||
|
||||
// TimestampMicro gets timestamp with microsecond like 1596604455000000.
|
||||
// 获取微秒级时间戳
|
||||
func (c Carbon) TimestampMicro() int64 {
|
||||
if c.Error != nil {
|
||||
// TimestampMicro gets timestamp with microsecond precision like 1596604455000000.
|
||||
func (c *Carbon) TimestampMicro() int64 {
|
||||
if c.IsInvalid() {
|
||||
return 0
|
||||
}
|
||||
t := c.StdTime()
|
||||
return t.Unix()*1e6 + int64(t.Nanosecond())/1e3
|
||||
return c.StdTime().UnixMicro()
|
||||
}
|
||||
|
||||
// TimestampNano gets timestamp with nanosecond like 1596604455000000000.
|
||||
// 获取纳秒级时间戳
|
||||
func (c Carbon) TimestampNano() int64 {
|
||||
if c.Error != nil {
|
||||
// TimestampNano gets timestamp with nanosecond precision like 1596604455000000000.
|
||||
func (c *Carbon) TimestampNano() int64 {
|
||||
if c.IsInvalid() {
|
||||
return 0
|
||||
}
|
||||
return c.StdTime().UnixNano()
|
||||
}
|
||||
|
||||
// Location gets location name like "PRC".
|
||||
// 获取位置
|
||||
func (c Carbon) Location() string {
|
||||
if c.Error != nil {
|
||||
// Timezone gets timezone location like "Asia/Shanghai".
|
||||
func (c *Carbon) Timezone() string {
|
||||
if c.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
return c.loc.String()
|
||||
}
|
||||
|
||||
// Timezone gets timezone name like "CST".
|
||||
// 获取时区
|
||||
func (c Carbon) Timezone() string {
|
||||
if c.Error != nil {
|
||||
// ZoneName gets timezone name like "CST".
|
||||
func (c *Carbon) ZoneName() string {
|
||||
if c.IsInvalid() {
|
||||
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 {
|
||||
// ZoneOffset gets timezone offset seconds from the UTC timezone like 28800.
|
||||
func (c *Carbon) ZoneOffset() int {
|
||||
if c.IsInvalid() {
|
||||
return 0
|
||||
}
|
||||
_, offset := c.StdTime().Zone()
|
||||
@@ -408,25 +364,44 @@ func (c Carbon) Offset() int {
|
||||
}
|
||||
|
||||
// Locale gets locale name like "zh-CN".
|
||||
// 获取语言区域
|
||||
func (c Carbon) Locale() string {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) Locale() string {
|
||||
if c.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
return c.lang.locale
|
||||
}
|
||||
|
||||
// Age gets age like 18.
|
||||
// 获取年龄
|
||||
func (c Carbon) Age() int {
|
||||
if c.Error != nil {
|
||||
// WeekStartsAt returns start day of the week.
|
||||
func (c *Carbon) WeekStartsAt() Weekday {
|
||||
if c.IsInvalid() {
|
||||
return 0
|
||||
}
|
||||
now := c.Now()
|
||||
if c.IsSetTestNow() {
|
||||
now = CreateFromTimestampNano(c.testNow, c.Location())
|
||||
return c.weekStartsAt
|
||||
}
|
||||
|
||||
// WeekEndsAt returns end day of the week.
|
||||
func (c *Carbon) WeekEndsAt() Weekday {
|
||||
if c.IsInvalid() {
|
||||
return 0
|
||||
}
|
||||
if c.TimestampNano() > now.TimestampNano() {
|
||||
return Weekday((int(c.weekStartsAt) + DaysPerWeek - 1) % 7)
|
||||
}
|
||||
|
||||
// CurrentLayout returns the layout used for parsing the time string.
|
||||
func (c *Carbon) CurrentLayout() string {
|
||||
if c.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
return c.currentLayout
|
||||
}
|
||||
|
||||
// Age gets age like 18.
|
||||
func (c *Carbon) Age() int {
|
||||
if c.IsInvalid() {
|
||||
return 0
|
||||
}
|
||||
now := Now().SetLocation(c.loc)
|
||||
if c.Gte(now) {
|
||||
return 0
|
||||
}
|
||||
return int(c.DiffInYears(now))
|
||||
|
||||
138
vendor/github.com/dromara/carbon/v2/helper.go
generated
vendored
138
vendor/github.com/dromara/carbon/v2/helper.go
generated
vendored
@@ -2,24 +2,13 @@ package carbon
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"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{
|
||||
// format map
|
||||
var formatMap = 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.
|
||||
@@ -39,52 +28,69 @@ var formats = map[byte]string{
|
||||
'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 ...
|
||||
'Q': "Z0700", // Zone: ISO8601 timezone. Eg: Z, +0200.
|
||||
'R': "Z07:00", // Zone: ISO8601 colon timezone. Eg: Z, +02:00.
|
||||
'Z': "MST", // Zone: Zone name. 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.
|
||||
'u': "999", // Second: Millisecond. Eg: 999.
|
||||
'v': "999999", // Second: Microsecond. Eg: 999999.
|
||||
'x': "999999999", // Second: Nanosecond. Eg: 999999999.
|
||||
|
||||
'S': TimestampLayout, // Timestamp: Timestamp with second precision. Eg: 1699677240.
|
||||
'U': TimestampMilliLayout, // Timestamp: Timestamp with millisecond precision. Eg: 1596604455666.
|
||||
'V': TimestampMicroLayout, // Timestamp: Timestamp with microsecond precision. Eg: 1596604455666666.
|
||||
'X': TimestampNanoLayout, // Timestamp: Timestamp with nanosecond precision. 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,
|
||||
// default layouts
|
||||
var defaultLayouts = []string{
|
||||
DateTimeLayout, DateLayout, TimeLayout, DayDateTimeLayout,
|
||||
|
||||
"2006-01-02 15:04:05 -0700 MST", "2006-01-02T15:04:05Z07:00", "2006-01-02T15:04:05-07:00", "2006-01-02T15:04:05-0700", "2006-01-02T15:04:05",
|
||||
|
||||
ISO8601Layout, RFC1036Layout, RFC822Layout, RFC822ZLayout, RFC850Layout, RFC1123Layout, RFC1123ZLayout, RFC3339Layout, RFC7231Layout,
|
||||
KitchenLayout, CookieLayout, ANSICLayout, UnixDateLayout, RubyDateLayout,
|
||||
|
||||
ShortDateTimeLayout, ShortDateLayout, ShortTimeLayout,
|
||||
|
||||
DateTimeMilliLayout, DateTimeMicroLayout, DateTimeNanoLayout,
|
||||
DateMilliLayout, DateMicroLayout, DateNanoLayout,
|
||||
TimeMilliLayout, TimeMicroLayout, TimeNanoLayout,
|
||||
|
||||
ShortDateTimeMilliLayout, ShortDateTimeMicroLayout, ShortDateTimeNanoLayout,
|
||||
ShortDateMilliLayout, ShortDateMicroLayout, ShortDateNanoLayout,
|
||||
ShortTimeMilliLayout, ShortTimeMicroLayout, ShortTimeNanoLayout,
|
||||
|
||||
ISO8601MilliLayout, ISO8601MicroLayout, ISO8601NanoLayout,
|
||||
RFC3339MilliLayout, RFC3339MicroLayout, RFC3339NanoLayout,
|
||||
|
||||
"15:04:05-07", // postgres time with time zone type
|
||||
"2006-01-02 15:04:05-07", // postgres timestamp with time zone type
|
||||
"2006-01-02 15:04:05-07:00", // sqlite text type
|
||||
"2006-01-02 15:04:05.999999999 -07:00", // sqlserver datetimeoffset type
|
||||
"2006",
|
||||
"2006-1-2 15:4:5 -0700 MST", "2006-1-2 3:4:5 -0700 MST",
|
||||
"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",
|
||||
"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.999999999", "2006-1-2T3:4:5", "2006-1-2T3:4:5.999999999",
|
||||
"2006-01-02T15:04:05.999999999Z07", "2006-1-2T15:4:5Z07", "2006-1-2T15:4:5.999999999Z07",
|
||||
"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.999999999-07:00", "2006-1-2T15:4:5-07:00", "2006-1-2T15:4:5.999999999-07:00",
|
||||
"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)
|
||||
buffer := &bytes.Buffer{}
|
||||
for i := 0; i < len(format); i++ {
|
||||
if layout, ok := formats[format[i]]; ok {
|
||||
if layout, ok := formatMap[format[i]]; ok {
|
||||
buffer.WriteString(layout)
|
||||
} else {
|
||||
switch format[i] {
|
||||
@@ -100,28 +106,40 @@ func format2layout(format string) string {
|
||||
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)
|
||||
// parses a timezone string as a time.Location instance.
|
||||
func parseTimezone(timezone string) (loc *Location, err error) {
|
||||
if timezone == "" {
|
||||
return nil, ErrEmptyTimezone()
|
||||
}
|
||||
return loc, err
|
||||
if loc, err = time.LoadLocation(timezone); err != nil {
|
||||
err = fmt.Errorf("%w: %w", ErrInvalidTimezone(timezone), err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// 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)
|
||||
// parses a duration string as a time.Duration instance.
|
||||
func parseDuration(duration string) (dur Duration, err error) {
|
||||
if duration == "" {
|
||||
return 0, ErrEmptyDuration()
|
||||
}
|
||||
return td, err
|
||||
if dur, err = time.ParseDuration(duration); err != nil {
|
||||
err = fmt.Errorf("%w: %w", ErrInvalidDuration(duration), err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// parses a timestamp string as a int64 format timestamp.
|
||||
func parseTimestamp(timestamp string) (ts int64, err error) {
|
||||
if ts, err = strconv.ParseInt(timestamp, 10, 64); err != nil {
|
||||
err = fmt.Errorf("%w: %w", ErrInvalidTimestamp(timestamp), err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// gets absolute value.
|
||||
// 获取绝对值
|
||||
func getAbsValue(value int64) int64 {
|
||||
return (value ^ value>>31) - value>>31
|
||||
if value < 0 {
|
||||
return -value
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
24
vendor/github.com/dromara/carbon/v2/interfaces.go
generated
vendored
Normal file
24
vendor/github.com/dromara/carbon/v2/interfaces.go
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
package carbon
|
||||
|
||||
// DataTyper defines a DataTyper interface
|
||||
type DataTyper interface {
|
||||
DataType() string
|
||||
}
|
||||
|
||||
// LayoutTyper defines a LayoutTyper interface
|
||||
type LayoutTyper interface {
|
||||
~string
|
||||
Layout() string
|
||||
}
|
||||
|
||||
// FormatTyper defines a FormatTyper interface.
|
||||
type FormatTyper interface {
|
||||
~string
|
||||
Format() string
|
||||
}
|
||||
|
||||
// TimestampTyper defines a TimestampTyper interface.
|
||||
type TimestampTyper interface {
|
||||
~int64
|
||||
Precision() string
|
||||
}
|
||||
39
vendor/github.com/dromara/carbon/v2/lang/ar.json
generated
vendored
39
vendor/github.com/dromara/carbon/v2/lang/ar.json
generated
vendored
@@ -1,21 +1,22 @@
|
||||
{
|
||||
"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 بعد"
|
||||
"name": "Arabic",
|
||||
"author": "https://github.com/zumoshi",
|
||||
"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 بعد"
|
||||
}
|
||||
|
||||
39
vendor/github.com/dromara/carbon/v2/lang/bg.json
generated
vendored
39
vendor/github.com/dromara/carbon/v2/lang/bg.json
generated
vendored
@@ -1,21 +1,22 @@
|
||||
{
|
||||
"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 след"
|
||||
"name": "Bulgarian",
|
||||
"author": "https://github.com/yuksbg",
|
||||
"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 след"
|
||||
}
|
||||
|
||||
41
vendor/github.com/dromara/carbon/v2/lang/de.json
generated
vendored
41
vendor/github.com/dromara/carbon/v2/lang/de.json
generated
vendored
@@ -1,21 +1,22 @@
|
||||
{
|
||||
"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"
|
||||
}
|
||||
"name": "German",
|
||||
"author": "https://github.com/benzammour",
|
||||
"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"
|
||||
}
|
||||
|
||||
39
vendor/github.com/dromara/carbon/v2/lang/dk.json
generated
vendored
39
vendor/github.com/dromara/carbon/v2/lang/dk.json
generated
vendored
@@ -1,21 +1,22 @@
|
||||
{
|
||||
"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"
|
||||
"name": "Dansk",
|
||||
"author": "https://github.com/Munk91",
|
||||
"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"
|
||||
}
|
||||
|
||||
41
vendor/github.com/dromara/carbon/v2/lang/en.json
generated
vendored
41
vendor/github.com/dromara/carbon/v2/lang/en.json
generated
vendored
@@ -1,21 +1,22 @@
|
||||
{
|
||||
"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"
|
||||
}
|
||||
"name": "English",
|
||||
"author": "https://github.com/gouguoyin",
|
||||
"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"
|
||||
}
|
||||
|
||||
39
vendor/github.com/dromara/carbon/v2/lang/es.json
generated
vendored
39
vendor/github.com/dromara/carbon/v2/lang/es.json
generated
vendored
@@ -1,21 +1,22 @@
|
||||
{
|
||||
"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"
|
||||
"name": "Spanish",
|
||||
"author": "https://github.com/hgisinger",
|
||||
"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"
|
||||
}
|
||||
|
||||
39
vendor/github.com/dromara/carbon/v2/lang/fa.json
generated
vendored
39
vendor/github.com/dromara/carbon/v2/lang/fa.json
generated
vendored
@@ -1,21 +1,22 @@
|
||||
{
|
||||
"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 بعد"
|
||||
"name": "Farsi",
|
||||
"author": "https://github.com/erfanMomeniii",
|
||||
"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 بعد"
|
||||
}
|
||||
|
||||
39
vendor/github.com/dromara/carbon/v2/lang/fr.json
generated
vendored
39
vendor/github.com/dromara/carbon/v2/lang/fr.json
generated
vendored
@@ -1,21 +1,22 @@
|
||||
{
|
||||
"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"
|
||||
"name": "French",
|
||||
"author": "https://github.com/hollowaykeanho",
|
||||
"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"
|
||||
}
|
||||
|
||||
39
vendor/github.com/dromara/carbon/v2/lang/hi.json
generated
vendored
39
vendor/github.com/dromara/carbon/v2/lang/hi.json
generated
vendored
@@ -1,21 +1,22 @@
|
||||
{
|
||||
"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 बाद"
|
||||
"name": "Hindi",
|
||||
"author": "https://github.com/chauhan17nitin",
|
||||
"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 बाद"
|
||||
}
|
||||
|
||||
39
vendor/github.com/dromara/carbon/v2/lang/hu.json
generated
vendored
39
vendor/github.com/dromara/carbon/v2/lang/hu.json
generated
vendored
@@ -1,21 +1,22 @@
|
||||
{
|
||||
"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"
|
||||
"name": "Hungarian",
|
||||
"author": "https://github.com/kenlas",
|
||||
"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"
|
||||
}
|
||||
|
||||
39
vendor/github.com/dromara/carbon/v2/lang/id.json
generated
vendored
39
vendor/github.com/dromara/carbon/v2/lang/id.json
generated
vendored
@@ -1,21 +1,22 @@
|
||||
{
|
||||
"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"
|
||||
"name": "Indonesian",
|
||||
"author": "https://github.com/justpoypoy",
|
||||
"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"
|
||||
}
|
||||
|
||||
37
vendor/github.com/dromara/carbon/v2/lang/it.json
generated
vendored
37
vendor/github.com/dromara/carbon/v2/lang/it.json
generated
vendored
@@ -1,20 +1,21 @@
|
||||
{
|
||||
"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"
|
||||
"name": "Italian",
|
||||
"author": "https://github.com/nicoloHevelop",
|
||||
"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"
|
||||
}
|
||||
|
||||
39
vendor/github.com/dromara/carbon/v2/lang/jp.json
generated
vendored
39
vendor/github.com/dromara/carbon/v2/lang/jp.json
generated
vendored
@@ -1,21 +1,22 @@
|
||||
{
|
||||
"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後"
|
||||
"name": "Japanese",
|
||||
"author": "https://github.com/gouguoyin",
|
||||
"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後"
|
||||
}
|
||||
|
||||
39
vendor/github.com/dromara/carbon/v2/lang/kr.json
generated
vendored
39
vendor/github.com/dromara/carbon/v2/lang/kr.json
generated
vendored
@@ -1,21 +1,22 @@
|
||||
{
|
||||
"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후"
|
||||
"name": "Korean",
|
||||
"author": "https://github.com/nannul",
|
||||
"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후"
|
||||
}
|
||||
|
||||
39
vendor/github.com/dromara/carbon/v2/lang/ms-MY.json
generated
vendored
39
vendor/github.com/dromara/carbon/v2/lang/ms-MY.json
generated
vendored
@@ -1,21 +1,22 @@
|
||||
{
|
||||
"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"
|
||||
"name": "Bahasa Malaysia",
|
||||
"author": "https://github.com/hollowaykeanho",
|
||||
"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"
|
||||
}
|
||||
|
||||
22
vendor/github.com/dromara/carbon/v2/lang/nb.json
generated
vendored
Normal file
22
vendor/github.com/dromara/carbon/v2/lang/nb.json
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"name": "Norsk bokmål",
|
||||
"author": "https://github.com/bendikrb ",
|
||||
"months": "januar|februar|mars|april|mai|juni|juli|august|september|oktober|november|desember",
|
||||
"short_months": "jan|feb|mar|apr|mai|jun|jul|aug|sep|okt|nov|des",
|
||||
"weeks": "søndag|mandag|tirsdag|onsdag|torsdag|fredag|lørdag",
|
||||
"short_weeks": "søn|man|tir|ons|tor|fre|lør",
|
||||
"seasons": "vår|sommer|høst|vinter",
|
||||
"constellations": "vær|tyr|tvilling|kreps|løve|jomfru|vekt|skorpion|skytten|steinbukk|vannmann|fisk",
|
||||
"year": "1 år|%d år",
|
||||
"month": "1 måned|%d måneder",
|
||||
"week": "1 uke|%d uker",
|
||||
"day": "1 dag|%d dager",
|
||||
"hour": "1 time|%d timer",
|
||||
"minute": "1 minutt|%d minutter",
|
||||
"second": "1 sekund|%d sekunder",
|
||||
"now": "nå nettopp",
|
||||
"ago": "%s siden",
|
||||
"from_now": "om %s",
|
||||
"before": "%s før",
|
||||
"after": "%s etter"
|
||||
}
|
||||
39
vendor/github.com/dromara/carbon/v2/lang/nl.json
generated
vendored
39
vendor/github.com/dromara/carbon/v2/lang/nl.json
generated
vendored
@@ -1,21 +1,22 @@
|
||||
{
|
||||
"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"
|
||||
"name": "Dutch",
|
||||
"author": "https://github.com/RemcoE33",
|
||||
"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"
|
||||
}
|
||||
|
||||
41
vendor/github.com/dromara/carbon/v2/lang/pl.json
generated
vendored
41
vendor/github.com/dromara/carbon/v2/lang/pl.json
generated
vendored
@@ -1,21 +1,22 @@
|
||||
{
|
||||
"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"
|
||||
}
|
||||
"name": "Polish",
|
||||
"author": "https://github.com/gouguoyin",
|
||||
"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"
|
||||
}
|
||||
|
||||
39
vendor/github.com/dromara/carbon/v2/lang/pt.json
generated
vendored
39
vendor/github.com/dromara/carbon/v2/lang/pt.json
generated
vendored
@@ -1,21 +1,22 @@
|
||||
{
|
||||
"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"
|
||||
"name": "Portuguese",
|
||||
"author": "https://github.com/felipear89",
|
||||
"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"
|
||||
}
|
||||
|
||||
39
vendor/github.com/dromara/carbon/v2/lang/ro.json
generated
vendored
39
vendor/github.com/dromara/carbon/v2/lang/ro.json
generated
vendored
@@ -1,21 +1,22 @@
|
||||
{
|
||||
"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ă"
|
||||
"name": "Romanian",
|
||||
"author": "https://github.com/DrOctavius",
|
||||
"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ă"
|
||||
}
|
||||
|
||||
39
vendor/github.com/dromara/carbon/v2/lang/ru.json
generated
vendored
39
vendor/github.com/dromara/carbon/v2/lang/ru.json
generated
vendored
@@ -1,21 +1,22 @@
|
||||
{
|
||||
"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 после"
|
||||
"name": "Russian",
|
||||
"author": "https://github.com/zemlyak",
|
||||
"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 после"
|
||||
}
|
||||
|
||||
41
vendor/github.com/dromara/carbon/v2/lang/se.json
generated
vendored
41
vendor/github.com/dromara/carbon/v2/lang/se.json
generated
vendored
@@ -1,21 +1,22 @@
|
||||
{
|
||||
"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"
|
||||
}
|
||||
"name": "Swedish",
|
||||
"author": "https://github.com/jwanglof",
|
||||
"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"
|
||||
}
|
||||
|
||||
41
vendor/github.com/dromara/carbon/v2/lang/th.json
generated
vendored
41
vendor/github.com/dromara/carbon/v2/lang/th.json
generated
vendored
@@ -1,21 +1,22 @@
|
||||
{
|
||||
"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 หลังจากนี้"
|
||||
}
|
||||
"name": "Thailand",
|
||||
"author": "https://github.com/izcream",
|
||||
"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 หลังจากนี้"
|
||||
}
|
||||
|
||||
39
vendor/github.com/dromara/carbon/v2/lang/tr.json
generated
vendored
39
vendor/github.com/dromara/carbon/v2/lang/tr.json
generated
vendored
@@ -1,21 +1,22 @@
|
||||
{
|
||||
"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"
|
||||
"name": "Turkish",
|
||||
"author": "https://github.com/emresenyuva",
|
||||
"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"
|
||||
}
|
||||
|
||||
41
vendor/github.com/dromara/carbon/v2/lang/uk.json
generated
vendored
41
vendor/github.com/dromara/carbon/v2/lang/uk.json
generated
vendored
@@ -1,21 +1,22 @@
|
||||
{
|
||||
"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 після"
|
||||
}
|
||||
"name": "Ukrainian",
|
||||
"author": "https://github.com/zumoshi",
|
||||
"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 після"
|
||||
}
|
||||
|
||||
39
vendor/github.com/dromara/carbon/v2/lang/vi.json
generated
vendored
39
vendor/github.com/dromara/carbon/v2/lang/vi.json
generated
vendored
@@ -1,21 +1,22 @@
|
||||
{
|
||||
"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"
|
||||
"name": "VietNamese",
|
||||
"author": "https://github.com/culy247",
|
||||
"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"
|
||||
}
|
||||
|
||||
39
vendor/github.com/dromara/carbon/v2/lang/zh-CN.json
generated
vendored
39
vendor/github.com/dromara/carbon/v2/lang/zh-CN.json
generated
vendored
@@ -1,21 +1,22 @@
|
||||
{
|
||||
"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后"
|
||||
"name": "Simplified Chinese",
|
||||
"author": "https://github.com/gouguoyin",
|
||||
"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后"
|
||||
}
|
||||
|
||||
39
vendor/github.com/dromara/carbon/v2/lang/zh-TW.json
generated
vendored
39
vendor/github.com/dromara/carbon/v2/lang/zh-TW.json
generated
vendored
@@ -1,21 +1,22 @@
|
||||
{
|
||||
"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後"
|
||||
"name": "Traditional Chinese",
|
||||
"author": "https://github.com/gouguoyin",
|
||||
"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後"
|
||||
}
|
||||
|
||||
104
vendor/github.com/dromara/carbon/v2/language.go
generated
vendored
104
vendor/github.com/dromara/carbon/v2/language.go
generated
vendored
@@ -4,6 +4,7 @@ import (
|
||||
"embed"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -12,16 +13,13 @@ import (
|
||||
//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)
|
||||
}
|
||||
)
|
||||
var validResourcesKey = []string{
|
||||
"months", "short_months", "weeks", "short_weeks", "seasons", "constellations",
|
||||
"year", "month", "week", "day", "hour", "minute", "second",
|
||||
"now", "ago", "from_now", "before", "after",
|
||||
}
|
||||
|
||||
// Language defines a Language struct.
|
||||
// 定义 Language 结构体
|
||||
type Language struct {
|
||||
dir string
|
||||
locale string
|
||||
@@ -31,68 +29,106 @@ type Language struct {
|
||||
}
|
||||
|
||||
// NewLanguage returns a new Language instance.
|
||||
// 初始化 Language 结构体
|
||||
func NewLanguage() *Language {
|
||||
return &Language{
|
||||
dir: "lang/",
|
||||
locale: defaultLocale,
|
||||
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
|
||||
// Copy returns a new copy of the current Language instance
|
||||
func (lang *Language) Copy() *Language {
|
||||
if lang == nil {
|
||||
return nil
|
||||
}
|
||||
newLang := &Language{
|
||||
dir: lang.dir,
|
||||
locale: lang.locale,
|
||||
Error: lang.Error,
|
||||
rw: new(sync.RWMutex),
|
||||
}
|
||||
if lang.resources == nil {
|
||||
return newLang
|
||||
}
|
||||
newLang.resources = make(map[string]string)
|
||||
for i := range lang.resources {
|
||||
newLang.resources[i] = lang.resources[i]
|
||||
}
|
||||
return newLang
|
||||
}
|
||||
|
||||
// SetLocale sets language locale.
|
||||
// 设置区域
|
||||
func (lang *Language) SetLocale(locale string) *Language {
|
||||
if lang == nil || lang.Error != nil {
|
||||
return lang
|
||||
}
|
||||
if locale == "" {
|
||||
lang.Error = ErrEmptyLocale()
|
||||
return lang
|
||||
}
|
||||
|
||||
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)
|
||||
fileName := fmt.Sprintf("%s/%s.json", lang.dir, locale)
|
||||
var (
|
||||
bs []byte
|
||||
err error
|
||||
)
|
||||
if bs, err = fs.ReadFile(fileName); err != nil {
|
||||
lang.Error = fmt.Errorf("%w: %w", ErrNotExistLocale(fileName), err)
|
||||
return lang
|
||||
}
|
||||
_ = json.Unmarshal(bytes, &lang.resources)
|
||||
_ = json.Unmarshal(bs, &lang.resources)
|
||||
return lang
|
||||
}
|
||||
|
||||
// SetResources sets language resources.
|
||||
// 设置资源
|
||||
func (lang *Language) SetResources(resources map[string]string) *Language {
|
||||
if lang == nil || lang.Error != nil {
|
||||
return lang
|
||||
}
|
||||
if len(resources) == 0 {
|
||||
lang.Error = ErrEmptyResources()
|
||||
return lang
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
for i := range resources {
|
||||
if !slices.Contains(validResourcesKey, i) {
|
||||
lang.Error = ErrInvalidResourcesError(resources)
|
||||
return lang
|
||||
}
|
||||
if _, ok := lang.resources[i]; ok {
|
||||
lang.resources[i] = resources[i]
|
||||
}
|
||||
}
|
||||
|
||||
return lang
|
||||
}
|
||||
|
||||
// returns a translated string.
|
||||
// 翻译转换
|
||||
func (lang *Language) translate(unit string, value int64) string {
|
||||
if lang == nil || lang.resources == nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
lang.rw.Lock()
|
||||
defer lang.rw.Unlock()
|
||||
|
||||
if len(lang.resources) == 0 {
|
||||
lang.SetLocale(defaultLocale)
|
||||
lang.rw.Unlock()
|
||||
lang.SetLocale(DefaultLocale)
|
||||
lang.rw.Lock()
|
||||
}
|
||||
slice := strings.Split(lang.resources[unit], "|")
|
||||
number := getAbsValue(value)
|
||||
|
||||
642
vendor/github.com/dromara/carbon/v2/outputer.go
generated
vendored
642
vendor/github.com/dromara/carbon/v2/outputer.go
generated
vendored
File diff suppressed because it is too large
Load Diff
246
vendor/github.com/dromara/carbon/v2/parser.go
generated
vendored
246
vendor/github.com/dromara/carbon/v2/parser.go
generated
vendored
@@ -1,104 +1,206 @@
|
||||
package carbon
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"fmt"
|
||||
"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
|
||||
// Parse parses a time string as a Carbon instance by default layouts.
|
||||
//
|
||||
// Note: it doesn't support parsing timestamp string.
|
||||
func Parse(value string, timezone ...string) *Carbon {
|
||||
if value == "" {
|
||||
return &Carbon{isEmpty: true}
|
||||
}
|
||||
var (
|
||||
tz string
|
||||
tt StdTime
|
||||
loc *Location
|
||||
err error
|
||||
)
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
tz = timezone[0]
|
||||
} else {
|
||||
tz = DefaultTimezone
|
||||
}
|
||||
if loc, err = parseTimezone(tz); err != nil {
|
||||
return &Carbon{Error: err}
|
||||
}
|
||||
switch value {
|
||||
case "now":
|
||||
return c.Now(timezone...)
|
||||
return Now().SetLocation(loc)
|
||||
case "yesterday":
|
||||
return c.Yesterday(timezone...)
|
||||
return Yesterday().SetLocation(loc)
|
||||
case "tomorrow":
|
||||
return c.Tomorrow(timezone...)
|
||||
return Tomorrow().SetLocation(loc)
|
||||
}
|
||||
for _, layout := range layouts {
|
||||
t, err := time.ParseInLocation(layout, value, c.loc)
|
||||
if err == nil {
|
||||
c.time = t
|
||||
c := NewCarbon().SetLocation(loc)
|
||||
for i := range defaultLayouts {
|
||||
if tt, err = time.ParseInLocation(defaultLayouts[i], value, loc); err == nil {
|
||||
c.time = tt
|
||||
c.currentLayout = defaultLayouts[i]
|
||||
return c
|
||||
}
|
||||
}
|
||||
c.Error = invalidValueError(value)
|
||||
c.Error = ErrFailedParse(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)
|
||||
// ParseByLayout parses a time string as a Carbon instance by a confirmed layout.
|
||||
//
|
||||
// Note: it will not support parsing timestamp string in the future,
|
||||
// use "CreateFromTimestamp" or "CreateFromTimestampXXX" instead
|
||||
func ParseByLayout(value, layout string, timezone ...string) *Carbon {
|
||||
if value == "" {
|
||||
return &Carbon{isEmpty: true}
|
||||
}
|
||||
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 layout == "" {
|
||||
return &Carbon{Error: ErrEmptyLayout()}
|
||||
}
|
||||
var (
|
||||
ts int64
|
||||
tz string
|
||||
tt StdTime
|
||||
loc *Location
|
||||
err error
|
||||
)
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
tz = timezone[0]
|
||||
} else {
|
||||
tz = DefaultTimezone
|
||||
}
|
||||
if c.Error != nil {
|
||||
return c
|
||||
if loc, err = parseTimezone(tz); err != nil {
|
||||
return &Carbon{Error: err}
|
||||
}
|
||||
if len(layout) == 0 {
|
||||
layout = defaultLayout
|
||||
|
||||
// timestamp layouts
|
||||
switch layout {
|
||||
case TimestampLayout:
|
||||
if ts, err = parseTimestamp(value); err != nil {
|
||||
return &Carbon{Error: err}
|
||||
}
|
||||
return CreateFromTimestamp(ts).SetLocation(loc)
|
||||
case TimestampMilliLayout:
|
||||
if ts, err = parseTimestamp(value); err != nil {
|
||||
return &Carbon{Error: err}
|
||||
}
|
||||
return CreateFromTimestampMilli(ts).SetLocation(loc)
|
||||
case TimestampMicroLayout:
|
||||
if ts, err = parseTimestamp(value); err != nil {
|
||||
return &Carbon{Error: err}
|
||||
}
|
||||
return CreateFromTimestampMicro(ts).SetLocation(loc)
|
||||
case TimestampNanoLayout:
|
||||
if ts, err = parseTimestamp(value); err != nil {
|
||||
return &Carbon{Error: err}
|
||||
}
|
||||
return CreateFromTimestampNano(ts).SetLocation(loc)
|
||||
}
|
||||
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
|
||||
|
||||
// other layouts
|
||||
if tt, err = time.ParseInLocation(layout, value, loc); err != nil {
|
||||
return &Carbon{Error: fmt.Errorf("%w: %w", ErrMismatchedLayout(value, layout), err)}
|
||||
}
|
||||
|
||||
c := NewCarbon()
|
||||
c.loc = loc
|
||||
c.time = tt
|
||||
c.currentLayout = layout
|
||||
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...)
|
||||
// ParseByFormat parses a time string as a Carbon instance by a confirmed format.
|
||||
//
|
||||
// Note: If the letter used conflicts with the format sign, please use the escape character "\" to escape the letter
|
||||
func ParseByFormat(value, format string, timezone ...string) *Carbon {
|
||||
if value == "" {
|
||||
return &Carbon{isEmpty: true}
|
||||
}
|
||||
if format == "" {
|
||||
return &Carbon{Error: ErrEmptyFormat()}
|
||||
}
|
||||
c := ParseByLayout(value, format2layout(format), timezone...)
|
||||
if c.HasError() {
|
||||
c.Error = fmt.Errorf("%w: %w", ErrMismatchedFormat(value, format), c.Error)
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
// ParseByLayouts parses a time string as a Carbon instance by multiple fuzzy layouts.
|
||||
//
|
||||
// Note: it doesn't support parsing timestamp string.
|
||||
func ParseByLayouts(value string, layouts []string, timezone ...string) *Carbon {
|
||||
if value == "" {
|
||||
return &Carbon{isEmpty: true}
|
||||
}
|
||||
if len(layouts) == 0 {
|
||||
return &Carbon{Error: ErrEmptyLayout()}
|
||||
}
|
||||
var (
|
||||
tz string
|
||||
tt StdTime
|
||||
loc *Location
|
||||
err error
|
||||
)
|
||||
if len(timezone) > 0 {
|
||||
tz = timezone[0]
|
||||
} else {
|
||||
tz = DefaultTimezone
|
||||
}
|
||||
if loc, err = parseTimezone(tz); err != nil {
|
||||
return &Carbon{Error: err}
|
||||
}
|
||||
c := NewCarbon().SetLocation(loc)
|
||||
for i := range layouts {
|
||||
if tt, err = time.ParseInLocation(layouts[i], value, loc); err == nil {
|
||||
c.time = tt
|
||||
c.currentLayout = layouts[i]
|
||||
return c
|
||||
}
|
||||
}
|
||||
c.Error = ErrFailedParse(value)
|
||||
return c
|
||||
}
|
||||
|
||||
// ParseByFormats parses a time string as a Carbon instance by multiple fuzzy formats.
|
||||
//
|
||||
// Note: it doesn't support parsing timestamp string.
|
||||
func ParseByFormats(value string, formats []string, timezone ...string) *Carbon {
|
||||
if value == "" {
|
||||
return &Carbon{isEmpty: true}
|
||||
}
|
||||
if len(formats) == 0 {
|
||||
return &Carbon{Error: ErrEmptyFormat()}
|
||||
}
|
||||
var (
|
||||
tz string
|
||||
err error
|
||||
)
|
||||
if len(timezone) > 0 {
|
||||
tz = timezone[0]
|
||||
} else {
|
||||
tz = DefaultTimezone
|
||||
}
|
||||
if _, err = parseTimezone(tz); err != nil {
|
||||
return &Carbon{Error: err}
|
||||
}
|
||||
var layouts []string
|
||||
for i := range formats {
|
||||
layouts = append(layouts, format2layout(formats[i]))
|
||||
}
|
||||
return ParseByLayouts(value, layouts, tz)
|
||||
}
|
||||
|
||||
// ParseWithLayouts parses a time string as a Carbon instance by multiple fuzzy layouts.
|
||||
//
|
||||
// Deprecated: it will be removed in the future, use "ParseByLayouts" instead.
|
||||
func ParseWithLayouts(value string, layouts []string, timezone ...string) *Carbon {
|
||||
return ParseByLayouts(value, layouts, timezone...)
|
||||
}
|
||||
|
||||
// ParseWithFormats parses a time string as a Carbon instance by multiple fuzzy formats.
|
||||
//
|
||||
// Deprecated: it will be removed in the future, use "ParseByFormats" instead.
|
||||
func ParseWithFormats(value string, formats []string, timezone ...string) *Carbon {
|
||||
return ParseByFormats(value, formats, timezone...)
|
||||
}
|
||||
|
||||
40
vendor/github.com/dromara/carbon/v2/season.go
generated
vendored
40
vendor/github.com/dromara/carbon/v2/season.go
generated
vendored
@@ -22,14 +22,10 @@ var seasons = []struct {
|
||||
}
|
||||
|
||||
// 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 {
|
||||
func (c *Carbon) Season() string {
|
||||
if c.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
if len(c.lang.resources) == 0 {
|
||||
c.lang.SetLocale(defaultLocale)
|
||||
}
|
||||
index := -1
|
||||
month := c.Month()
|
||||
for i := 0; i < len(seasons); i++ {
|
||||
@@ -38,8 +34,10 @@ func (c Carbon) Season() string {
|
||||
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 {
|
||||
@@ -50,9 +48,8 @@ func (c Carbon) Season() string {
|
||||
}
|
||||
|
||||
// StartOfSeason returns a Carbon instance for start of the season.
|
||||
// 本季节开始时间
|
||||
func (c Carbon) StartOfSeason() Carbon {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) StartOfSeason() *Carbon {
|
||||
if c.IsInvalid() {
|
||||
return c
|
||||
}
|
||||
year, month, _ := c.Date()
|
||||
@@ -63,9 +60,8 @@ func (c Carbon) StartOfSeason() Carbon {
|
||||
}
|
||||
|
||||
// EndOfSeason returns a Carbon instance for end of the season.
|
||||
// 本季节结束时间
|
||||
func (c Carbon) EndOfSeason() Carbon {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) EndOfSeason() *Carbon {
|
||||
if c.IsInvalid() {
|
||||
return c
|
||||
}
|
||||
year, month, _ := c.Date()
|
||||
@@ -79,9 +75,8 @@ func (c Carbon) EndOfSeason() Carbon {
|
||||
}
|
||||
|
||||
// IsSpring reports whether is spring.
|
||||
// 是否是春季
|
||||
func (c Carbon) IsSpring() bool {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) IsSpring() bool {
|
||||
if c.IsInvalid() {
|
||||
return false
|
||||
}
|
||||
month := c.Month()
|
||||
@@ -92,9 +87,8 @@ func (c Carbon) IsSpring() bool {
|
||||
}
|
||||
|
||||
// IsSummer reports whether is summer.
|
||||
// 是否是夏季
|
||||
func (c Carbon) IsSummer() bool {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) IsSummer() bool {
|
||||
if c.IsInvalid() {
|
||||
return false
|
||||
}
|
||||
month := c.Month()
|
||||
@@ -105,9 +99,8 @@ func (c Carbon) IsSummer() bool {
|
||||
}
|
||||
|
||||
// IsAutumn reports whether is autumn.
|
||||
// 是否是秋季
|
||||
func (c Carbon) IsAutumn() bool {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) IsAutumn() bool {
|
||||
if c.IsInvalid() {
|
||||
return false
|
||||
}
|
||||
month := c.Month()
|
||||
@@ -118,9 +111,8 @@ func (c Carbon) IsAutumn() bool {
|
||||
}
|
||||
|
||||
// IsWinter reports whether is winter.
|
||||
// 是否是冬季
|
||||
func (c Carbon) IsWinter() bool {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) IsWinter() bool {
|
||||
if c.IsInvalid() {
|
||||
return false
|
||||
}
|
||||
month := c.Month()
|
||||
|
||||
359
vendor/github.com/dromara/carbon/v2/setter.go
generated
vendored
359
vendor/github.com/dromara/carbon/v2/setter.go
generated
vendored
@@ -1,302 +1,393 @@
|
||||
package carbon
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
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
|
||||
// SetLayout sets globally default layout.
|
||||
func SetLayout(layout string) *Carbon {
|
||||
c := NewCarbon().SetLayout(layout)
|
||||
if !c.HasError() {
|
||||
DefaultLayout = layout
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
// SetWeekStartsAt sets start day of the week.
|
||||
// 设置一周的开始日期
|
||||
func SetWeekStartsAt(day string) Carbon {
|
||||
return NewCarbon().SetWeekStartsAt(day)
|
||||
// SetFormat sets globally default format.
|
||||
func SetFormat(format string) *Carbon {
|
||||
layout := format2layout(format)
|
||||
c := NewCarbon().SetLayout(layout)
|
||||
if !c.HasError() {
|
||||
DefaultLayout = layout
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
// SetTimezone sets timezone.
|
||||
// 设置时区
|
||||
func (c Carbon) SetTimezone(name string) Carbon {
|
||||
if c.Error != nil {
|
||||
// SetTimezone sets globally default timezone.
|
||||
func SetTimezone(name string) *Carbon {
|
||||
c := NewCarbon().SetTimezone(name)
|
||||
if !c.HasError() {
|
||||
DefaultTimezone = name
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
// SetLocation sets globally default location.
|
||||
func SetLocation(loc *Location) *Carbon {
|
||||
c := NewCarbon().SetLocation(loc)
|
||||
if !c.HasError() {
|
||||
DefaultTimezone = loc.String()
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
// SetLocale sets globally default locale.
|
||||
func SetLocale(locale string) *Carbon {
|
||||
c := NewCarbon().SetLocale(locale)
|
||||
if !c.HasError() {
|
||||
DefaultLocale = locale
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
// SetWeekStartsAt sets globally default start day of the week.
|
||||
func SetWeekStartsAt(weekday Weekday) *Carbon {
|
||||
c := NewCarbon().SetWeekStartsAt(weekday)
|
||||
if !c.HasError() {
|
||||
DefaultWeekStartsAt = weekday
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
// SetWeekendDays sets globally default weekend days of the week.
|
||||
func SetWeekendDays(weekDays []Weekday) *Carbon {
|
||||
c := NewCarbon().SetWeekendDays(weekDays)
|
||||
if !c.HasError() {
|
||||
DefaultWeekendDays = weekDays
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
// SetLayout sets layout.
|
||||
func (c *Carbon) SetLayout(layout string) *Carbon {
|
||||
if layout == "" {
|
||||
c.Error = ErrEmptyLayout()
|
||||
return c
|
||||
}
|
||||
c.loc, c.Error = getLocationByTimezone(name)
|
||||
if c.IsInvalid() {
|
||||
return c
|
||||
}
|
||||
c.currentLayout = layout
|
||||
return c
|
||||
}
|
||||
|
||||
// SetFormat sets format.
|
||||
func (c *Carbon) SetFormat(format string) *Carbon {
|
||||
if format == "" {
|
||||
c.Error = ErrEmptyFormat()
|
||||
return c
|
||||
}
|
||||
if c.IsInvalid() {
|
||||
return c
|
||||
}
|
||||
c.currentLayout = format2layout(format)
|
||||
return c
|
||||
}
|
||||
|
||||
// SetTimezone sets timezone.
|
||||
// 设置时区
|
||||
func SetTimezone(name string) Carbon {
|
||||
return NewCarbon().SetTimezone(name)
|
||||
func (c *Carbon) SetTimezone(name string) *Carbon {
|
||||
if name == "" {
|
||||
c.Error = ErrEmptyTimezone()
|
||||
return c
|
||||
}
|
||||
if c.IsInvalid() {
|
||||
return c
|
||||
}
|
||||
c.loc, c.Error = parseTimezone(name)
|
||||
return c
|
||||
}
|
||||
|
||||
// SetLocation sets location.
|
||||
// 设置地区
|
||||
func (c Carbon) SetLocation(loc *time.Location) Carbon {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) SetLocation(loc *Location) *Carbon {
|
||||
if loc == nil {
|
||||
c.Error = ErrNilLocation()
|
||||
return c
|
||||
}
|
||||
if loc == nil {
|
||||
c.Error = invalidLocationError()
|
||||
if c.IsInvalid() {
|
||||
return c
|
||||
}
|
||||
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 {
|
||||
func (c *Carbon) SetLocale(locale string) *Carbon {
|
||||
if locale == "" {
|
||||
c.Error = ErrEmptyLocale()
|
||||
return c
|
||||
}
|
||||
c.lang.SetLocale(locale)
|
||||
if c.IsInvalid() {
|
||||
return c
|
||||
}
|
||||
c.lang = NewLanguage().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
|
||||
// SetWeekStartsAt sets start day of the week.
|
||||
func (c *Carbon) SetWeekStartsAt(weekDay Weekday) *Carbon {
|
||||
if c.IsInvalid() {
|
||||
return c
|
||||
}
|
||||
c.weekStartsAt = weekDay
|
||||
return c
|
||||
}
|
||||
|
||||
// SetWeekendDays sets weekend days of the week.
|
||||
func (c *Carbon) SetWeekendDays(weekDays []Weekday) *Carbon {
|
||||
if c.IsInvalid() {
|
||||
return c
|
||||
}
|
||||
c.weekendDays = weekDays
|
||||
return c
|
||||
}
|
||||
|
||||
// SetLanguage sets language.
|
||||
func (c *Carbon) SetLanguage(lang *Language) *Carbon {
|
||||
if c.IsInvalid() || c.isEmpty {
|
||||
return c
|
||||
}
|
||||
if lang == nil {
|
||||
c.Error = ErrNilLanguage()
|
||||
return c
|
||||
}
|
||||
if lang.Error != nil {
|
||||
c.Error = ErrInvalidLanguage(lang)
|
||||
return c
|
||||
}
|
||||
c.lang.dir = lang.dir
|
||||
c.lang.locale = lang.locale
|
||||
c.lang.resources = lang.resources
|
||||
c.lang.Error = 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 {
|
||||
func (c *Carbon) SetDateTime(year, month, day, hour, minute, second int) *Carbon {
|
||||
if c.IsInvalid() {
|
||||
return c
|
||||
}
|
||||
return c.create(year, month, day, hour, minute, second, c.Nanosecond())
|
||||
c.time = time.Date(year, time.Month(month), day, hour, minute, second, c.Nanosecond(), c.loc)
|
||||
return c
|
||||
}
|
||||
|
||||
// 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 {
|
||||
func (c *Carbon) SetDateTimeMilli(year, month, day, hour, minute, second, millisecond int) *Carbon {
|
||||
if c.IsInvalid() {
|
||||
return c
|
||||
}
|
||||
return c.create(year, month, day, hour, minute, second, millisecond*1e6)
|
||||
c.time = time.Date(year, time.Month(month), day, hour, minute, second, millisecond*1e6, c.loc)
|
||||
return c
|
||||
}
|
||||
|
||||
// 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 {
|
||||
func (c *Carbon) SetDateTimeMicro(year, month, day, hour, minute, second, microsecond int) *Carbon {
|
||||
if c.IsInvalid() {
|
||||
return c
|
||||
}
|
||||
return c.create(year, month, day, hour, minute, second, microsecond*1e3)
|
||||
c.time = time.Date(year, time.Month(month), day, hour, minute, second, microsecond*1e3, c.loc)
|
||||
return c
|
||||
}
|
||||
|
||||
// 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 {
|
||||
func (c *Carbon) SetDateTimeNano(year, month, day, hour, minute, second, nanosecond int) *Carbon {
|
||||
if c.IsInvalid() {
|
||||
return c
|
||||
}
|
||||
return c.create(year, month, day, hour, minute, second, nanosecond)
|
||||
c.time = time.Date(year, time.Month(month), day, hour, minute, second, nanosecond, c.loc)
|
||||
return c
|
||||
}
|
||||
|
||||
// SetDate sets year, month and day.
|
||||
// 设置年、月、日
|
||||
func (c Carbon) SetDate(year, month, day int) Carbon {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) SetDate(year, month, day int) *Carbon {
|
||||
if c.IsInvalid() {
|
||||
return c
|
||||
}
|
||||
hour, minute, second := c.Time()
|
||||
return c.create(year, month, day, hour, minute, second, c.Nanosecond())
|
||||
c.time = time.Date(year, time.Month(month), day, hour, minute, second, c.Nanosecond(), c.loc)
|
||||
return c
|
||||
}
|
||||
|
||||
// SetDateMilli sets year, month, day and millisecond.
|
||||
// 设置年、月、日、毫秒
|
||||
func (c Carbon) SetDateMilli(year, month, day, millisecond int) Carbon {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) SetDateMilli(year, month, day, millisecond int) *Carbon {
|
||||
if c.IsInvalid() {
|
||||
return c
|
||||
}
|
||||
hour, minute, second := c.Time()
|
||||
return c.create(year, month, day, hour, minute, second, millisecond*1e6)
|
||||
c.time = time.Date(year, time.Month(month), day, hour, minute, second, millisecond*1e6, c.loc)
|
||||
return c
|
||||
}
|
||||
|
||||
// SetDateMicro sets year, month, day and microsecond.
|
||||
// 设置年、月、日、微秒
|
||||
func (c Carbon) SetDateMicro(year, month, day, microsecond int) Carbon {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) SetDateMicro(year, month, day, microsecond int) *Carbon {
|
||||
if c.IsInvalid() {
|
||||
return c
|
||||
}
|
||||
hour, minute, second := c.Time()
|
||||
return c.create(year, month, day, hour, minute, second, microsecond*1e3)
|
||||
c.time = time.Date(year, time.Month(month), day, hour, minute, second, microsecond*1e3, c.loc)
|
||||
return c
|
||||
}
|
||||
|
||||
// SetDateNano sets year, month, day and nanosecond.
|
||||
// 设置年、月、日、纳秒
|
||||
func (c Carbon) SetDateNano(year, month, day, nanosecond int) Carbon {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) SetDateNano(year, month, day, nanosecond int) *Carbon {
|
||||
if c.IsInvalid() {
|
||||
return c
|
||||
}
|
||||
hour, minute, second := c.Time()
|
||||
return c.create(year, month, day, hour, minute, second, nanosecond)
|
||||
c.time = time.Date(year, time.Month(month), day, hour, minute, second, nanosecond, c.loc)
|
||||
return c
|
||||
}
|
||||
|
||||
// SetTime sets hour, minute and second.
|
||||
// 设置时、分、秒
|
||||
func (c Carbon) SetTime(hour, minute, second int) Carbon {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) SetTime(hour, minute, second int) *Carbon {
|
||||
if c.IsInvalid() {
|
||||
return c
|
||||
}
|
||||
year, month, day := c.Date()
|
||||
return c.create(year, month, day, hour, minute, second, c.Nanosecond())
|
||||
c.time = time.Date(year, time.Month(month), day, hour, minute, second, c.Nanosecond(), c.loc)
|
||||
return c
|
||||
}
|
||||
|
||||
// SetTimeMilli sets hour, minute, second and millisecond.
|
||||
// 设置时、分、秒、毫秒
|
||||
func (c Carbon) SetTimeMilli(hour, minute, second, millisecond int) Carbon {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) SetTimeMilli(hour, minute, second, millisecond int) *Carbon {
|
||||
if c.IsInvalid() {
|
||||
return c
|
||||
}
|
||||
year, month, day := c.Date()
|
||||
return c.create(year, month, day, hour, minute, second, millisecond*1e6)
|
||||
c.time = time.Date(year, time.Month(month), day, hour, minute, second, millisecond*1e6, c.loc)
|
||||
return c
|
||||
}
|
||||
|
||||
// SetTimeMicro sets hour, minute, second and microsecond.
|
||||
// 设置时、分、秒、微秒
|
||||
func (c Carbon) SetTimeMicro(hour, minute, second, microsecond int) Carbon {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) SetTimeMicro(hour, minute, second, microsecond int) *Carbon {
|
||||
if c.IsInvalid() {
|
||||
return c
|
||||
}
|
||||
year, month, day := c.Date()
|
||||
return c.create(year, month, day, hour, minute, second, microsecond*1e3)
|
||||
c.time = time.Date(year, time.Month(month), day, hour, minute, second, microsecond*1e3, c.loc)
|
||||
return c
|
||||
}
|
||||
|
||||
// SetTimeNano sets hour, minute, second and nanosecond.
|
||||
// 设置、时、分、秒、纳秒
|
||||
func (c Carbon) SetTimeNano(hour, minute, second, nanosecond int) Carbon {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) SetTimeNano(hour, minute, second, nanosecond int) *Carbon {
|
||||
if c.IsInvalid() {
|
||||
return c
|
||||
}
|
||||
year, month, day := c.Date()
|
||||
return c.create(year, month, day, hour, minute, second, nanosecond)
|
||||
c.time = time.Date(year, time.Month(month), day, hour, minute, second, nanosecond, c.loc)
|
||||
return c
|
||||
}
|
||||
|
||||
// SetYear sets year.
|
||||
// 设置年份
|
||||
func (c Carbon) SetYear(year int) Carbon {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) SetYear(year int) *Carbon {
|
||||
if c.IsInvalid() {
|
||||
return c
|
||||
}
|
||||
_, month, day, hour, minute, second := c.DateTime()
|
||||
return c.create(year, month, day, hour, minute, second, c.Nanosecond())
|
||||
c.time = time.Date(year, time.Month(month), day, hour, minute, second, c.Nanosecond(), c.loc)
|
||||
return c
|
||||
}
|
||||
|
||||
// SetYearNoOverflow sets year without overflowing month.
|
||||
// 设置年份(月份不溢出)
|
||||
func (c Carbon) SetYearNoOverflow(year int) Carbon {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) SetYearNoOverflow(year int) *Carbon {
|
||||
if c.IsInvalid() {
|
||||
return c
|
||||
}
|
||||
return c.AddYearsNoOverflow(year - c.Year())
|
||||
}
|
||||
|
||||
// SetMonth sets month.
|
||||
// 设置月份
|
||||
func (c Carbon) SetMonth(month int) Carbon {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) SetMonth(month int) *Carbon {
|
||||
if c.IsInvalid() {
|
||||
return c
|
||||
}
|
||||
year, _, day, hour, minute, second := c.DateTime()
|
||||
return c.create(year, month, day, hour, minute, second, c.Nanosecond())
|
||||
c.time = time.Date(year, time.Month(month), day, hour, minute, second, c.Nanosecond(), c.loc)
|
||||
return c
|
||||
}
|
||||
|
||||
// SetMonthNoOverflow sets month without overflowing month.
|
||||
// 设置月份(月份不溢出)
|
||||
func (c Carbon) SetMonthNoOverflow(month int) Carbon {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) SetMonthNoOverflow(month int) *Carbon {
|
||||
if c.IsInvalid() {
|
||||
return c
|
||||
}
|
||||
return c.AddMonthsNoOverflow(month - c.Month())
|
||||
}
|
||||
|
||||
// SetDay sets day.
|
||||
// 设置日期
|
||||
func (c Carbon) SetDay(day int) Carbon {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) SetDay(day int) *Carbon {
|
||||
if c.IsInvalid() {
|
||||
return c
|
||||
}
|
||||
year, month, _, hour, minute, second := c.DateTime()
|
||||
return c.create(year, month, day, hour, minute, second, c.Nanosecond())
|
||||
c.time = time.Date(year, time.Month(month), day, hour, minute, second, c.Nanosecond(), c.loc)
|
||||
return c
|
||||
}
|
||||
|
||||
// SetHour sets hour.
|
||||
// 设置小时
|
||||
func (c Carbon) SetHour(hour int) Carbon {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) SetHour(hour int) *Carbon {
|
||||
if c.IsInvalid() {
|
||||
return c
|
||||
}
|
||||
year, month, day, _, minute, second := c.DateTime()
|
||||
return c.create(year, month, day, hour, minute, second, c.Nanosecond())
|
||||
c.time = time.Date(year, time.Month(month), day, hour, minute, second, c.Nanosecond(), c.loc)
|
||||
return c
|
||||
}
|
||||
|
||||
// SetMinute sets minute.
|
||||
// 设置分钟
|
||||
func (c Carbon) SetMinute(minute int) Carbon {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) SetMinute(minute int) *Carbon {
|
||||
if c.IsInvalid() {
|
||||
return c
|
||||
}
|
||||
year, month, day, hour, _, second := c.DateTime()
|
||||
return c.create(year, month, day, hour, minute, second, c.Nanosecond())
|
||||
c.time = time.Date(year, time.Month(month), day, hour, minute, second, c.Nanosecond(), c.loc)
|
||||
return c
|
||||
}
|
||||
|
||||
// SetSecond sets second.
|
||||
// 设置秒数
|
||||
func (c Carbon) SetSecond(second int) Carbon {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) SetSecond(second int) *Carbon {
|
||||
if c.IsInvalid() {
|
||||
return c
|
||||
}
|
||||
year, month, day, hour, minute, _ := c.DateTime()
|
||||
return c.create(year, month, day, hour, minute, second, c.Nanosecond())
|
||||
c.time = time.Date(year, time.Month(month), day, hour, minute, second, c.Nanosecond(), c.loc)
|
||||
return c
|
||||
}
|
||||
|
||||
// SetMillisecond sets millisecond.
|
||||
// 设置毫秒
|
||||
func (c Carbon) SetMillisecond(millisecond int) Carbon {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) SetMillisecond(millisecond int) *Carbon {
|
||||
if c.IsInvalid() {
|
||||
return c
|
||||
}
|
||||
year, month, day, hour, minute, second := c.DateTime()
|
||||
return c.create(year, month, day, hour, minute, second, millisecond*1e6)
|
||||
c.time = time.Date(year, time.Month(month), day, hour, minute, second, millisecond*1e6, c.loc)
|
||||
return c
|
||||
}
|
||||
|
||||
// SetMicrosecond sets microsecond.
|
||||
// 设置微秒
|
||||
func (c Carbon) SetMicrosecond(microsecond int) Carbon {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) SetMicrosecond(microsecond int) *Carbon {
|
||||
if c.IsInvalid() {
|
||||
return c
|
||||
}
|
||||
year, month, day, hour, minute, second := c.DateTime()
|
||||
return c.create(year, month, day, hour, minute, second, microsecond*1e3)
|
||||
c.time = time.Date(year, time.Month(month), day, hour, minute, second, microsecond*1e3, c.loc)
|
||||
return c
|
||||
}
|
||||
|
||||
// SetNanosecond sets nanosecond.
|
||||
// 设置纳秒
|
||||
func (c Carbon) SetNanosecond(nanosecond int) Carbon {
|
||||
if c.Error != nil {
|
||||
func (c *Carbon) SetNanosecond(nanosecond int) *Carbon {
|
||||
if c.IsInvalid() {
|
||||
return c
|
||||
}
|
||||
year, month, day, hour, minute, second := c.DateTime()
|
||||
return c.create(year, month, day, hour, minute, second, nanosecond)
|
||||
c.time = time.Date(year, time.Month(month), day, hour, minute, second, nanosecond, c.loc)
|
||||
return c
|
||||
}
|
||||
|
||||
19
vendor/github.com/dromara/carbon/v2/test.go
generated
vendored
19
vendor/github.com/dromara/carbon/v2/test.go
generated
vendored
@@ -1,19 +0,0 @@
|
||||
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
|
||||
}
|
||||
350
vendor/github.com/dromara/carbon/v2/traveler.go
generated
vendored
350
vendor/github.com/dromara/carbon/v2/traveler.go
generated
vendored
@@ -5,187 +5,148 @@ import (
|
||||
)
|
||||
|
||||
// Now returns a Carbon instance for now.
|
||||
// 当前
|
||||
func (c Carbon) Now(timezone ...string) Carbon {
|
||||
func Now(timezone ...string) *Carbon {
|
||||
var (
|
||||
tz string
|
||||
loc *Location
|
||||
err error
|
||||
)
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
tz = timezone[0]
|
||||
} else {
|
||||
tz = DefaultTimezone
|
||||
}
|
||||
if c.Error != nil {
|
||||
return c
|
||||
if loc, err = parseTimezone(tz); err != nil {
|
||||
return &Carbon{Error: err}
|
||||
}
|
||||
if c.IsSetTestNow() {
|
||||
now := CreateFromTimestampNano(c.testNow, c.Location())
|
||||
now.testNow = c.testNow
|
||||
if IsTestNow() {
|
||||
return frozenNow.testNow.Copy().SetLocation(loc)
|
||||
}
|
||||
return CreateFromStdTime(time.Now().In(loc))
|
||||
}
|
||||
|
||||
// Tomorrow returns a Carbon instance for tomorrow.
|
||||
func Tomorrow(timezone ...string) *Carbon {
|
||||
now := Now(timezone...)
|
||||
if now.IsInvalid() {
|
||||
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...)
|
||||
return now.AddDay()
|
||||
}
|
||||
|
||||
// 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])
|
||||
func Yesterday(timezone ...string) *Carbon {
|
||||
now := Now(timezone...)
|
||||
if now.IsInvalid() {
|
||||
return now
|
||||
}
|
||||
if c.Error != nil {
|
||||
return c
|
||||
}
|
||||
if !c.IsZero() {
|
||||
return c.SubDay()
|
||||
}
|
||||
return c.Now().SubDay()
|
||||
return 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 {
|
||||
// AddDuration adds duration.
|
||||
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
|
||||
var (
|
||||
td Duration
|
||||
err error
|
||||
)
|
||||
if td, err = parseDuration(duration); err != nil {
|
||||
c.Error = err
|
||||
return c
|
||||
}
|
||||
c.time = c.StdTime().Add(td)
|
||||
return c
|
||||
}
|
||||
|
||||
// SubDuration subtracts one duration.
|
||||
// 按照时长减少时间,支持整数/浮点数和符号ns(纳秒)、us(微妙)、ms(毫秒)、s(秒)、m(分钟)、h(小时)的组合
|
||||
func (c Carbon) SubDuration(duration string) Carbon {
|
||||
// SubDuration subtracts duration.
|
||||
func (c *Carbon) SubDuration(duration string) *Carbon {
|
||||
return c.AddDuration("-" + duration)
|
||||
}
|
||||
|
||||
// AddCenturies adds some centuries.
|
||||
// N个世纪后
|
||||
func (c Carbon) AddCenturies(centuries int) Carbon {
|
||||
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 {
|
||||
func (c *Carbon) AddCenturiesNoOverflow(centuries int) *Carbon {
|
||||
return c.AddYearsNoOverflow(centuries * YearsPerCentury)
|
||||
}
|
||||
|
||||
// AddCentury adds one century.
|
||||
// 1个世纪后
|
||||
func (c Carbon) AddCentury() Carbon {
|
||||
func (c *Carbon) AddCentury() *Carbon {
|
||||
return c.AddCenturies(1)
|
||||
}
|
||||
|
||||
// AddCenturyNoOverflow adds one century without overflowing month.
|
||||
// 1个世纪后(月份不溢出)
|
||||
func (c Carbon) AddCenturyNoOverflow() Carbon {
|
||||
func (c *Carbon) AddCenturyNoOverflow() *Carbon {
|
||||
return c.AddCenturiesNoOverflow(1)
|
||||
}
|
||||
|
||||
// SubCenturies subtracts some centuries.
|
||||
// N个世纪前
|
||||
func (c Carbon) SubCenturies(centuries int) Carbon {
|
||||
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 {
|
||||
func (c *Carbon) SubCenturiesNoOverflow(centuries int) *Carbon {
|
||||
return c.SubYearsNoOverflow(centuries * YearsPerCentury)
|
||||
}
|
||||
|
||||
// SubCentury subtracts one century.
|
||||
// 1个世纪前
|
||||
func (c Carbon) SubCentury() Carbon {
|
||||
func (c *Carbon) SubCentury() *Carbon {
|
||||
return c.SubCenturies(1)
|
||||
}
|
||||
|
||||
// SubCenturyNoOverflow subtracts one century without overflowing month.
|
||||
// 1个世纪前(月份不溢出)
|
||||
func (c Carbon) SubCenturyNoOverflow() Carbon {
|
||||
func (c *Carbon) SubCenturyNoOverflow() *Carbon {
|
||||
return c.SubCenturiesNoOverflow(1)
|
||||
}
|
||||
|
||||
// AddDecades adds some decades.
|
||||
// N个年代后
|
||||
func (c Carbon) AddDecades(decades int) Carbon {
|
||||
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 {
|
||||
func (c *Carbon) AddDecadesNoOverflow(decades int) *Carbon {
|
||||
return c.AddYearsNoOverflow(decades * YearsPerDecade)
|
||||
}
|
||||
|
||||
// AddDecade adds one decade.
|
||||
// 1个年代后
|
||||
func (c Carbon) AddDecade() Carbon {
|
||||
func (c *Carbon) AddDecade() *Carbon {
|
||||
return c.AddDecades(1)
|
||||
}
|
||||
|
||||
// AddDecadeNoOverflow adds one decade without overflowing month.
|
||||
// 1个年代后(月份不溢出)
|
||||
func (c Carbon) AddDecadeNoOverflow() Carbon {
|
||||
func (c *Carbon) AddDecadeNoOverflow() *Carbon {
|
||||
return c.AddDecadesNoOverflow(1)
|
||||
}
|
||||
|
||||
// SubDecades subtracts some decades.
|
||||
// N个年代后
|
||||
func (c Carbon) SubDecades(decades int) Carbon {
|
||||
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 {
|
||||
func (c *Carbon) SubDecadesNoOverflow(decades int) *Carbon {
|
||||
return c.SubYearsNoOverflow(decades * YearsPerDecade)
|
||||
}
|
||||
|
||||
// SubDecade subtracts one decade.
|
||||
// 1个年代后
|
||||
func (c Carbon) SubDecade() Carbon {
|
||||
func (c *Carbon) SubDecade() *Carbon {
|
||||
return c.SubDecades(1)
|
||||
}
|
||||
|
||||
// SubDecadeNoOverflow subtracts one decade without overflowing month.
|
||||
// 1个年代后(月份不溢出)
|
||||
func (c Carbon) SubDecadeNoOverflow() Carbon {
|
||||
func (c *Carbon) SubDecadeNoOverflow() *Carbon {
|
||||
return c.SubDecadesNoOverflow(1)
|
||||
}
|
||||
|
||||
// AddYears adds some years.
|
||||
// N年后
|
||||
func (c Carbon) AddYears(years int) Carbon {
|
||||
func (c *Carbon) AddYears(years int) *Carbon {
|
||||
if c.IsInvalid() {
|
||||
return c
|
||||
}
|
||||
@@ -194,36 +155,33 @@ func (c Carbon) AddYears(years int) Carbon {
|
||||
}
|
||||
|
||||
// AddYearsNoOverflow adds some years without overflowing month.
|
||||
// N年后(月份不溢出)
|
||||
func (c Carbon) AddYearsNoOverflow(years int) Carbon {
|
||||
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()
|
||||
// get the last day of this month after some years
|
||||
lastYear, lastMonth, lastDay := time.Date(year+years, time.Month(month+1), 0, hour, minute, second, nanosecond, c.loc).Date()
|
||||
if day > lastDay {
|
||||
day = lastDay
|
||||
}
|
||||
return c.create(lastYear, lastMonth, day, hour, minute, second, nanosecond)
|
||||
c.time = time.Date(lastYear, lastMonth, day, hour, minute, second, nanosecond, c.loc)
|
||||
return c
|
||||
}
|
||||
|
||||
// AddYear adds one year.
|
||||
// 1年后
|
||||
func (c Carbon) AddYear() Carbon {
|
||||
func (c *Carbon) AddYear() *Carbon {
|
||||
return c.AddYears(1)
|
||||
}
|
||||
|
||||
// AddYearNoOverflow adds one year without overflowing month.
|
||||
// 1年后(月份不溢出)
|
||||
func (c Carbon) AddYearNoOverflow() Carbon {
|
||||
func (c *Carbon) AddYearNoOverflow() *Carbon {
|
||||
return c.AddYearsNoOverflow(1)
|
||||
}
|
||||
|
||||
// SubYears subtracts some years.
|
||||
// N年前
|
||||
func (c Carbon) SubYears(years int) Carbon {
|
||||
func (c *Carbon) SubYears(years int) *Carbon {
|
||||
if c.IsInvalid() {
|
||||
return c
|
||||
}
|
||||
@@ -231,74 +189,62 @@ func (c Carbon) SubYears(years int) Carbon {
|
||||
}
|
||||
|
||||
// SubYearsNoOverflow subtracts some years without overflowing month.
|
||||
// N年前(月份不溢出)
|
||||
func (c Carbon) SubYearsNoOverflow(years int) Carbon {
|
||||
func (c *Carbon) SubYearsNoOverflow(years int) *Carbon {
|
||||
return c.AddYearsNoOverflow(-years)
|
||||
}
|
||||
|
||||
// SubYear subtracts one year.
|
||||
// 1年前
|
||||
func (c Carbon) SubYear() Carbon {
|
||||
func (c *Carbon) SubYear() *Carbon {
|
||||
return c.SubYears(1)
|
||||
}
|
||||
|
||||
// SubYearNoOverflow subtracts one year without overflowing month.
|
||||
// 1年前(月份不溢出)
|
||||
func (c Carbon) SubYearNoOverflow() Carbon {
|
||||
func (c *Carbon) SubYearNoOverflow() *Carbon {
|
||||
return c.SubYearsNoOverflow(1)
|
||||
}
|
||||
|
||||
// AddQuarters adds some quarters
|
||||
// N个季度后
|
||||
func (c Carbon) AddQuarters(quarters int) Carbon {
|
||||
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 {
|
||||
func (c *Carbon) AddQuartersNoOverflow(quarters int) *Carbon {
|
||||
return c.AddMonthsNoOverflow(quarters * MonthsPerQuarter)
|
||||
}
|
||||
|
||||
// AddQuarter adds one quarter
|
||||
// 1个季度后
|
||||
func (c Carbon) AddQuarter() Carbon {
|
||||
func (c *Carbon) AddQuarter() *Carbon {
|
||||
return c.AddQuarters(1)
|
||||
}
|
||||
|
||||
// AddQuarterNoOverflow adds one quarter without overflowing month.
|
||||
// 1个季度后(月份不溢出)
|
||||
func (c Carbon) AddQuarterNoOverflow() Carbon {
|
||||
func (c *Carbon) AddQuarterNoOverflow() *Carbon {
|
||||
return c.AddQuartersNoOverflow(1)
|
||||
}
|
||||
|
||||
// SubQuarters subtracts some quarters.
|
||||
// N个季度前
|
||||
func (c Carbon) SubQuarters(quarters int) Carbon {
|
||||
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 {
|
||||
func (c *Carbon) SubQuartersNoOverflow(quarters int) *Carbon {
|
||||
return c.AddMonthsNoOverflow(-quarters * MonthsPerQuarter)
|
||||
}
|
||||
|
||||
// SubQuarter subtracts one quarter.
|
||||
// 1个季度前
|
||||
func (c Carbon) SubQuarter() Carbon {
|
||||
func (c *Carbon) SubQuarter() *Carbon {
|
||||
return c.SubQuarters(1)
|
||||
}
|
||||
|
||||
// SubQuarterNoOverflow subtracts one quarter without overflowing month.
|
||||
// 1个季度前(月份不溢出)
|
||||
func (c Carbon) SubQuarterNoOverflow() Carbon {
|
||||
func (c *Carbon) SubQuarterNoOverflow() *Carbon {
|
||||
return c.SubQuartersNoOverflow(1)
|
||||
}
|
||||
|
||||
// AddMonths adds some months.
|
||||
// N个月后
|
||||
func (c Carbon) AddMonths(months int) Carbon {
|
||||
func (c *Carbon) AddMonths(months int) *Carbon {
|
||||
if c.IsInvalid() {
|
||||
return c
|
||||
}
|
||||
@@ -307,84 +253,73 @@ func (c Carbon) AddMonths(months int) Carbon {
|
||||
}
|
||||
|
||||
// AddMonthsNoOverflow adds some months without overflowing month.
|
||||
// N个月后(月份不溢出)
|
||||
func (c Carbon) AddMonthsNoOverflow(months int) Carbon {
|
||||
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()
|
||||
// get the last day of this month after some months
|
||||
lastYear, lastMonth, lastDay := time.Date(year, time.Month(month+months+1), 0, hour, minute, second, nanosecond, c.loc).Date()
|
||||
if day > lastDay {
|
||||
day = lastDay
|
||||
}
|
||||
return c.create(lastYear, lastMonth, day, hour, minute, second, nanosecond)
|
||||
c.time = time.Date(lastYear, lastMonth, day, hour, minute, second, nanosecond, c.loc)
|
||||
return c
|
||||
}
|
||||
|
||||
// AddMonth adds one month.
|
||||
// 1个月后
|
||||
func (c Carbon) AddMonth() Carbon {
|
||||
func (c *Carbon) AddMonth() *Carbon {
|
||||
return c.AddMonths(1)
|
||||
}
|
||||
|
||||
// AddMonthNoOverflow adds one month without overflowing month.
|
||||
// 1个月后(月份不溢出)
|
||||
func (c Carbon) AddMonthNoOverflow() Carbon {
|
||||
func (c *Carbon) AddMonthNoOverflow() *Carbon {
|
||||
return c.AddMonthsNoOverflow(1)
|
||||
}
|
||||
|
||||
// SubMonths subtracts some months.
|
||||
// N个月前
|
||||
func (c Carbon) SubMonths(months int) Carbon {
|
||||
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 {
|
||||
func (c *Carbon) SubMonthsNoOverflow(months int) *Carbon {
|
||||
return c.AddMonthsNoOverflow(-months)
|
||||
}
|
||||
|
||||
// SubMonth subtracts one month.
|
||||
// 1个月前
|
||||
func (c Carbon) SubMonth() Carbon {
|
||||
func (c *Carbon) SubMonth() *Carbon {
|
||||
return c.SubMonths(1)
|
||||
}
|
||||
|
||||
// SubMonthNoOverflow subtracts one month without overflowing month.
|
||||
// 1个月前(月份不溢出)
|
||||
func (c Carbon) SubMonthNoOverflow() Carbon {
|
||||
func (c *Carbon) SubMonthNoOverflow() *Carbon {
|
||||
return c.SubMonthsNoOverflow(1)
|
||||
}
|
||||
|
||||
// AddWeeks adds some weeks.
|
||||
// N周后
|
||||
func (c Carbon) AddWeeks(weeks int) Carbon {
|
||||
func (c *Carbon) AddWeeks(weeks int) *Carbon {
|
||||
return c.AddDays(weeks * DaysPerWeek)
|
||||
}
|
||||
|
||||
// AddWeek adds one week.
|
||||
// 1周后
|
||||
func (c Carbon) AddWeek() Carbon {
|
||||
func (c *Carbon) AddWeek() *Carbon {
|
||||
return c.AddWeeks(1)
|
||||
}
|
||||
|
||||
// SubWeeks subtracts some weeks.
|
||||
// N周前
|
||||
func (c Carbon) SubWeeks(weeks int) Carbon {
|
||||
func (c *Carbon) SubWeeks(weeks int) *Carbon {
|
||||
return c.SubDays(weeks * DaysPerWeek)
|
||||
}
|
||||
|
||||
// SubWeek subtracts one week.
|
||||
// 1周前
|
||||
func (c Carbon) SubWeek() Carbon {
|
||||
func (c *Carbon) SubWeek() *Carbon {
|
||||
return c.SubWeeks(1)
|
||||
}
|
||||
|
||||
// AddDays adds some days.
|
||||
// N天后
|
||||
func (c Carbon) AddDays(days int) Carbon {
|
||||
func (c *Carbon) AddDays(days int) *Carbon {
|
||||
if c.IsInvalid() {
|
||||
return c
|
||||
}
|
||||
@@ -393,193 +328,160 @@ func (c Carbon) AddDays(days int) Carbon {
|
||||
}
|
||||
|
||||
// AddDay adds one day.
|
||||
// 1天后
|
||||
func (c Carbon) AddDay() Carbon {
|
||||
func (c *Carbon) AddDay() *Carbon {
|
||||
return c.AddDays(1)
|
||||
}
|
||||
|
||||
// SubDays subtracts some days.
|
||||
// N天前
|
||||
func (c Carbon) SubDays(days int) Carbon {
|
||||
func (c *Carbon) SubDays(days int) *Carbon {
|
||||
return c.AddDays(-days)
|
||||
}
|
||||
|
||||
// SubDay subtracts one day.
|
||||
// 1天前
|
||||
func (c Carbon) SubDay() Carbon {
|
||||
func (c *Carbon) SubDay() *Carbon {
|
||||
return c.SubDays(1)
|
||||
}
|
||||
|
||||
// AddHours adds some hours.
|
||||
// N小时后
|
||||
func (c Carbon) AddHours(hours int) Carbon {
|
||||
func (c *Carbon) AddHours(hours int) *Carbon {
|
||||
if c.IsInvalid() {
|
||||
return c
|
||||
}
|
||||
td := time.Duration(hours) * time.Hour
|
||||
c.time = c.StdTime().Add(td)
|
||||
c.time = c.StdTime().Add(Duration(hours) * time.Hour)
|
||||
return c
|
||||
}
|
||||
|
||||
// AddHour adds one hour.
|
||||
// 1小时后
|
||||
func (c Carbon) AddHour() Carbon {
|
||||
func (c *Carbon) AddHour() *Carbon {
|
||||
return c.AddHours(1)
|
||||
}
|
||||
|
||||
// SubHours subtracts some hours.
|
||||
// N小时前
|
||||
func (c Carbon) SubHours(hours int) Carbon {
|
||||
func (c *Carbon) SubHours(hours int) *Carbon {
|
||||
return c.AddHours(-hours)
|
||||
}
|
||||
|
||||
// SubHour subtracts one hour.
|
||||
// 1小时前
|
||||
func (c Carbon) SubHour() Carbon {
|
||||
func (c *Carbon) SubHour() *Carbon {
|
||||
return c.SubHours(1)
|
||||
}
|
||||
|
||||
// AddMinutes adds some minutes.
|
||||
// N分钟后
|
||||
func (c Carbon) AddMinutes(minutes int) Carbon {
|
||||
func (c *Carbon) AddMinutes(minutes int) *Carbon {
|
||||
if c.IsInvalid() {
|
||||
return c
|
||||
}
|
||||
td := time.Duration(minutes) * time.Minute
|
||||
c.time = c.StdTime().Add(td)
|
||||
c.time = c.StdTime().Add(Duration(minutes) * time.Minute)
|
||||
return c
|
||||
}
|
||||
|
||||
// AddMinute adds one minute.
|
||||
// 1分钟后
|
||||
func (c Carbon) AddMinute() Carbon {
|
||||
func (c *Carbon) AddMinute() *Carbon {
|
||||
return c.AddMinutes(1)
|
||||
}
|
||||
|
||||
// SubMinutes subtracts some minutes.
|
||||
// N分钟前
|
||||
func (c Carbon) SubMinutes(minutes int) Carbon {
|
||||
func (c *Carbon) SubMinutes(minutes int) *Carbon {
|
||||
return c.AddMinutes(-minutes)
|
||||
}
|
||||
|
||||
// SubMinute subtracts one minute.
|
||||
// 1分钟前
|
||||
func (c Carbon) SubMinute() Carbon {
|
||||
func (c *Carbon) SubMinute() *Carbon {
|
||||
return c.SubMinutes(1)
|
||||
}
|
||||
|
||||
// AddSeconds adds some seconds.
|
||||
// N秒钟后
|
||||
func (c Carbon) AddSeconds(seconds int) Carbon {
|
||||
func (c *Carbon) AddSeconds(seconds int) *Carbon {
|
||||
if c.IsInvalid() {
|
||||
return c
|
||||
}
|
||||
td := time.Duration(seconds) * time.Second
|
||||
c.time = c.StdTime().Add(td)
|
||||
c.time = c.StdTime().Add(Duration(seconds) * time.Second)
|
||||
return c
|
||||
}
|
||||
|
||||
// AddSecond adds one second.
|
||||
// 1秒钟后
|
||||
func (c Carbon) AddSecond() Carbon {
|
||||
func (c *Carbon) AddSecond() *Carbon {
|
||||
return c.AddSeconds(1)
|
||||
}
|
||||
|
||||
// SubSeconds subtracts some seconds.
|
||||
// N秒钟前
|
||||
func (c Carbon) SubSeconds(seconds int) Carbon {
|
||||
func (c *Carbon) SubSeconds(seconds int) *Carbon {
|
||||
return c.AddSeconds(-seconds)
|
||||
}
|
||||
|
||||
// SubSecond subtracts one second.
|
||||
// 1秒钟前
|
||||
func (c Carbon) SubSecond() Carbon {
|
||||
func (c *Carbon) SubSecond() *Carbon {
|
||||
return c.SubSeconds(1)
|
||||
}
|
||||
|
||||
// AddMilliseconds adds some milliseconds.
|
||||
// N毫秒后
|
||||
func (c Carbon) AddMilliseconds(milliseconds int) Carbon {
|
||||
func (c *Carbon) AddMilliseconds(milliseconds int) *Carbon {
|
||||
if c.IsInvalid() {
|
||||
return c
|
||||
}
|
||||
td := time.Duration(milliseconds) * time.Millisecond
|
||||
c.time = c.StdTime().Add(td)
|
||||
c.time = c.StdTime().Add(Duration(milliseconds) * time.Millisecond)
|
||||
return c
|
||||
}
|
||||
|
||||
// AddMillisecond adds one millisecond.
|
||||
// 1毫秒后
|
||||
func (c Carbon) AddMillisecond() Carbon {
|
||||
func (c *Carbon) AddMillisecond() *Carbon {
|
||||
return c.AddMilliseconds(1)
|
||||
}
|
||||
|
||||
// SubMilliseconds subtracts some milliseconds.
|
||||
// N毫秒前
|
||||
func (c Carbon) SubMilliseconds(milliseconds int) Carbon {
|
||||
func (c *Carbon) SubMilliseconds(milliseconds int) *Carbon {
|
||||
return c.AddMilliseconds(-milliseconds)
|
||||
}
|
||||
|
||||
// SubMillisecond subtracts one millisecond.
|
||||
// 1毫秒前
|
||||
func (c Carbon) SubMillisecond() Carbon {
|
||||
func (c *Carbon) SubMillisecond() *Carbon {
|
||||
return c.SubMilliseconds(1)
|
||||
}
|
||||
|
||||
// AddMicroseconds adds some microseconds.
|
||||
// N微秒后
|
||||
func (c Carbon) AddMicroseconds(microseconds int) Carbon {
|
||||
func (c *Carbon) AddMicroseconds(microseconds int) *Carbon {
|
||||
if c.IsInvalid() {
|
||||
return c
|
||||
}
|
||||
td := time.Duration(microseconds) * time.Microsecond
|
||||
c.time = c.StdTime().Add(td)
|
||||
c.time = c.StdTime().Add(Duration(microseconds) * time.Microsecond)
|
||||
return c
|
||||
}
|
||||
|
||||
// AddMicrosecond adds one microsecond.
|
||||
// 1微秒后
|
||||
func (c Carbon) AddMicrosecond() Carbon {
|
||||
func (c *Carbon) AddMicrosecond() *Carbon {
|
||||
return c.AddMicroseconds(1)
|
||||
}
|
||||
|
||||
// SubMicroseconds subtracts some microseconds.
|
||||
// N微秒前
|
||||
func (c Carbon) SubMicroseconds(microseconds int) Carbon {
|
||||
func (c *Carbon) SubMicroseconds(microseconds int) *Carbon {
|
||||
return c.AddMicroseconds(-microseconds)
|
||||
}
|
||||
|
||||
// SubMicrosecond subtracts one microsecond.
|
||||
// 1微秒前
|
||||
func (c Carbon) SubMicrosecond() Carbon {
|
||||
func (c *Carbon) SubMicrosecond() *Carbon {
|
||||
return c.SubMicroseconds(1)
|
||||
}
|
||||
|
||||
// AddNanoseconds adds some nanoseconds.
|
||||
// N纳秒后
|
||||
func (c Carbon) AddNanoseconds(nanoseconds int) Carbon {
|
||||
func (c *Carbon) AddNanoseconds(nanoseconds int) *Carbon {
|
||||
if c.IsInvalid() {
|
||||
return c
|
||||
}
|
||||
td := time.Duration(nanoseconds) * time.Nanosecond
|
||||
c.time = c.StdTime().Add(td)
|
||||
c.time = c.StdTime().Add(Duration(nanoseconds) * time.Nanosecond)
|
||||
return c
|
||||
}
|
||||
|
||||
// AddNanosecond adds one nanosecond.
|
||||
// 1纳秒后
|
||||
func (c Carbon) AddNanosecond() Carbon {
|
||||
func (c *Carbon) AddNanosecond() *Carbon {
|
||||
return c.AddNanoseconds(1)
|
||||
}
|
||||
|
||||
// SubNanoseconds subtracts some nanoseconds.
|
||||
// N纳秒前
|
||||
func (c Carbon) SubNanoseconds(nanoseconds int) Carbon {
|
||||
func (c *Carbon) SubNanoseconds(nanoseconds int) *Carbon {
|
||||
return c.AddNanoseconds(-nanoseconds)
|
||||
}
|
||||
|
||||
// SubNanosecond subtracts one nanosecond.
|
||||
// 1纳秒前
|
||||
func (c Carbon) SubNanosecond() Carbon {
|
||||
func (c *Carbon) SubNanosecond() *Carbon {
|
||||
return c.SubNanoseconds(1)
|
||||
}
|
||||
|
||||
206
vendor/github.com/dromara/carbon/v2/type_builtin.go
generated
vendored
Normal file
206
vendor/github.com/dromara/carbon/v2/type_builtin.go
generated
vendored
Normal file
@@ -0,0 +1,206 @@
|
||||
package carbon
|
||||
|
||||
type (
|
||||
timestampType int64
|
||||
timestampMicroType int64
|
||||
timestampMilliType int64
|
||||
timestampNanoType int64
|
||||
|
||||
datetimeType string
|
||||
datetimeMicroType string
|
||||
datetimeMilliType string
|
||||
datetimeNanoType string
|
||||
|
||||
dateType string
|
||||
dateMilliType string
|
||||
dateMicroType string
|
||||
dateNanoType string
|
||||
|
||||
timeType string
|
||||
timeMilliType string
|
||||
timeMicroType string
|
||||
timeNanoType string
|
||||
)
|
||||
|
||||
type (
|
||||
Timestamp = TimestampType[timestampType]
|
||||
TimestampMilli = TimestampType[timestampMilliType]
|
||||
TimestampMicro = TimestampType[timestampMicroType]
|
||||
TimestampNano = TimestampType[timestampNanoType]
|
||||
|
||||
DateTime = LayoutType[datetimeType]
|
||||
DateTimeMicro = LayoutType[datetimeMicroType]
|
||||
DateTimeMilli = LayoutType[datetimeMilliType]
|
||||
DateTimeNano = LayoutType[datetimeNanoType]
|
||||
|
||||
Date = LayoutType[dateType]
|
||||
DateMilli = LayoutType[dateMilliType]
|
||||
DateMicro = LayoutType[dateMicroType]
|
||||
DateNano = LayoutType[dateNanoType]
|
||||
|
||||
Time = LayoutType[timeType]
|
||||
TimeMilli = LayoutType[timeMilliType]
|
||||
TimeMicro = LayoutType[timeMicroType]
|
||||
TimeNano = LayoutType[timeNanoType]
|
||||
)
|
||||
|
||||
func NewTimestamp(c *Carbon) *Timestamp {
|
||||
return NewTimestampType[timestampType](c)
|
||||
}
|
||||
func NewTimestampMilli(c *Carbon) *TimestampMilli {
|
||||
return NewTimestampType[timestampMilliType](c)
|
||||
}
|
||||
func NewTimestampMicro(c *Carbon) *TimestampMicro {
|
||||
return NewTimestampType[timestampMicroType](c)
|
||||
}
|
||||
func NewTimestampNano(c *Carbon) *TimestampNano {
|
||||
return NewTimestampType[timestampNanoType](c)
|
||||
}
|
||||
|
||||
func NewDateTime(c *Carbon) *DateTime {
|
||||
return NewLayoutType[datetimeType](c)
|
||||
}
|
||||
func NewDateTimeMilli(c *Carbon) *DateTimeMilli {
|
||||
return NewLayoutType[datetimeMilliType](c)
|
||||
}
|
||||
func NewDateTimeMicro(c *Carbon) *DateTimeMicro {
|
||||
return NewLayoutType[datetimeMicroType](c)
|
||||
}
|
||||
func NewDateTimeNano(c *Carbon) *DateTimeNano {
|
||||
return NewLayoutType[datetimeNanoType](c)
|
||||
}
|
||||
|
||||
func NewDate(c *Carbon) *Date {
|
||||
return NewLayoutType[dateType](c)
|
||||
}
|
||||
func NewDateMilli(c *Carbon) *DateMilli {
|
||||
return NewLayoutType[dateMilliType](c)
|
||||
}
|
||||
func NewDateMicro(c *Carbon) *DateMicro {
|
||||
return NewLayoutType[dateMicroType](c)
|
||||
}
|
||||
func NewDateNano(c *Carbon) *DateNano {
|
||||
return NewLayoutType[dateNanoType](c)
|
||||
}
|
||||
|
||||
func NewTime(c *Carbon) *Time {
|
||||
return NewLayoutType[timeType](c)
|
||||
}
|
||||
func NewTimeMilli(c *Carbon) *TimeMilli {
|
||||
return NewLayoutType[timeMilliType](c)
|
||||
}
|
||||
func NewTimeMicro(c *Carbon) *TimeMicro {
|
||||
return NewLayoutType[timeMicroType](c)
|
||||
}
|
||||
func NewTimeNano(c *Carbon) *TimeNano {
|
||||
return NewLayoutType[timeNanoType](c)
|
||||
}
|
||||
|
||||
func (t timestampType) Precision() string {
|
||||
return PrecisionSecond
|
||||
}
|
||||
|
||||
func (t timestampMilliType) Precision() string {
|
||||
return PrecisionMillisecond
|
||||
}
|
||||
func (t timestampMilliType) DataType() string {
|
||||
return "timestamp(6)"
|
||||
}
|
||||
|
||||
func (t timestampMicroType) Precision() string {
|
||||
return PrecisionMicrosecond
|
||||
}
|
||||
func (t timestampMicroType) DataType() string {
|
||||
return "timestamp(6)"
|
||||
}
|
||||
|
||||
func (t timestampNanoType) Precision() string {
|
||||
return PrecisionNanosecond
|
||||
}
|
||||
func (t timestampNanoType) DataType() string {
|
||||
return "timestamp(6)"
|
||||
}
|
||||
|
||||
func (t datetimeType) Layout() string {
|
||||
return DateTimeLayout
|
||||
}
|
||||
func (t datetimeType) DataType() string {
|
||||
return "datetime"
|
||||
}
|
||||
|
||||
func (t datetimeMilliType) Layout() string {
|
||||
return DateTimeMilliLayout
|
||||
}
|
||||
func (t datetimeMilliType) DataType() string {
|
||||
return "datetime(6)"
|
||||
}
|
||||
|
||||
func (t datetimeMicroType) Layout() string {
|
||||
return DateTimeMicroLayout
|
||||
}
|
||||
func (t datetimeMicroType) DataType() string {
|
||||
return "datetime(6)"
|
||||
}
|
||||
|
||||
func (t datetimeNanoType) Layout() string {
|
||||
return DateTimeNanoLayout
|
||||
}
|
||||
func (t datetimeNanoType) DataType() string {
|
||||
return "datetime(6)"
|
||||
}
|
||||
|
||||
func (t dateType) Layout() string {
|
||||
return DateLayout
|
||||
}
|
||||
func (t dateType) DataType() string {
|
||||
return "date"
|
||||
}
|
||||
|
||||
func (t dateMilliType) Layout() string {
|
||||
return DateMilliLayout
|
||||
}
|
||||
func (t dateMilliType) DataType() string {
|
||||
return "datetime(6)"
|
||||
}
|
||||
|
||||
func (t dateMicroType) Layout() string {
|
||||
return DateMicroLayout
|
||||
}
|
||||
func (t dateMicroType) DataType() string {
|
||||
return "datetime(6)"
|
||||
}
|
||||
|
||||
func (t dateNanoType) Layout() string {
|
||||
return DateNanoLayout
|
||||
}
|
||||
func (t dateNanoType) DataType() string {
|
||||
return "datetime(6)"
|
||||
}
|
||||
|
||||
func (t timeType) Layout() string {
|
||||
return TimeLayout
|
||||
}
|
||||
func (t timeType) DataType() string {
|
||||
return "time"
|
||||
}
|
||||
|
||||
func (t timeMilliType) Layout() string {
|
||||
return TimeMilliLayout
|
||||
}
|
||||
func (t timeMilliType) DataType() string {
|
||||
return "datetime(6)"
|
||||
}
|
||||
|
||||
func (t timeMicroType) Layout() string {
|
||||
return TimeMicroLayout
|
||||
}
|
||||
func (t timeMicroType) DataType() string {
|
||||
return "datetime(6)"
|
||||
}
|
||||
|
||||
func (t timeNanoType) Layout() string {
|
||||
return TimeNanoLayout
|
||||
}
|
||||
func (t timeNanoType) DataType() string {
|
||||
return "datetime(6)"
|
||||
}
|
||||
75
vendor/github.com/dromara/carbon/v2/type_carbon.go
generated
vendored
Normal file
75
vendor/github.com/dromara/carbon/v2/type_carbon.go
generated
vendored
Normal file
@@ -0,0 +1,75 @@
|
||||
package carbon
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"database/sql/driver"
|
||||
)
|
||||
|
||||
// Scan implements "driver.Scanner" interface for Carbon struct.
|
||||
func (c *Carbon) Scan(src any) error {
|
||||
switch v := src.(type) {
|
||||
case nil:
|
||||
return nil
|
||||
case []byte:
|
||||
*c = *Parse(string(v))
|
||||
case string:
|
||||
*c = *Parse(v)
|
||||
case StdTime:
|
||||
*c = *CreateFromStdTime(v)
|
||||
case *StdTime:
|
||||
*c = *CreateFromStdTime(*v)
|
||||
default:
|
||||
return ErrFailedScan(v)
|
||||
}
|
||||
return c.Error
|
||||
}
|
||||
|
||||
// Value implements "driver.Valuer" interface for Carbon struct.
|
||||
func (c Carbon) Value() (driver.Value, error) {
|
||||
if c.IsNil() || c.IsZero() || c.IsEmpty() {
|
||||
return nil, nil
|
||||
}
|
||||
if c.HasError() {
|
||||
return nil, c.Error
|
||||
}
|
||||
return c.StdTime(), nil
|
||||
}
|
||||
|
||||
// MarshalJSON implements "json.Marshaler" interface for Carbon struct.
|
||||
func (c Carbon) MarshalJSON() ([]byte, error) {
|
||||
if c.IsNil() || c.IsZero() || c.IsEmpty() {
|
||||
return []byte(`null`), nil
|
||||
}
|
||||
if c.HasError() {
|
||||
return []byte(`null`), c.Error
|
||||
}
|
||||
v := c.Layout(DefaultLayout)
|
||||
b := make([]byte, 0, len(v)+2)
|
||||
b = append(b, '"')
|
||||
b = append(b, v...)
|
||||
b = append(b, '"')
|
||||
return b, nil
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements "json.Unmarshaler" interface for Carbon struct.
|
||||
func (c *Carbon) UnmarshalJSON(src []byte) error {
|
||||
v := string(bytes.Trim(src, `"`))
|
||||
if v == "" || v == "null" {
|
||||
return nil
|
||||
}
|
||||
*c = *ParseByLayout(v, DefaultLayout)
|
||||
return c.Error
|
||||
}
|
||||
|
||||
// String implements "Stringer" interface for Carbon struct.
|
||||
func (c *Carbon) String() string {
|
||||
if c.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
return c.Layout(c.currentLayout)
|
||||
}
|
||||
|
||||
// GormDataType implements "gorm.GormDataTypeInterface" interface for Carbon struct.
|
||||
func (c *Carbon) GormDataType() string {
|
||||
return "datetime"
|
||||
}
|
||||
104
vendor/github.com/dromara/carbon/v2/type_format.go
generated
vendored
Normal file
104
vendor/github.com/dromara/carbon/v2/type_format.go
generated
vendored
Normal file
@@ -0,0 +1,104 @@
|
||||
package carbon
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"database/sql/driver"
|
||||
)
|
||||
|
||||
// FormatType defines a FormatType generic struct.
|
||||
type FormatType[T FormatTyper] struct {
|
||||
*Carbon
|
||||
}
|
||||
|
||||
// NewFormatType returns a new FormatType generic instance.
|
||||
func NewFormatType[T FormatTyper](c *Carbon) *FormatType[T] {
|
||||
return &FormatType[T]{
|
||||
Carbon: c,
|
||||
}
|
||||
}
|
||||
|
||||
// Scan implements "driver.Scanner" interface for FormatType generic struct.
|
||||
func (t *FormatType[T]) Scan(src any) error {
|
||||
var c *Carbon
|
||||
switch v := src.(type) {
|
||||
case nil:
|
||||
return nil
|
||||
case []byte:
|
||||
c = Parse(string(v))
|
||||
case string:
|
||||
c = Parse(v)
|
||||
case StdTime:
|
||||
c = CreateFromStdTime(v)
|
||||
case *StdTime:
|
||||
c = CreateFromStdTime(*v)
|
||||
default:
|
||||
return ErrFailedScan(v)
|
||||
}
|
||||
*t = *NewFormatType[T](c)
|
||||
return t.Error
|
||||
}
|
||||
|
||||
// Value implements "driver.Valuer" interface for FormatType generic struct.
|
||||
func (t FormatType[T]) Value() (driver.Value, error) {
|
||||
if t.IsNil() || t.IsZero() || t.IsEmpty() {
|
||||
return nil, nil
|
||||
}
|
||||
if t.HasError() {
|
||||
return nil, t.Error
|
||||
}
|
||||
return t.StdTime(), nil
|
||||
}
|
||||
|
||||
// MarshalJSON implements "json.Marshaler" interface for FormatType generic struct.
|
||||
func (t FormatType[T]) MarshalJSON() ([]byte, error) {
|
||||
if t.IsNil() || t.IsZero() || t.IsEmpty() {
|
||||
return []byte(`null`), nil
|
||||
}
|
||||
if t.HasError() {
|
||||
return []byte(`null`), t.Error
|
||||
}
|
||||
v := t.Format(t.getFormat())
|
||||
b := make([]byte, 0, len(v)+2)
|
||||
b = append(b, '"')
|
||||
b = append(b, v...)
|
||||
b = append(b, '"')
|
||||
return b, nil
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements "json.Unmarshaler" interface for FormatType generic struct.
|
||||
func (t *FormatType[T]) UnmarshalJSON(src []byte) error {
|
||||
v := string(bytes.Trim(src, `"`))
|
||||
if v == "" || v == "null" {
|
||||
return nil
|
||||
}
|
||||
*t = *NewFormatType[T](ParseByFormat(v, t.getFormat()))
|
||||
return t.Error
|
||||
}
|
||||
|
||||
// String implements "Stringer" interface for FormatType generic struct.
|
||||
func (t *FormatType[T]) String() string {
|
||||
if t == nil || t.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
return t.Format(t.getFormat())
|
||||
}
|
||||
|
||||
// GormDataType implements "gorm.GormDataTypeInterface" interface for FormatType generic struct.
|
||||
func (t *FormatType[T]) GormDataType() string {
|
||||
return t.getDataType()
|
||||
}
|
||||
|
||||
// getDataType returns the data type of FormatType generic struct.
|
||||
func (t *FormatType[T]) getDataType() string {
|
||||
var typer T
|
||||
if v, ok := any(typer).(DataTyper); ok {
|
||||
return v.DataType()
|
||||
}
|
||||
return "datetime"
|
||||
}
|
||||
|
||||
// getFormat returns the format of FormatType generic struct.
|
||||
func (t *FormatType[T]) getFormat() string {
|
||||
var typer T
|
||||
return typer.Format()
|
||||
}
|
||||
104
vendor/github.com/dromara/carbon/v2/type_layout.go
generated
vendored
Normal file
104
vendor/github.com/dromara/carbon/v2/type_layout.go
generated
vendored
Normal file
@@ -0,0 +1,104 @@
|
||||
package carbon
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"database/sql/driver"
|
||||
)
|
||||
|
||||
// LayoutType defines a LayoutType generic struct
|
||||
type LayoutType[T LayoutTyper] struct {
|
||||
*Carbon
|
||||
}
|
||||
|
||||
// NewLayoutType returns a new LayoutType generic instance.
|
||||
func NewLayoutType[T LayoutTyper](c *Carbon) *LayoutType[T] {
|
||||
return &LayoutType[T]{
|
||||
Carbon: c,
|
||||
}
|
||||
}
|
||||
|
||||
// Scan implements "driver.Scanner" interface for LayoutType generic struct.
|
||||
func (t *LayoutType[T]) Scan(src any) error {
|
||||
var c *Carbon
|
||||
switch v := src.(type) {
|
||||
case nil:
|
||||
return nil
|
||||
case []byte:
|
||||
c = Parse(string(v))
|
||||
case string:
|
||||
c = Parse(v)
|
||||
case StdTime:
|
||||
c = CreateFromStdTime(v)
|
||||
case *StdTime:
|
||||
c = CreateFromStdTime(*v)
|
||||
default:
|
||||
return ErrFailedScan(v)
|
||||
}
|
||||
*t = *NewLayoutType[T](c)
|
||||
return t.Error
|
||||
}
|
||||
|
||||
// Value implements "driver.Valuer" interface for LayoutType generic struct.
|
||||
func (t LayoutType[T]) Value() (driver.Value, error) {
|
||||
if t.IsNil() || t.IsZero() || t.IsEmpty() {
|
||||
return nil, nil
|
||||
}
|
||||
if t.HasError() {
|
||||
return nil, t.Error
|
||||
}
|
||||
return t.StdTime(), nil
|
||||
}
|
||||
|
||||
// MarshalJSON implements "json.Marshaler" interface for LayoutType generic struct.
|
||||
func (t LayoutType[T]) MarshalJSON() ([]byte, error) {
|
||||
if t.IsNil() || t.IsZero() || t.IsEmpty() {
|
||||
return []byte(`null`), nil
|
||||
}
|
||||
if t.HasError() {
|
||||
return []byte(`null`), t.Error
|
||||
}
|
||||
v := t.Layout(t.getLayout())
|
||||
b := make([]byte, 0, len(v)+2)
|
||||
b = append(b, '"')
|
||||
b = append(b, v...)
|
||||
b = append(b, '"')
|
||||
return b, nil
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements "json.Unmarshaler" interface for LayoutType generic struct.
|
||||
func (t *LayoutType[T]) UnmarshalJSON(src []byte) error {
|
||||
v := string(bytes.Trim(src, `"`))
|
||||
if v == "" || v == "null" {
|
||||
return nil
|
||||
}
|
||||
*t = *NewLayoutType[T](ParseByLayout(v, t.getLayout()))
|
||||
return t.Error
|
||||
}
|
||||
|
||||
// String implements "Stringer" interface for LayoutType generic struct.
|
||||
func (t *LayoutType[T]) String() string {
|
||||
if t == nil || t.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
return t.Layout(t.getLayout())
|
||||
}
|
||||
|
||||
// GormDataType implements "gorm.GormDataTypeInterface" interface for LayoutType generic struct.
|
||||
func (t *LayoutType[T]) GormDataType() string {
|
||||
return t.getDataType()
|
||||
}
|
||||
|
||||
// getDataType returns the data type of LayoutType generic struct.
|
||||
func (t *LayoutType[T]) getDataType() string {
|
||||
var typer T
|
||||
if v, ok := any(typer).(DataTyper); ok {
|
||||
return v.DataType()
|
||||
}
|
||||
return "datetime"
|
||||
}
|
||||
|
||||
// getLayout returns the layout of LayoutType generic struct.
|
||||
func (t *LayoutType[T]) getLayout() string {
|
||||
var typer T
|
||||
return typer.Layout()
|
||||
}
|
||||
155
vendor/github.com/dromara/carbon/v2/type_timestamp.go
generated
vendored
Normal file
155
vendor/github.com/dromara/carbon/v2/type_timestamp.go
generated
vendored
Normal file
@@ -0,0 +1,155 @@
|
||||
package carbon
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"database/sql/driver"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// timestamp precision constants
|
||||
const (
|
||||
PrecisionSecond = "second"
|
||||
PrecisionMillisecond = "millisecond"
|
||||
PrecisionMicrosecond = "microsecond"
|
||||
PrecisionNanosecond = "nanosecond"
|
||||
)
|
||||
|
||||
// TimestampType defines a TimestampType generic struct.
|
||||
type TimestampType[T TimestampTyper] struct {
|
||||
*Carbon
|
||||
}
|
||||
|
||||
// NewTimestampType returns a new TimestampType generic instance.
|
||||
func NewTimestampType[T TimestampTyper](c *Carbon) *TimestampType[T] {
|
||||
return &TimestampType[T]{
|
||||
Carbon: c,
|
||||
}
|
||||
}
|
||||
|
||||
// Scan implements "driver.Scanner" interface for TimestampType generic struct.
|
||||
func (t *TimestampType[T]) Scan(src any) (err error) {
|
||||
var c *Carbon
|
||||
switch v := src.(type) {
|
||||
case nil:
|
||||
return nil
|
||||
case []byte:
|
||||
c = Parse(string(v))
|
||||
case string:
|
||||
c = Parse(v)
|
||||
case StdTime:
|
||||
c = CreateFromStdTime(v)
|
||||
case *StdTime:
|
||||
c = CreateFromStdTime(*v)
|
||||
default:
|
||||
return ErrFailedScan(src)
|
||||
}
|
||||
*t = *NewTimestampType[T](c)
|
||||
return t.Error
|
||||
}
|
||||
|
||||
// Value implements "driver.Valuer" interface for TimestampType generic struct.
|
||||
func (t TimestampType[T]) Value() (driver.Value, error) {
|
||||
if t.IsNil() || t.IsZero() || t.IsEmpty() {
|
||||
return nil, nil
|
||||
}
|
||||
if t.HasError() {
|
||||
return nil, t.Error
|
||||
}
|
||||
return t.StdTime(), nil
|
||||
}
|
||||
|
||||
// MarshalJSON implements "json.Marshaler" interface for TimestampType generic struct.
|
||||
func (t TimestampType[T]) MarshalJSON() ([]byte, error) {
|
||||
if t.IsNil() || t.IsZero() || t.IsEmpty() {
|
||||
return []byte(`null`), nil
|
||||
}
|
||||
if t.HasError() {
|
||||
return []byte(`null`), t.Error
|
||||
}
|
||||
var ts int64
|
||||
switch t.getPrecision() {
|
||||
case PrecisionSecond:
|
||||
ts = t.Timestamp()
|
||||
case PrecisionMillisecond:
|
||||
ts = t.TimestampMilli()
|
||||
case PrecisionMicrosecond:
|
||||
ts = t.TimestampMicro()
|
||||
case PrecisionNanosecond:
|
||||
ts = t.TimestampNano()
|
||||
}
|
||||
return []byte(strconv.FormatInt(ts, 10)), nil
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements "json.Unmarshaler" interface for TimestampType generic struct.
|
||||
func (t *TimestampType[T]) UnmarshalJSON(src []byte) error {
|
||||
v := string(bytes.Trim(src, `"`))
|
||||
if v == "" || v == "null" {
|
||||
return nil
|
||||
}
|
||||
var (
|
||||
ts int64
|
||||
err error
|
||||
)
|
||||
if ts, err = parseTimestamp(v); err != nil {
|
||||
return err
|
||||
}
|
||||
var c *Carbon
|
||||
switch t.getPrecision() {
|
||||
case PrecisionSecond:
|
||||
c = CreateFromTimestamp(ts, DefaultTimezone)
|
||||
case PrecisionMillisecond:
|
||||
c = CreateFromTimestampMilli(ts, DefaultTimezone)
|
||||
case PrecisionMicrosecond:
|
||||
c = CreateFromTimestampMicro(ts, DefaultTimezone)
|
||||
case PrecisionNanosecond:
|
||||
c = CreateFromTimestampNano(ts, DefaultTimezone)
|
||||
}
|
||||
*t = *NewTimestampType[T](c)
|
||||
return t.Error
|
||||
}
|
||||
|
||||
// String implements "Stringer" interface for TimestampType generic struct.
|
||||
func (t *TimestampType[T]) String() string {
|
||||
if t == nil || t.IsInvalid() {
|
||||
return "0"
|
||||
}
|
||||
return strconv.FormatInt(t.Int64(), 10)
|
||||
}
|
||||
|
||||
// Int64 returns the timestamp value.
|
||||
func (t *TimestampType[T]) Int64() (ts int64) {
|
||||
if t == nil || t.IsInvalid() || t.IsZero() {
|
||||
return
|
||||
}
|
||||
switch t.getPrecision() {
|
||||
case PrecisionSecond:
|
||||
ts = t.Timestamp()
|
||||
case PrecisionMillisecond:
|
||||
ts = t.TimestampMilli()
|
||||
case PrecisionMicrosecond:
|
||||
ts = t.TimestampMicro()
|
||||
case PrecisionNanosecond:
|
||||
ts = t.TimestampNano()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// GormDataType implements "gorm.GormDataTypeInterface" interface for TimestampType generic struct.
|
||||
func (t *TimestampType[T]) GormDataType() string {
|
||||
return t.getDataType()
|
||||
}
|
||||
|
||||
// getDataType returns data type of TimestampType generic struct.
|
||||
func (t *TimestampType[T]) getDataType() string {
|
||||
var typer T
|
||||
if v, ok := any(typer).(DataTyper); ok {
|
||||
return v.DataType()
|
||||
}
|
||||
return "timestamp"
|
||||
}
|
||||
|
||||
// getPrecision returns precision of TimestampType generic struct.
|
||||
func (t *TimestampType[T]) getPrecision() string {
|
||||
var typer T
|
||||
return typer.Precision()
|
||||
}
|
||||
4
vendor/modules.txt
vendored
4
vendor/modules.txt
vendored
@@ -174,8 +174,8 @@ 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 v2.6.8
|
||||
## explicit; go 1.21
|
||||
github.com/dromara/carbon/v2
|
||||
github.com/dromara/carbon/v2/calendar
|
||||
github.com/dromara/carbon/v2/calendar/julian
|
||||
|
||||
Reference in New Issue
Block a user