mirror of
https://github.com/ManyakRus/starter.git
synced 2025-12-01 23:51:28 +02:00
сделал make mod
This commit is contained in:
14
vendor/github.com/dromara/carbon/v2/.editorconfig
generated
vendored
Normal file
14
vendor/github.com/dromara/carbon/v2/.editorconfig
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
# http://editorconfig.org
|
||||
root = true
|
||||
|
||||
[*]
|
||||
indent_style = tab
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
[*.md]
|
||||
indent_size = 4
|
||||
trim_trailing_whitespace = false
|
||||
|
||||
[lang/*.json]
|
||||
indent_size = 4
|
||||
21
vendor/github.com/dromara/carbon/v2/LICENSE
generated
vendored
Normal file
21
vendor/github.com/dromara/carbon/v2/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2022 gouguoyin
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
1580
vendor/github.com/dromara/carbon/v2/README.cn.md
generated
vendored
Normal file
1580
vendor/github.com/dromara/carbon/v2/README.cn.md
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1562
vendor/github.com/dromara/carbon/v2/README.jp.md
generated
vendored
Normal file
1562
vendor/github.com/dromara/carbon/v2/README.jp.md
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1561
vendor/github.com/dromara/carbon/v2/README.md
generated
vendored
Normal file
1561
vendor/github.com/dromara/carbon/v2/README.md
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
201
vendor/github.com/dromara/carbon/v2/boundary.go
generated
vendored
Normal file
201
vendor/github.com/dromara/carbon/v2/boundary.go
generated
vendored
Normal file
@@ -0,0 +1,201 @@
|
||||
package carbon
|
||||
|
||||
// StartOfCentury returns a Carbon instance for start of the century.
|
||||
// 本世纪开始时间
|
||||
func (c Carbon) StartOfCentury() Carbon {
|
||||
if c.Error != nil {
|
||||
return c
|
||||
}
|
||||
return c.create(c.Year()/YearsPerCentury*YearsPerCentury, 1, 1, 0, 0, 0, 0)
|
||||
}
|
||||
|
||||
// EndOfCentury returns a Carbon instance for end of the century.
|
||||
// 本世纪结束时间
|
||||
func (c Carbon) EndOfCentury() Carbon {
|
||||
if c.Error != nil {
|
||||
return c
|
||||
}
|
||||
return c.create(c.Year()/YearsPerCentury*YearsPerCentury+99, 12, 31, 23, 59, 59, 999999999)
|
||||
}
|
||||
|
||||
// StartOfDecade returns a Carbon instance for start of the decade.
|
||||
// 本年代开始时间
|
||||
func (c Carbon) StartOfDecade() Carbon {
|
||||
if c.Error != nil {
|
||||
return c
|
||||
}
|
||||
return c.create(c.Year()/YearsPerDecade*YearsPerDecade, 1, 1, 0, 0, 0, 0)
|
||||
}
|
||||
|
||||
// EndOfDecade returns a Carbon instance for end of the decade.
|
||||
// 本年代结束时间
|
||||
func (c Carbon) EndOfDecade() Carbon {
|
||||
if c.Error != nil {
|
||||
return c
|
||||
}
|
||||
return c.create(c.Year()/YearsPerDecade*YearsPerDecade+9, 12, 31, 23, 59, 59, 999999999)
|
||||
}
|
||||
|
||||
// StartOfYear returns a Carbon instance for start of the year.
|
||||
// 本年开始时间
|
||||
func (c Carbon) StartOfYear() Carbon {
|
||||
if c.Error != nil {
|
||||
return c
|
||||
}
|
||||
return c.create(c.Year(), 1, 1, 0, 0, 0, 0)
|
||||
}
|
||||
|
||||
// EndOfYear returns a Carbon instance for end of the year.
|
||||
// 本年结束时间
|
||||
func (c Carbon) EndOfYear() Carbon {
|
||||
if c.Error != nil {
|
||||
return c
|
||||
}
|
||||
return c.create(c.Year(), 12, 31, 23, 59, 59, 999999999)
|
||||
}
|
||||
|
||||
// StartOfQuarter returns a Carbon instance for start of the quarter.
|
||||
// 本季度开始时间
|
||||
func (c Carbon) StartOfQuarter() Carbon {
|
||||
if c.Error != nil {
|
||||
return c
|
||||
}
|
||||
year, quarter, day := c.Year(), c.Quarter(), 1
|
||||
return c.create(year, 3*quarter-2, day, 0, 0, 0, 0)
|
||||
}
|
||||
|
||||
// EndOfQuarter returns a Carbon instance for end of the quarter.
|
||||
// 本季度结束时间
|
||||
func (c Carbon) EndOfQuarter() Carbon {
|
||||
if c.Error != nil {
|
||||
return c
|
||||
}
|
||||
year, quarter, day := c.Year(), c.Quarter(), 30
|
||||
switch quarter {
|
||||
case 1, 4:
|
||||
day = 31
|
||||
case 2, 3:
|
||||
day = 30
|
||||
}
|
||||
return c.create(year, 3*quarter, day, 23, 59, 59, 999999999)
|
||||
}
|
||||
|
||||
// StartOfMonth returns a Carbon instance for start of the month.
|
||||
// 本月开始时间
|
||||
func (c Carbon) StartOfMonth() Carbon {
|
||||
if c.Error != nil {
|
||||
return c
|
||||
}
|
||||
year, month, _ := c.Date()
|
||||
return c.create(year, month, 1, 0, 0, 0, 0)
|
||||
}
|
||||
|
||||
// EndOfMonth returns a Carbon instance for end of the month.
|
||||
// 本月结束时间
|
||||
func (c Carbon) EndOfMonth() Carbon {
|
||||
if c.Error != nil {
|
||||
return c
|
||||
}
|
||||
year, month, _ := c.Date()
|
||||
return c.create(year, month+1, 0, 23, 59, 59, 999999999)
|
||||
}
|
||||
|
||||
// StartOfWeek returns a Carbon instance for start of the week.
|
||||
// 本周开始时间
|
||||
func (c Carbon) StartOfWeek() Carbon {
|
||||
if c.Error != nil {
|
||||
return c
|
||||
}
|
||||
dayOfWeek, weekStartsAt := c.DayOfWeek(), int(c.weekStartsAt)
|
||||
return c.SubDays((DaysPerWeek + dayOfWeek - weekStartsAt) % DaysPerWeek).StartOfDay()
|
||||
}
|
||||
|
||||
// EndOfWeek returns a Carbon instance for end of the week.
|
||||
// 本周结束时间
|
||||
func (c Carbon) EndOfWeek() Carbon {
|
||||
if c.Error != nil {
|
||||
return c
|
||||
}
|
||||
dayOfWeek, weekEndsAt := c.DayOfWeek(), int(c.weekStartsAt)+DaysPerWeek-1
|
||||
return c.AddDays((DaysPerWeek - dayOfWeek + weekEndsAt) % DaysPerWeek).EndOfDay()
|
||||
}
|
||||
|
||||
// StartOfDay returns a Carbon instance for start of the day.
|
||||
// 本日开始时间
|
||||
func (c Carbon) StartOfDay() Carbon {
|
||||
if c.Error != nil {
|
||||
return c
|
||||
}
|
||||
year, month, day := c.Date()
|
||||
return c.create(year, month, day, 0, 0, 0, 0)
|
||||
}
|
||||
|
||||
// EndOfDay returns a Carbon instance for end of the day.
|
||||
// 本日结束时间
|
||||
func (c Carbon) EndOfDay() Carbon {
|
||||
if c.Error != nil {
|
||||
return c
|
||||
}
|
||||
year, month, day := c.Date()
|
||||
return c.create(year, month, day, 23, 59, 59, 999999999)
|
||||
}
|
||||
|
||||
// StartOfHour returns a Carbon instance for start of the hour.
|
||||
// 小时开始时间
|
||||
func (c Carbon) StartOfHour() Carbon {
|
||||
if c.Error != nil {
|
||||
return c
|
||||
}
|
||||
year, month, day := c.Date()
|
||||
return c.create(year, month, day, c.Hour(), 0, 0, 0)
|
||||
}
|
||||
|
||||
// EndOfHour returns a Carbon instance for end of the hour.
|
||||
// 小时结束时间
|
||||
func (c Carbon) EndOfHour() Carbon {
|
||||
if c.Error != nil {
|
||||
return c
|
||||
}
|
||||
year, month, day := c.Date()
|
||||
return c.create(year, month, day, c.Hour(), 59, 59, 999999999)
|
||||
}
|
||||
|
||||
// StartOfMinute returns a Carbon instance for start of the minute.
|
||||
// 分钟开始时间
|
||||
func (c Carbon) StartOfMinute() Carbon {
|
||||
if c.Error != nil {
|
||||
return c
|
||||
}
|
||||
year, month, day, hour, minute, _ := c.DateTime()
|
||||
return c.create(year, month, day, hour, minute, 0, 0)
|
||||
}
|
||||
|
||||
// EndOfMinute returns a Carbon instance for end of the minute.
|
||||
// 分钟结束时间
|
||||
func (c Carbon) EndOfMinute() Carbon {
|
||||
if c.Error != nil {
|
||||
return c
|
||||
}
|
||||
year, month, day, hour, minute, _ := c.DateTime()
|
||||
return c.create(year, month, day, hour, minute, 59, 999999999)
|
||||
}
|
||||
|
||||
// StartOfSecond returns a Carbon instance for start of the second.
|
||||
// 秒开始时间
|
||||
func (c Carbon) StartOfSecond() Carbon {
|
||||
if c.Error != nil {
|
||||
return c
|
||||
}
|
||||
year, month, day, hour, minute, second := c.DateTime()
|
||||
return c.create(year, month, day, hour, minute, second, 0)
|
||||
}
|
||||
|
||||
// EndOfSecond returns a Carbon instance for end of the second.
|
||||
// 秒结束时间
|
||||
func (c Carbon) EndOfSecond() Carbon {
|
||||
if c.Error != nil {
|
||||
return c
|
||||
}
|
||||
year, month, day, hour, minute, second := c.DateTime()
|
||||
return c.create(year, month, day, hour, minute, second, 999999999)
|
||||
}
|
||||
61
vendor/github.com/dromara/carbon/v2/calendar.go
generated
vendored
Normal file
61
vendor/github.com/dromara/carbon/v2/calendar.go
generated
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
package carbon
|
||||
|
||||
import (
|
||||
"github.com/dromara/carbon/v2/calendar/julian"
|
||||
"github.com/dromara/carbon/v2/calendar/lunar"
|
||||
"github.com/dromara/carbon/v2/calendar/persian"
|
||||
)
|
||||
|
||||
// Lunar converts Carbon instance to Lunar instance.
|
||||
// 将 Carbon 实例转化为 Lunar 实例
|
||||
func (c Carbon) Lunar() (l lunar.Lunar) {
|
||||
if c.Error != nil {
|
||||
l.Error = c.Error
|
||||
return
|
||||
}
|
||||
return lunar.FromGregorian(c.StdTime()).ToLunar()
|
||||
}
|
||||
|
||||
// CreateFromLunar creates a Carbon instance from Lunar date and time.
|
||||
// 从 农历日期 创建 Carbon 实例
|
||||
func CreateFromLunar(year, month, day, hour, minute, second int, isLeapMonth bool) Carbon {
|
||||
t := lunar.FromLunar(year, month, day, hour, minute, second, isLeapMonth).ToGregorian().Time
|
||||
return CreateFromStdTime(t)
|
||||
}
|
||||
|
||||
// Julian converts Carbon instance to Julian instance.
|
||||
// 将 Carbon 实例转化为 Julian 实例
|
||||
func (c Carbon) Julian() (j julian.Julian) {
|
||||
if c.Error != nil {
|
||||
return
|
||||
}
|
||||
return julian.FromGregorian(c.StdTime()).ToJulian()
|
||||
}
|
||||
|
||||
// CreateFromJulian creates a Carbon instance from Julian Day or Modified Julian Day.
|
||||
// 从 儒略日/简化儒略日 创建 Carbon 实例
|
||||
func CreateFromJulian(f float64) Carbon {
|
||||
t := julian.FromJulian(f).ToGregorian().Time
|
||||
return CreateFromStdTime(t)
|
||||
}
|
||||
|
||||
// Persian converts Carbon instance to Persian instance.
|
||||
// 将 Carbon 实例转化为 Persian 实例
|
||||
func (c Carbon) Persian() (p persian.Persian) {
|
||||
if c.Error != nil {
|
||||
return
|
||||
}
|
||||
return persian.FromGregorian(c.StdTime()).ToPersian()
|
||||
}
|
||||
|
||||
// CreateFromPersian creates a Carbon instance from Persian date and time.
|
||||
// 从 波斯日期 创建 Carbon 实例
|
||||
func CreateFromPersian(year, month, day, hour, minute, second int) (c Carbon) {
|
||||
p := persian.FromPersian(year, month, day, hour, minute, second)
|
||||
if p.Error != nil {
|
||||
c.Error = p.Error
|
||||
return
|
||||
}
|
||||
t := p.ToGregorian().Time
|
||||
return CreateFromStdTime(t)
|
||||
}
|
||||
280
vendor/github.com/dromara/carbon/v2/calendar/gregorian.go
generated
vendored
Normal file
280
vendor/github.com/dromara/carbon/v2/calendar/gregorian.go
generated
vendored
Normal file
@@ -0,0 +1,280 @@
|
||||
// Package calendar is part of the carbon package.
|
||||
package calendar
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
var InvalidDateError = func() error {
|
||||
return fmt.Errorf("invalid gregorian date, please make sure the date is valid")
|
||||
}
|
||||
|
||||
// month constants
|
||||
// 月份常量
|
||||
const (
|
||||
January = "January" // 一月
|
||||
February = "February" // 二月
|
||||
March = "March" // 三月
|
||||
April = "April" // 四月
|
||||
May = "May" // 五月
|
||||
June = "June" // 六月
|
||||
July = "July" // 七月
|
||||
August = "August" // 八月
|
||||
September = "September" // 九月
|
||||
October = "October" // 十月
|
||||
November = "November" // 十一月
|
||||
December = "December" // 十二月
|
||||
)
|
||||
|
||||
// week constants
|
||||
// 星期常量
|
||||
const (
|
||||
Monday = "Monday" // 周一
|
||||
Tuesday = "Tuesday" // 周二
|
||||
Wednesday = "Wednesday" // 周三
|
||||
Thursday = "Thursday" // 周四
|
||||
Friday = "Friday" // 周五
|
||||
Saturday = "Saturday" // 周六
|
||||
Sunday = "Sunday" // 周日
|
||||
)
|
||||
|
||||
// number constants
|
||||
// 数字常量
|
||||
const (
|
||||
YearsPerMillennium = 1000 // 每千年1000年
|
||||
YearsPerCentury = 100 // 每世纪100年
|
||||
YearsPerDecade = 10 // 每十年10年
|
||||
QuartersPerYear = 4 // 每年4个季度
|
||||
MonthsPerYear = 12 // 每年12月
|
||||
MonthsPerQuarter = 3 // 每季度3月
|
||||
WeeksPerNormalYear = 52 // 每常规年52周
|
||||
weeksPerLongYear = 53 // 每长年53周
|
||||
WeeksPerMonth = 4 // 每月4周
|
||||
DaysPerLeapYear = 366 // 每闰年366天
|
||||
DaysPerNormalYear = 365 // 每常规年365天
|
||||
DaysPerWeek = 7 // 每周7天
|
||||
HoursPerWeek = 168 // 每周168小时
|
||||
HoursPerDay = 24 // 每天24小时
|
||||
MinutesPerDay = 1440 // 每天1440分钟
|
||||
MinutesPerHour = 60 // 每小时60分钟
|
||||
SecondsPerWeek = 604800 // 每周604800秒
|
||||
SecondsPerDay = 86400 // 每天86400秒
|
||||
SecondsPerHour = 3600 // 每小时3600秒
|
||||
SecondsPerMinute = 60 // 每分钟60秒
|
||||
)
|
||||
|
||||
// layout constants
|
||||
// 布局模板常量
|
||||
const (
|
||||
AtomLayout = RFC3339Layout
|
||||
ANSICLayout = time.ANSIC
|
||||
CookieLayout = "Monday, 02-Jan-2006 15:04:05 MST"
|
||||
KitchenLayout = time.Kitchen
|
||||
RssLayout = time.RFC1123Z
|
||||
RubyDateLayout = time.RubyDate
|
||||
UnixDateLayout = time.UnixDate
|
||||
W3cLayout = RFC3339Layout
|
||||
|
||||
RFC1036Layout = "Mon, 02 Jan 06 15:04:05 -0700"
|
||||
RFC1123Layout = time.RFC1123
|
||||
RFC1123ZLayout = time.RFC1123Z
|
||||
RFC2822Layout = time.RFC1123Z
|
||||
RFC3339Layout = "2006-01-02T15:04:05Z07:00"
|
||||
RFC3339MilliLayout = "2006-01-02T15:04:05.999Z07:00"
|
||||
RFC3339MicroLayout = "2006-01-02T15:04:05.999999Z07:00"
|
||||
RFC3339NanoLayout = "2006-01-02T15:04:05.999999999Z07:00"
|
||||
RFC7231Layout = "Mon, 02 Jan 2006 15:04:05 MST"
|
||||
RFC822Layout = time.RFC822
|
||||
RFC822ZLayout = time.RFC822Z
|
||||
RFC850Layout = time.RFC850
|
||||
|
||||
ISO8601Layout = "2006-01-02T15:04:05-07:00"
|
||||
ISO8601MilliLayout = "2006-01-02T15:04:05.999-07:00"
|
||||
ISO8601MicroLayout = "2006-01-02T15:04:05.999999-07:00"
|
||||
ISO8601NanoLayout = "2006-01-02T15:04:05.999999999-07:00"
|
||||
|
||||
DayDateTimeLayout = "Mon, Jan 2, 2006 3:04 PM"
|
||||
DateTimeLayout = "2006-01-02 15:04:05"
|
||||
DateTimeMilliLayout = "2006-01-02 15:04:05.999"
|
||||
DateTimeMicroLayout = "2006-01-02 15:04:05.999999"
|
||||
DateTimeNanoLayout = "2006-01-02 15:04:05.999999999"
|
||||
ShortDateTimeLayout = "20060102150405"
|
||||
ShortDateTimeMilliLayout = "20060102150405.999"
|
||||
ShortDateTimeMicroLayout = "20060102150405.999999"
|
||||
ShortDateTimeNanoLayout = "20060102150405.999999999"
|
||||
|
||||
DateLayout = "2006-01-02"
|
||||
DateMilliLayout = "2006-01-02.999"
|
||||
DateMicroLayout = "2006-01-02.999999"
|
||||
DateNanoLayout = "2006-01-02.999999999"
|
||||
ShortDateLayout = "20060102"
|
||||
ShortDateMilliLayout = "20060102.999"
|
||||
ShortDateMicroLayout = "20060102.999999"
|
||||
ShortDateNanoLayout = "20060102.999999999"
|
||||
|
||||
TimeLayout = "15:04:05"
|
||||
TimeMilliLayout = "15:04:05.999"
|
||||
TimeMicroLayout = "15:04:05.999999"
|
||||
TimeNanoLayout = "15:04:05.999999999"
|
||||
ShortTimeLayout = "150405"
|
||||
ShortTimeMilliLayout = "150405.999"
|
||||
ShortTimeMicroLayout = "150405.999999"
|
||||
ShortTimeNanoLayout = "150405.999999999"
|
||||
)
|
||||
|
||||
// Gregorian defines a Gregorian struct.
|
||||
// 定义 Gregorian 结构体
|
||||
type Gregorian struct {
|
||||
Time time.Time
|
||||
Error error
|
||||
}
|
||||
|
||||
// NewGregorian returns a new Gregorian instance.
|
||||
// 初始化 Gregorian 结构体
|
||||
func NewGregorian(t time.Time) (g Gregorian) {
|
||||
if t.IsZero() {
|
||||
return
|
||||
}
|
||||
g.Time = t
|
||||
return
|
||||
}
|
||||
|
||||
// MaxValue returns a Gregorian instance for the greatest supported date.
|
||||
// 返回 Gregorian 的最大值
|
||||
func MaxValue() Gregorian {
|
||||
return NewGregorian(time.Date(9999, 12, 31, 23, 59, 59, 999999999, time.UTC))
|
||||
}
|
||||
|
||||
// MinValue returns a Gregorian instance for the lowest supported date.
|
||||
// 返回 Gregorian 的最小值
|
||||
func MinValue() Gregorian {
|
||||
return NewGregorian(time.Date(-9998, 1, 1, 0, 0, 0, 0, time.UTC))
|
||||
}
|
||||
|
||||
// Date gets gregorian year, month, and day like 2020, 8, 5.
|
||||
// 获取公历年、月、日
|
||||
func (g Gregorian) Date() (year, month, day int) {
|
||||
if g.IsZero() {
|
||||
return 0, 0, 0
|
||||
}
|
||||
var tm time.Month
|
||||
year, tm, day = g.Time.Date()
|
||||
month = int(tm)
|
||||
return
|
||||
}
|
||||
|
||||
// Clock gets gregorian hour, minute, and second like 13, 14, 15.
|
||||
// 获取公历时、分、秒
|
||||
func (g Gregorian) Clock() (hour, minute, second int) {
|
||||
if g.IsZero() {
|
||||
return 0, 0, 0
|
||||
}
|
||||
return g.Time.Clock()
|
||||
}
|
||||
|
||||
// Year gets gregorian year like 2020.
|
||||
// 获取公历年
|
||||
func (g Gregorian) Year() int {
|
||||
if g.IsZero() {
|
||||
return 0
|
||||
}
|
||||
return g.Time.Year()
|
||||
}
|
||||
|
||||
// Month gets gregorian month like 8.
|
||||
// 获取公历月,如 8
|
||||
func (g Gregorian) Month() int {
|
||||
if g.IsZero() {
|
||||
return 0
|
||||
}
|
||||
return int(g.Time.Month())
|
||||
}
|
||||
|
||||
// Week gets gregorian week day like 0.
|
||||
// 获取周
|
||||
func (g Gregorian) Week() int {
|
||||
if g.IsZero() {
|
||||
return 0
|
||||
}
|
||||
return int(g.Time.Weekday())
|
||||
}
|
||||
|
||||
// Day gets gregorian day like 5.
|
||||
// 获取公历日,如 0
|
||||
func (g Gregorian) Day() int {
|
||||
if g.IsZero() {
|
||||
return 0
|
||||
}
|
||||
return g.Time.Day()
|
||||
}
|
||||
|
||||
// Hour gets gregorian hour like 13.
|
||||
// 获取公历小时,如 13
|
||||
func (g Gregorian) Hour() int {
|
||||
if g.IsZero() {
|
||||
return 0
|
||||
}
|
||||
return g.Time.Hour()
|
||||
}
|
||||
|
||||
// Minute gets gregorian minute like 14.
|
||||
// 获取公历分钟数,如 14
|
||||
func (g Gregorian) Minute() int {
|
||||
if g.IsZero() {
|
||||
return 0
|
||||
}
|
||||
return g.Time.Minute()
|
||||
}
|
||||
|
||||
// Second gets gregorian second like 15.
|
||||
// 获取公历秒数,如 15
|
||||
func (g Gregorian) Second() int {
|
||||
if g.IsZero() {
|
||||
return 0
|
||||
}
|
||||
return g.Time.Second()
|
||||
}
|
||||
|
||||
// Location gets gregorian timezone information.
|
||||
// 获取时区信息
|
||||
func (g Gregorian) Location() *time.Location {
|
||||
return g.Time.Location()
|
||||
}
|
||||
|
||||
// String implements Stringer interface and outputs a string in YYYY-MM-DD HH::ii::ss format like "2019-12-07 00:00:00".
|
||||
// 实现 Stringer 接口, 输出 YYYY-MM-DD HH::ii::ss 格式字符串,如 "2019-12-07 00:00:00"
|
||||
func (g Gregorian) String() string {
|
||||
if g.IsZero() {
|
||||
return ""
|
||||
}
|
||||
return g.Time.Format(DateTimeLayout)
|
||||
}
|
||||
|
||||
// IsZero reports whether is zero time.
|
||||
// 是否是零值时间
|
||||
func (g Gregorian) IsZero() bool {
|
||||
return g.Time.IsZero()
|
||||
}
|
||||
|
||||
// IsValid reports whether is a valid gregorian date.
|
||||
// 是否是有效的年份
|
||||
func (g Gregorian) IsValid() bool {
|
||||
if g.Year() >= MinValue().Year() && g.Year() <= MaxValue().Year() && g.Month() >= MinValue().Month() && g.Month() <= MaxValue().Month() && g.Day() >= MinValue().Day() && g.Day() <= MaxValue().Day() {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// IsLeapYear reports whether is a leap year.
|
||||
// 是否是闰年
|
||||
func (g Gregorian) IsLeapYear() bool {
|
||||
if g.IsZero() {
|
||||
return false
|
||||
}
|
||||
year := g.Year()
|
||||
if year%400 == 0 || (year%4 == 0 && year%100 != 0) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
61
vendor/github.com/dromara/carbon/v2/calendar/julian/README.cn.md
generated
vendored
Normal file
61
vendor/github.com/dromara/carbon/v2/calendar/julian/README.cn.md
generated
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
# 儒略日/简化儒略日
|
||||
|
||||
简体中文 | [English](README.md) | [日本語](README.jp.md)
|
||||
|
||||
#### 用法示例
|
||||
##### 将 `公历` 转换成 `儒略日`
|
||||
```go
|
||||
// 默认保留 6 位小数精度
|
||||
carbon.Parse("2024-01-24 12:00:00").Julian().JD() // 2460334
|
||||
carbon.Parse("2024-01-24 13:14:15").Julian().JD() // 2460334.051563
|
||||
|
||||
// 保留 4 位小数精度
|
||||
carbon.Parse("2024-01-24 12:00:00").Julian().JD(4) // 2460334
|
||||
carbon.Parse("2024-01-24 13:14:15").Julian().JD(4) // 2460334.0516
|
||||
```
|
||||
|
||||
##### 将 `公历` 转换成 `简化儒略日`
|
||||
```go
|
||||
// 默认保留 6 位小数精度
|
||||
carbon.Parse("2024-01-24 12:00:00").Julian().MJD() // 60333.5
|
||||
carbon.Parse("2024-01-24 13:14:15").Julian().MJD() // 60333.551563
|
||||
|
||||
// 保留 4 位小数精度
|
||||
carbon.Parse("2024-01-24 12:00:00").Julian().MJD(4) // 60333.5
|
||||
carbon.Parse("2024-01-24 13:14:15").Julian().MJD(4) // 60333.5516
|
||||
```
|
||||
|
||||
##### 将 `儒略日` 转换成 `简化儒略日`
|
||||
```go
|
||||
// 默认保留 6 位小数精度
|
||||
carbon.CreateFromJulian(2460334).Julian().MJD() // 60333.5
|
||||
carbon.CreateFromJulian(2460334.051563).Julian().MJD() // 60332.551563
|
||||
|
||||
// 保留 4 位小数精度
|
||||
carbon.CreateFromJulian(2460334).Julian().MJD(4) // 60333.5
|
||||
carbon.CreateFromJulian(2460334.051563).Julian().MJD(4) // 60332.5516
|
||||
```
|
||||
|
||||
##### 将 `简化儒略日` 转换成 `儒略日`
|
||||
```go
|
||||
// 默认保留 6 位小数精度
|
||||
carbon.CreateFromJulian(60333.5).Julian().JD()() // 2460334
|
||||
carbon.CreateFromJulian(60333.551563).Julian().JD()() // 2460333.051563
|
||||
|
||||
// 保留 4 位小数精度
|
||||
carbon.CreateFromJulian(60333.5).Julian().JD(4) // 2460334
|
||||
carbon.CreateFromJulian(60333.551563).Julian().JD(4) // 2460333.0516
|
||||
```
|
||||
|
||||
##### 将 `儒略日`/`简化儒略日` 转换成 `公历`
|
||||
```go
|
||||
// 将 儒略日 转换成 公历
|
||||
carbon.CreateFromJulian(2460334).ToDateTimeString() // 2024-01-24 12:00:00
|
||||
carbon.CreateFromJulian(2460334.051563).ToDateTimeString() // 2024-01-24 13:14:15
|
||||
|
||||
// 将 简化儒略日 转换成 公历
|
||||
carbon.CreateFromJulian(60333.5).ToDateTimeString() // 2024-01-24 12:00:00
|
||||
carbon.CreateFromJulian(60333.551563).ToDateTimeString() // 2024-01-24 13:14:15
|
||||
```
|
||||
|
||||
|
||||
60
vendor/github.com/dromara/carbon/v2/calendar/julian/README.jp.md
generated
vendored
Normal file
60
vendor/github.com/dromara/carbon/v2/calendar/julian/README.jp.md
generated
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
# 儒略の日/簡略儒略の日
|
||||
|
||||
日本語 | [English](README.md) | [简体中文](README.cn.md)
|
||||
|
||||
#### 使い方の例
|
||||
|
||||
##### `西暦` を `儒略日` に変換する
|
||||
```go
|
||||
// デフォルトの保持 6 ビット小数点精度
|
||||
carbon.Parse("2024-01-24 12:00:00").Julian().JD() // 2460334
|
||||
carbon.Parse("2024-01-24 13:14:15").Julian().JD() // 2460334.051563
|
||||
|
||||
// 4 ビット小数点精度の保持
|
||||
carbon.Parse("2024-01-24 12:00:00").Julian().JD(4) // 2460334
|
||||
carbon.Parse("2024-01-24 13:14:15").Julian().JD(4) // 2460334.0516
|
||||
```
|
||||
|
||||
##### `西暦` を `簡略儒略日` に変換する
|
||||
```go
|
||||
// デフォルトの保持 6 ビット小数点精度
|
||||
carbon.Parse("2024-01-24 12:00:00").Julian().MJD() // 60333.5
|
||||
carbon.Parse("2024-01-24 13:14:15").Julian().MJD() // 60333.551563
|
||||
|
||||
// 4 ビット小数点精度の保持
|
||||
carbon.Parse("2024-01-24 12:00:00").Julian().MJD(4) // 60333.5
|
||||
carbon.Parse("2024-01-24 13:14:15").Julian().MJD(4) // 60333.5516
|
||||
```
|
||||
|
||||
##### `儒略日` を `簡略儒略日` に変換する
|
||||
```go
|
||||
// デフォルトの保持 6 ビット小数点精度
|
||||
carbon.CreateFromJulian(2460334).Julian().MJD() // 60333.5
|
||||
carbon.CreateFromJulian(2460334.051563).Julian().MJD() // 60332.551563
|
||||
|
||||
// 4 ビット小数点精度の保持
|
||||
carbon.CreateFromJulian(2460334).Julian().MJD(4) // 60333.5
|
||||
carbon.CreateFromJulian(2460334.051563).Julian().MJD(4) // 60332.5516
|
||||
```
|
||||
|
||||
##### `簡略儒略日` を `儒略日` に変換する
|
||||
```go
|
||||
// デフォルトの保持 6 ビット小数点精度
|
||||
carbon.CreateFromJulian(60333.5).Julian().JD()() // 2460334
|
||||
carbon.CreateFromJulian(60333.551563).Julian().JD()() // 2460333.051563
|
||||
|
||||
// 4 ビット小数点精度の保持
|
||||
carbon.CreateFromJulian(60333.5).Julian().JD(4) // 2460334
|
||||
carbon.CreateFromJulian(60333.551563).Julian().JD(4) // 2460333.0516
|
||||
```
|
||||
|
||||
##### `儒略日`/`簡略儒略日` を `公历` に変換する
|
||||
```go
|
||||
// 儒略日 を 公历 に変換する
|
||||
carbon.CreateFromJulian(2460334).ToDateTimeString() // 2024-01-24 12:00:00
|
||||
carbon.CreateFromJulian(2460334.051563).ToDateTimeString() // 2024-01-24 13:14:15
|
||||
|
||||
// 簡略儒略日 を 公历 に変換する
|
||||
carbon.CreateFromJulian(60333.5).ToDateTimeString() // 2024-01-24 12:00:00
|
||||
carbon.CreateFromJulian(60333.551563).ToDateTimeString() // 2024-01-24 13:14:15
|
||||
```
|
||||
60
vendor/github.com/dromara/carbon/v2/calendar/julian/README.md
generated
vendored
Normal file
60
vendor/github.com/dromara/carbon/v2/calendar/julian/README.md
generated
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
# Julian Day/Modified Julian Day
|
||||
|
||||
English | [简体中文](README.cn.md) | [日本語](README.jp.md)
|
||||
|
||||
#### Usage and example
|
||||
|
||||
##### Convert `Gregorian` calendar to `Julian Day`
|
||||
```go
|
||||
// By default, 6 decimal places are retained for precision
|
||||
carbon.Parse("2024-01-24 12:00:00").Julian().JD() // 2460334
|
||||
carbon.Parse("2024-01-24 13:14:15").Julian().JD() // 2460334.051563
|
||||
|
||||
// 4 decimal places are retained for precision
|
||||
carbon.Parse("2024-01-24 12:00:00").Julian().JD(4) // 2460334
|
||||
carbon.Parse("2024-01-24 13:14:15").Julian().JD(4) // 2460334.0516
|
||||
```
|
||||
|
||||
##### Convert `Gregorian` calendar to `Modified Julian Day`
|
||||
```go
|
||||
// By default, 6 decimal places are retained for precision
|
||||
carbon.Parse("2024-01-24 12:00:00").Julian().MJD() // 60333.5
|
||||
carbon.Parse("2024-01-24 13:14:15").Julian().MJD() // 60333.551563
|
||||
|
||||
// 4 decimal places are retained for precision
|
||||
carbon.Parse("2024-01-24 12:00:00").Julian().MJD(4) // 60333.5
|
||||
carbon.Parse("2024-01-24 13:14:15").Julian().MJD(4) // 60333.5516
|
||||
```
|
||||
|
||||
##### Convert `Julian Day` to `Modified Julian Day`
|
||||
```go
|
||||
// By default, 6 decimal places are retained for precision
|
||||
carbon.CreateFromJulian(2460334).Julian().MJD() // 60333.5
|
||||
carbon.CreateFromJulian(2460334.051563).Julian().MJD() // 60332.551563
|
||||
|
||||
// 4 decimal places are retained for precision
|
||||
carbon.CreateFromJulian(2460334).Julian().MJD(4) // 60333.5
|
||||
carbon.CreateFromJulian(2460334.051563).Julian().MJD(4) // 60332.5516
|
||||
```
|
||||
|
||||
##### Convert `Modified Julian Day` to `Julian Day`
|
||||
```go
|
||||
// By default, 6 decimal places are retained for precision
|
||||
carbon.CreateFromJulian(60333.5).Julian().JD()() // 2460334
|
||||
carbon.CreateFromJulian(60333.551563).Julian().JD()() // 2460333.051563
|
||||
|
||||
// 4 decimal places are retained for precision
|
||||
carbon.CreateFromJulian(60333.5).Julian().JD(4) // 2460334
|
||||
carbon.CreateFromJulian(60333.551563).Julian().JD(4) // 2460333.0516
|
||||
```
|
||||
|
||||
##### Convert `Julian Day`/`Modified Julian Day` to `Gregorian` calendar
|
||||
```go
|
||||
// Convert Julian Day to Gregorian calendar
|
||||
carbon.CreateFromJulian(2460334).ToDateTimeString() // 2024-01-24 12:00:00
|
||||
carbon.CreateFromJulian(2460334.051563).ToDateTimeString() // 2024-01-24 13:14:15
|
||||
|
||||
// Convert Modified Julian Day to Gregorian calendar
|
||||
carbon.CreateFromJulian(60333.5).ToDateTimeString() // 2024-01-24 12:00:00
|
||||
carbon.CreateFromJulian(60333.551563).ToDateTimeString() // 2024-01-24 13:14:15
|
||||
```
|
||||
161
vendor/github.com/dromara/carbon/v2/calendar/julian/julian.go
generated
vendored
Normal file
161
vendor/github.com/dromara/carbon/v2/calendar/julian/julian.go
generated
vendored
Normal file
@@ -0,0 +1,161 @@
|
||||
// Package julian is part of the carbon package.
|
||||
package julian
|
||||
|
||||
import (
|
||||
"math"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/dromara/carbon/v2/calendar"
|
||||
)
|
||||
|
||||
var (
|
||||
// julian day or modified julian day decimal precision
|
||||
// 儒略日或简化儒略日小数精度
|
||||
decimalPrecision = 6
|
||||
|
||||
// difference between Julian Day and Modified Julian Day
|
||||
// 儒略日和简化儒略日之间的差值
|
||||
diffJdFromMjd = 2400000.5
|
||||
)
|
||||
|
||||
// Gregorian defines a Gregorian struct.
|
||||
// 定义 Gregorian 结构体
|
||||
type Gregorian struct {
|
||||
calendar.Gregorian
|
||||
}
|
||||
|
||||
// Julian defines a Julian struct.
|
||||
// 定义 Julian 结构体
|
||||
type Julian struct {
|
||||
jd, mjd float64
|
||||
}
|
||||
|
||||
// FromGregorian creates a Gregorian instance from time.Time.
|
||||
// 从标准 time.Time 创建 Gregorian 实例
|
||||
func FromGregorian(t time.Time) (g Gregorian) {
|
||||
if t.IsZero() {
|
||||
return
|
||||
}
|
||||
g.Time = t
|
||||
return g
|
||||
}
|
||||
|
||||
// FromJulian creates a Julian instance from julian day or modified julian day.
|
||||
// 从 儒略日 或 简化儒略日 创建 Julian 实例
|
||||
func FromJulian(f float64) (j Julian) {
|
||||
// get length of the integer part
|
||||
l := len(strconv.Itoa(int(math.Ceil(f))))
|
||||
switch l {
|
||||
// modified julian day
|
||||
case 5:
|
||||
j.mjd = f
|
||||
j.jd = f + diffJdFromMjd
|
||||
// julian day
|
||||
case 7:
|
||||
j.jd = f
|
||||
j.mjd = f - diffJdFromMjd
|
||||
default:
|
||||
j.jd = 0
|
||||
j.mjd = 0
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// ToJulian converts Gregorian instance to Julian instance.
|
||||
// 将 Gregorian 实例转化为 Julian 实例
|
||||
func (g Gregorian) ToJulian() (j Julian) {
|
||||
if g.IsZero() {
|
||||
return
|
||||
}
|
||||
y := g.Year()
|
||||
m := g.Month()
|
||||
d := float64(g.Day()) + ((float64(g.Second())/60+float64(g.Minute()))/60+float64(g.Hour()))/24
|
||||
n := 0
|
||||
f := false
|
||||
if y*372+m*31+int(d) >= 588829 {
|
||||
f = true
|
||||
}
|
||||
if m <= 2 {
|
||||
m += 12
|
||||
y--
|
||||
}
|
||||
if f {
|
||||
n = y / 100
|
||||
n = 2 - n + n/4
|
||||
}
|
||||
jd := float64(int(365.25*(float64(y)+4716))) + float64(int(30.6001*(float64(m)+1))) + d + float64(n) - 1524.5
|
||||
return FromJulian(jd)
|
||||
}
|
||||
|
||||
// ToGregorian converts Julian instance to Gregorian instance.
|
||||
// 将 Julian 实例转化为 Gregorian 实例
|
||||
func (j Julian) ToGregorian() (g Gregorian) {
|
||||
if j.IsZero() {
|
||||
return
|
||||
}
|
||||
d := int(j.jd + 0.5)
|
||||
f := j.jd + 0.5 - float64(d)
|
||||
if d >= 2299161 {
|
||||
c := int((float64(d) - 1867216.25) / 36524.25)
|
||||
d += 1 + c - c/4
|
||||
}
|
||||
d += 1524
|
||||
year := int((float64(d) - 122.1) / 365.25)
|
||||
d -= int(365.25 * float64(year))
|
||||
month := int(float64(d) / 30.601)
|
||||
d -= int(30.601 * float64(month))
|
||||
day := d
|
||||
if month > 13 {
|
||||
month -= 13
|
||||
year -= 4715
|
||||
} else {
|
||||
month -= 1
|
||||
year -= 4716
|
||||
}
|
||||
f *= 24
|
||||
hour := int(f)
|
||||
|
||||
f -= float64(hour)
|
||||
f *= 60
|
||||
minute := int(f)
|
||||
|
||||
f -= float64(minute)
|
||||
f *= 60
|
||||
second := int(math.Round(f))
|
||||
return FromGregorian(time.Date(year, time.Month(month), day, hour, minute, second, 0, time.Local))
|
||||
}
|
||||
|
||||
// JD gets julian day like 2460332.5
|
||||
// 获取儒略日
|
||||
func (j Julian) JD(precision ...int) float64 {
|
||||
if len(precision) > 0 {
|
||||
decimalPrecision = precision[0]
|
||||
}
|
||||
return parseFloat64(j.jd, decimalPrecision)
|
||||
}
|
||||
|
||||
// MJD gets modified julian day like 60332
|
||||
// 获取简化儒略日
|
||||
func (j Julian) MJD(precision ...int) float64 {
|
||||
if len(precision) > 0 {
|
||||
decimalPrecision = precision[0]
|
||||
}
|
||||
return parseFloat64(j.mjd, decimalPrecision)
|
||||
}
|
||||
|
||||
// IsZero reports whether is zero time.
|
||||
// 是否是零值时间
|
||||
func (j Julian) IsZero() bool {
|
||||
if j.jd == 0 || j.mjd == 0 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// parseFloat64 round to n decimal places
|
||||
// 四舍五入保留 n 位小数点
|
||||
func parseFloat64(f float64, n int) float64 {
|
||||
p10 := math.Pow10(n)
|
||||
return math.Round(f*p10) / p10
|
||||
}
|
||||
98
vendor/github.com/dromara/carbon/v2/calendar/lunar/README.cn.md
generated
vendored
Normal file
98
vendor/github.com/dromara/carbon/v2/calendar/lunar/README.cn.md
generated
vendored
Normal file
@@ -0,0 +1,98 @@
|
||||
# 中国农历
|
||||
|
||||
简体中文 | [English](README.md) | [日本語](README.jp.md)
|
||||
|
||||
#### 用法示例
|
||||
|
||||
> 目前仅支持公元 `1900` 年至 `2100` 年的 `200` 年时间跨度
|
||||
|
||||
##### 将 `公历` 转换成 `农历`
|
||||
|
||||
```go
|
||||
// 获取农历生肖
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().Animal() // 鼠
|
||||
// 获取农历节日
|
||||
carbon.Parse("2021-02-12 13:14:15").Lunar().Festival() // 春节
|
||||
|
||||
// 获取农历年份
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().Year() // 2020
|
||||
// 获取农历月份
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().Month() // 6
|
||||
// 获取农历闰月月份
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().LeapMonth() // 4
|
||||
// 获取农历日期
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().Day() // 16
|
||||
// 获取农历时辰
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().Hour() // 13
|
||||
// 获取农历分钟
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().Minute() // 14
|
||||
// 获取农历秒数
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().Second() // 15
|
||||
|
||||
// 获取农历日期时间字符串
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().String() // 2020-06-16 13:14:15
|
||||
fmt.Printf("%s", carbon.Parse("2020-08-05 13:14:15").Lunar()) // 2020-06-16 13:14:15
|
||||
// 获取农历年字符串
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().ToYearString() // 二零二零
|
||||
// 获取农历月字符串
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().ToMonthString() // 六月
|
||||
// 获取农历闰月字符串
|
||||
carbon.Parse("2020-04-23 13:14:15").Lunar().ToMonthString() // 闰四月
|
||||
// 获取农历周字符串
|
||||
carbon.Parse("2020-04-23 13:14:15").Lunar().ToWeekString() // 周四
|
||||
// 获取农历天字符串
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().ToDayString() // 十六
|
||||
// 获取农历日期字符串
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().ToDateString() // 二零二零年六月十六
|
||||
|
||||
```
|
||||
|
||||
##### 将 `农历` 转化成 `公历`
|
||||
|
||||
```go
|
||||
// 将农历 二零二三年腊月十一 转化为 公历
|
||||
carbon.CreateFromLunar(2023, 12, 11, 0, 0, 0, false).ToDateTimeString() // 2024-01-21 00:00:00
|
||||
// 将农历 二零二三年二月十一 转化为 公历
|
||||
carbon.CreateFromLunar(2023, 2, 11, 0, 0, 0, false).ToDateTimeString() // 2023-03-02 00:00:00
|
||||
// 将农历 二零二三年闰二月十一 转化为 公历
|
||||
carbon.CreateFromLunar(2023, 2, 11, 0, 0, 0, true).ToDateTimeString() // 2023-04-01 00:00:00
|
||||
```
|
||||
|
||||
##### 日期判断
|
||||
|
||||
```go
|
||||
|
||||
// 是否是合法农历日期
|
||||
carbon.Parse("0000-00-00 00:00:00").Lunar().IsValid() // false
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsValid() // true
|
||||
|
||||
// 是否是农历闰年
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsLeapYear() // true
|
||||
// 是否是农历闰月
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsLeapMonth() // false
|
||||
|
||||
// 是否是鼠年
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsRatYear() // true
|
||||
// 是否是牛年
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsOxYear() // false
|
||||
// 是否是虎年
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsTigerYear() // false
|
||||
// 是否是兔年
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsRabbitYear() // false
|
||||
// 是否是龙年
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsDragonYear() // false
|
||||
// 是否是蛇年
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsSnakeYear() // false
|
||||
// 是否是马年
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsHorseYear() // false
|
||||
// 是否是羊年
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsGoatYear() // false
|
||||
// 是否是猴年
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsMonkeyYear() // false
|
||||
// 是否是鸡年
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsRoosterYear() // false
|
||||
// 是否是狗年
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsDogYear() // false
|
||||
// 是否是猪年
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsPigYear() // false
|
||||
```
|
||||
97
vendor/github.com/dromara/carbon/v2/calendar/lunar/README.jp.md
generated
vendored
Normal file
97
vendor/github.com/dromara/carbon/v2/calendar/lunar/README.jp.md
generated
vendored
Normal file
@@ -0,0 +1,97 @@
|
||||
# 中国の旧暦
|
||||
|
||||
日本語 | [English](README.md) | [简体中文](README.cn.md)
|
||||
|
||||
#### 使い方の例
|
||||
|
||||
> 現在は西暦` 1900 `年から` 2100 `年までの` 200 `年の時間スパンのみをサポートしている
|
||||
|
||||
##### `西暦`を`旧暦`に変換する
|
||||
|
||||
```go
|
||||
// 旧暦の干支を手に入れる
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().Animal() // 鼠
|
||||
// 旧暦の祝日を取得する
|
||||
carbon.Parse("2021-02-12 13:14:15").Lunar().Festival() // 春节
|
||||
|
||||
// 旧正月の取得
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().Year() // 2020
|
||||
// 旧暦月の取得
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().Month() // 6
|
||||
// 旧暦うるう月の取得
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().LeapMonth() // 4
|
||||
// 旧暦日の取得
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().Day() // 16
|
||||
// 旧暦時刻の取得
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().Hour() // 13
|
||||
// 旧暦分の取得
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().Minute() // 14
|
||||
// 旧暦の取得秒数
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().Second() // 15
|
||||
|
||||
// 旧暦日時文字列の取得
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().String() // 2020-06-16 13:14:15
|
||||
fmt.Printf("%s", carbon.Parse("2020-08-05 13:14:15").Lunar()) // 2020-06-16 13:14:15
|
||||
// 旧正月文字列の取得
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().ToYearString() // 二零二零
|
||||
// 旧暦月文字列の取得
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().ToMonthString() // 六月
|
||||
// 旧暦うるう月文字列の取得
|
||||
carbon.Parse("2020-04-23 13:14:15").Lunar().ToMonthString() // 闰四月
|
||||
// 旧暦週文字列の取得
|
||||
carbon.Parse("2020-04-23 13:14:15").Lunar().ToWeekString() // 周四
|
||||
// 旧暦日文字列の取得
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().ToDayString() // 十六
|
||||
// 旧暦日付文字列の取得
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().ToDateString() // 二零二零年六月十六
|
||||
|
||||
```
|
||||
|
||||
##### `旧暦`を`西暦`に変換する
|
||||
|
||||
```go
|
||||
// 2023 年の旧暦 12 月 11 日をグレゴリオ暦に変換します
|
||||
carbon.CreateFromLunar(2023, 12, 11, 0, 0, 0, false).ToDateTimeString() // 2024-01-21 00:00:00
|
||||
// 旧暦の 2023 年 2 月 11 日をグレゴリオ暦に変換します
|
||||
carbon.CreateFromLunar(2023, 2, 11, 0, 0, 0, false).ToDateTimeString() // 2023-03-02 00:00:00
|
||||
// 旧暦 2023 年、閏 2 月 11 日をグレゴリオ暦に変換します
|
||||
carbon.CreateFromLunar(2023, 2, 11, 0, 0, 0, true).ToDateTimeString() // 2023-04-01 00:00:00
|
||||
```
|
||||
|
||||
##### 日付判断
|
||||
```go
|
||||
// 合法的なペルシャ暦の日付かどうか
|
||||
carbon.Parse("0000-00-00 00:00:00").Lunar().IsValid() // false
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsValid() // true
|
||||
|
||||
// 旧暦うるう年かどうか
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsLeapYear() // true
|
||||
// 旧暦うるう月かどうか
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsLeapMonth() // false
|
||||
|
||||
// ねずみ年かどうか
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsRatYear() // true
|
||||
// 牛年かどうか
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsOxYear() // false
|
||||
// 寅年かどうか
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsTigerYear() // false
|
||||
// うさぎ年かどうか
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsRabbitYear() // false
|
||||
// 龍年かどうか
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsDragonYear() // false
|
||||
// 蛇の年かどうか
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsSnakeYear() // false
|
||||
// 馬年かどうか
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsHorseYear() // false
|
||||
// 羊年かどうか
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsGoatYear() // false
|
||||
// 申年かどうか
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsMonkeyYear() // false
|
||||
// 鶏の年かどうか
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsRoosterYear() // false
|
||||
// 犬年かどうか
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsDogYear() // false
|
||||
// 豚年かどうか
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsPigYear() // false
|
||||
|
||||
```
|
||||
97
vendor/github.com/dromara/carbon/v2/calendar/lunar/README.md
generated
vendored
Normal file
97
vendor/github.com/dromara/carbon/v2/calendar/lunar/README.md
generated
vendored
Normal file
@@ -0,0 +1,97 @@
|
||||
# Chinese Lunar
|
||||
|
||||
English | [简体中文](README.cn.md) | [日本語](README.jp.md)
|
||||
|
||||
#### Usage and example
|
||||
|
||||
> Currently only `200` years from `1900` to `2100` are supported
|
||||
|
||||
##### Convert `Gregorian` calendar to `Lunar` calendar
|
||||
|
||||
```go
|
||||
// Get Lunar year of animal
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().Animal() // 鼠
|
||||
// Get lunar festival
|
||||
carbon.Parse("2021-02-12 13:14:15").Lunar().Festival() // 春节
|
||||
|
||||
// Get lunar year
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().Year() // 2020
|
||||
// Get lunar month
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().Month() // 6
|
||||
// Get lunar leap month
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().LeapMonth() // 4
|
||||
// Get lunar day
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().Day() // 16
|
||||
// Get lunar hour
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().Hour() // 13
|
||||
// Get lunar minute
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().Minute() // 14
|
||||
// Get lunar second
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().Second() // 15
|
||||
|
||||
// Get lunar date and time string
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().String() // 2020-06-16 13:14:15
|
||||
fmt.Printf("%s", carbon.Parse("2020-08-05 13:14:15").Lunar()) // 2020-06-16 13:14:15
|
||||
// Get lunar year as string
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().ToYearString() // 二零二零
|
||||
// Get lunar month as string
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().ToMonthString() // 六月
|
||||
// Get lunar leap month as string
|
||||
carbon.Parse("2020-04-23 13:14:15").Lunar().ToMonthString() // 闰四月
|
||||
// Get lunar week as string
|
||||
carbon.Parse("2020-04-23 13:14:15").Lunar().ToWeekString() // 周四
|
||||
// Get lunar day as string
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().ToDayString() // 十六
|
||||
// Get lunar date as string
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().ToDateString() // 二零二零年六月十六
|
||||
|
||||
```
|
||||
|
||||
##### Convert `Lunar` calendar to `Gregorian` calendar
|
||||
|
||||
```go
|
||||
// Convert the Lunar Calendar December 11, 2023 to the gregorian calendar
|
||||
carbon.CreateFromLunar(2023, 12, 11, 0, 0, 0, false).ToDateTimeString() // 2024-01-21 00:00:00
|
||||
// Convert lunar calendar February 11, 2023 to gregorian calendar
|
||||
carbon.CreateFromLunar(2023, 2, 11, 0, 0, 0, false).ToDateTimeString() // 2024-03-02 00:00:00
|
||||
// Convert the Lunar Calendar Leap February 11, 2024 to the gregorian calendar
|
||||
carbon.CreateFromLunar(2023, 2, 11, 0, 0, 0, true).ToDateTimeString() // 2023-04-01 00:00:00
|
||||
```
|
||||
|
||||
##### Comparison
|
||||
```go
|
||||
// Whether is a valid lunar date
|
||||
carbon.Parse("0000-00-00 00:00:00").Lunar().IsValid() // false
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsValid() // true
|
||||
|
||||
// Whether is a lunar leap year
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsLeapYear() // true
|
||||
// Whether is a lunar leap month
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsLeapMonth() // false
|
||||
|
||||
// Whether is a lunar year of the rat
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsRatYear() // true
|
||||
// Whether is a lunar year of the ox
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsOxYear() // false
|
||||
// Whether is a lunar year of the tiger
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsTigerYear() // false
|
||||
// Whether is a lunar year of the rabbit
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsRabbitYear() // false
|
||||
// Whether is a lunar year of the dragon
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsDragonYear() // false
|
||||
// Whether is a lunar year of the snake
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsSnakeYear() // false
|
||||
// Whether is a lunar year of the horse
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsHorseYear() // false
|
||||
// Whether is a lunar year of the goat
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsGoatYear() // false
|
||||
// Whether is a lunar year of the monkey
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsMonkeyYear() // false
|
||||
// Whether is a lunar year of the rooster
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsRoosterYear() // false
|
||||
// Whether is a lunar year of the dog
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsDogYear() // false
|
||||
// Whether is a lunar year of the dig
|
||||
carbon.Parse("2020-08-05 13:14:15").Lunar().IsPigYear() // false
|
||||
|
||||
```
|
||||
590
vendor/github.com/dromara/carbon/v2/calendar/lunar/lunar.go
generated
vendored
Normal file
590
vendor/github.com/dromara/carbon/v2/calendar/lunar/lunar.go
generated
vendored
Normal file
@@ -0,0 +1,590 @@
|
||||
// Package lunar is part of the carbon package.
|
||||
package lunar
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/dromara/carbon/v2/calendar"
|
||||
)
|
||||
|
||||
var (
|
||||
numbers = []string{"零", "一", "二", "三", "四", "五", "六", "七", "八", "九"}
|
||||
months = []string{"正", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "腊"}
|
||||
weeks = []string{"周日", "周一", "周二", "周三", "周四", "周五", "周六"}
|
||||
animals = []string{"猴", "鸡", "狗", "猪", "鼠", "牛", "虎", "兔", "龙", "蛇", "马", "羊"}
|
||||
|
||||
festivals = map[string]string{
|
||||
// "month-day": "name"
|
||||
"1-1": "春节",
|
||||
"1-15": "元宵节",
|
||||
"2-2": "龙抬头",
|
||||
"3-3": "上巳节",
|
||||
"5-5": "端午节",
|
||||
"7-7": "七夕节",
|
||||
"7-15": "中元节",
|
||||
"8-15": "中秋节",
|
||||
"9-9": "重阳节",
|
||||
"10-1": "寒衣节",
|
||||
"10-15": "下元节",
|
||||
"12-8": "腊八节",
|
||||
}
|
||||
|
||||
years = []int{
|
||||
0x04bd8, 0x04ae0, 0x0a570, 0x054d5, 0x0d260, 0x0d950, 0x16554, 0x056a0, 0x09ad0, 0x055d2, // 1900-1909
|
||||
0x04ae0, 0x0a5b6, 0x0a4d0, 0x0d250, 0x1d255, 0x0b540, 0x0d6a0, 0x0ada2, 0x095b0, 0x14977, // 1910-1919
|
||||
0x04970, 0x0a4b0, 0x0b4b5, 0x06a50, 0x06d40, 0x1ab54, 0x02b60, 0x09570, 0x052f2, 0x04970, // 1920-1929
|
||||
0x06566, 0x0d4a0, 0x0ea50, 0x16a95, 0x05ad0, 0x02b60, 0x186e3, 0x092e0, 0x1c8d7, 0x0c950, // 1930-1939
|
||||
0x0d4a0, 0x1d8a6, 0x0b550, 0x056a0, 0x1a5b4, 0x025d0, 0x092d0, 0x0d2b2, 0x0a950, 0x0b557, // 1940-1949
|
||||
0x06ca0, 0x0b550, 0x15355, 0x04da0, 0x0a5d0, 0x14573, 0x052d0, 0x0a9a8, 0x0e950, 0x06aa0, // 1950-1959
|
||||
0x0aea6, 0x0ab50, 0x04b60, 0x0aae4, 0x0a570, 0x05260, 0x0f263, 0x0d950, 0x05b57, 0x056a0, // 1960-1969
|
||||
0x096d0, 0x04dd5, 0x04ad0, 0x0a4d0, 0x0d4d4, 0x0d250, 0x0d558, 0x0b540, 0x0b5a0, 0x195a6, // 1970-1979
|
||||
0x095b0, 0x049b0, 0x0a974, 0x0a4b0, 0x0b27a, 0x06a50, 0x06d40, 0x0af46, 0x0ab60, 0x09570, // 1980-1989
|
||||
0x04af5, 0x04970, 0x064b0, 0x074a3, 0x0ea50, 0x06b58, 0x05ac0, 0x0ab60, 0x096d5, 0x092e0, // 1990-1999
|
||||
0x0c960, 0x0d954, 0x0d4a0, 0x0da50, 0x07552, 0x056a0, 0x0abb7, 0x025d0, 0x092d0, 0x0cab5, // 2000-2009
|
||||
0x0a950, 0x0b4a0, 0x0baa4, 0x0ad50, 0x055d9, 0x04ba0, 0x0a5b0, 0x15176, 0x052b0, 0x0a930, // 2010-2019
|
||||
0x07954, 0x06aa0, 0x0ad50, 0x05b52, 0x04b60, 0x0a6e6, 0x0a4e0, 0x0d260, 0x0ea65, 0x0d530, // 2020-2029
|
||||
0x05aa0, 0x076a3, 0x096d0, 0x04bd7, 0x04ad0, 0x0a4d0, 0x1d0b6, 0x0d250, 0x0d520, 0x0dd45, // 2030-2039
|
||||
0x0b5a0, 0x056d0, 0x055b2, 0x049b0, 0x0a577, 0x0a4b0, 0x0aa50, 0x1b255, 0x06d20, 0x0ada0, // 2040-2049
|
||||
0x14b63, 0x09370, 0x049f8, 0x04970, 0x064b0, 0x168a6, 0x0ea50, 0x06b20, 0x1a6c4, 0x0aae0, // 2050-2059
|
||||
0x0a2e0, 0x0d2e3, 0x0c960, 0x0d557, 0x0d4a0, 0x0da50, 0x05d55, 0x056a0, 0x0a6d0, 0x055d4, // 2060-2069
|
||||
0x052d0, 0x0a9b8, 0x0a950, 0x0b4a0, 0x0b6a6, 0x0ad50, 0x055a0, 0x0aba4, 0x0a5b0, 0x052b0, // 2070-2079
|
||||
0x0b273, 0x06930, 0x07337, 0x06aa0, 0x0ad50, 0x14b55, 0x04b60, 0x0a570, 0x054e4, 0x0d160, // 2080-2089
|
||||
0x0e968, 0x0d520, 0x0daa0, 0x16aa6, 0x056d0, 0x04ae0, 0x0a9d4, 0x0a2d0, 0x0d150, 0x0f252, // 2090-2099
|
||||
0x0d520, // 2100
|
||||
}
|
||||
|
||||
InvalidDateError = func() error {
|
||||
return fmt.Errorf("invalid invalid date, please make sure the date is valid")
|
||||
}
|
||||
)
|
||||
|
||||
// Gregorian defines a Gregorian struct.
|
||||
// 定义 Gregorian 结构体
|
||||
type Gregorian struct {
|
||||
calendar.Gregorian
|
||||
}
|
||||
|
||||
// Lunar defines a Lunar struct.
|
||||
// 定义 Lunar 结构体
|
||||
type Lunar struct {
|
||||
year, month, day, hour, minute, second int
|
||||
isLeapMonth bool
|
||||
Error error
|
||||
}
|
||||
|
||||
// MaxValue returns a Lunar instance for the greatest supported date.
|
||||
// 返回 Carbon 的最大值
|
||||
func MaxValue() Lunar {
|
||||
return Lunar{
|
||||
year: 2100,
|
||||
month: 12,
|
||||
day: 31,
|
||||
hour: 23,
|
||||
minute: 59,
|
||||
second: 59,
|
||||
}
|
||||
}
|
||||
|
||||
// MinValue returns a Lunar instance for the lowest supported date.
|
||||
// 返回 Lunar 的最小值
|
||||
func MinValue() Lunar {
|
||||
return Lunar{
|
||||
year: 1900,
|
||||
month: 1,
|
||||
day: 1,
|
||||
hour: 0,
|
||||
minute: 0,
|
||||
second: 0,
|
||||
}
|
||||
}
|
||||
|
||||
// FromGregorian creates a Gregorian instance from time.Time.
|
||||
// 从标准 time.Time 创建 Gregorian 实例
|
||||
func FromGregorian(t time.Time) (g Gregorian) {
|
||||
if t.IsZero() {
|
||||
return
|
||||
}
|
||||
g.Time = t
|
||||
return
|
||||
}
|
||||
|
||||
// FromLunar creates a Lunar instance from lunar datetime.
|
||||
// 从 农历日期 创建 Lunar 实例
|
||||
func FromLunar(year, month, day, hour, minute, second int, isLeapMonth bool) (l Lunar) {
|
||||
l.year, l.month, l.day = year, month, day
|
||||
l.hour, l.minute, l.second = hour, minute, second
|
||||
l.isLeapMonth = isLeapMonth
|
||||
if !l.IsValid() {
|
||||
l.Error = InvalidDateError()
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// ToLunar converts Gregorian instance to Lunar instance.
|
||||
// 将 Gregorian 实例转化为 Lunar 实例
|
||||
func (g Gregorian) ToLunar() (l Lunar) {
|
||||
if g.IsZero() {
|
||||
return
|
||||
}
|
||||
daysInYear, daysInMonth, leapMonth := 365, 30, 0
|
||||
maxYear, minYear := MaxValue().year, MinValue().year
|
||||
|
||||
// 与 1900-01-31 相差多少天
|
||||
offset := g.diffInDays(time.Date(minYear, 1, 31, 0, 0, 0, 0, g.Location()))
|
||||
for l.year = minYear; l.year <= maxYear && offset > 0; l.year++ {
|
||||
daysInYear = l.getDaysInYear()
|
||||
offset -= daysInYear
|
||||
}
|
||||
if offset < 0 {
|
||||
offset += daysInYear
|
||||
l.year--
|
||||
}
|
||||
leapMonth = l.LeapMonth()
|
||||
for l.month = 1; l.month <= 12 && offset > 0; l.month++ {
|
||||
if leapMonth > 0 && l.month == (leapMonth+1) && !l.isLeapMonth {
|
||||
l.month--
|
||||
l.isLeapMonth = true
|
||||
daysInMonth = l.getDaysInLeapMonth()
|
||||
} else {
|
||||
daysInMonth = l.getDaysInMonth()
|
||||
}
|
||||
offset -= daysInMonth
|
||||
if l.isLeapMonth && l.month == (leapMonth+1) {
|
||||
l.isLeapMonth = false
|
||||
}
|
||||
}
|
||||
// offset为0时,并且刚才计算的月份是闰月,要校正
|
||||
if offset == 0 && leapMonth > 0 && l.month == leapMonth+1 {
|
||||
if l.isLeapMonth {
|
||||
l.isLeapMonth = false
|
||||
} else {
|
||||
l.isLeapMonth = true
|
||||
l.month--
|
||||
}
|
||||
}
|
||||
// offset小于0时,也要校正
|
||||
if offset < 0 {
|
||||
offset += daysInMonth
|
||||
l.month--
|
||||
}
|
||||
l.day = offset + 1
|
||||
l.hour, l.minute, l.second = g.Clock()
|
||||
if !l.IsValid() {
|
||||
l.Error = InvalidDateError()
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// ToGregorian converts Lunar instance to Gregorian instance.
|
||||
// 将 Lunar 实例转化为 Gregorian 实例
|
||||
func (l Lunar) ToGregorian() (g Gregorian) {
|
||||
if !l.IsValid() {
|
||||
return
|
||||
}
|
||||
days := l.getDaysInMonth()
|
||||
offset := l.getOffsetInYear()
|
||||
offset += l.getOffsetInMonth()
|
||||
// 转换闰月农历 需补充该年闰月的前一个月的时差
|
||||
if l.isLeapMonth {
|
||||
offset += days
|
||||
}
|
||||
// https://github.com/golang-module/carbon/issues/219
|
||||
ts := int64(offset+l.day)*86400 - int64(2206512000) + int64(l.hour)*3600 + int64(l.minute)*60 + int64(l.second)
|
||||
g.Time = time.Unix(ts, 0)
|
||||
return
|
||||
}
|
||||
|
||||
// Animal gets lunar animal name like "猴".
|
||||
// 获取农历生肖
|
||||
func (l Lunar) Animal() string {
|
||||
if !l.IsValid() {
|
||||
return ""
|
||||
}
|
||||
return animals[l.year%calendar.MonthsPerYear]
|
||||
}
|
||||
|
||||
// Festival gets lunar festival name like "春节".
|
||||
// 获取农历节日
|
||||
func (l Lunar) Festival() string {
|
||||
if !l.IsValid() {
|
||||
return ""
|
||||
}
|
||||
return festivals[fmt.Sprintf("%d-%d", l.month, l.day)]
|
||||
}
|
||||
|
||||
// Year gets lunar year like 2020.
|
||||
// 获取农历年份
|
||||
func (l Lunar) Year() int {
|
||||
if l.Error != nil {
|
||||
return 0
|
||||
}
|
||||
return l.year
|
||||
}
|
||||
|
||||
// Month gets lunar month like 8.
|
||||
// 获取农历月份
|
||||
func (l Lunar) Month() int {
|
||||
if l.Error != nil {
|
||||
return 0
|
||||
}
|
||||
return l.month
|
||||
}
|
||||
|
||||
// Day gets lunar day like 5.
|
||||
// 获取农历日,如 5
|
||||
func (l Lunar) Day() int {
|
||||
if l.Error != nil {
|
||||
return 0
|
||||
}
|
||||
return l.day
|
||||
}
|
||||
|
||||
// Hour gets current hour like 13.
|
||||
// 获取农历时辰
|
||||
func (l Lunar) Hour() int {
|
||||
if l.Error != nil {
|
||||
return 0
|
||||
}
|
||||
return l.hour
|
||||
}
|
||||
|
||||
// Minute gets current minute like 14.
|
||||
// 获取农历分钟数
|
||||
func (l Lunar) Minute() int {
|
||||
if l.Error != nil {
|
||||
return 0
|
||||
}
|
||||
return l.minute
|
||||
}
|
||||
|
||||
// Second gets current second like 15.
|
||||
// 获取农历秒数
|
||||
func (l Lunar) Second() int {
|
||||
if l.Error != nil {
|
||||
return 0
|
||||
}
|
||||
return l.second
|
||||
}
|
||||
|
||||
// LeapMonth gets lunar leap month like 2.
|
||||
// 获取农历闰月月份,如 2
|
||||
func (l Lunar) LeapMonth() int {
|
||||
if l.Error != nil {
|
||||
return 0
|
||||
}
|
||||
minYear := MinValue().year
|
||||
if l.year-minYear < 0 {
|
||||
return 0
|
||||
}
|
||||
return years[l.year-minYear] & 0xf
|
||||
}
|
||||
|
||||
// String implements Stringer interface and outputs a string in YYYY-MM-DD HH::ii::ss format like "2019-12-07 00:00:00".
|
||||
// 实现 Stringer 接口, 输出 YYYY-MM-DD HH::ii::ss 格式字符串,如 "2019-12-07 00:00:00"
|
||||
func (l Lunar) String() string {
|
||||
if !l.IsValid() {
|
||||
return ""
|
||||
}
|
||||
return fmt.Sprintf("%04d-%02d-%02d %02d:%02d:%02d", l.year, l.month, l.day, l.hour, l.minute, l.second)
|
||||
}
|
||||
|
||||
// ToYearString outputs a string in lunar year format like "二零二零".
|
||||
// 获取农历年份字符串,如 "二零二零"
|
||||
func (l Lunar) ToYearString() (year string) {
|
||||
if !l.IsValid() {
|
||||
return ""
|
||||
}
|
||||
year = fmt.Sprintf("%d", l.year)
|
||||
for index, number := range numbers {
|
||||
year = strings.Replace(year, fmt.Sprintf("%d", index), number, -1)
|
||||
}
|
||||
return year
|
||||
}
|
||||
|
||||
// ToMonthString outputs a string in lunar month format like "正月".
|
||||
// 获取农历月份字符串,如 "正月"
|
||||
func (l Lunar) ToMonthString() (month string) {
|
||||
if !l.IsValid() {
|
||||
return ""
|
||||
}
|
||||
month = months[l.month-1] + "月"
|
||||
if l.IsLeapMonth() {
|
||||
return "闰" + month
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// ToWeekString outputs a string in week layout like "周一".
|
||||
// 输出完整农历星期字符串,如 "周一"
|
||||
func (l Lunar) ToWeekString() (month string) {
|
||||
if !l.IsValid() {
|
||||
return ""
|
||||
}
|
||||
return weeks[l.ToGregorian().Week()]
|
||||
}
|
||||
|
||||
// ToDayString outputs a string in lunar day format like "廿一".
|
||||
// 获取农历日字符串,如 "廿一"
|
||||
func (l Lunar) ToDayString() (day string) {
|
||||
if !l.IsValid() {
|
||||
return ""
|
||||
}
|
||||
num := numbers[l.day%10]
|
||||
switch {
|
||||
case l.day == 30:
|
||||
day = "三十"
|
||||
case l.day > 20:
|
||||
day = "廿" + num
|
||||
case l.day == 20:
|
||||
day = "二十"
|
||||
case l.day > 10:
|
||||
day = "十" + num
|
||||
case l.day == 10:
|
||||
day = "初十"
|
||||
case l.day < 10:
|
||||
day = "初" + num
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// ToDateString outputs a string in lunar date format like "二零二零年腊月初五".
|
||||
// 获取农历日期字符串,如 "二零二零年腊月初五"
|
||||
func (l Lunar) ToDateString() string {
|
||||
if !l.IsValid() {
|
||||
return ""
|
||||
}
|
||||
return l.ToYearString() + "年" + l.ToMonthString() + l.ToDayString()
|
||||
}
|
||||
|
||||
// IsValid reports whether is a valid lunar date.
|
||||
// 是否是有效的年份
|
||||
func (l Lunar) IsValid() bool {
|
||||
if l.Year() >= MinValue().year && l.Year() <= MaxValue().year && l.month >= MinValue().month && l.month <= MaxValue().month && l.day >= MinValue().day && l.day <= MaxValue().day {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// IsLeapYear reports whether is a lunar leap year.
|
||||
// 是否是农历闰年
|
||||
func (l Lunar) IsLeapYear() bool {
|
||||
if l.Error != nil {
|
||||
return false
|
||||
}
|
||||
return l.LeapMonth() != 0
|
||||
}
|
||||
|
||||
// IsLeapMonth reports whether is a lunar leap month.
|
||||
// 是否是农历闰月
|
||||
func (l Lunar) IsLeapMonth() bool {
|
||||
if l.Error != nil {
|
||||
return false
|
||||
}
|
||||
return l.month == l.LeapMonth()
|
||||
}
|
||||
|
||||
// IsRatYear reports whether is lunar year of Rat.
|
||||
// 是否是鼠年
|
||||
func (l Lunar) IsRatYear() bool {
|
||||
if l.Error != nil {
|
||||
return false
|
||||
}
|
||||
if l.year%calendar.MonthsPerYear == 4 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// IsOxYear reports whether is lunar year of Ox.
|
||||
// 是否是牛年
|
||||
func (l Lunar) IsOxYear() bool {
|
||||
if l.Error != nil {
|
||||
return false
|
||||
}
|
||||
if l.year%calendar.MonthsPerYear == 5 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// IsTigerYear reports whether is lunar year of Tiger.
|
||||
// 是否是虎年
|
||||
func (l Lunar) IsTigerYear() bool {
|
||||
if l.Error != nil {
|
||||
return false
|
||||
}
|
||||
if l.year%calendar.MonthsPerYear == 6 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// IsRabbitYear reports whether is lunar year of Rabbit.
|
||||
// 是否是兔年
|
||||
func (l Lunar) IsRabbitYear() bool {
|
||||
if l.Error != nil {
|
||||
return false
|
||||
}
|
||||
if l.year%calendar.MonthsPerYear == 7 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// IsDragonYear reports whether is lunar year of Dragon.
|
||||
// 是否是龙年
|
||||
func (l Lunar) IsDragonYear() bool {
|
||||
if l.Error != nil {
|
||||
return false
|
||||
}
|
||||
if l.year%calendar.MonthsPerYear == 8 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// IsSnakeYear reports whether is lunar year of Snake.
|
||||
// 是否是蛇年
|
||||
func (l Lunar) IsSnakeYear() bool {
|
||||
if l.Error != nil {
|
||||
return false
|
||||
}
|
||||
if l.year%calendar.MonthsPerYear == 9 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// IsHorseYear reports whether is lunar year of Horse.
|
||||
// 是否是马年
|
||||
func (l Lunar) IsHorseYear() bool {
|
||||
if l.Error != nil {
|
||||
return false
|
||||
}
|
||||
if l.year%calendar.MonthsPerYear == 10 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// IsGoatYear reports whether is lunar year of Goat.
|
||||
// 是否是羊年
|
||||
func (l Lunar) IsGoatYear() bool {
|
||||
if l.Error != nil {
|
||||
return false
|
||||
}
|
||||
if l.year%calendar.MonthsPerYear == 11 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// IsMonkeyYear reports whether is lunar year of Monkey.
|
||||
// 是否是猴年
|
||||
func (l Lunar) IsMonkeyYear() bool {
|
||||
if l.Error != nil {
|
||||
return false
|
||||
}
|
||||
if l.year%calendar.MonthsPerYear == 0 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// IsRoosterYear reports whether is lunar year of Rooster.
|
||||
// 是否是鸡年
|
||||
func (l Lunar) IsRoosterYear() bool {
|
||||
if l.Error != nil {
|
||||
return false
|
||||
}
|
||||
if l.year%calendar.MonthsPerYear == 1 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// IsDogYear reports whether is lunar year of Dog.
|
||||
// 是否是狗年
|
||||
func (l Lunar) IsDogYear() bool {
|
||||
if l.Error != nil {
|
||||
return false
|
||||
}
|
||||
if l.year%calendar.MonthsPerYear == 2 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// IsPigYear reports whether is lunar year of Pig.
|
||||
// 是否是猪年
|
||||
func (l Lunar) IsPigYear() bool {
|
||||
if l.Error != nil {
|
||||
return false
|
||||
}
|
||||
if l.year%calendar.MonthsPerYear == 3 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (g Gregorian) diffInDays(t time.Time) int {
|
||||
return int(g.Time.Truncate(time.Hour).Sub(t).Hours() / 24)
|
||||
}
|
||||
|
||||
func (l Lunar) getOffsetInYear() int {
|
||||
flag := false
|
||||
clone, month, offset := l, 0, 0
|
||||
for month = 1; month < l.month; month++ {
|
||||
leapMonth := l.LeapMonth()
|
||||
if !flag {
|
||||
// 处理闰月
|
||||
if leapMonth <= month && leapMonth > 0 {
|
||||
offset += l.getDaysInLeapMonth()
|
||||
flag = true
|
||||
}
|
||||
}
|
||||
clone.month = month
|
||||
offset += clone.getDaysInMonth()
|
||||
}
|
||||
return offset
|
||||
}
|
||||
|
||||
func (l Lunar) getOffsetInMonth() int {
|
||||
clone, year, offset := l, 0, 0
|
||||
for year = MinValue().year; year < l.year; year++ {
|
||||
clone.year = year
|
||||
offset += clone.getDaysInYear()
|
||||
}
|
||||
return offset
|
||||
}
|
||||
|
||||
func (l Lunar) getDaysInYear() int {
|
||||
var days = 348
|
||||
for i := 0x8000; i > 0x8; i >>= 1 {
|
||||
if (years[l.year-MinValue().year] & i) != 0 {
|
||||
days++
|
||||
}
|
||||
}
|
||||
return days + l.getDaysInLeapMonth()
|
||||
}
|
||||
|
||||
func (l Lunar) getDaysInMonth() int {
|
||||
if (years[l.year-MinValue().year] & (0x10000 >> uint(l.month))) != 0 {
|
||||
return 30
|
||||
}
|
||||
return 29
|
||||
}
|
||||
|
||||
func (l Lunar) getDaysInLeapMonth() int {
|
||||
if l.LeapMonth() == 0 {
|
||||
return 0
|
||||
}
|
||||
if years[l.year-MinValue().year]&0x10000 != 0 {
|
||||
return 30
|
||||
}
|
||||
return 29
|
||||
}
|
||||
74
vendor/github.com/dromara/carbon/v2/calendar/persian/README.cn.md
generated
vendored
Normal file
74
vendor/github.com/dromara/carbon/v2/calendar/persian/README.cn.md
generated
vendored
Normal file
@@ -0,0 +1,74 @@
|
||||
# 波斯历(伊朗历)
|
||||
|
||||
简体中文 | [English](README.md) | [日本語](README.jp.md)
|
||||
|
||||
#### 用法示例
|
||||
|
||||
##### 将 `公历` 转换成 `波斯历`
|
||||
|
||||
```go
|
||||
// 获取波斯历年份
|
||||
carbon.Parse("2020-08-05 13:14:15").Persian().Year() // 1399
|
||||
// 获取波斯历月份
|
||||
carbon.Parse("2020-08-05 13:14:15").Persian().Month() // 5
|
||||
// 获取波斯历日期
|
||||
carbon.Parse("2020-08-05 13:14:15").Persian().Day() // 15
|
||||
// 获取波斯历小时
|
||||
carbon.Parse("2020-08-05 13:14:15").Persian().Hour() // 13
|
||||
// 获取波斯历分钟
|
||||
carbon.Parse("2020-08-05 13:14:15").Persian().Minute() // 14
|
||||
// 获取波斯历秒数
|
||||
carbon.Parse("2020-08-05 13:14:15").Persian().Second() // 15
|
||||
|
||||
// 获取波斯历日期时间字符串
|
||||
carbon.Parse("2020-08-05 13:14:15").Persian().String() // 1399-05-15 13:14:15
|
||||
fmt.Printf("%s", carbon.Parse("2020-08-05 13:14:15").Persian()) // 1399-05-15 13:14:15
|
||||
|
||||
// 获取波斯历月字符串
|
||||
carbon.Parse("2020-08-05 13:14:15").Persian().ToMonthString() // Mordad
|
||||
carbon.Parse("2020-08-05 13:14:15").Persian().ToMonthString("en") // Mordad
|
||||
carbon.Parse("2020-08-05 13:14:15").Persian().ToMonthString("fa") // مرداد
|
||||
|
||||
// 获取简写波斯历月字符串
|
||||
carbon.Parse("2020-08-05 13:14:15").Persian().ToShortMonthString() // Mor
|
||||
carbon.Parse("2020-08-05 13:14:15").Persian().ToShortMonthString("en") // Mor
|
||||
carbon.Parse("2020-08-05 13:14:15").Persian().ToShortMonthString("fa") // مرد
|
||||
|
||||
// 获取波斯历周字符串
|
||||
carbon.Parse("2020-08-05 13:14:15").Persian().ToWeekString() // Chaharshanbeh
|
||||
carbon.Parse("2020-08-05 13:14:15").Persian().ToWeekString("en") // Chaharshanbeh
|
||||
carbon.Parse("2020-08-05 13:14:15").Persian().ToWeekString("fa") // چهارشنبه
|
||||
|
||||
// 获取简写波斯历周字符串
|
||||
carbon.Parse("2020-08-05 13:14:15").Persian().ToShortWeekString() // Cha
|
||||
carbon.Parse("2020-08-05 13:14:15").Persian().ToShortWeekString("en") // Cha
|
||||
carbon.Parse("2020-08-05 13:14:15").Persian().ToShortWeekString("fa") // د
|
||||
|
||||
```
|
||||
|
||||
##### 将 `波斯历` 转化成 `公历`
|
||||
|
||||
```go
|
||||
carbon.CreateFromPersian(1, 1, 1, 0, 0, 0).ToDateTimeString() // 2016-03-20 00:00:00
|
||||
carbon.CreateFromPersian(622, 1, 1, 0, 0, 0).ToDateTimeString() // 1243-03-21 00:00:00
|
||||
carbon.CreateFromPersian(1395, 1, 1, 0, 0, 0).ToDateTimeString() // 2016-03-20 00:00:00
|
||||
carbon.CreateFromPersian(9377, 1, 1, 0, 0, 0).ToDateTimeString() // 9998-03-19 00:00:00
|
||||
```
|
||||
|
||||
##### 日期判断
|
||||
```go
|
||||
// 是否是合法的波斯历日期
|
||||
carbon.CreateFromPersian(1, 1, 1, 0, 0, 0).IsValid() // true
|
||||
carbon.CreateFromPersian(622, 1, 1, 0, 0, 0).IsValid() // true
|
||||
carbon.CreateFromPersian(9377, 1, 1, 0, 0, 0).IsValid() // true
|
||||
carbon.CreateFromPersian(0, 0, 0, 0, 0, 0).IsValid() // false
|
||||
carbon.CreateFromPersian(2024, 0, 1, 0, 0, 0).IsValid() // false
|
||||
carbon.CreateFromPersian(2024, 1, 0, 0, 0, 0).IsValid() // false
|
||||
|
||||
// 是否是波斯历闰年
|
||||
carbon.CreateFromPersian(1395, 1, 1, 0, 0, 0).IsLeapYear() // true
|
||||
carbon.CreateFromPersian(9377, 1, 1, 0, 0, 0).IsLeapYear() // true
|
||||
carbon.CreateFromPersian(622, 1, 1, 0, 0, 0).IsLeapYear() // false
|
||||
carbon.CreateFromPersian(9999, 1, 1, 0, 0, 0).IsLeapYear() // false
|
||||
|
||||
```
|
||||
73
vendor/github.com/dromara/carbon/v2/calendar/persian/README.jp.md
generated
vendored
Normal file
73
vendor/github.com/dromara/carbon/v2/calendar/persian/README.jp.md
generated
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
# ペルシア暦(イラン暦)
|
||||
|
||||
日本語 | [English](README.md) | [简体中文](README.cn.md)
|
||||
|
||||
#### 使い方の例
|
||||
|
||||
##### `西暦` を `ペルシャ暦` に変換
|
||||
|
||||
```go
|
||||
// ペルシャ暦の取得
|
||||
carbon.Parse("2020-08-05 13:14:15").Persian().Year() // 1399
|
||||
// ペルシャ暦月の取得
|
||||
carbon.Parse("2020-08-05 13:14:15").Persian().Month() // 5
|
||||
// ペルシャ暦の取得日
|
||||
carbon.Parse("2020-08-05 13:14:15").Persian().Day() // 15
|
||||
// ペルシャ暦時間の取得
|
||||
carbon.Parse("2020-08-05 13:14:15").Persian().Hour() // 13
|
||||
// ペルシャ暦分の取得
|
||||
carbon.Parse("2020-08-05 13:14:15").Persian().Minute() // 14
|
||||
// ペルシャ暦秒の取得
|
||||
carbon.Parse("2020-08-05 13:14:15").Persian().Second() // 15
|
||||
|
||||
// ペルシャ暦日時文字列の取得
|
||||
carbon.Parse("2020-08-05 13:14:15").Persian().String() // 1399-05-15 13:14:15
|
||||
fmt.Printf("%s", carbon.Parse("2020-08-05 13:14:15").Persian()) // 1399-05-15 13:14:15
|
||||
|
||||
// ペルシア暦月文字列の取得
|
||||
carbon.Parse("2020-08-05 13:14:15").Persian().ToMonthString() // Mordad
|
||||
carbon.Parse("2020-08-05 13:14:15").Persian().ToMonthString("en") // Mordad
|
||||
carbon.Parse("2020-08-05 13:14:15").Persian().ToMonthString("fa") // مرداد
|
||||
|
||||
// 略語ペルシャ暦文字列の取得
|
||||
carbon.Parse("2020-08-05 13:14:15").Persian().ToShortMonthString() // Mor
|
||||
carbon.Parse("2020-08-05 13:14:15").Persian().ToShortMonthString("en") // Mor
|
||||
carbon.Parse("2020-08-05 13:14:15").Persian().ToShortMonthString("fa") // مرد
|
||||
|
||||
// ペルシャ暦週文字列の取得
|
||||
carbon.Parse("2020-08-05 13:14:15").Persian().ToWeekString() // Chaharshanbeh
|
||||
carbon.Parse("2020-08-05 13:14:15").Persian().ToWeekString("en") // Chaharshanbeh
|
||||
carbon.Parse("2020-08-05 13:14:15").Persian().ToWeekString("fa") // چهارشنبه
|
||||
|
||||
// 略語ペルシャ暦週文字列の取得
|
||||
carbon.Parse("2020-08-05 13:14:15").Persian().ToShortWeekString() // Cha
|
||||
carbon.Parse("2020-08-05 13:14:15").Persian().ToShortWeekString("en") // Cha
|
||||
carbon.Parse("2020-08-05 13:14:15").Persian().ToShortWeekString("fa") // د
|
||||
```
|
||||
|
||||
##### ペルシャ暦を西暦に変換する
|
||||
|
||||
```go
|
||||
carbon.CreateFromPersian(1, 1, 1, 0, 0, 0).ToDateTimeString() // 2016-03-20 00:00:00
|
||||
carbon.CreateFromPersian(622, 1, 1, 0, 0, 0).ToDateTimeString() // 1243-03-21 00:00:00
|
||||
carbon.CreateFromPersian(1395, 1, 1, 0, 0, 0).ToDateTimeString() // 2016-03-20 00:00:00
|
||||
carbon.CreateFromPersian(9377, 1, 1, 0, 0, 0).ToDateTimeString() // 9998-03-19 00:00:00
|
||||
```
|
||||
|
||||
##### 日付判断
|
||||
```go
|
||||
// 合法的なペルシャ暦の日付かどうか
|
||||
carbon.CreateFromPersian(1, 1, 1, 0, 0, 0).IsValid() // true
|
||||
carbon.CreateFromPersian(622, 1, 1, 0, 0, 0).IsValid() // true
|
||||
carbon.CreateFromPersian(9377, 1, 1, 0, 0, 0).IsValid() // true
|
||||
carbon.CreateFromPersian(0, 0, 0, 0, 0, 0).IsValid() // false
|
||||
carbon.CreateFromPersian(2024, 0, 1, 0, 0, 0).IsValid() // false
|
||||
carbon.CreateFromPersian(2024, 1, 0, 0, 0, 0).IsValid() // false
|
||||
|
||||
// ペルシア暦閏年かどうか
|
||||
carbon.CreateFromPersian(1395, 1, 1, 0, 0, 0).IsLeapYear() // true
|
||||
carbon.CreateFromPersian(9377, 1, 1, 0, 0, 0).IsLeapYear() // true
|
||||
carbon.CreateFromPersian(622, 1, 1, 0, 0, 0).IsLeapYear() // false
|
||||
carbon.CreateFromPersian(9999, 1, 1, 0, 0, 0).IsLeapYear() // false
|
||||
|
||||
```
|
||||
74
vendor/github.com/dromara/carbon/v2/calendar/persian/README.md
generated
vendored
Normal file
74
vendor/github.com/dromara/carbon/v2/calendar/persian/README.md
generated
vendored
Normal file
@@ -0,0 +1,74 @@
|
||||
# Persian(Jalaali) Calendar
|
||||
|
||||
English | [简体中文](README.cn.md) | [日本語](README.jp.md)
|
||||
|
||||
#### Usage and example
|
||||
|
||||
##### Convert `Gregorian` calendar to `Persian` calendar
|
||||
|
||||
```go
|
||||
// Get persian year
|
||||
carbon.Parse("2020-08-05 13:14:15").Persian().Year() // 1399
|
||||
// Get persian month
|
||||
carbon.Parse("2020-08-05 13:14:15").Persian().Month() // 5
|
||||
// Get persian day
|
||||
carbon.Parse("2020-08-05 13:14:15").Persian().Day() // 15
|
||||
// Get persian hour
|
||||
carbon.Parse("2020-08-05 13:14:15").Persian().Hour() // 13
|
||||
// Get persian minute
|
||||
carbon.Parse("2020-08-05 13:14:15").Persian().Minute() // 14
|
||||
// Get persian second
|
||||
carbon.Parse("2020-08-05 13:14:15").Persian().Second() // 15
|
||||
|
||||
// Get persian date and time string
|
||||
carbon.Parse("2020-08-05 13:14:15").Persian().String() // 1399-05-15 13:14:15
|
||||
fmt.Printf("%s", carbon.Parse("2020-08-05 13:14:15").Persian()) // 1399-05-15 13:14:15
|
||||
|
||||
// Get persian month as string
|
||||
carbon.Parse("2020-08-05 13:14:15").Persian().ToMonthString() // Mordad
|
||||
carbon.Parse("2020-08-05 13:14:15").Persian().ToMonthString("en") // Mordad
|
||||
carbon.Parse("2020-08-05 13:14:15").Persian().ToMonthString("fa") // مرداد
|
||||
|
||||
// Get persian short month as string
|
||||
carbon.Parse("2020-08-05 13:14:15").Persian().ToShortMonthString() // Mor
|
||||
carbon.Parse("2020-08-05 13:14:15").Persian().ToShortMonthString("en") // Mor
|
||||
carbon.Parse("2020-08-05 13:14:15").Persian().ToShortMonthString("fa") // مرد
|
||||
|
||||
// Get persian week as string
|
||||
carbon.Parse("2020-08-05 13:14:15").Persian().ToWeekString() // Chaharshanbeh
|
||||
carbon.Parse("2020-08-05 13:14:15").Persian().ToWeekString("en") // Chaharshanbeh
|
||||
carbon.Parse("2020-08-05 13:14:15").Persian().ToWeekString("fa") // چهارشنبه
|
||||
|
||||
// Get persian short week as string
|
||||
carbon.Parse("2020-08-05 13:14:15").Persian().ToShortWeekString() // Cha
|
||||
carbon.Parse("2020-08-05 13:14:15").Persian().ToShortWeekString("en") // Cha
|
||||
carbon.Parse("2020-08-05 13:14:15").Persian().ToShortWeekString("fa") // د
|
||||
|
||||
```
|
||||
|
||||
##### Convert `Persian` calendar to `Gregorian` calendar
|
||||
|
||||
```go
|
||||
carbon.CreateFromPersian(1, 1, 1, 0, 0, 0).ToDateTimeString() // 2016-03-20 00:00:00
|
||||
carbon.CreateFromPersian(622, 1, 1, 0, 0, 0).ToDateTimeString() // 1243-03-21 00:00:00
|
||||
carbon.CreateFromPersian(1395, 1, 1, 0, 0, 0).ToDateTimeString() // 2016-03-20 00:00:00
|
||||
carbon.CreateFromPersian(9377, 1, 1, 0, 0, 0).ToDateTimeString() // 9998-03-19 00:00:00
|
||||
```
|
||||
|
||||
##### Comparison
|
||||
```go
|
||||
// Whether is a valid persian date
|
||||
carbon.CreateFromPersian(1, 1, 1, 0, 0, 0).IsValid() // true
|
||||
carbon.CreateFromPersian(622, 1, 1, 0, 0, 0).IsValid() // true
|
||||
carbon.CreateFromPersian(9377, 1, 1, 0, 0, 0).IsValid() // true
|
||||
carbon.CreateFromPersian(0, 0, 0, 0, 0, 0).IsValid() // false
|
||||
carbon.CreateFromPersian(2024, 0, 1, 0, 0, 0).IsValid() // false
|
||||
carbon.CreateFromPersian(2024, 1, 0, 0, 0, 0).IsValid() // false
|
||||
|
||||
// Whether is a persian leap year
|
||||
carbon.CreateFromPersian(1395, 1, 1, 0, 0, 0).IsLeapYear() // true
|
||||
carbon.CreateFromPersian(9377, 1, 1, 0, 0, 0).IsLeapYear() // true
|
||||
carbon.CreateFromPersian(622, 1, 1, 0, 0, 0).IsLeapYear() // false
|
||||
carbon.CreateFromPersian(9999, 1, 1, 0, 0, 0).IsLeapYear() // false
|
||||
|
||||
```
|
||||
321
vendor/github.com/dromara/carbon/v2/calendar/persian/persian.go
generated
vendored
Normal file
321
vendor/github.com/dromara/carbon/v2/calendar/persian/persian.go
generated
vendored
Normal file
@@ -0,0 +1,321 @@
|
||||
// Package persian is part of the carbon package.
|
||||
package persian
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"time"
|
||||
|
||||
"github.com/dromara/carbon/v2/calendar"
|
||||
"github.com/dromara/carbon/v2/calendar/julian"
|
||||
)
|
||||
|
||||
var (
|
||||
EnMonths = []string{"Farvardin", "Ordibehesht", "Khordad", "Tir", "Mordad", "Shahrivar", "Mehr", "Aban", "Azar", "Dey", "Bahman", "Esfand"}
|
||||
ShortEnMonths = []string{"Far", "Ord", "Kho", "Tir", "Mor", "Sha", "Meh", "Aba", "Aza", "Dey", "Bah", "Esf"}
|
||||
|
||||
FaMonths = []string{"فروردین", "اردیبهشت", "خرداد", "تیر", "مرداد", "شهریور", "مهر", "آبان", "آذر", "دی", "بهمن", "اسفند"}
|
||||
ShortFaMonths = []string{"فرو", "ارد", "خرد", "تیر", "مرد", "شهر", "مهر", "آبا", "آذر", "دی", "بهم", "اسف"}
|
||||
|
||||
EnWeeks = []string{"Yekshanbeh", "Doshanbeh", "Seshanbeh", "Chaharshanbeh", "Panjshanbeh", "Jomeh", "Shanbeh"}
|
||||
ShortEnWeeks = []string{"Yek", "Dos", "Ses", "Cha", "Pan", "Jom", "Sha"}
|
||||
|
||||
FaWeeks = []string{"نجشنبه", "دوشنبه", "سه شنبه", "چهارشنبه", "پنجشنبه", "جمعه", "شنبه"}
|
||||
ShortFaWeeks = []string{"پ", "چ", "س", "د", "ی", "ش", "ج"}
|
||||
|
||||
InvalidDateError = func() error {
|
||||
return fmt.Errorf("invalid persian date, please make sure the date is valid")
|
||||
}
|
||||
)
|
||||
|
||||
// Gregorian defines a Gregorian struct.
|
||||
// 定义 Gregorian 结构体
|
||||
type Gregorian struct {
|
||||
calendar.Gregorian
|
||||
}
|
||||
|
||||
// Persian defines a Persian struct.
|
||||
// 定义 Persian 结构体
|
||||
type Persian struct {
|
||||
year, month, day, hour, minute, second int
|
||||
Error error
|
||||
}
|
||||
|
||||
// MaxValue returns a Persian instance for the greatest supported date.
|
||||
// 返回 Persian 的最大值
|
||||
func MaxValue() Persian {
|
||||
return Persian{
|
||||
year: 9377,
|
||||
month: 12,
|
||||
day: 31,
|
||||
hour: 23,
|
||||
minute: 59,
|
||||
second: 59,
|
||||
}
|
||||
}
|
||||
|
||||
// MinValue returns a Persian instance for the lowest supported date.
|
||||
// 返回 Persian 的最小值
|
||||
func MinValue() Persian {
|
||||
return Persian{
|
||||
year: 1,
|
||||
month: 1,
|
||||
day: 1,
|
||||
hour: 0,
|
||||
minute: 0,
|
||||
second: 0,
|
||||
}
|
||||
}
|
||||
|
||||
// FromGregorian creates a Gregorian instance from time.Time.
|
||||
// 从标准 time.Time 创建 Gregorian 实例
|
||||
func FromGregorian(t time.Time) (g Gregorian) {
|
||||
if t.IsZero() {
|
||||
return
|
||||
}
|
||||
g.Time = t
|
||||
return
|
||||
}
|
||||
|
||||
// FromPersian creates a Persian instance from persian datetime.
|
||||
// 从 波斯日期 创建 Persian 实例
|
||||
func FromPersian(year, month, day, hour, minute, second int) (p Persian) {
|
||||
p.year, p.month, p.day = year, month, day
|
||||
p.hour, p.minute, p.second = hour, minute, second
|
||||
if !p.IsValid() {
|
||||
p.Error = InvalidDateError()
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// ToPersian converts Gregorian instance to Persian instance.
|
||||
// 将 Gregorian 实例转化为 Persian 实例
|
||||
func (g Gregorian) ToPersian() (p Persian) {
|
||||
p.hour, p.minute, p.second = g.Hour(), g.Minute(), g.Second()
|
||||
gjdn := getGregorianJdn(g.Year(), g.Month(), g.Day())
|
||||
pjdn := getPersianJdn(475, 1, 1)
|
||||
|
||||
diff := gjdn - pjdn
|
||||
div := diff / 1029983
|
||||
mod := diff % 1029983
|
||||
p.year = (2134*mod/366+2816*(mod%366)+2815)/1028522 + mod/366 + 1 + 2820*div + 474
|
||||
pjdn = getPersianJdn(p.year, 1, 1)
|
||||
fjdn := float64(gjdn - pjdn + 1)
|
||||
if fjdn <= 186 {
|
||||
p.month = int(math.Ceil(fjdn / 31.0))
|
||||
} else {
|
||||
p.month = int(math.Ceil((fjdn - 6) / 30.0))
|
||||
}
|
||||
pjdn = getPersianJdn(p.year, p.month, 1)
|
||||
p.day = gjdn - pjdn + 1
|
||||
if !p.IsValid() {
|
||||
p.Error = InvalidDateError()
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// ToGregorian converts Persian instance to Gregorian instance.
|
||||
// 将 Persian 实例转化为 Gregorian 实例
|
||||
func (p Persian) ToGregorian() (g Gregorian) {
|
||||
if !p.IsValid() {
|
||||
return
|
||||
}
|
||||
jdn := getPersianJdn(p.year, p.month, p.day)
|
||||
|
||||
l := jdn + 68569
|
||||
n := 4 * l / 146097
|
||||
l = l - (146097*n+3)/4
|
||||
i := 4000 * (l + 1) / 1461001
|
||||
l = l - 1461*i/4 + 31
|
||||
j := 80 * l / 2447
|
||||
d := l - 2447*j/80
|
||||
l = j / 11
|
||||
m := j + 2 - 12*l
|
||||
y := 100*(n-49) + i + l
|
||||
|
||||
g.Time = time.Date(y, time.Month(m), d, p.hour, p.minute, p.second, 0, time.Local)
|
||||
return
|
||||
}
|
||||
|
||||
// Year gets lunar year like 2020.
|
||||
// 获取年份,如 2020
|
||||
func (p Persian) Year() int {
|
||||
if p.Error != nil {
|
||||
return 0
|
||||
}
|
||||
return p.year
|
||||
}
|
||||
|
||||
// Month gets lunar month like 8.
|
||||
// 获取月份,如 8
|
||||
func (p Persian) Month() int {
|
||||
if p.Error != nil {
|
||||
return 0
|
||||
}
|
||||
return p.month
|
||||
}
|
||||
|
||||
// Day gets lunar day like 5.
|
||||
// 获取日,如 5
|
||||
func (p Persian) Day() int {
|
||||
if p.Error != nil {
|
||||
return 0
|
||||
}
|
||||
return p.day
|
||||
}
|
||||
|
||||
// Hour gets current hour like 13.
|
||||
// 获取小时,如 13
|
||||
func (p Persian) Hour() int {
|
||||
if p.Error != nil {
|
||||
return 0
|
||||
}
|
||||
return p.hour
|
||||
}
|
||||
|
||||
// Minute gets current minute like 14.
|
||||
// 获取分钟数,如 14
|
||||
func (p Persian) Minute() int {
|
||||
if p.Error != nil {
|
||||
return 0
|
||||
}
|
||||
return p.minute
|
||||
}
|
||||
|
||||
// Second gets current second like 15.
|
||||
// 获取秒数,如 15
|
||||
func (p Persian) Second() int {
|
||||
if p.Error != nil {
|
||||
return 0
|
||||
}
|
||||
return p.second
|
||||
}
|
||||
|
||||
// String implements Stringer interface and outputs a string in YYYY-MM-DD HH::ii::ss format like "1402-11-11 00:00:00".
|
||||
// 实现 Stringer 接口, 输出 YYYY-MM-DD HH::ii::ss 格式字符串,如 "1402-11-11 00:00:00"
|
||||
func (p Persian) String() string {
|
||||
if !p.IsValid() {
|
||||
return ""
|
||||
}
|
||||
return fmt.Sprintf("%d-%02d-%02d %02d:%02d:%02d", p.year, p.month, p.day, p.hour, p.minute, p.second)
|
||||
}
|
||||
|
||||
// ToMonthString outputs a string in persian month format like "فروردین".
|
||||
// 获取完整月份字符串,如 "فروردین"
|
||||
func (p Persian) ToMonthString(locale ...string) (month string) {
|
||||
if !p.IsValid() {
|
||||
return ""
|
||||
}
|
||||
loc := "en"
|
||||
if len(locale) > 0 {
|
||||
loc = locale[0]
|
||||
}
|
||||
switch loc {
|
||||
case "en":
|
||||
return EnMonths[p.month-1]
|
||||
case "fa":
|
||||
return FaMonths[p.month-1]
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// ToShortMonthString outputs a short string in persian month format like "فروردین".
|
||||
// 获取缩写月份字符串,如 "فروردین"
|
||||
func (p Persian) ToShortMonthString(locale ...string) (month string) {
|
||||
if !p.IsValid() {
|
||||
return ""
|
||||
}
|
||||
loc := "en"
|
||||
if len(locale) > 0 {
|
||||
loc = locale[0]
|
||||
}
|
||||
switch loc {
|
||||
case "en":
|
||||
return ShortEnMonths[p.month-1]
|
||||
case "fa":
|
||||
return ShortFaMonths[p.month-1]
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// ToWeekString outputs a string in week layout like "چهارشنبه".
|
||||
// 输出完整星期字符串,如 "چهارشنبه"
|
||||
func (p Persian) ToWeekString(locale ...string) (month string) {
|
||||
if !p.IsValid() {
|
||||
return ""
|
||||
}
|
||||
loc := "en"
|
||||
if len(locale) > 0 {
|
||||
loc = locale[0]
|
||||
}
|
||||
switch loc {
|
||||
case "en":
|
||||
return EnWeeks[p.ToGregorian().Week()]
|
||||
case "fa":
|
||||
return FaWeeks[p.ToGregorian().Week()]
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// ToShortWeekString outputs a short string in week layout like "چهارشنبه".
|
||||
// 输出缩写星期字符串,如 "چهارشنبه"
|
||||
func (p Persian) ToShortWeekString(locale ...string) (month string) {
|
||||
if !p.IsValid() {
|
||||
return ""
|
||||
}
|
||||
loc := "en"
|
||||
if len(locale) > 0 {
|
||||
loc = locale[0]
|
||||
}
|
||||
switch loc {
|
||||
case "en":
|
||||
return ShortEnWeeks[p.ToGregorian().Week()]
|
||||
case "fa":
|
||||
return ShortFaWeeks[p.ToGregorian().Week()]
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// IsValid reports whether is a valid persian date.
|
||||
// 是否是有效的日期
|
||||
func (p Persian) IsValid() bool {
|
||||
if p.Year() >= MinValue().year && p.Year() <= MaxValue().year && p.month >= MinValue().month && p.month <= MaxValue().month && p.day >= MinValue().day && p.day <= MaxValue().day {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// IsLeapYear reports whether is a persian leap year.
|
||||
// 是否是闰年
|
||||
func (p Persian) IsLeapYear() bool {
|
||||
if !p.IsValid() {
|
||||
return false
|
||||
}
|
||||
return (25*p.year+11)%33 < 8
|
||||
}
|
||||
|
||||
// gets Julian day number in Persian calendar
|
||||
// 获取波斯历儒略日计数
|
||||
func getPersianJdn(year, month, day int) int {
|
||||
year = year - 473
|
||||
if year >= 0 {
|
||||
year--
|
||||
}
|
||||
epy := 474 + (year % 2820)
|
||||
var md int
|
||||
if month <= 7 {
|
||||
md = (month - 1) * 31
|
||||
} else {
|
||||
md = (month-1)*30 + 6
|
||||
}
|
||||
return day + md + (epy*682-110)/2816 + (epy-1)*365 + year/2820*1029983 + 1948320
|
||||
}
|
||||
|
||||
// gets Julian day number in Gregorian calendar
|
||||
// 获取公历儒略日计数
|
||||
func getGregorianJdn(year, month, day int) int {
|
||||
jdn := julian.FromGregorian(time.Date(year, time.Month(month), day, 0, 0, 0, 0, time.Local)).ToJulian().JD(0)
|
||||
return int(jdn)
|
||||
}
|
||||
483
vendor/github.com/dromara/carbon/v2/carbon.go
generated
vendored
Normal file
483
vendor/github.com/dromara/carbon/v2/carbon.go
generated
vendored
Normal file
@@ -0,0 +1,483 @@
|
||||
// @Package carbon
|
||||
// @Description a simple, semantic and developer-friendly golang package for datetime
|
||||
// @Page github.com/dromara/carbon
|
||||
// @Developer gouguoyin
|
||||
// @Blog www.gouguoyin.com
|
||||
// @Email 245629560@qq.com
|
||||
|
||||
// Package carbon is a simple, semantic and developer-friendly golang package for datetime.
|
||||
package carbon
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// Version current version
|
||||
// 当前版本号
|
||||
const Version = "2.5.2"
|
||||
|
||||
// timezone constants
|
||||
// 时区常量
|
||||
const (
|
||||
Local = "Local" // 本地时间
|
||||
UTC = "UTC" // 世界协调时间
|
||||
GMT = "GMT" // 格林尼治标准时间
|
||||
CST = "CST" // 中国标准时间
|
||||
EET = "EET" // 欧洲东部标准时间
|
||||
WET = "WET" // 欧洲西部标准时间
|
||||
CET = "CET" // 欧洲中部标准时间
|
||||
EST = "EST" // 美国东部标准时间
|
||||
MST = "MST" // 美国山地标准时间
|
||||
|
||||
Cuba = "Cuba" // 古巴
|
||||
Egypt = "Egypt" // 埃及
|
||||
Eire = "Eire" // 爱尔兰
|
||||
Greenwich = "Greenwich" // 格林尼治
|
||||
Iceland = "Iceland" // 冰岛
|
||||
Iran = "Iran" // 伊朗
|
||||
Israel = "Israel" // 以色列
|
||||
Jamaica = "Jamaica" // 牙买加
|
||||
Japan = "Japan" // 日本
|
||||
Libya = "Libya" // 利比亚
|
||||
Poland = "Poland" // 波兰
|
||||
Portugal = "Portugal" // 葡萄牙
|
||||
PRC = "PRC" // 中国
|
||||
Singapore = "Singapore" // 新加坡
|
||||
Turkey = "Turkey" // 土耳其
|
||||
|
||||
Shanghai = "Asia/Shanghai" // 上海
|
||||
Chongqing = "Asia/Chongqing" // 重庆
|
||||
Harbin = "Asia/Harbin" // 哈尔滨
|
||||
Urumqi = "Asia/Urumqi" // 乌鲁木齐
|
||||
HongKong = "Asia/Hong_Kong" // 香港
|
||||
Macao = "Asia/Macao" // 澳门
|
||||
Taipei = "Asia/Taipei" // 台北
|
||||
Tokyo = "Asia/Tokyo" // 东京
|
||||
HoChiMinh = "Asia/Ho_Chi_Minh" // 胡志明
|
||||
Hanoi = "Asia/Hanoi" // 河内
|
||||
Saigon = "Asia/Saigon" // 西贡
|
||||
Seoul = "Asia/Seoul" // 首尔
|
||||
Pyongyang = "Asia/Pyongyang" // 平壤
|
||||
Bangkok = "Asia/Bangkok" // 曼谷
|
||||
Dubai = "Asia/Dubai" // 迪拜
|
||||
Qatar = "Asia/Qatar" // 卡塔尔
|
||||
Bangalore = "Asia/Bangalore" // 班加罗尔
|
||||
Kolkata = "Asia/Kolkata" // 加尔各答
|
||||
Mumbai = "Asia/Mumbai" // 孟买
|
||||
MexicoCity = "America/Mexico_City" // 墨西哥
|
||||
NewYork = "America/New_York" // 纽约
|
||||
LosAngeles = "America/Los_Angeles" // 洛杉矶
|
||||
Chicago = "America/Chicago" // 芝加哥
|
||||
SaoPaulo = "America/Sao_Paulo" // 圣保罗
|
||||
Moscow = "Europe/Moscow" // 莫斯科
|
||||
London = "Europe/London" // 伦敦
|
||||
Berlin = "Europe/Berlin" // 柏林
|
||||
Paris = "Europe/Paris" // 巴黎
|
||||
Rome = "Europe/Rome" // 罗马
|
||||
Sydney = "Australia/Sydney" // 悉尼
|
||||
Melbourne = "Australia/Melbourne" // 墨尔本
|
||||
Darwin = "Australia/Darwin" // 达尔文
|
||||
)
|
||||
|
||||
// month constants
|
||||
// 月份常量
|
||||
const (
|
||||
January = "January" // 一月
|
||||
February = "February" // 二月
|
||||
March = "March" // 三月
|
||||
April = "April" // 四月
|
||||
May = "May" // 五月
|
||||
June = "June" // 六月
|
||||
July = "July" // 七月
|
||||
August = "August" // 八月
|
||||
September = "September" // 九月
|
||||
October = "October" // 十月
|
||||
November = "November" // 十一月
|
||||
December = "December" // 十二月
|
||||
)
|
||||
|
||||
// week constants
|
||||
// 星期常量
|
||||
const (
|
||||
Monday = "Monday" // 周一
|
||||
Tuesday = "Tuesday" // 周二
|
||||
Wednesday = "Wednesday" // 周三
|
||||
Thursday = "Thursday" // 周四
|
||||
Friday = "Friday" // 周五
|
||||
Saturday = "Saturday" // 周六
|
||||
Sunday = "Sunday" // 周日
|
||||
)
|
||||
|
||||
// number constants
|
||||
// 数字常量
|
||||
const (
|
||||
YearsPerMillennium = 1000 // 每千年1000年
|
||||
YearsPerCentury = 100 // 每世纪100年
|
||||
YearsPerDecade = 10 // 每十年10年
|
||||
QuartersPerYear = 4 // 每年4个季度
|
||||
MonthsPerYear = 12 // 每年12月
|
||||
MonthsPerQuarter = 3 // 每季度3月
|
||||
WeeksPerNormalYear = 52 // 每常规年52周
|
||||
weeksPerLongYear = 53 // 每长年53周
|
||||
WeeksPerMonth = 4 // 每月4周
|
||||
DaysPerLeapYear = 366 // 每闰年366天
|
||||
DaysPerNormalYear = 365 // 每常规年365天
|
||||
DaysPerWeek = 7 // 每周7天
|
||||
HoursPerWeek = 168 // 每周168小时
|
||||
HoursPerDay = 24 // 每天24小时
|
||||
MinutesPerDay = 1440 // 每天1440分钟
|
||||
MinutesPerHour = 60 // 每小时60分钟
|
||||
SecondsPerWeek = 604800 // 每周604800秒
|
||||
SecondsPerDay = 86400 // 每天86400秒
|
||||
SecondsPerHour = 3600 // 每小时3600秒
|
||||
SecondsPerMinute = 60 // 每分钟60秒
|
||||
)
|
||||
|
||||
// layout constants
|
||||
// 布局模板常量
|
||||
const (
|
||||
AtomLayout = RFC3339Layout
|
||||
ANSICLayout = time.ANSIC
|
||||
CookieLayout = "Monday, 02-Jan-2006 15:04:05 MST"
|
||||
KitchenLayout = time.Kitchen
|
||||
RssLayout = time.RFC1123Z
|
||||
RubyDateLayout = time.RubyDate
|
||||
UnixDateLayout = time.UnixDate
|
||||
W3cLayout = RFC3339Layout
|
||||
|
||||
RFC1036Layout = "Mon, 02 Jan 06 15:04:05 -0700"
|
||||
RFC1123Layout = time.RFC1123
|
||||
RFC1123ZLayout = time.RFC1123Z
|
||||
RFC2822Layout = time.RFC1123Z
|
||||
RFC3339Layout = "2006-01-02T15:04:05Z07:00"
|
||||
RFC3339MilliLayout = "2006-01-02T15:04:05.999Z07:00"
|
||||
RFC3339MicroLayout = "2006-01-02T15:04:05.999999Z07:00"
|
||||
RFC3339NanoLayout = "2006-01-02T15:04:05.999999999Z07:00"
|
||||
RFC7231Layout = "Mon, 02 Jan 2006 15:04:05 MST"
|
||||
RFC822Layout = time.RFC822
|
||||
RFC822ZLayout = time.RFC822Z
|
||||
RFC850Layout = time.RFC850
|
||||
|
||||
ISO8601Layout = "2006-01-02T15:04:05-07:00"
|
||||
ISO8601MilliLayout = "2006-01-02T15:04:05.999-07:00"
|
||||
ISO8601MicroLayout = "2006-01-02T15:04:05.999999-07:00"
|
||||
ISO8601NanoLayout = "2006-01-02T15:04:05.999999999-07:00"
|
||||
|
||||
ISO8601ZuluLayout = "2006-01-02T15:04:05Z"
|
||||
ISO8601ZuluMilliLayout = "2006-01-02T15:04:05.999Z"
|
||||
ISO8601ZuluMicroLayout = "2006-01-02T15:04:05.999999Z"
|
||||
ISO8601ZuluNanoLayout = "2006-01-02T15:04:05.999999999Z"
|
||||
|
||||
FormattedDateLayout = "Jan 2, 2006"
|
||||
FormattedDayDateLayout = "Mon, Jan 2, 2006"
|
||||
|
||||
DayDateTimeLayout = "Mon, Jan 2, 2006 3:04 PM"
|
||||
DateTimeLayout = "2006-01-02 15:04:05"
|
||||
DateTimeMilliLayout = "2006-01-02 15:04:05.999"
|
||||
DateTimeMicroLayout = "2006-01-02 15:04:05.999999"
|
||||
DateTimeNanoLayout = "2006-01-02 15:04:05.999999999"
|
||||
ShortDateTimeLayout = "20060102150405"
|
||||
ShortDateTimeMilliLayout = "20060102150405.999"
|
||||
ShortDateTimeMicroLayout = "20060102150405.999999"
|
||||
ShortDateTimeNanoLayout = "20060102150405.999999999"
|
||||
|
||||
DateLayout = "2006-01-02"
|
||||
DateMilliLayout = "2006-01-02.999"
|
||||
DateMicroLayout = "2006-01-02.999999"
|
||||
DateNanoLayout = "2006-01-02.999999999"
|
||||
ShortDateLayout = "20060102"
|
||||
ShortDateMilliLayout = "20060102.999"
|
||||
ShortDateMicroLayout = "20060102.999999"
|
||||
ShortDateNanoLayout = "20060102.999999999"
|
||||
|
||||
TimeLayout = "15:04:05"
|
||||
TimeMilliLayout = "15:04:05.999"
|
||||
TimeMicroLayout = "15:04:05.999999"
|
||||
TimeNanoLayout = "15:04:05.999999999"
|
||||
ShortTimeLayout = "150405"
|
||||
ShortTimeMilliLayout = "150405.999"
|
||||
ShortTimeMicroLayout = "150405.999999"
|
||||
ShortTimeNanoLayout = "150405.999999999"
|
||||
)
|
||||
|
||||
// format constants
|
||||
// 格式模板常量
|
||||
const (
|
||||
AtomFormat = "Y-m-d\\TH:i:sP"
|
||||
ANSICFormat = "D M j H:i:s Y"
|
||||
CookieFormat = "l, d-M-Y H:i:s T"
|
||||
KitchenFormat = "g:iA"
|
||||
RssFormat = "D, d M Y H:i:s O"
|
||||
RubyDateFormat = "D M d H:i:s O Y"
|
||||
UnixDateFormat = "D M j H:i:s T Y"
|
||||
|
||||
RFC1036Format = "D, d M y H:i:s O"
|
||||
RFC1123Format = "D, d M Y H:i:s T"
|
||||
RFC1123ZFormat = "D, d M Y H:i:s O"
|
||||
RFC2822Format = "D, d M Y H:i:s O"
|
||||
RFC3339Format = "Y-m-d\\TH:i:sP"
|
||||
RFC3339MilliFormat = "Y-m-d\\TH:i:s.vP"
|
||||
RFC3339MicroFormat = "Y-m-d\\TH:i:s.uP"
|
||||
RFC3339NanoFormat = "Y-m-d\\TH:i:s.xP"
|
||||
RFC7231Format = "D, d M Y H:i:s T"
|
||||
RFC822Format = "d M y H:i T"
|
||||
RFC822ZFormat = "d M y H:i O"
|
||||
RFC850Format = "l, d-M-y H:i:s T"
|
||||
|
||||
ISO8601Format = "Y-m-d\\TH:i:sP"
|
||||
ISO8601MilliFormat = "Y-m-d\\TH:i:s.vP"
|
||||
ISO8601MicroFormat = "Y-m-d\\TH:i:s.uP"
|
||||
ISO8601NanoFormat = "Y-m-d\\TH:i:s.xP"
|
||||
|
||||
ISO8601ZuluFormat = "Y-m-d\\TH:i:s\\Z"
|
||||
ISO8601ZuluMilliFormat = "Y-m-d\\TH:i:s.v\\Z"
|
||||
ISO8601ZuluMicroFormat = "Y-m-d\\TH:i:s.u\\Z"
|
||||
ISO8601ZuluNanoFormat = "Y-m-d\\TH:i:s.x\\Z"
|
||||
|
||||
FormattedDateFormat = "M j, Y"
|
||||
FormattedDayDateFormat = "D, M j, Y"
|
||||
|
||||
DayDateTimeFormat = "D, M j, Y g:i A"
|
||||
DateTimeFormat = "Y-m-d H:i:s"
|
||||
DateTimeMilliFormat = "Y-m-d H:i:s.v"
|
||||
DateTimeMicroFormat = "Y-m-d H:i:s.u"
|
||||
DateTimeNanoFormat = "Y-m-d H:i:s.x"
|
||||
ShortDateTimeFormat = "YmdHis"
|
||||
ShortDateTimeMilliFormat = "YmdHis.v"
|
||||
ShortDateTimeMicroFormat = "YmdHis.u"
|
||||
ShortDateTimeNanoFormat = "YmdHis.x"
|
||||
|
||||
DateFormat = "Y-m-d"
|
||||
DateMilliFormat = "Y-m-d.v"
|
||||
DateMicroFormat = "Y-m-d.u"
|
||||
DateNanoFormat = "Y-m-d.x"
|
||||
ShortDateFormat = "Ymd"
|
||||
ShortDateMilliFormat = "Ymd.v"
|
||||
ShortDateMicroFormat = "Ymd.u"
|
||||
ShortDateNanoFormat = "Ymd.x"
|
||||
|
||||
TimeFormat = "H:i:s"
|
||||
TimeMilliFormat = "H:i:s.v"
|
||||
TimeMicroFormat = "H:i:s.u"
|
||||
TimeNanoFormat = "H:i:s.x"
|
||||
ShortTimeFormat = "His"
|
||||
ShortTimeMilliFormat = "His.v"
|
||||
ShortTimeMicroFormat = "His.u"
|
||||
ShortTimeNanoFormat = "His.x"
|
||||
)
|
||||
|
||||
// Carbon defines a Carbon struct.
|
||||
// 定义 Carbon 结构体
|
||||
type Carbon struct {
|
||||
time time.Time
|
||||
testNow int64 // nanosecond timestamp of test now time
|
||||
layout string
|
||||
weekStartsAt time.Weekday
|
||||
loc *time.Location
|
||||
lang *Language
|
||||
Error error
|
||||
}
|
||||
|
||||
// NewCarbon returns a new Carbon instance.
|
||||
// 初始化 Carbon 结构体
|
||||
func NewCarbon() Carbon {
|
||||
c := Carbon{lang: NewLanguage()}
|
||||
c.loc, c.Error = getLocationByTimezone(defaultTimezone)
|
||||
if weekday, ok := weekdays[defaultWeekStartsAt]; ok {
|
||||
c.weekStartsAt = weekday
|
||||
}
|
||||
c.layout = defaultLayout
|
||||
return c
|
||||
}
|
||||
|
||||
// DateTime defines a DateTime struct.
|
||||
// 定义 DateTime 结构体
|
||||
type DateTime struct {
|
||||
Carbon
|
||||
}
|
||||
|
||||
// NewDateTime returns a new DateTime instance.
|
||||
// 初始化 DateTime 结构体
|
||||
func NewDateTime(carbon Carbon) DateTime {
|
||||
return DateTime{Carbon: carbon}
|
||||
}
|
||||
|
||||
// DateTimeMilli defines a DateTimeMilli struct.
|
||||
// 定义 DateTimeMilli 结构体
|
||||
type DateTimeMilli struct {
|
||||
Carbon
|
||||
}
|
||||
|
||||
// NewDateTimeMilli returns a new DateTimeMilli instance.
|
||||
// 初始化 DateTimeMilli 结构体
|
||||
func NewDateTimeMilli(carbon Carbon) DateTimeMilli {
|
||||
return DateTimeMilli{Carbon: carbon}
|
||||
}
|
||||
|
||||
// DateTimeMicro defines a DateTimeMicro struct.
|
||||
// 定义 DateTimeMicro 结构体
|
||||
type DateTimeMicro struct {
|
||||
Carbon
|
||||
}
|
||||
|
||||
// NewDateTimeMicro returns a new DateTimeMicro instance.
|
||||
// 初始化 DateTimeMicro 结构体
|
||||
func NewDateTimeMicro(carbon Carbon) DateTimeMicro {
|
||||
return DateTimeMicro{Carbon: carbon}
|
||||
}
|
||||
|
||||
// DateTimeNano defines a DateTimeNano struct.
|
||||
// 定义 DateTimeNano 结构体
|
||||
type DateTimeNano struct {
|
||||
Carbon
|
||||
}
|
||||
|
||||
// NewDateTimeNano returns a new DateTimeNano instance.
|
||||
// 初始化 DateTimeNano 结构体
|
||||
func NewDateTimeNano(carbon Carbon) DateTimeNano {
|
||||
return DateTimeNano{Carbon: carbon}
|
||||
}
|
||||
|
||||
// Date defines a Date struct.
|
||||
// 定义 Date 结构体
|
||||
type Date struct {
|
||||
Carbon
|
||||
}
|
||||
|
||||
// NewDate returns a new Date instance.
|
||||
// 初始化 Date 结构体
|
||||
func NewDate(carbon Carbon) Date {
|
||||
return Date{Carbon: carbon}
|
||||
}
|
||||
|
||||
// DateMilli defines a DateMilli struct.
|
||||
// 定义 DateMilli 结构体
|
||||
type DateMilli struct {
|
||||
Carbon
|
||||
}
|
||||
|
||||
// NewDateMilli returns a new DateMilli instance.
|
||||
// 初始化 DateMilli 结构体
|
||||
func NewDateMilli(carbon Carbon) DateMilli {
|
||||
return DateMilli{Carbon: carbon}
|
||||
}
|
||||
|
||||
// DateMicro defines a DateMicro struct.
|
||||
// 定义 DateMicro 结构体
|
||||
type DateMicro struct {
|
||||
Carbon
|
||||
}
|
||||
|
||||
// NewDateMicro returns a new DateMicro instance.
|
||||
// 初始化 DateMicro 结构体
|
||||
func NewDateMicro(carbon Carbon) DateMicro {
|
||||
return DateMicro{Carbon: carbon}
|
||||
}
|
||||
|
||||
// DateNano defines a DateNano struct.
|
||||
// 定义 DateNano 结构体
|
||||
type DateNano struct {
|
||||
Carbon
|
||||
}
|
||||
|
||||
// NewDateNano returns a new DateNano instance.
|
||||
// 初始化 DateNano 结构体
|
||||
func NewDateNano(carbon Carbon) DateNano {
|
||||
return DateNano{Carbon: carbon}
|
||||
}
|
||||
|
||||
// Time defines a Time struct.
|
||||
// 定义 Time 结构体
|
||||
type Time struct {
|
||||
Carbon
|
||||
}
|
||||
|
||||
// NewTime returns a new Time instance.
|
||||
// 初始化 Time 结构体
|
||||
func NewTime(carbon Carbon) Time {
|
||||
return Time{Carbon: carbon}
|
||||
}
|
||||
|
||||
// TimeMilli defines a TimeMilli struct.
|
||||
// 定义 TimeMilli 结构体
|
||||
type TimeMilli struct {
|
||||
Carbon
|
||||
}
|
||||
|
||||
// NewTimeMilli returns a new TimeMilli instance.
|
||||
// 初始化 TimeMilli 结构体
|
||||
func NewTimeMilli(carbon Carbon) TimeMilli {
|
||||
return TimeMilli{Carbon: carbon}
|
||||
}
|
||||
|
||||
// TimeMicro defines a TimeMicro struct.
|
||||
// 定义 TimeMicro 结构体
|
||||
type TimeMicro struct {
|
||||
Carbon
|
||||
}
|
||||
|
||||
// NewTimeMicro returns a new TimeMicro instance.
|
||||
// 初始化 TimeMicro 结构体
|
||||
func NewTimeMicro(carbon Carbon) TimeMicro {
|
||||
return TimeMicro{Carbon: carbon}
|
||||
}
|
||||
|
||||
// TimeNano defines a TimeNano struct.
|
||||
// 定义 TimeNano 结构体
|
||||
type TimeNano struct {
|
||||
Carbon
|
||||
}
|
||||
|
||||
// NewTimeNano returns a new TimeNano instance.
|
||||
// 初始化 TimeNano 结构体
|
||||
func NewTimeNano(carbon Carbon) TimeNano {
|
||||
return TimeNano{Carbon: carbon}
|
||||
}
|
||||
|
||||
// Timestamp defines a Timestamp struct.
|
||||
// 定义 Timestamp 结构体
|
||||
type Timestamp struct {
|
||||
Carbon
|
||||
}
|
||||
|
||||
// NewTimestamp returns a new Timestamp instance.
|
||||
// 初始化 Timestamp 结构体
|
||||
func NewTimestamp(carbon Carbon) Timestamp {
|
||||
return Timestamp{Carbon: carbon}
|
||||
}
|
||||
|
||||
// TimestampMilli defines a TimestampMilli struct.
|
||||
// 定义 TimestampMilli 结构体
|
||||
type TimestampMilli struct {
|
||||
Carbon
|
||||
}
|
||||
|
||||
// NewTimestampMilli returns a new TimestampMilli instance.
|
||||
// 初始化 TimestampMilli 结构体
|
||||
func NewTimestampMilli(carbon Carbon) TimestampMilli {
|
||||
return TimestampMilli{Carbon: carbon}
|
||||
}
|
||||
|
||||
// TimestampMicro defines a TimestampMicro struct.
|
||||
// 定义 TimestampMicro 结构体
|
||||
type TimestampMicro struct {
|
||||
Carbon
|
||||
}
|
||||
|
||||
// NewTimestampMicro returns a new TimestampMicro instance.
|
||||
// 初始化 TimestampMicro 结构体
|
||||
func NewTimestampMicro(carbon Carbon) TimestampMicro {
|
||||
return TimestampMicro{Carbon: carbon}
|
||||
}
|
||||
|
||||
// TimestampNano defines a TimestampNano struct.
|
||||
// 定义 TimestampNano 结构体
|
||||
type TimestampNano struct {
|
||||
Carbon
|
||||
}
|
||||
|
||||
// NewTimestampNano returns a new TimestampNano instance.
|
||||
// 初始化 TimestampNano 结构体
|
||||
func NewTimestampNano(carbon Carbon) TimestampNano {
|
||||
return TimestampNano{Carbon: carbon}
|
||||
}
|
||||
517
vendor/github.com/dromara/carbon/v2/comparer.go
generated
vendored
Normal file
517
vendor/github.com/dromara/carbon/v2/comparer.go
generated
vendored
Normal file
@@ -0,0 +1,517 @@
|
||||
package carbon
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// IsDST reports whether is daylight saving time.
|
||||
// 是否是夏令时
|
||||
func (c Carbon) IsDST() bool {
|
||||
return c.time.IsDST()
|
||||
}
|
||||
|
||||
// IsZero reports whether is zero time(0001-01-01 00:00:00 +0000 UTC).
|
||||
// 是否是零值时间(0001-01-01 00:00:00 +0000 UTC)
|
||||
func (c Carbon) IsZero() bool {
|
||||
return c.time.IsZero()
|
||||
}
|
||||
|
||||
// IsValid reports whether is valid time.
|
||||
// 是否是有效时间
|
||||
func (c Carbon) IsValid() bool {
|
||||
if c.IsZero() {
|
||||
return false
|
||||
}
|
||||
if c.Year() >= MinValue().Year() && c.Year() <= MaxValue().Year() && c.Month() > 0 && c.Day() > 0 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// IsInvalid reports whether is invalid time.
|
||||
// 是否是无效时间
|
||||
func (c Carbon) IsInvalid() bool {
|
||||
return !c.IsValid()
|
||||
}
|
||||
|
||||
// IsAM reports whether is before noon.
|
||||
// 是否是上午
|
||||
func (c Carbon) IsAM() bool {
|
||||
return c.Format("a") == "am"
|
||||
}
|
||||
|
||||
// IsPM reports whether is after noon.
|
||||
// 是否是下午
|
||||
func (c Carbon) IsPM() bool {
|
||||
return c.Format("a") == "pm"
|
||||
}
|
||||
|
||||
// IsNow reports whether is now time.
|
||||
// 是否是当前时间
|
||||
func (c Carbon) IsNow() bool {
|
||||
if c.Error != nil {
|
||||
return false
|
||||
}
|
||||
return c.Timestamp() == c.Now().Timestamp()
|
||||
}
|
||||
|
||||
// IsFuture reports whether is future time.
|
||||
// 是否是未来时间
|
||||
func (c Carbon) IsFuture() bool {
|
||||
if c.Error != nil {
|
||||
return false
|
||||
}
|
||||
return c.Timestamp() > c.Now().Timestamp()
|
||||
}
|
||||
|
||||
// IsPast reports whether is past time.
|
||||
// 是否是过去时间
|
||||
func (c Carbon) IsPast() bool {
|
||||
if c.Error != nil {
|
||||
return false
|
||||
}
|
||||
return c.Timestamp() < c.Now().Timestamp()
|
||||
}
|
||||
|
||||
// IsLeapYear reports whether is a leap year.
|
||||
// 是否是闰年
|
||||
func (c Carbon) IsLeapYear() bool {
|
||||
if c.Error != nil {
|
||||
return false
|
||||
}
|
||||
year := c.Year()
|
||||
if year%400 == 0 || (year%4 == 0 && year%100 != 0) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// IsLongYear reports whether is a long year, see https://en.wikipedia.org/wiki/ISO_8601#Week_dates.
|
||||
// 是否是长年
|
||||
func (c Carbon) IsLongYear() bool {
|
||||
if c.Error != nil {
|
||||
return false
|
||||
}
|
||||
_, w := time.Date(c.Year(), 12, 31, 0, 0, 0, 0, c.loc).ISOWeek()
|
||||
return w == weeksPerLongYear
|
||||
}
|
||||
|
||||
// IsJanuary reports whether is January.
|
||||
// 是否是一月
|
||||
func (c Carbon) IsJanuary() bool {
|
||||
if c.Error != nil {
|
||||
return false
|
||||
}
|
||||
return c.Month() == int(time.January)
|
||||
}
|
||||
|
||||
// IsFebruary reports whether is February.
|
||||
// 是否是二月
|
||||
func (c Carbon) IsFebruary() bool {
|
||||
if c.Error != nil {
|
||||
return false
|
||||
}
|
||||
return c.Month() == int(time.February)
|
||||
}
|
||||
|
||||
// IsMarch reports whether is March.
|
||||
// 是否是三月
|
||||
func (c Carbon) IsMarch() bool {
|
||||
if c.Error != nil {
|
||||
return false
|
||||
}
|
||||
return c.Month() == int(time.March)
|
||||
}
|
||||
|
||||
// IsApril reports whether is April.
|
||||
// 是否是四月
|
||||
func (c Carbon) IsApril() bool {
|
||||
if c.Error != nil {
|
||||
return false
|
||||
}
|
||||
return c.Month() == int(time.April)
|
||||
}
|
||||
|
||||
// IsMay reports whether is May.
|
||||
// 是否是五月
|
||||
func (c Carbon) IsMay() bool {
|
||||
if c.Error != nil {
|
||||
return false
|
||||
}
|
||||
return c.Month() == int(time.May)
|
||||
}
|
||||
|
||||
// IsJune reports whether is June.
|
||||
// 是否是六月
|
||||
func (c Carbon) IsJune() bool {
|
||||
if c.Error != nil {
|
||||
return false
|
||||
}
|
||||
return c.Month() == int(time.June)
|
||||
}
|
||||
|
||||
// IsJuly reports whether is July.
|
||||
// 是否是七月
|
||||
func (c Carbon) IsJuly() bool {
|
||||
if c.Error != nil {
|
||||
return false
|
||||
}
|
||||
return c.Month() == int(time.July)
|
||||
}
|
||||
|
||||
// IsAugust reports whether is August.
|
||||
// 是否是八月
|
||||
func (c Carbon) IsAugust() bool {
|
||||
if c.Error != nil {
|
||||
return false
|
||||
}
|
||||
return c.Month() == int(time.August)
|
||||
}
|
||||
|
||||
// IsSeptember reports whether is September.
|
||||
// 是否是九月
|
||||
func (c Carbon) IsSeptember() bool {
|
||||
if c.Error != nil {
|
||||
return false
|
||||
}
|
||||
return c.Month() == int(time.September)
|
||||
}
|
||||
|
||||
// IsOctober reports whether is October.
|
||||
// 是否是十月
|
||||
func (c Carbon) IsOctober() bool {
|
||||
if c.Error != nil {
|
||||
return false
|
||||
}
|
||||
return c.Month() == int(time.October)
|
||||
}
|
||||
|
||||
// IsNovember reports whether is November.
|
||||
// 是否是十一月
|
||||
func (c Carbon) IsNovember() bool {
|
||||
if c.Error != nil {
|
||||
return false
|
||||
}
|
||||
return c.Month() == int(time.November)
|
||||
}
|
||||
|
||||
// IsDecember reports whether is December.
|
||||
// 是否是十二月
|
||||
func (c Carbon) IsDecember() bool {
|
||||
if c.Error != nil {
|
||||
return false
|
||||
}
|
||||
return c.Month() == int(time.December)
|
||||
}
|
||||
|
||||
// IsMonday reports whether is Monday.
|
||||
// 是否是周一
|
||||
func (c Carbon) IsMonday() bool {
|
||||
if c.Error != nil {
|
||||
return false
|
||||
}
|
||||
return c.StdTime().Weekday() == time.Monday
|
||||
}
|
||||
|
||||
// IsTuesday reports whether is Tuesday.
|
||||
// 是否是周二
|
||||
func (c Carbon) IsTuesday() bool {
|
||||
if c.Error != nil {
|
||||
return false
|
||||
}
|
||||
return c.StdTime().Weekday() == time.Tuesday
|
||||
}
|
||||
|
||||
// IsWednesday reports whether is Wednesday.
|
||||
// 是否是周三
|
||||
func (c Carbon) IsWednesday() bool {
|
||||
if c.Error != nil {
|
||||
return false
|
||||
}
|
||||
return c.StdTime().Weekday() == time.Wednesday
|
||||
}
|
||||
|
||||
// IsThursday reports whether is Thursday.
|
||||
// 是否是周四
|
||||
func (c Carbon) IsThursday() bool {
|
||||
if c.Error != nil {
|
||||
return false
|
||||
}
|
||||
return c.StdTime().Weekday() == time.Thursday
|
||||
}
|
||||
|
||||
// IsFriday reports whether is Friday.
|
||||
// 是否是周五
|
||||
func (c Carbon) IsFriday() bool {
|
||||
if c.Error != nil {
|
||||
return false
|
||||
}
|
||||
return c.StdTime().Weekday() == time.Friday
|
||||
}
|
||||
|
||||
// IsSaturday reports whether is Saturday.
|
||||
// 是否是周六
|
||||
func (c Carbon) IsSaturday() bool {
|
||||
if c.Error != nil {
|
||||
return false
|
||||
}
|
||||
return c.StdTime().Weekday() == time.Saturday
|
||||
}
|
||||
|
||||
// IsSunday reports whether is Sunday.
|
||||
// 是否是周日
|
||||
func (c Carbon) IsSunday() bool {
|
||||
if c.Error != nil {
|
||||
return false
|
||||
}
|
||||
return c.StdTime().Weekday() == time.Sunday
|
||||
}
|
||||
|
||||
// IsWeekday reports whether is weekday.
|
||||
// 是否是工作日
|
||||
func (c Carbon) IsWeekday() bool {
|
||||
if c.Error != nil {
|
||||
return false
|
||||
}
|
||||
return !c.IsSaturday() && !c.IsSunday()
|
||||
}
|
||||
|
||||
// IsWeekend reports whether is weekend.
|
||||
// 是否是周末
|
||||
func (c Carbon) IsWeekend() bool {
|
||||
if c.Error != nil {
|
||||
return false
|
||||
}
|
||||
return c.IsSaturday() || c.IsSunday()
|
||||
}
|
||||
|
||||
// IsYesterday reports whether is yesterday.
|
||||
// 是否是昨天
|
||||
func (c Carbon) IsYesterday() bool {
|
||||
if c.Error != nil {
|
||||
return false
|
||||
}
|
||||
return c.ToDateString() == Yesterday().ToDateString()
|
||||
}
|
||||
|
||||
// IsToday reports whether is today.
|
||||
// 是否是今天
|
||||
func (c Carbon) IsToday() bool {
|
||||
if c.Error != nil {
|
||||
return false
|
||||
}
|
||||
return c.ToDateString() == Now().ToDateString()
|
||||
}
|
||||
|
||||
// IsTomorrow reports whether is tomorrow.
|
||||
// 是否是明天
|
||||
func (c Carbon) IsTomorrow() bool {
|
||||
if c.Error != nil {
|
||||
return false
|
||||
}
|
||||
return c.ToDateString() == Tomorrow().ToDateString()
|
||||
}
|
||||
|
||||
// IsSameCentury reports whether is same century.
|
||||
// 是否是同一世纪
|
||||
func (c Carbon) IsSameCentury(t Carbon) bool {
|
||||
if c.Error != nil || t.Error != nil {
|
||||
return false
|
||||
}
|
||||
return c.Century() == t.Century()
|
||||
}
|
||||
|
||||
// IsSameDecade reports whether is same decade.
|
||||
// 是否是同一年代
|
||||
func (c Carbon) IsSameDecade(t Carbon) bool {
|
||||
if c.Error != nil || t.Error != nil {
|
||||
return false
|
||||
}
|
||||
return c.Decade() == t.Decade()
|
||||
}
|
||||
|
||||
// IsSameYear reports whether is same year.
|
||||
// 是否是同一年
|
||||
func (c Carbon) IsSameYear(t Carbon) bool {
|
||||
if c.Error != nil || t.Error != nil {
|
||||
return false
|
||||
}
|
||||
return c.Year() == t.Year()
|
||||
}
|
||||
|
||||
// IsSameQuarter reports whether is same quarter.
|
||||
// 是否是同一季节
|
||||
func (c Carbon) IsSameQuarter(t Carbon) bool {
|
||||
if c.Error != nil || t.Error != nil {
|
||||
return false
|
||||
}
|
||||
return c.Quarter() == t.Quarter()
|
||||
}
|
||||
|
||||
// IsSameMonth reports whether is same month.
|
||||
// 是否是同一月
|
||||
func (c Carbon) IsSameMonth(t Carbon) bool {
|
||||
if c.Error != nil || t.Error != nil {
|
||||
return false
|
||||
}
|
||||
return c.Format("Ym") == t.Format("Ym")
|
||||
}
|
||||
|
||||
// IsSameDay reports whether is same day.
|
||||
// 是否是同一天
|
||||
func (c Carbon) IsSameDay(t Carbon) bool {
|
||||
if c.Error != nil || t.Error != nil {
|
||||
return false
|
||||
}
|
||||
return c.Format("Ymd") == t.Format("Ymd")
|
||||
}
|
||||
|
||||
// IsSameHour reports whether is same hour.
|
||||
// 是否是同一小时
|
||||
func (c Carbon) IsSameHour(t Carbon) bool {
|
||||
if c.Error != nil || t.Error != nil {
|
||||
return false
|
||||
}
|
||||
return c.Format("YmdH") == t.Format("YmdH")
|
||||
}
|
||||
|
||||
// IsSameMinute reports whether is same minute.
|
||||
// 是否是同一分钟
|
||||
func (c Carbon) IsSameMinute(t Carbon) bool {
|
||||
if c.Error != nil || t.Error != nil {
|
||||
return false
|
||||
}
|
||||
return c.Format("YmdHi") == t.Format("YmdHi")
|
||||
}
|
||||
|
||||
// IsSameSecond reports whether is same second.
|
||||
// 是否是同一秒
|
||||
func (c Carbon) IsSameSecond(t Carbon) bool {
|
||||
if c.Error != nil || t.Error != nil {
|
||||
return false
|
||||
}
|
||||
return c.Format("YmdHis") == t.Format("YmdHis")
|
||||
|
||||
}
|
||||
|
||||
// Compare compares by an operator.
|
||||
// 时间比较
|
||||
func (c Carbon) Compare(operator string, t Carbon) bool {
|
||||
if c.Error != nil || t.Error != nil {
|
||||
return false
|
||||
}
|
||||
switch operator {
|
||||
case "=":
|
||||
return c.Eq(t)
|
||||
case "<>", "!=":
|
||||
return !c.Eq(t)
|
||||
case ">":
|
||||
return c.Gt(t)
|
||||
case ">=":
|
||||
return c.Gte(t)
|
||||
case "<":
|
||||
return c.Lt(t)
|
||||
case "<=":
|
||||
return c.Lte(t)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Gt reports whether greater than.
|
||||
// 是否大于
|
||||
func (c Carbon) Gt(t Carbon) bool {
|
||||
if c.Error != nil || t.Error != nil {
|
||||
return false
|
||||
}
|
||||
return c.time.After(t.time)
|
||||
}
|
||||
|
||||
// Lt reports whether less than.
|
||||
// 是否小于
|
||||
func (c Carbon) Lt(t Carbon) bool {
|
||||
if c.Error != nil || t.Error != nil {
|
||||
return false
|
||||
}
|
||||
return c.time.Before(t.time)
|
||||
}
|
||||
|
||||
// Eq reports whether equal.
|
||||
// 是否等于
|
||||
func (c Carbon) Eq(t Carbon) bool {
|
||||
if c.Error != nil || t.Error != nil {
|
||||
return false
|
||||
}
|
||||
return c.time.Equal(t.time)
|
||||
}
|
||||
|
||||
// Ne reports whether not equal.
|
||||
// 是否不等于
|
||||
func (c Carbon) Ne(t Carbon) bool {
|
||||
return !c.Eq(t)
|
||||
}
|
||||
|
||||
// Gte reports whether greater than or equal.
|
||||
// 是否大于等于
|
||||
func (c Carbon) Gte(t Carbon) bool {
|
||||
if c.Error != nil || t.Error != nil {
|
||||
return false
|
||||
}
|
||||
return c.Gt(t) || c.Eq(t)
|
||||
}
|
||||
|
||||
// Lte reports whether less than or equal.
|
||||
// 是否小于等于
|
||||
func (c Carbon) Lte(t Carbon) bool {
|
||||
if c.Error != nil || t.Error != nil {
|
||||
return false
|
||||
}
|
||||
return c.Lt(t) || c.Eq(t)
|
||||
}
|
||||
|
||||
// Between reports whether between two times, excluded the start and end time.
|
||||
// 是否在两个时间之间(不包括这两个时间)
|
||||
func (c Carbon) Between(start Carbon, end Carbon) bool {
|
||||
if c.Error != nil || start.Error != nil || end.Error != nil {
|
||||
return false
|
||||
}
|
||||
if c.Gt(start) && c.Lt(end) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// BetweenIncludedStart reports whether between two times, included the start time.
|
||||
// 是否在两个时间之间(包括开始时间)
|
||||
func (c Carbon) BetweenIncludedStart(start Carbon, end Carbon) bool {
|
||||
if c.Error != nil || start.Error != nil || end.Error != nil {
|
||||
return false
|
||||
}
|
||||
if c.Gte(start) && c.Lt(end) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// BetweenIncludedEnd reports whether between two times, included the end time.
|
||||
// 是否在两个时间之间(包括结束时间)
|
||||
func (c Carbon) BetweenIncludedEnd(start Carbon, end Carbon) bool {
|
||||
if c.Error != nil || start.Error != nil || end.Error != nil {
|
||||
return false
|
||||
}
|
||||
if c.Gt(start) && c.Lte(end) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// BetweenIncludedBoth reports whether between two times, included the start and end time.
|
||||
// 是否在两个时间之间(包括这两个时间)
|
||||
func (c Carbon) BetweenIncludedBoth(start Carbon, end Carbon) bool {
|
||||
if c.Error != nil || start.Error != nil || end.Error != nil {
|
||||
return false
|
||||
}
|
||||
if c.Gte(start) && c.Lte(end) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
246
vendor/github.com/dromara/carbon/v2/constellation.go
generated
vendored
Normal file
246
vendor/github.com/dromara/carbon/v2/constellation.go
generated
vendored
Normal file
@@ -0,0 +1,246 @@
|
||||
package carbon
|
||||
|
||||
import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
var constellations = []struct {
|
||||
startMonth, startDay int
|
||||
endMonth, endDay int
|
||||
}{
|
||||
{3, 21, 4, 19}, // Aries
|
||||
{4, 20, 5, 20}, // Taurus
|
||||
{5, 21, 6, 21}, // Gemini
|
||||
{6, 22, 7, 22}, // Cancer
|
||||
{7, 23, 8, 22}, // Leo
|
||||
{8, 23, 9, 22}, // Virgo
|
||||
{9, 23, 10, 23}, // Libra
|
||||
{10, 24, 11, 22}, // Scorpio
|
||||
{11, 23, 12, 21}, // Sagittarius
|
||||
{12, 22, 1, 19}, // Capricorn
|
||||
{1, 20, 2, 18}, // Aquarius
|
||||
{2, 19, 3, 20}, // Pisces
|
||||
}
|
||||
|
||||
// Constellation gets constellation name like "Aries", i18n is supported.
|
||||
// 获取星座,支持i18n
|
||||
func (c Carbon) Constellation() string {
|
||||
if c.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
if len(c.lang.resources) == 0 {
|
||||
c.lang.SetLocale(defaultLocale)
|
||||
}
|
||||
index := -1
|
||||
_, month, day := c.Date()
|
||||
for i := 0; i < len(constellations); i++ {
|
||||
constellation := constellations[i]
|
||||
if month == constellation.startMonth && day >= constellation.startDay {
|
||||
index = i
|
||||
}
|
||||
if month == constellation.endMonth && day <= constellation.endDay {
|
||||
index = i
|
||||
}
|
||||
}
|
||||
c.lang.rw.RLock()
|
||||
defer c.lang.rw.RUnlock()
|
||||
if resources, ok := c.lang.resources["constellations"]; ok {
|
||||
slice := strings.Split(resources, "|")
|
||||
if len(slice) == MonthsPerYear {
|
||||
return slice[index]
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// IsAries reports whether is Aries.
|
||||
// 是否是白羊座
|
||||
func (c Carbon) IsAries() bool {
|
||||
if c.IsInvalid() {
|
||||
return false
|
||||
}
|
||||
_, month, day := c.Date()
|
||||
if month == 3 && day >= 21 {
|
||||
return true
|
||||
}
|
||||
if month == 4 && day <= 19 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// IsTaurus reports whether is Taurus.
|
||||
// 是否是金牛座
|
||||
func (c Carbon) IsTaurus() bool {
|
||||
if c.IsInvalid() {
|
||||
return false
|
||||
}
|
||||
_, month, day := c.Date()
|
||||
if month == 4 && day >= 20 {
|
||||
return true
|
||||
}
|
||||
if month == 5 && day <= 20 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// IsGemini reports whether is Gemini.
|
||||
// 是否是双子座
|
||||
func (c Carbon) IsGemini() bool {
|
||||
if c.IsInvalid() {
|
||||
return false
|
||||
}
|
||||
_, month, day := c.Date()
|
||||
if month == 5 && day >= 21 {
|
||||
return true
|
||||
}
|
||||
if month == 6 && day <= 21 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// IsCancer reports whether is Cancer.
|
||||
// 是否是巨蟹座
|
||||
func (c Carbon) IsCancer() bool {
|
||||
if c.IsInvalid() {
|
||||
return false
|
||||
}
|
||||
_, month, day := c.Date()
|
||||
if month == 6 && day >= 22 {
|
||||
return true
|
||||
}
|
||||
if month == 7 && day <= 22 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// IsLeo reports whether is Leo.
|
||||
// 是否是狮子座
|
||||
func (c Carbon) IsLeo() bool {
|
||||
if c.IsInvalid() {
|
||||
return false
|
||||
}
|
||||
_, month, day := c.Date()
|
||||
if month == 7 && day >= 23 {
|
||||
return true
|
||||
}
|
||||
if month == 8 && day <= 22 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// IsVirgo reports whether is Virgo.
|
||||
// 是否是处女座
|
||||
func (c Carbon) IsVirgo() bool {
|
||||
if c.IsInvalid() {
|
||||
return false
|
||||
}
|
||||
_, month, day := c.Date()
|
||||
if month == 8 && day >= 23 {
|
||||
return true
|
||||
}
|
||||
if month == 9 && day <= 22 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// IsLibra reports whether is Libra.
|
||||
// 是否是天秤座
|
||||
func (c Carbon) IsLibra() bool {
|
||||
if c.IsInvalid() {
|
||||
return false
|
||||
}
|
||||
_, month, day := c.Date()
|
||||
if month == 9 && day >= 23 {
|
||||
return true
|
||||
}
|
||||
if month == 10 && day <= 23 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// IsScorpio reports whether is Scorpio.
|
||||
// 是否是天蝎座
|
||||
func (c Carbon) IsScorpio() bool {
|
||||
if c.IsInvalid() {
|
||||
return false
|
||||
}
|
||||
_, month, day := c.Date()
|
||||
if month == 10 && day >= 24 {
|
||||
return true
|
||||
}
|
||||
if month == 11 && day <= 22 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// IsSagittarius reports whether is Sagittarius.
|
||||
// 是否是射手座
|
||||
func (c Carbon) IsSagittarius() bool {
|
||||
if c.IsInvalid() {
|
||||
return false
|
||||
}
|
||||
_, month, day := c.Date()
|
||||
if month == 11 && day >= 22 {
|
||||
return true
|
||||
}
|
||||
if month == 12 && day <= 21 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// IsCapricorn reports whether is Capricorn.
|
||||
// 是否是摩羯座
|
||||
func (c Carbon) IsCapricorn() bool {
|
||||
if c.IsInvalid() {
|
||||
return false
|
||||
}
|
||||
_, month, day := c.Date()
|
||||
if month == 12 && day >= 22 {
|
||||
return true
|
||||
}
|
||||
if month == 1 && day <= 19 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// IsAquarius reports whether is Aquarius.
|
||||
// 是否是水瓶座
|
||||
func (c Carbon) IsAquarius() bool {
|
||||
if c.IsInvalid() {
|
||||
return false
|
||||
}
|
||||
_, month, day := c.Date()
|
||||
if month == 1 && day >= 20 {
|
||||
return true
|
||||
}
|
||||
if month == 2 && day <= 18 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// IsPisces reports whether is Pisces.
|
||||
// 是否是双鱼座
|
||||
func (c Carbon) IsPisces() bool {
|
||||
if c.IsInvalid() {
|
||||
return false
|
||||
}
|
||||
_, month, day := c.Date()
|
||||
if month == 2 && day >= 19 {
|
||||
return true
|
||||
}
|
||||
if month == 3 && day <= 20 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
254
vendor/github.com/dromara/carbon/v2/creator.go
generated
vendored
Normal file
254
vendor/github.com/dromara/carbon/v2/creator.go
generated
vendored
Normal file
@@ -0,0 +1,254 @@
|
||||
package carbon
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// CreateFromStdTime creates a Carbon instance from standard time.Time.
|
||||
// 从标准的 time.Time 创建 Carbon 实例
|
||||
func CreateFromStdTime(tt time.Time, timezone ...string) Carbon {
|
||||
c := NewCarbon()
|
||||
c.loc = tt.Location()
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
c.time = tt
|
||||
return c
|
||||
}
|
||||
|
||||
// CreateFromTimestamp creates a Carbon instance from a given timestamp with second.
|
||||
// 从给定的秒级时间戳创建 Carbon 实例
|
||||
func (c Carbon) CreateFromTimestamp(timestamp int64, timezone ...string) Carbon {
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
if c.Error != nil {
|
||||
return c
|
||||
}
|
||||
c.time = time.Unix(timestamp, 0)
|
||||
return c
|
||||
}
|
||||
|
||||
// CreateFromTimestamp creates a Carbon instance from a given timestamp with second.
|
||||
// 从给定的秒级时间戳创建 Carbon 实例
|
||||
func CreateFromTimestamp(timestamp int64, timezone ...string) Carbon {
|
||||
return NewCarbon().CreateFromTimestamp(timestamp, timezone...)
|
||||
}
|
||||
|
||||
// CreateFromTimestampMilli creates a Carbon instance from a given timestamp with millisecond.
|
||||
// 从给定的毫秒级时间戳创建 Carbon 实例
|
||||
func (c Carbon) CreateFromTimestampMilli(timestamp int64, timezone ...string) Carbon {
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
if c.Error != nil {
|
||||
return c
|
||||
}
|
||||
c.time = time.Unix(timestamp/1e3, (timestamp%1e3)*1e6)
|
||||
return c
|
||||
}
|
||||
|
||||
// CreateFromTimestampMilli creates a Carbon instance from a given timestamp with millisecond.
|
||||
// 从给定的毫秒级时间戳创建 Carbon 实例
|
||||
func CreateFromTimestampMilli(timestamp int64, timezone ...string) Carbon {
|
||||
return NewCarbon().CreateFromTimestampMilli(timestamp, timezone...)
|
||||
}
|
||||
|
||||
// CreateFromTimestampMicro creates a Carbon instance from a given timestamp with microsecond.
|
||||
// 从给定的微秒级时间戳创建 Carbon 实例
|
||||
func (c Carbon) CreateFromTimestampMicro(timestamp int64, timezone ...string) Carbon {
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
if c.Error != nil {
|
||||
return c
|
||||
}
|
||||
c.time = time.Unix(timestamp/1e6, (timestamp%1e6)*1e3)
|
||||
return c
|
||||
}
|
||||
|
||||
// CreateFromTimestampMicro creates a Carbon instance from a given timestamp with microsecond.
|
||||
// 从给定的微秒级时间戳创建 Carbon 实例
|
||||
func CreateFromTimestampMicro(timestamp int64, timezone ...string) Carbon {
|
||||
return NewCarbon().CreateFromTimestampMicro(timestamp, timezone...)
|
||||
}
|
||||
|
||||
// CreateFromTimestampNano creates a Carbon instance from a given timestamp with nanosecond.
|
||||
// 从给定的纳秒级时间戳创建 Carbon 实例
|
||||
func (c Carbon) CreateFromTimestampNano(timestamp int64, timezone ...string) Carbon {
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
if c.Error != nil {
|
||||
return c
|
||||
}
|
||||
c.time = time.Unix(timestamp/1e9, timestamp%1e9)
|
||||
return c
|
||||
}
|
||||
|
||||
// CreateFromTimestampNano creates a Carbon instance from a given timestamp with nanosecond.
|
||||
// 从给定的纳秒级时间戳创建 Carbon 实例
|
||||
func CreateFromTimestampNano(timestamp int64, timezone ...string) Carbon {
|
||||
return NewCarbon().CreateFromTimestampNano(timestamp, timezone...)
|
||||
}
|
||||
|
||||
// CreateFromDateTime creates a Carbon instance from a given date and time.
|
||||
// 从给定的年、月、日、时、分、秒创建 Carbon 实例
|
||||
func (c Carbon) CreateFromDateTime(year, month, day, hour, minute, second int, timezone ...string) Carbon {
|
||||
return c.create(year, month, day, hour, minute, second, 0, timezone...)
|
||||
}
|
||||
|
||||
// CreateFromDateTime creates a Carbon instance from a given date and time.
|
||||
// 从给定的年、月、日、时、分、秒创建 Carbon 实例
|
||||
func CreateFromDateTime(year, month, day, hour, minute, second int, timezone ...string) Carbon {
|
||||
return NewCarbon().CreateFromDateTime(year, month, day, hour, minute, second, timezone...)
|
||||
}
|
||||
|
||||
// CreateFromDateTimeMilli creates a Carbon instance from a given date, time and millisecond.
|
||||
// 从给定的年、月、日、时、分、秒、毫秒创建 Carbon 实例
|
||||
func (c Carbon) CreateFromDateTimeMilli(year, month, day, hour, minute, second, millisecond int, timezone ...string) Carbon {
|
||||
return c.create(year, month, day, hour, minute, second, millisecond*1e6, timezone...)
|
||||
}
|
||||
|
||||
// CreateFromDateTimeMilli creates a Carbon instance from a given date, time and millisecond.
|
||||
// 从给定的年、月、日、时、分、秒、毫秒创建 Carbon 实例
|
||||
func CreateFromDateTimeMilli(year, month, day, hour, minute, second, millisecond int, timezone ...string) Carbon {
|
||||
return NewCarbon().CreateFromDateTimeMilli(year, month, day, hour, minute, second, millisecond, timezone...)
|
||||
}
|
||||
|
||||
// CreateFromDateTimeMicro creates a Carbon instance from a given date, time and microsecond.
|
||||
// 从给定的年、月、日、时、分、秒、微秒创建 Carbon 实例
|
||||
func (c Carbon) CreateFromDateTimeMicro(year, month, day, hour, minute, second, microsecond int, timezone ...string) Carbon {
|
||||
return c.create(year, month, day, hour, minute, second, microsecond*1e3, timezone...)
|
||||
}
|
||||
|
||||
// CreateFromDateTimeMicro creates a Carbon instance from a given date, time and microsecond.
|
||||
// 从给定的年、月、日、时、分、秒、微秒创建 Carbon 实例
|
||||
func CreateFromDateTimeMicro(year, month, day, hour, minute, second, microsecond int, timezone ...string) Carbon {
|
||||
return NewCarbon().CreateFromDateTimeMicro(year, month, day, hour, minute, second, microsecond, timezone...)
|
||||
}
|
||||
|
||||
// CreateFromDateTimeNano creates a Carbon instance from a given date, time and nanosecond.
|
||||
// 从给定的年、月、日、时、分、秒、纳秒创建 Carbon 实例
|
||||
func (c Carbon) CreateFromDateTimeNano(year, month, day, hour, minute, second, nanosecond int, timezone ...string) Carbon {
|
||||
return c.create(year, month, day, hour, minute, second, nanosecond, timezone...)
|
||||
}
|
||||
|
||||
// CreateFromDateTimeNano creates a Carbon instance from a given date, time and nanosecond.
|
||||
// 从给定的年、月、日、时、分、秒、纳秒创建 Carbon 实例
|
||||
func CreateFromDateTimeNano(year, month, day, hour, minute, second, nanosecond int, timezone ...string) Carbon {
|
||||
return NewCarbon().CreateFromDateTimeNano(year, month, day, hour, minute, second, nanosecond, timezone...)
|
||||
}
|
||||
|
||||
// CreateFromDate creates a Carbon instance from a given date.
|
||||
// 从给定的年、月、日创建 Carbon 实例
|
||||
func (c Carbon) CreateFromDate(year, month, day int, timezone ...string) Carbon {
|
||||
return c.create(year, month, day, 0, 0, 0, 0, timezone...)
|
||||
}
|
||||
|
||||
// CreateFromDate creates a Carbon instance from a given date.
|
||||
// 从给定的年、月、日创建 Carbon 实例
|
||||
func CreateFromDate(year, month, day int, timezone ...string) Carbon {
|
||||
return NewCarbon().CreateFromDate(year, month, day, timezone...)
|
||||
}
|
||||
|
||||
// CreateFromDateMilli creates a Carbon instance from a given date and millisecond.
|
||||
// 从给定的年、月、日、毫秒创建 Carbon 实例
|
||||
func (c Carbon) CreateFromDateMilli(year, month, day, millisecond int, timezone ...string) Carbon {
|
||||
return c.create(year, month, day, 0, 0, 0, millisecond*1e6, timezone...)
|
||||
}
|
||||
|
||||
// CreateFromDateMilli creates a Carbon instance from a given date and millisecond.
|
||||
// 从给定的年、月、日、毫秒创建 Carbon 实例
|
||||
func CreateFromDateMilli(year, month, day, millisecond int, timezone ...string) Carbon {
|
||||
return NewCarbon().CreateFromDateMilli(year, month, day, millisecond, timezone...)
|
||||
}
|
||||
|
||||
// CreateFromDateMicro creates a Carbon instance from a given date and microsecond.
|
||||
// 从给定的年、月、日、微秒创建 Carbon 实例
|
||||
func (c Carbon) CreateFromDateMicro(year, month, day, microsecond int, timezone ...string) Carbon {
|
||||
return c.create(year, month, day, 0, 0, 0, microsecond*1e3, timezone...)
|
||||
}
|
||||
|
||||
// CreateFromDateMicro creates a Carbon instance from a given date and microsecond.
|
||||
// 从给定的年、月、日、微秒创建 Carbon 实例
|
||||
func CreateFromDateMicro(year, month, day, microsecond int, timezone ...string) Carbon {
|
||||
return NewCarbon().CreateFromDateMicro(year, month, day, microsecond, timezone...)
|
||||
}
|
||||
|
||||
// CreateFromDateNano creates a Carbon instance from a given date and nanosecond.
|
||||
// 从给定的年、月、日、纳秒创建 Carbon 实例
|
||||
func (c Carbon) CreateFromDateNano(year, month, day, nanosecond int, timezone ...string) Carbon {
|
||||
return c.create(year, month, day, 0, 0, 0, nanosecond, timezone...)
|
||||
}
|
||||
|
||||
// CreateFromDateNano creates a Carbon instance from a given date and nanosecond.
|
||||
// 从给定的年、月、日、纳秒创建 Carbon 实例
|
||||
func CreateFromDateNano(year, month, day, nanosecond int, timezone ...string) Carbon {
|
||||
return NewCarbon().CreateFromDateNano(year, month, day, nanosecond, timezone...)
|
||||
}
|
||||
|
||||
// CreateFromTime creates a Carbon instance from a given time(year, month and day are taken from the current time).
|
||||
// 从给定的时、分、秒创建 Carbon 实例(年、月、日取自当前时间)
|
||||
func (c Carbon) CreateFromTime(hour, minute, second int, timezone ...string) Carbon {
|
||||
year, month, day := c.Now(timezone...).Date()
|
||||
return c.create(year, month, day, hour, minute, second, 0, timezone...)
|
||||
}
|
||||
|
||||
// CreateFromTime creates a Carbon instance from a given time(year, month and day are taken from the current time).
|
||||
// 从给定的时、分、秒创建 Carbon 实例(年、月、日取自当前时间)
|
||||
func CreateFromTime(hour, minute, second int, timezone ...string) Carbon {
|
||||
return NewCarbon().CreateFromTime(hour, minute, second, timezone...)
|
||||
}
|
||||
|
||||
// CreateFromTimeMilli creates a Carbon instance from a given time and millisecond(year, month and day are taken from the current time).
|
||||
// 从给定的时、分、秒、毫秒创建 Carbon 实例(年、月、日取自当前时间)
|
||||
func (c Carbon) CreateFromTimeMilli(hour, minute, second, millisecond int, timezone ...string) Carbon {
|
||||
year, month, day := c.Now(timezone...).Date()
|
||||
return c.create(year, month, day, hour, minute, second, millisecond*1e6, timezone...)
|
||||
}
|
||||
|
||||
// CreateFromTimeMilli creates a Carbon instance from a given time and millisecond(year, month and day are taken from the current time).
|
||||
// 从给定的时、分、秒、毫秒创建 Carbon 实例(年、月、日取自当前时间)
|
||||
func CreateFromTimeMilli(hour, minute, second, millisecond int, timezone ...string) Carbon {
|
||||
return NewCarbon().CreateFromTimeMilli(hour, minute, second, millisecond, timezone...)
|
||||
}
|
||||
|
||||
// CreateFromTimeMicro creates a Carbon instance from a given time and microsecond(year, month and day are taken from the current time).
|
||||
// 从给定的时、分、秒、微秒创建 Carbon 实例(年、月、日取自当前时间)
|
||||
func (c Carbon) CreateFromTimeMicro(hour, minute, second, microsecond int, timezone ...string) Carbon {
|
||||
year, month, day := c.Now(timezone...).Date()
|
||||
return c.create(year, month, day, hour, minute, second, microsecond*1e3, timezone...)
|
||||
}
|
||||
|
||||
// CreateFromTimeMicro creates a Carbon instance from a given time and microsecond(year, month and day are taken from the current time).
|
||||
// 从给定的时、分、秒、微秒创建 Carbon 实例(年、月、日取自当前时间)
|
||||
func CreateFromTimeMicro(hour, minute, second, microsecond int, timezone ...string) Carbon {
|
||||
return NewCarbon().CreateFromTimeMicro(hour, minute, second, microsecond, timezone...)
|
||||
}
|
||||
|
||||
// CreateFromTimeNano creates a Carbon instance from a given time and nanosecond(year, month and day are taken from the current time).
|
||||
// 从给定的时、分、秒、纳秒创建 Carbon 实例(年、月、日取自当前时间)
|
||||
func (c Carbon) CreateFromTimeNano(hour, minute, second, nanosecond int, timezone ...string) Carbon {
|
||||
year, month, day := c.Now(timezone...).Date()
|
||||
return c.create(year, month, day, hour, minute, second, nanosecond, timezone...)
|
||||
}
|
||||
|
||||
// CreateFromTimeNano creates a Carbon instance from a given time and nanosecond(year, month and day are taken from the current time).
|
||||
// 从给定的时、分、秒、纳秒创建 Carbon 实例(年、月、日取自当前时间)
|
||||
func CreateFromTimeNano(hour, minute, second, nanosecond int, timezone ...string) Carbon {
|
||||
return NewCarbon().CreateFromTimeNano(hour, minute, second, nanosecond, timezone...)
|
||||
}
|
||||
|
||||
// creates a Carbon instance from a given date, time and nanosecond.
|
||||
// 从给定的年、月、日、时、分、秒、纳秒创建 Carbon 实例
|
||||
func (c Carbon) create(year, month, day, hour, minute, second, nanosecond int, timezone ...string) Carbon {
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
if c.Error != nil {
|
||||
return c
|
||||
}
|
||||
c.time = time.Date(year, time.Month(month), day, hour, minute, second, nanosecond, c.loc)
|
||||
return c
|
||||
}
|
||||
890
vendor/github.com/dromara/carbon/v2/database.go
generated
vendored
Normal file
890
vendor/github.com/dromara/carbon/v2/database.go
generated
vendored
Normal file
@@ -0,0 +1,890 @@
|
||||
package carbon
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"database/sql/driver"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
// returns a failed scan error.
|
||||
// 失败的扫描错误
|
||||
var failedScanError = func(src interface{}) error {
|
||||
return errors.New(fmt.Sprintf("failed to scan value: %v", src))
|
||||
}
|
||||
|
||||
// Scan an interface used by Scan in package database/sql for Scanning value from database to local golang variable.
|
||||
func (c *Carbon) Scan(src interface{}) error {
|
||||
switch v := src.(type) {
|
||||
case []byte:
|
||||
*c = Parse(string(v))
|
||||
case string:
|
||||
*c = Parse(v)
|
||||
case time.Time:
|
||||
*c = CreateFromStdTime(v)
|
||||
}
|
||||
if c.Error == nil {
|
||||
return nil
|
||||
}
|
||||
return failedScanError(src)
|
||||
}
|
||||
|
||||
// Value the interface providing the Value method for package database/sql/driver.
|
||||
func (c Carbon) Value() (driver.Value, error) {
|
||||
if c.IsZero() {
|
||||
return nil, nil
|
||||
}
|
||||
return c.StdTime(), nil
|
||||
}
|
||||
|
||||
// MarshalJSON implements the interface json.Marshal for Carbon struct.
|
||||
// 实现 json.Marshaler 接口
|
||||
func (c Carbon) MarshalJSON() ([]byte, error) {
|
||||
return []byte(fmt.Sprintf(`"%s"`, c.Layout(c.layout))), nil
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements the interface json.Unmarshal for Carbon struct.
|
||||
// 实现 json.Unmarshaler 接口
|
||||
func (c *Carbon) UnmarshalJSON(b []byte) error {
|
||||
value := fmt.Sprintf("%s", bytes.Trim(b, `"`))
|
||||
if value == "" || value == "null" {
|
||||
return nil
|
||||
}
|
||||
*c = ParseByLayout(value, c.layout)
|
||||
return c.Error
|
||||
}
|
||||
|
||||
// Scan an interface used by Scan in package database/sql for Scanning value from database to local golang variable.
|
||||
func (t *DateTime) Scan(src interface{}) error {
|
||||
switch v := src.(type) {
|
||||
case []byte:
|
||||
*t = NewDateTime(Parse(string(v)))
|
||||
case string:
|
||||
*t = NewDateTime(Parse(v))
|
||||
case time.Time:
|
||||
*t = NewDateTime(CreateFromStdTime(v))
|
||||
}
|
||||
if t.Error == nil {
|
||||
return nil
|
||||
}
|
||||
return failedScanError(src)
|
||||
}
|
||||
|
||||
// Value the interface providing the Value method for package database/sql/driver.
|
||||
func (t *DateTime) Value() (driver.Value, error) {
|
||||
if t.IsZero() {
|
||||
return nil, nil
|
||||
}
|
||||
return t.StdTime(), nil
|
||||
}
|
||||
|
||||
// MarshalJSON implements the interface json.Marshal for DateTime struct.
|
||||
// 实现 MarshalJSON 接口
|
||||
func (t DateTime) MarshalJSON() ([]byte, error) {
|
||||
return []byte(fmt.Sprintf(`"%s"`, t.ToDateTimeString())), nil
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements the interface json.Unmarshal for DateTime struct.
|
||||
// 实现 UnmarshalJSON 接口
|
||||
func (t *DateTime) UnmarshalJSON(b []byte) error {
|
||||
value := fmt.Sprintf("%s", bytes.Trim(b, `"`))
|
||||
if value == "" || value == "null" {
|
||||
return nil
|
||||
}
|
||||
c := ParseByLayout(value, DateTimeLayout)
|
||||
if c.Error == nil {
|
||||
*t = NewDateTime(c)
|
||||
}
|
||||
return c.Error
|
||||
}
|
||||
|
||||
// Scan an interface used by Scan in package database/sql for Scanning value from database to local golang variable.
|
||||
func (t *DateTimeMilli) Scan(src interface{}) error {
|
||||
switch v := src.(type) {
|
||||
case []byte:
|
||||
*t = NewDateTimeMilli(Parse(string(v)))
|
||||
case string:
|
||||
*t = NewDateTimeMilli(Parse(v))
|
||||
case time.Time:
|
||||
*t = NewDateTimeMilli(CreateFromStdTime(v))
|
||||
}
|
||||
if t.Error == nil {
|
||||
return nil
|
||||
}
|
||||
return failedScanError(src)
|
||||
}
|
||||
|
||||
// Value the interface providing the Value method for package database/sql/driver.
|
||||
func (t *DateTimeMilli) Value() (driver.Value, error) {
|
||||
if t.IsZero() {
|
||||
return nil, nil
|
||||
}
|
||||
return t.StdTime(), nil
|
||||
}
|
||||
|
||||
// MarshalJSON implements the interface json.Marshal for DateTimeMilli struct.
|
||||
// 实现 MarshalJSON 接口
|
||||
func (t DateTimeMilli) MarshalJSON() ([]byte, error) {
|
||||
return []byte(fmt.Sprintf(`"%s"`, t.ToDateTimeMilliString())), nil
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements the interface json.Unmarshal for DateTimeMilli struct.
|
||||
// 实现 UnmarshalJSON 接口
|
||||
func (t *DateTimeMilli) UnmarshalJSON(b []byte) error {
|
||||
value := fmt.Sprintf("%s", bytes.Trim(b, `"`))
|
||||
if value == "" || value == "null" {
|
||||
return nil
|
||||
}
|
||||
c := ParseByLayout(value, DateTimeMilliLayout)
|
||||
if c.Error == nil {
|
||||
*t = NewDateTimeMilli(c)
|
||||
}
|
||||
return c.Error
|
||||
}
|
||||
|
||||
// Scan an interface used by Scan in package database/sql for Scanning value from database to local golang variable.
|
||||
func (t *DateTimeMicro) Scan(src interface{}) error {
|
||||
switch v := src.(type) {
|
||||
case []byte:
|
||||
*t = NewDateTimeMicro(Parse(string(v)))
|
||||
case string:
|
||||
*t = NewDateTimeMicro(Parse(v))
|
||||
case time.Time:
|
||||
*t = NewDateTimeMicro(CreateFromStdTime(v))
|
||||
}
|
||||
if t.Error == nil {
|
||||
return nil
|
||||
}
|
||||
return failedScanError(src)
|
||||
}
|
||||
|
||||
// Value the interface providing the Value method for package database/sql/driver.
|
||||
func (t *DateTimeMicro) Value() (driver.Value, error) {
|
||||
if t.IsZero() {
|
||||
return nil, nil
|
||||
}
|
||||
return t.StdTime(), nil
|
||||
}
|
||||
|
||||
// MarshalJSON implements the interface json.Marshal for DateTimeMicro struct.
|
||||
// 实现 MarshalJSON 接口
|
||||
func (t DateTimeMicro) MarshalJSON() ([]byte, error) {
|
||||
return []byte(fmt.Sprintf(`"%s"`, t.ToDateTimeMicroString())), nil
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements the interface json.Unmarshal for DateTimeMicro struct.
|
||||
// 实现 UnmarshalJSON 接口
|
||||
func (t *DateTimeMicro) UnmarshalJSON(b []byte) error {
|
||||
value := fmt.Sprintf("%s", bytes.Trim(b, `"`))
|
||||
if value == "" || value == "null" {
|
||||
return nil
|
||||
}
|
||||
c := ParseByLayout(value, DateTimeMicroLayout)
|
||||
if c.Error == nil {
|
||||
*t = NewDateTimeMicro(c)
|
||||
}
|
||||
return c.Error
|
||||
}
|
||||
|
||||
// Scan an interface used by Scan in package database/sql for Scanning value from database to local golang variable.
|
||||
func (t *DateTimeNano) Scan(src interface{}) error {
|
||||
switch v := src.(type) {
|
||||
case []byte:
|
||||
*t = NewDateTimeNano(Parse(string(v)))
|
||||
case string:
|
||||
*t = NewDateTimeNano(Parse(v))
|
||||
case time.Time:
|
||||
*t = NewDateTimeNano(CreateFromStdTime(v))
|
||||
}
|
||||
if t.Error == nil {
|
||||
return nil
|
||||
}
|
||||
return failedScanError(src)
|
||||
}
|
||||
|
||||
// Value the interface providing the Value method for package database/sql/driver.
|
||||
func (t *DateTimeNano) Value() (driver.Value, error) {
|
||||
if t.IsZero() {
|
||||
return nil, nil
|
||||
}
|
||||
return t.StdTime(), nil
|
||||
}
|
||||
|
||||
// MarshalJSON implements the interface json.Marshal for DateTimeNano struct.
|
||||
// 实现 MarshalJSON 接口
|
||||
func (t DateTimeNano) MarshalJSON() ([]byte, error) {
|
||||
return []byte(fmt.Sprintf(`"%s"`, t.ToDateTimeNanoString())), nil
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements the interface json.Unmarshal for DateTimeNano struct.
|
||||
// 实现 UnmarshalJSON 接口
|
||||
func (t *DateTimeNano) UnmarshalJSON(b []byte) error {
|
||||
value := fmt.Sprintf("%s", bytes.Trim(b, `"`))
|
||||
if value == "" || value == "null" {
|
||||
return nil
|
||||
}
|
||||
c := ParseByLayout(value, DateTimeNanoLayout)
|
||||
if c.Error == nil {
|
||||
*t = NewDateTimeNano(c)
|
||||
}
|
||||
return c.Error
|
||||
}
|
||||
|
||||
// Scan an interface used by Scan in package database/sql for Scanning value from database to local golang variable.
|
||||
func (t *Date) Scan(src interface{}) error {
|
||||
switch v := src.(type) {
|
||||
case []byte:
|
||||
*t = NewDate(Parse(string(v)))
|
||||
case string:
|
||||
*t = NewDate(Parse(v))
|
||||
case time.Time:
|
||||
*t = NewDate(CreateFromStdTime(v))
|
||||
}
|
||||
if t.Error == nil {
|
||||
return nil
|
||||
}
|
||||
return failedScanError(src)
|
||||
}
|
||||
|
||||
// Value the interface providing the Value method for package database/sql/driver.
|
||||
func (t *Date) Value() (driver.Value, error) {
|
||||
if t.IsZero() {
|
||||
return nil, nil
|
||||
}
|
||||
return t.StdTime(), nil
|
||||
}
|
||||
|
||||
// MarshalJSON implements the interface json.Marshal for Date struct.
|
||||
// 实现 MarshalJSON 接口
|
||||
func (t Date) MarshalJSON() ([]byte, error) {
|
||||
return []byte(fmt.Sprintf(`"%s"`, t.ToDateString())), nil
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements the interface json.Unmarshal for Date struct.
|
||||
// 实现 UnmarshalJSON 接口
|
||||
func (t *Date) UnmarshalJSON(b []byte) error {
|
||||
value := fmt.Sprintf("%s", bytes.Trim(b, `"`))
|
||||
if value == "" || value == "null" {
|
||||
return nil
|
||||
}
|
||||
c := ParseByLayout(value, DateLayout)
|
||||
if c.Error == nil {
|
||||
*t = NewDate(c)
|
||||
}
|
||||
return c.Error
|
||||
}
|
||||
|
||||
// Scan an interface used by Scan in package database/sql for Scanning value from database to local golang variable.
|
||||
func (t *DateMilli) Scan(src interface{}) error {
|
||||
switch v := src.(type) {
|
||||
case []byte:
|
||||
*t = NewDateMilli(Parse(string(v)))
|
||||
case string:
|
||||
*t = NewDateMilli(Parse(v))
|
||||
case time.Time:
|
||||
*t = NewDateMilli(CreateFromStdTime(v))
|
||||
}
|
||||
if t.Error == nil {
|
||||
return nil
|
||||
}
|
||||
return failedScanError(src)
|
||||
}
|
||||
|
||||
// Value the interface providing the Value method for package database/sql/driver.
|
||||
func (t *DateMilli) Value() (driver.Value, error) {
|
||||
if t.IsZero() {
|
||||
return nil, nil
|
||||
}
|
||||
return t.StdTime(), nil
|
||||
}
|
||||
|
||||
// MarshalJSON implements the interface json.Marshal for DateMilli struct.
|
||||
// 实现 MarshalJSON 接口
|
||||
func (t DateMilli) MarshalJSON() ([]byte, error) {
|
||||
return []byte(fmt.Sprintf(`"%s"`, t.ToDateMilliString())), nil
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements the interface json.Unmarshal for DateMilli struct.
|
||||
// 实现 UnmarshalJSON 接口
|
||||
func (t *DateMilli) UnmarshalJSON(b []byte) error {
|
||||
value := fmt.Sprintf("%s", bytes.Trim(b, `"`))
|
||||
if value == "" || value == "null" {
|
||||
return nil
|
||||
}
|
||||
c := ParseByLayout(value, DateMilliLayout)
|
||||
if c.Error == nil {
|
||||
*t = NewDateMilli(c)
|
||||
}
|
||||
return c.Error
|
||||
}
|
||||
|
||||
// Scan an interface used by Scan in package database/sql for Scanning value from database to local golang variable.
|
||||
func (t *DateMicro) Scan(src interface{}) error {
|
||||
switch v := src.(type) {
|
||||
case []byte:
|
||||
*t = NewDateMicro(Parse(string(v)))
|
||||
case string:
|
||||
*t = NewDateMicro(Parse(v))
|
||||
case time.Time:
|
||||
*t = NewDateMicro(CreateFromStdTime(v))
|
||||
}
|
||||
if t.Error == nil {
|
||||
return nil
|
||||
}
|
||||
return failedScanError(src)
|
||||
}
|
||||
|
||||
// Value the interface providing the Value method for package database/sql/driver.
|
||||
func (t *DateMicro) Value() (driver.Value, error) {
|
||||
if t.IsZero() {
|
||||
return nil, nil
|
||||
}
|
||||
return t.StdTime(), nil
|
||||
}
|
||||
|
||||
// MarshalJSON implements the interface json.Marshal for DateMicro struct.
|
||||
// 实现 MarshalJSON 接口
|
||||
func (t DateMicro) MarshalJSON() ([]byte, error) {
|
||||
return []byte(fmt.Sprintf(`"%s"`, t.ToDateMicroString())), nil
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements the interface json.Unmarshal for DateMicro struct.
|
||||
// 实现 UnmarshalJSON 接口
|
||||
func (t *DateMicro) UnmarshalJSON(b []byte) error {
|
||||
value := fmt.Sprintf("%s", bytes.Trim(b, `"`))
|
||||
if value == "" || value == "null" {
|
||||
return nil
|
||||
}
|
||||
c := ParseByLayout(value, DateMicroLayout)
|
||||
if c.Error == nil {
|
||||
*t = NewDateMicro(c)
|
||||
}
|
||||
return c.Error
|
||||
}
|
||||
|
||||
// Scan an interface used by Scan in package database/sql for Scanning value from database to local golang variable.
|
||||
func (t *DateNano) Scan(src interface{}) error {
|
||||
switch v := src.(type) {
|
||||
case []byte:
|
||||
*t = NewDateNano(Parse(string(v)))
|
||||
case string:
|
||||
*t = NewDateNano(Parse(v))
|
||||
case time.Time:
|
||||
*t = NewDateNano(CreateFromStdTime(v))
|
||||
}
|
||||
if t.Error == nil {
|
||||
return nil
|
||||
}
|
||||
return failedScanError(src)
|
||||
}
|
||||
|
||||
// Value the interface providing the Value method for package database/sql/driver.
|
||||
func (t *DateNano) Value() (driver.Value, error) {
|
||||
if t.IsZero() {
|
||||
return nil, nil
|
||||
}
|
||||
return t.StdTime(), nil
|
||||
}
|
||||
|
||||
// MarshalJSON implements the interface json.Marshal for DateNano struct.
|
||||
// 实现 MarshalJSON 接口
|
||||
func (t DateNano) MarshalJSON() ([]byte, error) {
|
||||
return []byte(fmt.Sprintf(`"%s"`, t.ToDateNanoString())), nil
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements the interface json.Unmarshal for DateNano struct.
|
||||
// 实现 UnmarshalJSON 接口
|
||||
func (t *DateNano) UnmarshalJSON(b []byte) error {
|
||||
value := fmt.Sprintf("%s", bytes.Trim(b, `"`))
|
||||
if value == "" || value == "null" {
|
||||
return nil
|
||||
}
|
||||
c := ParseByLayout(value, DateNanoLayout)
|
||||
if c.Error == nil {
|
||||
*t = NewDateNano(c)
|
||||
}
|
||||
return c.Error
|
||||
}
|
||||
|
||||
// Scan an interface used by Scan in package database/sql for Scanning value from database to local golang variable.
|
||||
func (t *Time) Scan(src interface{}) error {
|
||||
switch v := src.(type) {
|
||||
case []byte:
|
||||
*t = NewTime(Parse(string(v)))
|
||||
case string:
|
||||
*t = NewTime(Parse(v))
|
||||
case time.Time:
|
||||
*t = NewTime(CreateFromStdTime(v))
|
||||
}
|
||||
if t.Error == nil {
|
||||
return nil
|
||||
}
|
||||
return failedScanError(src)
|
||||
}
|
||||
|
||||
// Value the interface providing the Value method for package database/sql/driver.
|
||||
func (t *Time) Value() (driver.Value, error) {
|
||||
if t.IsZero() {
|
||||
return nil, nil
|
||||
}
|
||||
return t.StdTime(), nil
|
||||
}
|
||||
|
||||
// MarshalJSON implements the interface json.Marshal for Time struct.
|
||||
// 实现 MarshalJSON 接口
|
||||
func (t Time) MarshalJSON() ([]byte, error) {
|
||||
return []byte(fmt.Sprintf(`"%s"`, t.ToTimeString())), nil
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements the interface json.Unmarshal for Time struct.
|
||||
// 实现 UnmarshalJSON 接口
|
||||
func (t *Time) UnmarshalJSON(b []byte) error {
|
||||
value := fmt.Sprintf("%s", bytes.Trim(b, `"`))
|
||||
if value == "" || value == "null" {
|
||||
return nil
|
||||
}
|
||||
year, month, day := Now().Date()
|
||||
c := ParseByLayout(fmt.Sprintf("%d-%02d-%02d %s", year, month, day, value), DateTimeLayout)
|
||||
fmt.Println("c", c)
|
||||
if c.Error == nil {
|
||||
*t = NewTime(c)
|
||||
}
|
||||
return c.Error
|
||||
}
|
||||
|
||||
// Scan an interface used by Scan in package database/sql for Scanning value from database to local golang variable.
|
||||
func (t *TimeMilli) Scan(src interface{}) error {
|
||||
switch v := src.(type) {
|
||||
case []byte:
|
||||
*t = NewTimeMilli(Parse(string(v)))
|
||||
case string:
|
||||
*t = NewTimeMilli(Parse(v))
|
||||
case time.Time:
|
||||
*t = NewTimeMilli(CreateFromStdTime(v))
|
||||
}
|
||||
if t.Error == nil {
|
||||
return nil
|
||||
}
|
||||
return failedScanError(src)
|
||||
}
|
||||
|
||||
// Value the interface providing the Value method for package database/sql/driver.
|
||||
func (t *TimeMilli) Value() (driver.Value, error) {
|
||||
if t.IsZero() {
|
||||
return nil, nil
|
||||
}
|
||||
return t.StdTime(), nil
|
||||
}
|
||||
|
||||
// MarshalJSON implements the interface json.Marshal for TimeMilli struct.
|
||||
// 实现 MarshalJSON 接口
|
||||
func (t TimeMilli) MarshalJSON() ([]byte, error) {
|
||||
return []byte(fmt.Sprintf(`"%s"`, t.ToTimeMilliString())), nil
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements the interface json.Unmarshal for TimeMilli struct.
|
||||
// 实现 UnmarshalJSON 接口
|
||||
func (t *TimeMilli) UnmarshalJSON(b []byte) error {
|
||||
value := fmt.Sprintf("%s", bytes.Trim(b, `"`))
|
||||
if value == "" || value == "null" {
|
||||
return nil
|
||||
}
|
||||
year, month, day := Now().Date()
|
||||
c := ParseByLayout(fmt.Sprintf("%d-%02d-%02d %s", year, month, day, value), DateTimeMilliLayout)
|
||||
if c.Error == nil {
|
||||
*t = NewTimeMilli(c)
|
||||
}
|
||||
return c.Error
|
||||
}
|
||||
|
||||
// Scan an interface used by Scan in package database/sql for Scanning value from database to local golang variable.
|
||||
func (t *TimeMicro) Scan(src interface{}) error {
|
||||
switch v := src.(type) {
|
||||
case []byte:
|
||||
*t = NewTimeMicro(Parse(string(v)))
|
||||
case string:
|
||||
*t = NewTimeMicro(Parse(v))
|
||||
case time.Time:
|
||||
*t = NewTimeMicro(CreateFromStdTime(v))
|
||||
}
|
||||
if t.Error == nil {
|
||||
return nil
|
||||
}
|
||||
return failedScanError(src)
|
||||
}
|
||||
|
||||
// Value the interface providing the Value method for package database/sql/driver.
|
||||
func (t *TimeMicro) Value() (driver.Value, error) {
|
||||
if t.IsZero() {
|
||||
return nil, nil
|
||||
}
|
||||
return t.StdTime(), nil
|
||||
}
|
||||
|
||||
// MarshalJSON implements the interface json.Marshal for TimeMicro struct.
|
||||
// 实现 MarshalJSON 接口
|
||||
func (t TimeMicro) MarshalJSON() ([]byte, error) {
|
||||
return []byte(fmt.Sprintf(`"%s"`, t.ToTimeMicroString())), nil
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements the interface json.Unmarshal for TimeMicro struct.
|
||||
// 实现 UnmarshalJSON 接口
|
||||
func (t *TimeMicro) UnmarshalJSON(b []byte) error {
|
||||
value := fmt.Sprintf("%s", bytes.Trim(b, `"`))
|
||||
if value == "" || value == "null" {
|
||||
return nil
|
||||
}
|
||||
year, month, day := Now().Date()
|
||||
c := ParseByLayout(fmt.Sprintf("%d-%02d-%02d %s", year, month, day, value), DateTimeMicroLayout)
|
||||
if c.Error == nil {
|
||||
*t = NewTimeMicro(c)
|
||||
}
|
||||
return c.Error
|
||||
}
|
||||
|
||||
// Scan an interface used by Scan in package database/sql for Scanning value from database to local golang variable.
|
||||
func (t *TimeNano) Scan(src interface{}) error {
|
||||
switch v := src.(type) {
|
||||
case []byte:
|
||||
*t = NewTimeNano(Parse(string(v)))
|
||||
case string:
|
||||
*t = NewTimeNano(Parse(v))
|
||||
case time.Time:
|
||||
*t = NewTimeNano(CreateFromStdTime(v))
|
||||
}
|
||||
if t.Error == nil {
|
||||
return nil
|
||||
}
|
||||
return failedScanError(src)
|
||||
}
|
||||
|
||||
// Value the interface providing the Value method for package database/sql/driver.
|
||||
func (t *TimeNano) Value() (driver.Value, error) {
|
||||
if t.IsZero() {
|
||||
return nil, nil
|
||||
}
|
||||
return t.StdTime(), nil
|
||||
}
|
||||
|
||||
// MarshalJSON implements the interface json.Marshal for TimeNano struct.
|
||||
// 实现 MarshalJSON 接口
|
||||
func (t TimeNano) MarshalJSON() ([]byte, error) {
|
||||
return []byte(fmt.Sprintf(`"%s"`, t.ToTimeNanoString())), nil
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements the interface json.Unmarshal for TimeNano struct.
|
||||
// 实现 UnmarshalJSON 接口
|
||||
func (t *TimeNano) UnmarshalJSON(b []byte) error {
|
||||
value := fmt.Sprintf("%s", bytes.Trim(b, `"`))
|
||||
if value == "" || value == "null" {
|
||||
return nil
|
||||
}
|
||||
year, month, day := Now().Date()
|
||||
c := ParseByLayout(fmt.Sprintf("%d-%02d-%02d %s", year, month, day, value), DateTimeNanoLayout)
|
||||
if c.Error == nil {
|
||||
*t = NewTimeNano(c)
|
||||
}
|
||||
return c.Error
|
||||
}
|
||||
|
||||
// Scan an interface used by Scan in package database/sql for Scanning value from database to local golang variable.
|
||||
func (t *Timestamp) Scan(src interface{}) error {
|
||||
switch v := src.(type) {
|
||||
case []byte:
|
||||
*t = NewTimestamp(Parse(string(v)))
|
||||
case string:
|
||||
*t = NewTimestamp(Parse(v))
|
||||
case time.Time:
|
||||
*t = NewTimestamp(CreateFromStdTime(v))
|
||||
}
|
||||
if t.Error == nil {
|
||||
return nil
|
||||
}
|
||||
return failedScanError(src)
|
||||
}
|
||||
|
||||
// Value the interface providing the Value method for package database/sql/driver.
|
||||
func (t *Timestamp) Value() (driver.Value, error) {
|
||||
if t.IsZero() {
|
||||
return nil, nil
|
||||
}
|
||||
return t.StdTime(), nil
|
||||
}
|
||||
|
||||
// MarshalJSON implements the interface json.Marshal for Timestamp struct.
|
||||
// 实现 MarshalJSON 接口
|
||||
func (t Timestamp) MarshalJSON() ([]byte, error) {
|
||||
return []byte(fmt.Sprintf(`%d`, t.Timestamp())), nil
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements the interface json.Unmarshal for Timestamp struct.
|
||||
// 实现 UnmarshalJSON 接口
|
||||
func (t *Timestamp) UnmarshalJSON(b []byte) error {
|
||||
value := fmt.Sprintf("%s", bytes.Trim(b, `"`))
|
||||
if value == "" || value == "null" {
|
||||
return nil
|
||||
}
|
||||
ts, _ := strconv.ParseInt(value, 10, 64)
|
||||
c := CreateFromTimestamp(ts)
|
||||
if c.Error == nil {
|
||||
*t = NewTimestamp(c)
|
||||
}
|
||||
return c.Error
|
||||
}
|
||||
|
||||
// Scan an interface used by Scan in package database/sql for Scanning value from database to local golang variable.
|
||||
func (t *TimestampMilli) Scan(src interface{}) error {
|
||||
switch v := src.(type) {
|
||||
case []byte:
|
||||
*t = NewTimestampMilli(Parse(string(v)))
|
||||
case string:
|
||||
*t = NewTimestampMilli(Parse(v))
|
||||
case time.Time:
|
||||
*t = NewTimestampMilli(CreateFromStdTime(v))
|
||||
}
|
||||
if t.Error == nil {
|
||||
return nil
|
||||
}
|
||||
return failedScanError(src)
|
||||
}
|
||||
|
||||
// Value the interface providing the Value method for package database/sql/driver.
|
||||
func (t *TimestampMilli) Value() (driver.Value, error) {
|
||||
if t.IsZero() {
|
||||
return nil, nil
|
||||
}
|
||||
return t.StdTime(), nil
|
||||
}
|
||||
|
||||
// MarshalJSON implements the interface json.Marshal for TimestampMilli struct.
|
||||
// 实现 MarshalJSON 接口
|
||||
func (t TimestampMilli) MarshalJSON() ([]byte, error) {
|
||||
return []byte(fmt.Sprintf(`%d`, t.TimestampMilli())), nil
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements the interface json.Unmarshal for TimestampMilli struct.
|
||||
// 实现 UnmarshalJSON 接口
|
||||
func (t *TimestampMilli) UnmarshalJSON(b []byte) error {
|
||||
value := fmt.Sprintf("%s", bytes.Trim(b, `"`))
|
||||
if value == "" || value == "null" {
|
||||
return nil
|
||||
}
|
||||
ts, _ := strconv.ParseInt(value, 10, 64)
|
||||
c := CreateFromTimestampMilli(ts)
|
||||
if c.Error == nil {
|
||||
*t = NewTimestampMilli(c)
|
||||
}
|
||||
return c.Error
|
||||
}
|
||||
|
||||
// Scan an interface used by Scan in package database/sql for Scanning value from database to local golang variable.
|
||||
func (t *TimestampMicro) Scan(src interface{}) error {
|
||||
switch v := src.(type) {
|
||||
case []byte:
|
||||
*t = NewTimestampMicro(Parse(string(v)))
|
||||
case string:
|
||||
*t = NewTimestampMicro(Parse(v))
|
||||
case time.Time:
|
||||
*t = NewTimestampMicro(CreateFromStdTime(v))
|
||||
}
|
||||
if t.Error == nil {
|
||||
return nil
|
||||
}
|
||||
return failedScanError(src)
|
||||
}
|
||||
|
||||
// Value the interface providing the Value method for package database/sql/driver.
|
||||
func (t *TimestampMicro) Value() (driver.Value, error) {
|
||||
if t.IsZero() {
|
||||
return nil, nil
|
||||
}
|
||||
return t.StdTime(), nil
|
||||
}
|
||||
|
||||
// MarshalJSON implements the interface MarshalJSON for TimestampMicro struct.
|
||||
// 实现 MarshalJSON 接口
|
||||
func (t TimestampMicro) MarshalJSON() ([]byte, error) {
|
||||
return []byte(fmt.Sprintf(`%d`, t.TimestampMicro())), nil
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements the interface json.Unmarshal for TimestampMicro struct.
|
||||
// 实现 UnmarshalJSON 接口
|
||||
func (t *TimestampMicro) UnmarshalJSON(b []byte) error {
|
||||
value := fmt.Sprintf("%s", bytes.Trim(b, `"`))
|
||||
if value == "" || value == "null" {
|
||||
return nil
|
||||
}
|
||||
ts, _ := strconv.ParseInt(value, 10, 64)
|
||||
c := CreateFromTimestampMicro(ts)
|
||||
if c.Error == nil {
|
||||
*t = NewTimestampMicro(c)
|
||||
}
|
||||
return c.Error
|
||||
}
|
||||
|
||||
// Scan an interface used by Scan in package database/sql for Scanning value from database to local golang variable.
|
||||
func (t *TimestampNano) Scan(src interface{}) error {
|
||||
switch v := src.(type) {
|
||||
case []byte:
|
||||
*t = NewTimestampNano(Parse(string(v)))
|
||||
case string:
|
||||
*t = NewTimestampNano(Parse(v))
|
||||
case time.Time:
|
||||
*t = NewTimestampNano(CreateFromStdTime(v))
|
||||
}
|
||||
if t.Error == nil {
|
||||
return nil
|
||||
}
|
||||
return failedScanError(src)
|
||||
}
|
||||
|
||||
// Value the interface providing the Value method for package database/sql/driver.
|
||||
func (t *TimestampNano) Value() (driver.Value, error) {
|
||||
if t.IsZero() {
|
||||
return nil, nil
|
||||
}
|
||||
return t.StdTime(), nil
|
||||
}
|
||||
|
||||
// MarshalJSON implements the interface json.Marshal for TimestampNano struct.
|
||||
// 实现 MarshalJSON 接口
|
||||
func (t TimestampNano) MarshalJSON() ([]byte, error) {
|
||||
return []byte(fmt.Sprintf(`%d`, t.TimestampNano())), nil
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements the interface json.Unmarshal for TimestampNano struct.
|
||||
// 实现 UnmarshalJSON 接口
|
||||
func (t *TimestampNano) UnmarshalJSON(b []byte) error {
|
||||
value := fmt.Sprintf("%s", bytes.Trim(b, `"`))
|
||||
if value == "" || value == "null" {
|
||||
return nil
|
||||
}
|
||||
ts, _ := strconv.ParseInt(value, 10, 64)
|
||||
c := CreateFromTimestampNano(ts)
|
||||
if c.Error == nil {
|
||||
*t = NewTimestampNano(c)
|
||||
}
|
||||
return c.Error
|
||||
}
|
||||
|
||||
// Int64 outputs timestamp with second.
|
||||
// 输出秒级时间戳
|
||||
func (t Timestamp) Int64() int64 {
|
||||
return t.Timestamp()
|
||||
}
|
||||
|
||||
// Int64 outputs timestamp with millisecond.
|
||||
// 输出豪秒级时间戳
|
||||
func (t TimestampMilli) Int64() int64 {
|
||||
return t.TimestampMilli()
|
||||
}
|
||||
|
||||
// Int64 outputs timestamp with microsecond.
|
||||
// 输出微秒级时间戳
|
||||
func (t TimestampMicro) Int64() int64 {
|
||||
return t.TimestampMicro()
|
||||
}
|
||||
|
||||
// Int64 outputs timestamp with nanosecond.
|
||||
// 输出纳秒级时间戳
|
||||
func (t TimestampNano) Int64() int64 {
|
||||
return t.TimestampNano()
|
||||
}
|
||||
|
||||
// String implements the interface Stringer for DateTime struct.
|
||||
// 实现 Stringer 接口
|
||||
func (t DateTime) String() string {
|
||||
return t.ToDateTimeString()
|
||||
}
|
||||
|
||||
// String implements the interface Stringer for DateTimeMilli struct.
|
||||
// 实现 Stringer 接口
|
||||
func (t DateTimeMilli) String() string {
|
||||
return t.ToDateTimeMilliString()
|
||||
}
|
||||
|
||||
// String implements the interface Stringer for DateTimeMicro struct.
|
||||
// 实现 Stringer 接口
|
||||
func (t DateTimeMicro) String() string {
|
||||
return t.ToDateTimeMicroString()
|
||||
}
|
||||
|
||||
// String implements the interface Stringer for DateTimeNano struct.
|
||||
// 实现 Stringer 接口
|
||||
func (t DateTimeNano) String() string {
|
||||
return t.ToDateTimeNanoString()
|
||||
}
|
||||
|
||||
// String implements the interface Stringer for Date struct.
|
||||
// 实现 Stringer 接口
|
||||
func (t Date) String() string {
|
||||
return t.ToDateString()
|
||||
}
|
||||
|
||||
// String implements the interface Stringer for DateMilli struct.
|
||||
// 实现 Stringer 接口
|
||||
func (t DateMilli) String() string {
|
||||
return t.ToDateMilliString()
|
||||
}
|
||||
|
||||
// String implements the interface Stringer for DateMicro struct.
|
||||
// 实现 Stringer 接口
|
||||
func (t DateMicro) String() string {
|
||||
return t.ToDateMicroString()
|
||||
}
|
||||
|
||||
// String implements the interface Stringer for DateNano struct.
|
||||
// 实现 Stringer 接口
|
||||
func (t DateNano) String() string {
|
||||
return t.ToDateNanoString()
|
||||
}
|
||||
|
||||
// String implements the interface Stringer for Time struct.
|
||||
// 实现 Stringer 接口
|
||||
func (t Time) String() string {
|
||||
return t.ToTimeString()
|
||||
}
|
||||
|
||||
// String implements the interface Stringer for TimeMilli struct.
|
||||
// 实现 Stringer 接口
|
||||
func (t TimeMilli) String() string {
|
||||
return t.ToTimeMilliString()
|
||||
}
|
||||
|
||||
// String implements the interface Stringer for TimeMicro struct.
|
||||
// 实现 Stringer 接口
|
||||
func (t TimeMicro) String() string {
|
||||
return t.ToTimeMicroString()
|
||||
}
|
||||
|
||||
// String implements the interface Stringer for TimeNano struct.
|
||||
// 实现 Stringer 接口
|
||||
func (t TimeNano) String() string {
|
||||
return t.ToTimeNanoString()
|
||||
}
|
||||
|
||||
// String implements the interface Stringer for Timestamp struct.
|
||||
// 实现 Stringer 接口
|
||||
func (t Timestamp) String() string {
|
||||
return strconv.FormatInt(t.Timestamp(), 10)
|
||||
}
|
||||
|
||||
// String implements the interface Stringer for TimestampMilli struct.
|
||||
// 实现 Stringer 接口
|
||||
func (t TimestampMilli) String() string {
|
||||
return strconv.FormatInt(t.TimestampMilli(), 10)
|
||||
}
|
||||
|
||||
// String implements the interface Stringer for TimestampMicro struct.
|
||||
// 实现 Stringer 接口
|
||||
func (t TimestampMicro) String() string {
|
||||
return strconv.FormatInt(t.TimestampMicro(), 10)
|
||||
}
|
||||
|
||||
// String implements the interface Stringer for TimestampNano struct.
|
||||
// 实现 Stringer 接口
|
||||
func (t TimestampNano) String() string {
|
||||
return strconv.FormatInt(t.TimestampNano(), 10)
|
||||
}
|
||||
45
vendor/github.com/dromara/carbon/v2/default.go
generated
vendored
Normal file
45
vendor/github.com/dromara/carbon/v2/default.go
generated
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
package carbon
|
||||
|
||||
var (
|
||||
// default layout
|
||||
// 默认布局模板
|
||||
defaultLayout = DateTimeLayout
|
||||
|
||||
// default timezone
|
||||
// 默认时区
|
||||
defaultTimezone = Local
|
||||
|
||||
// default week start date
|
||||
// 默认一周开始日期
|
||||
defaultWeekStartsAt = Sunday
|
||||
|
||||
// default language locale
|
||||
// 默认语言区域
|
||||
defaultLocale = "en"
|
||||
)
|
||||
|
||||
// Default defines a Default struct.
|
||||
// 定义 Default 结构体
|
||||
type Default struct {
|
||||
Layout string
|
||||
Timezone string
|
||||
WeekStartsAt string
|
||||
Locale string
|
||||
}
|
||||
|
||||
// SetDefault sets default.
|
||||
// 设置全局默认值
|
||||
func SetDefault(d Default) {
|
||||
if d.Layout != "" {
|
||||
defaultLayout = d.Layout
|
||||
}
|
||||
if d.Timezone != "" {
|
||||
defaultTimezone = d.Timezone
|
||||
}
|
||||
if d.WeekStartsAt != "" {
|
||||
defaultWeekStartsAt = d.WeekStartsAt
|
||||
}
|
||||
if d.Locale != "" {
|
||||
defaultLocale = d.Locale
|
||||
}
|
||||
}
|
||||
292
vendor/github.com/dromara/carbon/v2/difference.go
generated
vendored
Normal file
292
vendor/github.com/dromara/carbon/v2/difference.go
generated
vendored
Normal file
@@ -0,0 +1,292 @@
|
||||
package carbon
|
||||
|
||||
import (
|
||||
"math"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
minDuration time.Duration = -1 << 63
|
||||
maxDuration time.Duration = 1<<63 - 1
|
||||
)
|
||||
|
||||
// DiffInYears gets the difference in years.
|
||||
// 相差多少年
|
||||
func (c Carbon) DiffInYears(carbon ...Carbon) int64 {
|
||||
start, end := c, c.Now()
|
||||
if c.IsSetTestNow() {
|
||||
end = CreateFromTimestampNano(c.testNow, c.Location())
|
||||
}
|
||||
if len(carbon) > 0 {
|
||||
end = carbon[0]
|
||||
}
|
||||
dy, dm, dd := end.Year()-start.Year(), end.Month()-start.Month(), end.Day()-start.Day()
|
||||
if dm < 0 || (dm == 0 && dd < 0) {
|
||||
dy--
|
||||
}
|
||||
if dy < 0 && (dd != 0 || dm != 0) {
|
||||
dy++
|
||||
}
|
||||
return int64(dy)
|
||||
}
|
||||
|
||||
// DiffAbsInYears gets the difference in years with absolute value.
|
||||
// 相差多少年(绝对值)
|
||||
func (c Carbon) DiffAbsInYears(carbon ...Carbon) int64 {
|
||||
return getAbsValue(c.DiffInYears(carbon...))
|
||||
}
|
||||
|
||||
// DiffInMonths gets the difference in months.
|
||||
// 相差多少月
|
||||
func (c Carbon) DiffInMonths(carbon ...Carbon) int64 {
|
||||
start, end := c, c.Now()
|
||||
if start.IsSetTestNow() {
|
||||
end = CreateFromTimestampNano(c.testNow, c.Location())
|
||||
}
|
||||
if len(carbon) > 0 {
|
||||
end = carbon[0]
|
||||
}
|
||||
if start.Month() == end.Month() && start.Year() == end.Year() {
|
||||
return 0
|
||||
}
|
||||
dd := start.DiffInDays(end)
|
||||
sign := 1
|
||||
if dd <= 0 {
|
||||
start, end = end, start
|
||||
sign = -1
|
||||
}
|
||||
months := getDiffInMonths(start, end, 0)
|
||||
return months * int64(sign)
|
||||
}
|
||||
|
||||
// DiffAbsInMonths gets the difference in months with absolute value.
|
||||
// 相差多少月(绝对值)
|
||||
func (c Carbon) DiffAbsInMonths(carbon ...Carbon) int64 {
|
||||
return getAbsValue(c.DiffInMonths(carbon...))
|
||||
}
|
||||
|
||||
// DiffInWeeks gets the difference in weeks.
|
||||
// 相差多少周
|
||||
func (c Carbon) DiffInWeeks(carbon ...Carbon) int64 {
|
||||
start, end := c, c.Now()
|
||||
if c.IsSetTestNow() {
|
||||
end = CreateFromTimestampNano(c.testNow, c.Location())
|
||||
}
|
||||
if len(carbon) > 0 {
|
||||
end = carbon[0]
|
||||
}
|
||||
return int64(math.Floor(float64((end.Timestamp() - start.Timestamp()) / (7 * 24 * 3600))))
|
||||
}
|
||||
|
||||
// DiffAbsInWeeks gets the difference in weeks with absolute value.
|
||||
// 相差多少周(绝对值)
|
||||
func (c Carbon) DiffAbsInWeeks(carbon ...Carbon) int64 {
|
||||
return getAbsValue(c.DiffInWeeks(carbon...))
|
||||
}
|
||||
|
||||
// DiffInDays gets the difference in days.
|
||||
// 相差多少天
|
||||
func (c Carbon) DiffInDays(carbon ...Carbon) int64 {
|
||||
start, end := c, c.Now()
|
||||
if c.IsSetTestNow() {
|
||||
end = CreateFromTimestampNano(c.testNow, c.Location())
|
||||
}
|
||||
if len(carbon) > 0 {
|
||||
end = carbon[0]
|
||||
}
|
||||
return int64(math.Floor(float64((end.Timestamp() - start.Timestamp()) / (24 * 3600))))
|
||||
}
|
||||
|
||||
// DiffAbsInDays gets the difference in days with absolute value.
|
||||
// 相差多少天(绝对值)
|
||||
func (c Carbon) DiffAbsInDays(carbon ...Carbon) int64 {
|
||||
return getAbsValue(c.DiffInDays(carbon...))
|
||||
}
|
||||
|
||||
// DiffInHours gets the difference in hours.
|
||||
// 相差多少小时
|
||||
func (c Carbon) DiffInHours(carbon ...Carbon) int64 {
|
||||
end := c.Now()
|
||||
if c.IsSetTestNow() {
|
||||
end = CreateFromTimestampNano(c.testNow, c.Location())
|
||||
}
|
||||
if len(carbon) > 0 {
|
||||
end = carbon[0]
|
||||
}
|
||||
return c.DiffInSeconds(end) / SecondsPerHour
|
||||
}
|
||||
|
||||
// DiffAbsInHours gets the difference in hours with absolute value.
|
||||
// 相差多少小时(绝对值)
|
||||
func (c Carbon) DiffAbsInHours(carbon ...Carbon) int64 {
|
||||
return getAbsValue(c.DiffInHours(carbon...))
|
||||
}
|
||||
|
||||
// DiffInMinutes gets the difference in minutes.
|
||||
// 相差多少分钟
|
||||
func (c Carbon) DiffInMinutes(carbon ...Carbon) int64 {
|
||||
end := c.Now()
|
||||
if c.IsSetTestNow() {
|
||||
end = CreateFromTimestampNano(c.testNow, c.Location())
|
||||
}
|
||||
if len(carbon) > 0 {
|
||||
end = carbon[0]
|
||||
}
|
||||
return c.DiffInSeconds(end) / SecondsPerMinute
|
||||
}
|
||||
|
||||
// DiffAbsInMinutes gets the difference in minutes with absolute value.
|
||||
// 相差多少分钟(绝对值)
|
||||
func (c Carbon) DiffAbsInMinutes(carbon ...Carbon) int64 {
|
||||
return getAbsValue(c.DiffInMinutes(carbon...))
|
||||
}
|
||||
|
||||
// DiffInSeconds gets the difference in seconds.
|
||||
// 相差多少秒
|
||||
func (c Carbon) DiffInSeconds(carbon ...Carbon) int64 {
|
||||
end := c.Now()
|
||||
if c.IsSetTestNow() {
|
||||
end = CreateFromTimestampNano(c.testNow, c.Location())
|
||||
}
|
||||
if len(carbon) > 0 {
|
||||
end = carbon[0]
|
||||
}
|
||||
return end.Timestamp() - c.Timestamp()
|
||||
}
|
||||
|
||||
// DiffAbsInSeconds gets the difference in seconds with absolute value.
|
||||
// 相差多少秒(绝对值)
|
||||
func (c Carbon) DiffAbsInSeconds(carbon ...Carbon) int64 {
|
||||
return getAbsValue(c.DiffInSeconds(carbon...))
|
||||
}
|
||||
|
||||
// DiffInString gets the difference in string, i18n is supported.
|
||||
// 相差字符串,支持i18n
|
||||
func (c Carbon) DiffInString(carbon ...Carbon) string {
|
||||
end := c.Now()
|
||||
if c.IsSetTestNow() {
|
||||
end = CreateFromTimestampNano(c.testNow, c.Location())
|
||||
}
|
||||
if len(carbon) > 0 {
|
||||
end = carbon[0]
|
||||
}
|
||||
if c.Error != nil || end.Error != nil {
|
||||
return ""
|
||||
}
|
||||
unit, value := c.diff(end)
|
||||
return c.lang.translate(unit, value)
|
||||
}
|
||||
|
||||
// DiffAbsInString gets the difference in string with absolute value, i18n is supported.
|
||||
// 相差字符串,支持i18n(绝对值)
|
||||
func (c Carbon) DiffAbsInString(carbon ...Carbon) string {
|
||||
end := c.Now()
|
||||
if c.IsSetTestNow() {
|
||||
end = CreateFromTimestampNano(c.testNow, c.Location())
|
||||
}
|
||||
if len(carbon) > 0 {
|
||||
end = carbon[0]
|
||||
}
|
||||
if c.Error != nil || end.Error != nil {
|
||||
return ""
|
||||
}
|
||||
unit, value := c.diff(end)
|
||||
return c.lang.translate(unit, getAbsValue(value))
|
||||
}
|
||||
|
||||
// DiffInDuration gets the difference in duration.
|
||||
// 相差时长
|
||||
func (c Carbon) DiffInDuration(carbon ...Carbon) time.Duration {
|
||||
end := c.Now()
|
||||
if c.IsSetTestNow() {
|
||||
end = CreateFromTimestampNano(c.testNow, c.Location())
|
||||
}
|
||||
if len(carbon) > 0 {
|
||||
end = carbon[0]
|
||||
}
|
||||
return end.StdTime().Sub(c.StdTime())
|
||||
}
|
||||
|
||||
// DiffAbsInDuration gets the difference in duration with absolute value.
|
||||
// 相差时长(绝对值)
|
||||
func (c Carbon) DiffAbsInDuration(carbon ...Carbon) time.Duration {
|
||||
d := c.DiffInDuration(carbon...)
|
||||
if d >= 0 {
|
||||
return d
|
||||
}
|
||||
return -d
|
||||
}
|
||||
|
||||
// DiffForHumans gets the difference in a human-readable format, i18n is supported.
|
||||
// 获取对人类友好的可读格式时间差,支持i18n
|
||||
func (c Carbon) DiffForHumans(carbon ...Carbon) string {
|
||||
end := c.Now()
|
||||
if c.IsSetTestNow() {
|
||||
end = CreateFromTimestampNano(c.testNow, c.Location())
|
||||
}
|
||||
if len(carbon) > 0 {
|
||||
end = carbon[0]
|
||||
}
|
||||
if c.Error != nil || end.Error != nil {
|
||||
return ""
|
||||
}
|
||||
unit, value := c.diff(end)
|
||||
translation := c.lang.translate(unit, getAbsValue(value))
|
||||
if unit == "now" {
|
||||
return translation
|
||||
}
|
||||
if c.Lt(end) && len(carbon) == 0 {
|
||||
return strings.Replace(c.lang.resources["ago"], "%s", translation, 1)
|
||||
}
|
||||
if c.Lt(end) && len(carbon) > 0 {
|
||||
return strings.Replace(c.lang.resources["before"], "%s", translation, 1)
|
||||
}
|
||||
if c.Gt(end) && len(carbon) == 0 {
|
||||
return strings.Replace(c.lang.resources["from_now"], "%s", translation, 1)
|
||||
}
|
||||
return strings.Replace(c.lang.resources["after"], "%s", translation, 1)
|
||||
}
|
||||
|
||||
// gets the difference for unit and value.
|
||||
// 获取相差单位和差值
|
||||
func (c Carbon) diff(end Carbon) (unit string, value int64) {
|
||||
switch true {
|
||||
case c.DiffAbsInYears(end) > 0:
|
||||
unit = "year"
|
||||
value = c.DiffInYears(end)
|
||||
case c.DiffAbsInMonths(end) > 0:
|
||||
unit = "month"
|
||||
value = c.DiffInMonths(end)
|
||||
case c.DiffAbsInWeeks(end) > 0:
|
||||
unit = "week"
|
||||
value = c.DiffInWeeks(end)
|
||||
case c.DiffAbsInDays(end) > 0:
|
||||
unit = "day"
|
||||
value = c.DiffInDays(end)
|
||||
case c.DiffAbsInHours(end) > 0:
|
||||
unit = "hour"
|
||||
value = c.DiffInHours(end)
|
||||
case c.DiffAbsInMinutes(end) > 0:
|
||||
unit = "minute"
|
||||
value = c.DiffInMinutes(end)
|
||||
case c.DiffAbsInSeconds(end) > 0:
|
||||
unit = "second"
|
||||
value = c.DiffInSeconds(end)
|
||||
case c.DiffAbsInSeconds(end) == 0:
|
||||
unit = "now"
|
||||
value = 0
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func getDiffInMonths(start, end Carbon, months int64) int64 {
|
||||
next := start.AddDays(start.DaysInMonth())
|
||||
days := next.DiffInDays(end)
|
||||
seconds := next.DiffInSeconds(end)
|
||||
if days < 0 || (days == 0 && seconds < 0) {
|
||||
return months
|
||||
}
|
||||
months += 1
|
||||
return getDiffInMonths(next, end, months)
|
||||
}
|
||||
41
vendor/github.com/dromara/carbon/v2/errors.go
generated
vendored
Normal file
41
vendor/github.com/dromara/carbon/v2/errors.go
generated
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
package carbon
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// returns an invalid timezone error.
|
||||
// 无效的时区错误
|
||||
var invalidTimezoneError = func(timezone string) error {
|
||||
return fmt.Errorf("invalid timezone %q, please see the file %q for all valid timezones", timezone, "$GOROOT/lib/time/zoneinfo.zip")
|
||||
}
|
||||
|
||||
// returns an invalid location error.
|
||||
// 无效的地区错误
|
||||
var invalidLocationError = func() error {
|
||||
return fmt.Errorf("invalid location, please make sure the location is valid")
|
||||
}
|
||||
|
||||
// returns an invalid duration error.
|
||||
// 无效的时长错误
|
||||
var invalidDurationError = func(duration string) error {
|
||||
return fmt.Errorf("invalid duration %q, please make sure the duration is valid", duration)
|
||||
}
|
||||
|
||||
// returns an invalid value error.
|
||||
// 无效的时间字符串错误
|
||||
var invalidValueError = func(value string) error {
|
||||
return fmt.Errorf("cannot parse string %q as carbon, please make sure the value is valid", value)
|
||||
}
|
||||
|
||||
// returns an invalid layout error.
|
||||
// 无效的布局模板错误
|
||||
var invalidLayoutError = func(value, layout string) error {
|
||||
return fmt.Errorf("cannot parse string %q as carbon by layout %q, please make sure the value and layout match", value, layout)
|
||||
}
|
||||
|
||||
// returns an invalid format error.
|
||||
// 无效的格式模板错误
|
||||
var invalidFormatError = func(value, format string) error {
|
||||
return fmt.Errorf("cannot parse string %q as carbon by format %q, please make sure the value and format match", value, format)
|
||||
}
|
||||
67
vendor/github.com/dromara/carbon/v2/extremum.go
generated
vendored
Normal file
67
vendor/github.com/dromara/carbon/v2/extremum.go
generated
vendored
Normal file
@@ -0,0 +1,67 @@
|
||||
package carbon
|
||||
|
||||
// MaxValue returns a Carbon instance for the greatest supported date.
|
||||
// 返回 Carbon 的最大值
|
||||
func MaxValue() Carbon {
|
||||
return NewCarbon().create(9999, 12, 31, 23, 59, 59, 999999999, UTC)
|
||||
}
|
||||
|
||||
// MinValue returns a Carbon instance for the lowest supported date.
|
||||
// 返回 Carbon 的最小值
|
||||
func MinValue() Carbon {
|
||||
return NewCarbon().create(-9998, 1, 1, 0, 0, 0, 0, UTC)
|
||||
}
|
||||
|
||||
// Closest returns the closest Carbon instance from the given Carbon instance.
|
||||
// 返回离给定 carbon 实例最近的 Carbon 实例
|
||||
func (c Carbon) Closest(c1 Carbon, c2 Carbon) Carbon {
|
||||
if c1.Error != nil {
|
||||
return c2
|
||||
}
|
||||
if c2.Error != nil {
|
||||
return c1
|
||||
}
|
||||
if c.DiffAbsInSeconds(c1) < c.DiffAbsInSeconds(c2) {
|
||||
return c1
|
||||
}
|
||||
return c2
|
||||
}
|
||||
|
||||
// Farthest returns the farthest Carbon instance from the given Carbon instance.
|
||||
// 返回离给定 carbon 实例最远的 Carbon 实例
|
||||
func (c Carbon) Farthest(c1 Carbon, c2 Carbon) Carbon {
|
||||
if c1.IsZero() || c1.IsInvalid() {
|
||||
return c2
|
||||
}
|
||||
if c2.IsZero() || c2.IsInvalid() {
|
||||
return c1
|
||||
}
|
||||
if c.DiffAbsInSeconds(c1) > c.DiffAbsInSeconds(c2) {
|
||||
return c1
|
||||
}
|
||||
return c2
|
||||
}
|
||||
|
||||
// Max returns the maximum Carbon instance from the given Carbon instance (second-precision).
|
||||
// 返回最大的 Carbon 实例
|
||||
func Max(c1 Carbon, c2 ...Carbon) (c Carbon) {
|
||||
c = c1
|
||||
for i := range c2 {
|
||||
if c2[i].Gte(c) {
|
||||
c = c2[i]
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Min returns the minimum Carbon instance from the given Carbon instance (second-precision).
|
||||
// 返回最小的 Carbon 实例
|
||||
func Min(c1 Carbon, c2 ...Carbon) (c Carbon) {
|
||||
c = c1
|
||||
for i := range c2 {
|
||||
if c2[i].Lte(c) {
|
||||
c = c2[i]
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
433
vendor/github.com/dromara/carbon/v2/getter.go
generated
vendored
Normal file
433
vendor/github.com/dromara/carbon/v2/getter.go
generated
vendored
Normal file
@@ -0,0 +1,433 @@
|
||||
package carbon
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// StdTime gets standard time.Time.
|
||||
// 获取标准 time.Time
|
||||
func (c Carbon) StdTime() time.Time {
|
||||
if c.time.IsZero() {
|
||||
return c.time
|
||||
}
|
||||
return c.time.In(c.loc)
|
||||
}
|
||||
|
||||
// DaysInYear gets total days in year like 365.
|
||||
// 获取本年的总天数
|
||||
func (c Carbon) DaysInYear() int {
|
||||
if c.Error != nil {
|
||||
return 0
|
||||
}
|
||||
if c.IsLeapYear() {
|
||||
return DaysPerLeapYear
|
||||
}
|
||||
return DaysPerNormalYear
|
||||
}
|
||||
|
||||
// DaysInMonth gets total days in month like 30.
|
||||
// 获取本月的总天数
|
||||
func (c Carbon) DaysInMonth() int {
|
||||
if c.Error != nil {
|
||||
return 0
|
||||
}
|
||||
return c.EndOfMonth().StdTime().Day()
|
||||
}
|
||||
|
||||
// MonthOfYear gets month of year like 12.
|
||||
// 获取本年的第几月
|
||||
func (c Carbon) MonthOfYear() int {
|
||||
if c.Error != nil {
|
||||
return 0
|
||||
}
|
||||
return int(c.StdTime().Month())
|
||||
}
|
||||
|
||||
// DayOfYear gets day of year like 365.
|
||||
// 获取本年的第几天
|
||||
func (c Carbon) DayOfYear() int {
|
||||
if c.Error != nil {
|
||||
return 0
|
||||
}
|
||||
return c.StdTime().YearDay()
|
||||
}
|
||||
|
||||
// DayOfMonth gets day of month like 30.
|
||||
// 获取本月的第几天
|
||||
func (c Carbon) DayOfMonth() int {
|
||||
if c.Error != nil {
|
||||
return 0
|
||||
}
|
||||
return c.StdTime().Day()
|
||||
}
|
||||
|
||||
// DayOfWeek gets day of week like 6.
|
||||
// 获取本周的第几天
|
||||
func (c Carbon) DayOfWeek() int {
|
||||
if c.Error != nil {
|
||||
return 0
|
||||
}
|
||||
day := int(c.StdTime().Weekday())
|
||||
if day == 0 {
|
||||
return DaysPerWeek
|
||||
}
|
||||
return day
|
||||
}
|
||||
|
||||
// WeekOfYear gets week of year like 1, see https://en.wikipedia.org/wiki/ISO_8601#Week_dates.
|
||||
// 获取本年的第几周
|
||||
func (c Carbon) WeekOfYear() int {
|
||||
if c.Error != nil {
|
||||
return 0
|
||||
}
|
||||
_, week := c.StdTime().ISOWeek()
|
||||
return week
|
||||
}
|
||||
|
||||
// WeekOfMonth gets week of month like 1.
|
||||
// 获取本月的第几周
|
||||
func (c Carbon) WeekOfMonth() int {
|
||||
if c.Error != nil {
|
||||
return 0
|
||||
}
|
||||
days := c.Day() + c.StartOfMonth().DayOfWeek() - 1
|
||||
if days%DaysPerWeek == 0 {
|
||||
return days / DaysPerWeek
|
||||
}
|
||||
return days/DaysPerWeek + 1
|
||||
}
|
||||
|
||||
// DateTime gets current year, month, day, hour, minute, and second like 2020, 8, 5, 13, 14, 15.
|
||||
// 获取当前年、月、日、时、分、秒
|
||||
func (c Carbon) DateTime() (year, month, day, hour, minute, second int) {
|
||||
if c.Error != nil {
|
||||
return
|
||||
}
|
||||
year, month, day = c.Date()
|
||||
hour, minute, second = c.Time()
|
||||
return year, month, day, hour, minute, second
|
||||
}
|
||||
|
||||
// DateTimeMilli gets current year, month, day, hour, minute, second and millisecond like 2020, 8, 5, 13, 14, 15, 999.
|
||||
// 获取当前年、月、日、时、分、秒、毫秒
|
||||
func (c Carbon) DateTimeMilli() (year, month, day, hour, minute, second, millisecond int) {
|
||||
if c.Error != nil {
|
||||
return
|
||||
}
|
||||
year, month, day, hour, minute, second = c.DateTime()
|
||||
return year, month, day, hour, minute, second, c.Millisecond()
|
||||
}
|
||||
|
||||
// DateTimeMicro gets current year, month, day, hour, minute, second and microsecond like 2020, 8, 5, 13, 14, 15, 999999.
|
||||
// 获取当前年、月、日、时、分、秒、微秒
|
||||
func (c Carbon) DateTimeMicro() (year, month, day, hour, minute, second, microsecond int) {
|
||||
if c.Error != nil {
|
||||
return
|
||||
}
|
||||
year, month, day, hour, minute, second = c.DateTime()
|
||||
return year, month, day, hour, minute, second, c.Microsecond()
|
||||
}
|
||||
|
||||
// DateTimeNano gets current year, month, day, hour, minute, second and nanosecond like 2020, 8, 5, 13, 14, 15, 999999999.
|
||||
// 获取当前年、月、日、时、分、秒、纳秒
|
||||
func (c Carbon) DateTimeNano() (year, month, day, hour, minute, second, nanosecond int) {
|
||||
if c.Error != nil {
|
||||
return
|
||||
}
|
||||
year, month, day, hour, minute, second = c.DateTime()
|
||||
return year, month, day, hour, minute, second, c.Nanosecond()
|
||||
}
|
||||
|
||||
// Date gets current year, month, and day like 2020, 8, 5.
|
||||
// 获取当前年、月、日
|
||||
func (c Carbon) Date() (year, month, day int) {
|
||||
if c.Error != nil {
|
||||
return
|
||||
}
|
||||
var tm time.Month
|
||||
year, tm, day = c.StdTime().Date()
|
||||
return year, int(tm), day
|
||||
}
|
||||
|
||||
// DateMilli gets current year, month, day and millisecond like 2020, 8, 5, 999.
|
||||
// 获取当前年、月、日、毫秒
|
||||
func (c Carbon) DateMilli() (year, month, day, millisecond int) {
|
||||
if c.Error != nil {
|
||||
return
|
||||
}
|
||||
year, month, day = c.Date()
|
||||
return year, month, day, c.Millisecond()
|
||||
}
|
||||
|
||||
// DateMicro gets current year, month, day and microsecond like 2020, 8, 5, 999999.
|
||||
// 获取当前年、月、日、微秒
|
||||
func (c Carbon) DateMicro() (year, month, day, microsecond int) {
|
||||
if c.Error != nil {
|
||||
return
|
||||
}
|
||||
year, month, day = c.Date()
|
||||
return year, month, day, c.Microsecond()
|
||||
}
|
||||
|
||||
// DateNano gets current year, month, day and nanosecond like 2020, 8, 5, 999999999.
|
||||
// 获取当前年、月、日、纳秒
|
||||
func (c Carbon) DateNano() (year, month, day, nanosecond int) {
|
||||
if c.Error != nil {
|
||||
return
|
||||
}
|
||||
year, month, day = c.Date()
|
||||
return year, month, day, c.Nanosecond()
|
||||
}
|
||||
|
||||
// Time gets current hour, minute, and second like 13, 14, 15.
|
||||
// 获取当前时、分、秒
|
||||
func (c Carbon) Time() (hour, minute, second int) {
|
||||
if c.Error != nil {
|
||||
return
|
||||
}
|
||||
return c.StdTime().Clock()
|
||||
}
|
||||
|
||||
// TimeMilli gets current hour, minute, second and millisecond like 13, 14, 15, 999.
|
||||
// 获取当前时、分、秒、毫秒
|
||||
func (c Carbon) TimeMilli() (hour, minute, second, millisecond int) {
|
||||
if c.Error != nil {
|
||||
return
|
||||
}
|
||||
hour, minute, second = c.Time()
|
||||
return hour, minute, second, c.Millisecond()
|
||||
}
|
||||
|
||||
// TimeMicro gets current hour, minute, second and microsecond like 13, 14, 15, 999999.
|
||||
// 获取当前时、分、秒、微秒
|
||||
func (c Carbon) TimeMicro() (hour, minute, second, microsecond int) {
|
||||
if c.Error != nil {
|
||||
return
|
||||
}
|
||||
hour, minute, second = c.Time()
|
||||
return hour, minute, second, c.Microsecond()
|
||||
}
|
||||
|
||||
// TimeNano gets current hour, minute, second and nanosecond like 13, 14, 15, 999999999.
|
||||
// 获取当前时、分、秒、纳秒
|
||||
func (c Carbon) TimeNano() (hour, minute, second, nanosecond int) {
|
||||
if c.Error != nil {
|
||||
return
|
||||
}
|
||||
hour, minute, second = c.Time()
|
||||
return hour, minute, second, c.Nanosecond()
|
||||
}
|
||||
|
||||
// Century gets current century like 21.
|
||||
// 获取当前世纪
|
||||
func (c Carbon) Century() int {
|
||||
if c.Error != nil {
|
||||
return 0
|
||||
}
|
||||
return c.Year()/YearsPerCentury + 1
|
||||
}
|
||||
|
||||
// Decade gets current decade like 20.
|
||||
// 获取当前年代
|
||||
func (c Carbon) Decade() int {
|
||||
if c.Error != nil {
|
||||
return 0
|
||||
}
|
||||
return c.Year() % YearsPerCentury / YearsPerDecade * YearsPerDecade
|
||||
}
|
||||
|
||||
// Year gets current year like 2020.
|
||||
// 获取当前年
|
||||
func (c Carbon) Year() int {
|
||||
if c.Error != nil {
|
||||
return 0
|
||||
}
|
||||
return c.StdTime().Year()
|
||||
}
|
||||
|
||||
// Quarter gets current quarter like 3.
|
||||
// 获取当前季度
|
||||
func (c Carbon) Quarter() (quarter int) {
|
||||
if c.Error != nil {
|
||||
return
|
||||
}
|
||||
month := c.Month()
|
||||
switch {
|
||||
case month >= 10:
|
||||
quarter = 4
|
||||
case month >= 7:
|
||||
quarter = 3
|
||||
case month >= 4:
|
||||
quarter = 2
|
||||
case month >= 1:
|
||||
quarter = 1
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Month gets current month like 8.
|
||||
// 获取当前月
|
||||
func (c Carbon) Month() int {
|
||||
return c.MonthOfYear()
|
||||
}
|
||||
|
||||
// Week gets current week like 6, start from 0.
|
||||
// 获取当前周(从0开始)
|
||||
func (c Carbon) Week() int {
|
||||
if c.Error != nil {
|
||||
return -1
|
||||
}
|
||||
return (c.DayOfWeek() + DaysPerWeek - int(c.weekStartsAt)) % DaysPerWeek
|
||||
}
|
||||
|
||||
// Day gets current day like 5.
|
||||
// 获取当前日
|
||||
func (c Carbon) Day() int {
|
||||
return c.DayOfMonth()
|
||||
}
|
||||
|
||||
// Hour gets current hour like 13.
|
||||
// 获取当前小时
|
||||
func (c Carbon) Hour() int {
|
||||
if c.Error != nil {
|
||||
return 0
|
||||
}
|
||||
return c.StdTime().Hour()
|
||||
}
|
||||
|
||||
// Minute gets current minute like 14.
|
||||
// 获取当前分钟数
|
||||
func (c Carbon) Minute() int {
|
||||
if c.Error != nil {
|
||||
return 0
|
||||
}
|
||||
return c.StdTime().Minute()
|
||||
}
|
||||
|
||||
// Second gets current second like 15.
|
||||
// 获取当前秒数
|
||||
func (c Carbon) Second() int {
|
||||
if c.Error != nil {
|
||||
return 0
|
||||
}
|
||||
return c.StdTime().Second()
|
||||
}
|
||||
|
||||
// Millisecond gets current millisecond like 999.
|
||||
// 获取当前毫秒数
|
||||
func (c Carbon) Millisecond() int {
|
||||
if c.Error != nil {
|
||||
return 0
|
||||
}
|
||||
return c.StdTime().Nanosecond() / 1e6
|
||||
}
|
||||
|
||||
// Microsecond gets current microsecond like 999999.
|
||||
// 获取当前微秒数
|
||||
func (c Carbon) Microsecond() int {
|
||||
if c.Error != nil {
|
||||
return 0
|
||||
}
|
||||
return c.StdTime().Nanosecond() / 1e3
|
||||
}
|
||||
|
||||
// Nanosecond gets current nanosecond like 999999999.
|
||||
// 获取当前纳秒数
|
||||
func (c Carbon) Nanosecond() int {
|
||||
if c.Error != nil {
|
||||
return 0
|
||||
}
|
||||
return c.StdTime().Nanosecond()
|
||||
}
|
||||
|
||||
// Timestamp gets timestamp with second like 1596604455.
|
||||
// 输出秒级时间戳
|
||||
func (c Carbon) Timestamp() int64 {
|
||||
if c.Error != nil {
|
||||
return 0
|
||||
}
|
||||
return c.StdTime().Unix()
|
||||
}
|
||||
|
||||
// TimestampMilli gets timestamp with millisecond like 1596604455000.
|
||||
// 获取毫秒级时间戳
|
||||
func (c Carbon) TimestampMilli() int64 {
|
||||
if c.Error != nil {
|
||||
return 0
|
||||
}
|
||||
t := c.StdTime()
|
||||
return t.Unix()*1e3 + int64(t.Nanosecond())/1e6
|
||||
}
|
||||
|
||||
// TimestampMicro gets timestamp with microsecond like 1596604455000000.
|
||||
// 获取微秒级时间戳
|
||||
func (c Carbon) TimestampMicro() int64 {
|
||||
if c.Error != nil {
|
||||
return 0
|
||||
}
|
||||
t := c.StdTime()
|
||||
return t.Unix()*1e6 + int64(t.Nanosecond())/1e3
|
||||
}
|
||||
|
||||
// TimestampNano gets timestamp with nanosecond like 1596604455000000000.
|
||||
// 获取纳秒级时间戳
|
||||
func (c Carbon) TimestampNano() int64 {
|
||||
if c.Error != nil {
|
||||
return 0
|
||||
}
|
||||
return c.StdTime().UnixNano()
|
||||
}
|
||||
|
||||
// Location gets location name like "PRC".
|
||||
// 获取位置
|
||||
func (c Carbon) Location() string {
|
||||
if c.Error != nil {
|
||||
return ""
|
||||
}
|
||||
return c.loc.String()
|
||||
}
|
||||
|
||||
// Timezone gets timezone name like "CST".
|
||||
// 获取时区
|
||||
func (c Carbon) Timezone() string {
|
||||
if c.Error != nil {
|
||||
return ""
|
||||
}
|
||||
name, _ := c.StdTime().Zone()
|
||||
return name
|
||||
}
|
||||
|
||||
// Offset gets offset seconds from the UTC timezone like 28800.
|
||||
// 获取距离UTC时区的偏移量,单位秒
|
||||
func (c Carbon) Offset() int {
|
||||
if c.Error != nil {
|
||||
return 0
|
||||
}
|
||||
_, offset := c.StdTime().Zone()
|
||||
return offset
|
||||
}
|
||||
|
||||
// Locale gets locale name like "zh-CN".
|
||||
// 获取语言区域
|
||||
func (c Carbon) Locale() string {
|
||||
if c.Error != nil {
|
||||
return ""
|
||||
}
|
||||
return c.lang.locale
|
||||
}
|
||||
|
||||
// Age gets age like 18.
|
||||
// 获取年龄
|
||||
func (c Carbon) Age() int {
|
||||
if c.Error != nil {
|
||||
return 0
|
||||
}
|
||||
now := c.Now()
|
||||
if c.IsSetTestNow() {
|
||||
now = CreateFromTimestampNano(c.testNow, c.Location())
|
||||
}
|
||||
if c.TimestampNano() > now.TimestampNano() {
|
||||
return 0
|
||||
}
|
||||
return int(c.DiffInYears(now))
|
||||
}
|
||||
127
vendor/github.com/dromara/carbon/v2/helper.go
generated
vendored
Normal file
127
vendor/github.com/dromara/carbon/v2/helper.go
generated
vendored
Normal file
@@ -0,0 +1,127 @@
|
||||
package carbon
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"time"
|
||||
)
|
||||
|
||||
// week days
|
||||
// 工作日
|
||||
var weekdays = map[string]time.Weekday{
|
||||
Monday: time.Monday,
|
||||
Tuesday: time.Tuesday,
|
||||
Wednesday: time.Wednesday,
|
||||
Thursday: time.Thursday,
|
||||
Friday: time.Friday,
|
||||
Saturday: time.Saturday,
|
||||
Sunday: time.Sunday,
|
||||
}
|
||||
|
||||
// common formatting symbols
|
||||
// 常规格式化符号
|
||||
var formats = map[byte]string{
|
||||
'd': "02", // Day: Day of the month, 2 digits with leading zeros. Eg: 01 to 31.
|
||||
'D': "Mon", // Day: A textual representation of a day, three letters. Eg: Mon through Sun.
|
||||
'j': "2", // Day: Day of the month without leading zeros. Eg: 1 to 31.
|
||||
'l': "Monday", // Day: A full textual representation of the day of the week. Eg: Sunday through Saturday.
|
||||
'F': "January", // Month: A full textual representation of a month, such as January or March. Eg: January through December.
|
||||
'm': "01", // Month: Numeric representation of a month, with leading zeros. Eg: 01 through 12.
|
||||
'M': "Jan", // Month: A short textual representation of a month, three letters. Eg: Jan through Dec.
|
||||
'n': "1", // Month: Numeric representation of a month, without leading zeros. Eg: 1 through 12.
|
||||
'Y': "2006", // Year: A full numeric representation of a year, 4 digits. Eg: 1999 or 2003.
|
||||
'y': "06", // Year: A two digit representation of a year. Eg: 99 or 03.
|
||||
'a': "pm", // Time: Lowercase morning or afternoon sign. Eg: am or pm.
|
||||
'A': "PM", // Time: Uppercase morning or afternoon sign. Eg: AM or PM.
|
||||
'g': "3", // Time: 12-hour format of an hour without leading zeros. Eg: 1 through 12.
|
||||
'h': "03", // Time: 12-hour format of an hour with leading zeros. Eg: 01 through 12.
|
||||
'H': "15", // Time: 24-hour format of an hour with leading zeros. Eg: 00 through 23.
|
||||
'i': "04", // Time: Minutes with leading zeros. Eg: 00 to 59.
|
||||
's': "05", // Time: Seconds with leading zeros. Eg: 00 through 59.
|
||||
'O': "-0700", // Zone: Difference to Greenwich time (GMT) in hours. Eg: +0200.
|
||||
'P': "-07:00", // Zone: Difference to Greenwich time (GMT) with colon between hours and minutes. Eg: +02:00.
|
||||
'T': "MST", // Zone: Timezone abbreviation. Eg: UTC, EST, MDT ...
|
||||
|
||||
'U': "timestamp", // Timestamp with second. Eg: 1699677240.
|
||||
'V': "timestampMilli", // TimestampMilli with second. Eg: 1596604455666.
|
||||
'X': "timestampMicro", // TimestampMicro with second. Eg: 1596604455666666.
|
||||
'Z': "timestampNano", // TimestampNano with second. Eg: 1596604455666666666.
|
||||
}
|
||||
|
||||
// common layout symbols
|
||||
// 常规布局模板符号
|
||||
var layouts = []string{
|
||||
DayDateTimeLayout,
|
||||
DateTimeLayout, DateTimeNanoLayout, ShortDateTimeLayout, ShortDateTimeNanoLayout,
|
||||
DateLayout, DateNanoLayout, ShortDateLayout, ShortDateNanoLayout,
|
||||
ISO8601Layout, ISO8601NanoLayout,
|
||||
RFC822Layout, RFC822ZLayout, RFC850Layout, RFC1123Layout, RFC1123ZLayout, RFC3339Layout, RFC3339NanoLayout, RFC1036Layout, RFC7231Layout,
|
||||
KitchenLayout,
|
||||
CookieLayout,
|
||||
ANSICLayout,
|
||||
UnixDateLayout,
|
||||
RubyDateLayout,
|
||||
"2006",
|
||||
"2006-1", "2006-1-2", "2006-1-2 15", "2006-1-2 15:4", "2006-1-2 15:4:5", "2006-1-2 15:4:5.999999999",
|
||||
"2006.1", "2006.1.2", "2006.1.2 15", "2006.1.2 15:4", "2006.1.2 15:4:5", "2006.1.2 15:4:5.999999999",
|
||||
"2006/1", "2006/1/2", "2006/1/2 15", "2006/1/2 15:4", "2006/1/2 15:4:5", "2006/1/2 15:4:5.999999999",
|
||||
"2006-01-02 15:04:05 -0700 MST",
|
||||
"2006-01-02 15:04:05PM MST", "2006-01-02 15:04:05.999999999PM MST", "2006-1-2 15:4:5PM MST", "2006-1-2 15:4:5.999999999PM MST",
|
||||
"2006-01-02 15:04:05 PM MST", "2006-01-02 15:04:05.999999999 PM MST", "2006-1-2 15:4:5 PM MST", "2006-1-2 15:4:5.999999999 PM MST",
|
||||
"1/2/2006", "1/2/2006 15", "1/2/2006 15:4", "1/2/2006 15:4:5", "1/2/2006 15:4:5.999999999",
|
||||
"2006-1-2 15:4:5 -0700 MST", "2006-1-2 15:4:5.999999999 -0700 MST", "2006-1-2 15:04:05 -0700 MST", "2006-1-2 15:04:05.999999999 -0700 MST",
|
||||
"2006-01-02T15:04:05", "2006-01-02T15:04:05.999999999", "2006-1-2T3:4:5", "2006-1-2T3:4:5.999999999",
|
||||
"2006-01-02T15:04:05Z07", "2006-01-02T15:04:05.999999999Z07", "2006-1-2T15:4:5Z07", "2006-1-2T15:4:5.999999999Z07",
|
||||
"2006-01-02T15:04:05Z07:00", "2006-01-02T15:04:05.999999999Z07:00", "2006-1-2T15:4:5Z07:00", "2006-1-2T15:4:5.999999999Z07:00",
|
||||
"2006-01-02T15:04:05-07:00", "2006-01-02T15:04:05.999999999-07:00", "2006-1-2T15:4:5-07:00", "2006-1-2T15:4:5.999999999-07:00",
|
||||
"2006-01-02T15:04:05-0700", "2006-01-02T15:04:05.999999999-0700", "2006-1-2T3:4:5-0700", "2006-1-2T3:4:5.999999999-0700",
|
||||
"20060102150405-07:00", "20060102150405.999999999-07:00",
|
||||
"20060102150405Z07", "20060102150405.999999999Z07",
|
||||
"20060102150405Z07:00", "20060102150405.999999999Z07:00",
|
||||
}
|
||||
|
||||
// converts format to layout.
|
||||
// format 转 layout
|
||||
func format2layout(format string) string {
|
||||
buffer := bytes.NewBuffer(nil)
|
||||
for i := 0; i < len(format); i++ {
|
||||
if layout, ok := formats[format[i]]; ok {
|
||||
buffer.WriteString(layout)
|
||||
} else {
|
||||
switch format[i] {
|
||||
case '\\': // raw output, no parse
|
||||
buffer.WriteByte(format[i+1])
|
||||
i++
|
||||
continue
|
||||
default:
|
||||
buffer.WriteByte(format[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
return buffer.String()
|
||||
}
|
||||
|
||||
// gets a Location instance by a timezone string.
|
||||
// 通过时区获取 Location 实例
|
||||
func getLocationByTimezone(timezone string) (*time.Location, error) {
|
||||
loc, err := time.LoadLocation(timezone)
|
||||
if err != nil {
|
||||
err = invalidTimezoneError(timezone)
|
||||
}
|
||||
return loc, err
|
||||
}
|
||||
|
||||
// parses as a Duration instance by a duration string.
|
||||
// 通过时长解析
|
||||
func parseByDuration(duration string) (time.Duration, error) {
|
||||
td, err := time.ParseDuration(duration)
|
||||
if err != nil {
|
||||
err = invalidDurationError(duration)
|
||||
}
|
||||
return td, err
|
||||
}
|
||||
|
||||
// gets absolute value.
|
||||
// 获取绝对值
|
||||
func getAbsValue(value int64) int64 {
|
||||
return (value ^ value>>31) - value>>31
|
||||
}
|
||||
21
vendor/github.com/dromara/carbon/v2/lang/ar.json
generated
vendored
Normal file
21
vendor/github.com/dromara/carbon/v2/lang/ar.json
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "Arabic",
|
||||
"months": "يناير|فبراير|مارس|أبريل|مايو|يونيو|يوليو|أغسطس|سبتمبر|أكتوبر|نوفمبر|ديسمبر",
|
||||
"short_months": "يناير|فبراير|مارس|أبريل|مايو|يونيو|يوليو|أغسطس|سبتمبر|أكتوبر|نوفمبر|ديسمبر",
|
||||
"weeks": "الأحد|الإثنين|الثلاثاء|الأربعاء|الخميس|الجمعة|السبت",
|
||||
"short_weeks": "أحد|إثنين|ثلاثاء|أربعاء|خميس|جمعة|سبت",
|
||||
"seasons": "الربيع|الصيف|الخريف|الشتاء",
|
||||
"constellations": "الحمل|الثور|الجوزاء|السرطان|الأسد|العذراء|الميزان|العقرب|القوس|الجدي|الدلو|الحوت",
|
||||
"year": "1 سنة|%d سنوات",
|
||||
"month": "1 شهر|%d أشهر",
|
||||
"week": "1 أسبوع|%d أسابيع",
|
||||
"day": "1 يوم|%d أيام",
|
||||
"hour": "1 ساعة|%d ساعات",
|
||||
"minute": "1 دقيقة|%d دقائق",
|
||||
"second": "1 ثانية|%d ثواني",
|
||||
"now": "الآن",
|
||||
"ago": "%s مضت",
|
||||
"from_now": "من %s",
|
||||
"before": "%s قبل",
|
||||
"after": "%s بعد"
|
||||
}
|
||||
21
vendor/github.com/dromara/carbon/v2/lang/bg.json
generated
vendored
Normal file
21
vendor/github.com/dromara/carbon/v2/lang/bg.json
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "Български",
|
||||
"months": "Януари|Февруари|Март|Април|Май|Юни|Юли|Август|Септември|Октомври|Ноември|Декември",
|
||||
"short_months": "Ян|Фев|Март|Апр|Май|Юни|Юли|Авг|Сеп|Окт|Ноем|Дек",
|
||||
"weeks": "Неделя|Понеделник|Вторник|Сряда|Четвъртък|Петък|Събота",
|
||||
"short_weeks": "Нд|Пн|Вт|Ср|Чт|Пт|Сб",
|
||||
"seasons": "Пролет|Лято|Есен|Зима",
|
||||
"constellations": "Овен|Телец|Близнаци|Рак|Лъв|Дева|Везни|Скорпион|Стрелец|Козирог|Водолей|Риби",
|
||||
"year": "1 година|%d години",
|
||||
"month": "1 месец|%d месеца",
|
||||
"week": "1 седмица|%d седмици",
|
||||
"day": "1 ден|%d дни",
|
||||
"hour": "1 час|%d часа",
|
||||
"minute": "1 минута|%d минути",
|
||||
"second": "1 секунда|%d секунди",
|
||||
"now": "в момента",
|
||||
"ago": "%s преди",
|
||||
"from_now": "%s от сега",
|
||||
"before": "%s преди",
|
||||
"after": "%s след"
|
||||
}
|
||||
21
vendor/github.com/dromara/carbon/v2/lang/de.json
generated
vendored
Normal file
21
vendor/github.com/dromara/carbon/v2/lang/de.json
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "German",
|
||||
"months": "Januar|Februar|März|April|Mai|Juni|Juli|August|September|Oktober|November|Dezember",
|
||||
"short_months": "Jan|Feb|Mär|Apr|Mai|Jun|Jul|Aug|Sep|Okt|Nov|Dez",
|
||||
"weeks": "Sonntag|Montag|Dienstag|Mittwoch|Donnerstag|Freitag|Samstag",
|
||||
"short_weeks": "So|Mo|Di|Mi|Do|Fr|Sa",
|
||||
"seasons": "Frühling|Sommer|Herbst|Winter",
|
||||
"constellations": "Widder|Stier|Zwilling|Krebs|Löwe|Jungfrau|Waage|Skorpion|Schütze|Steinbock|Wassermann|Fisch",
|
||||
"year": "1 Jahr|%d Jahre",
|
||||
"month": "1 Monat|%d Monate",
|
||||
"week": "1 Woche|%d Wochen",
|
||||
"day": "1 Tag|%d Tage",
|
||||
"hour": "1 Stunde|%d Stunden",
|
||||
"minute": "1 Minute|%d Minuten",
|
||||
"second": "1 Sekunde|%d Sekunden",
|
||||
"now": "gerade eben",
|
||||
"ago": "vor %s",
|
||||
"from_now": "%s ab jetzt",
|
||||
"before": "%s davor",
|
||||
"after": "%s danach"
|
||||
}
|
||||
21
vendor/github.com/dromara/carbon/v2/lang/dk.json
generated
vendored
Normal file
21
vendor/github.com/dromara/carbon/v2/lang/dk.json
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "Dansk",
|
||||
"months": "januar|februar|marts|april|maj|juni|juli|august|september|oktober|november|december",
|
||||
"short_months": "jan|feb|mar|apr|maj|jun|jul|aug|sep|okt|nov|dec",
|
||||
"weeks": "søndag|mandag|tirsdag|onsdag|torsdag|fredag|lørdag",
|
||||
"short_weeks": "søn|man|tir|ons|tor|fre|lør",
|
||||
"seasons": "forår|sommer|efterår|vinter",
|
||||
"constellations": "vædder|tyr|tvilling|krebs|løve|jomfru|vægt|skorpion|skytte|stenbuk|vandmand|fisk",
|
||||
"year": "1 år|%d år",
|
||||
"month": "1 måned|%d måneder",
|
||||
"week": "1 uge|%d uger",
|
||||
"day": "1 dag|%d dage",
|
||||
"hour": "1 time|%d timer",
|
||||
"minute": "1 minut|%d minutter",
|
||||
"second": "1 sekund|%d sekunder",
|
||||
"now": "lige nu",
|
||||
"ago": "%s siden",
|
||||
"from_now": "om %s",
|
||||
"before": "%s før",
|
||||
"after": "%s efter"
|
||||
}
|
||||
21
vendor/github.com/dromara/carbon/v2/lang/en.json
generated
vendored
Normal file
21
vendor/github.com/dromara/carbon/v2/lang/en.json
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "English",
|
||||
"months": "January|February|March|April|May|June|July|August|September|October|November|December",
|
||||
"short_months": "Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec",
|
||||
"weeks": "Sunday|Monday|Tuesday|Wednesday|Thursday|Friday|Saturday",
|
||||
"short_weeks": "Sun|Mon|Tue|Wed|Thu|Fri|Sat",
|
||||
"seasons": "Spring|Summer|Autumn|Winter",
|
||||
"constellations": "Aries|Taurus|Gemini|Cancer|Leo|Virgo|Libra|Scorpio|Sagittarius|Capricorn|Aquarius|Pisces",
|
||||
"year": "1 year|%d years",
|
||||
"month": "1 month|%d months",
|
||||
"week": "1 week|%d weeks",
|
||||
"day": "1 day|%d days",
|
||||
"hour": "1 hour|%d hours",
|
||||
"minute": "1 minute|%d minutes",
|
||||
"second": "1 second|%d seconds",
|
||||
"now": "just now",
|
||||
"ago": "%s ago",
|
||||
"from_now": "%s from now",
|
||||
"before": "%s before",
|
||||
"after": "%s after"
|
||||
}
|
||||
21
vendor/github.com/dromara/carbon/v2/lang/es.json
generated
vendored
Normal file
21
vendor/github.com/dromara/carbon/v2/lang/es.json
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "Spanish",
|
||||
"months": "Enero|Febrero|Marzo|Abril|Mayo|Junio|Julio|Agosto|Septiembre|Octubre|Noviembre|Diciembre",
|
||||
"short_months": "Ene|Feb|Mar|Abr|May|Jun|Jul|Ago|Sep|Oct|Nov|Dic",
|
||||
"weeks": "Domingo|Lunes|Martes|Miércoles|Jueves|Viernes|Sábado",
|
||||
"short_weeks": "Dom|Lun|Mar|Mie|Jue|Vie|Sab",
|
||||
"seasons": "Primavera|Verano|Otoño|Invierno",
|
||||
"constellations": "Aries|Tauro|Geminis|Cancer|Leo|Virgo|Libra|Escorpio|Sagitario|Capricornio|Acuario|Piscis",
|
||||
"year": "1 año|%d años",
|
||||
"month": "1 mes|%d meses",
|
||||
"week": "1 semana|%d semanas",
|
||||
"day": "1 día|%d días",
|
||||
"hour": "1 hora|%d horas",
|
||||
"minute": "1 minuto|%d minutos",
|
||||
"second": "1 segundo|%d segundos",
|
||||
"now": "ahora",
|
||||
"ago": "hace %s",
|
||||
"from_now": "%s desde ahora",
|
||||
"before": "%s antes",
|
||||
"after": "%s después"
|
||||
}
|
||||
21
vendor/github.com/dromara/carbon/v2/lang/fa.json
generated
vendored
Normal file
21
vendor/github.com/dromara/carbon/v2/lang/fa.json
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "Farsi",
|
||||
"months": "ژانویه|فوریه|مارس|آوریل|مه|ژوئن|ژوئیه|اوت|سپتامبر|اکتبر|نوامبر|دسامبر",
|
||||
"short_months": "ژانویه|فوریه|مارس|آوریل|مه|ژوئن|ژوئیه|اوت|سپتامبر|اکتبر|نوامبر|دسامبر",
|
||||
"weeks": "یکشنبه|دوشنبه|سهشنبه|چهارشنبه|پنجشنبه|جمعه|شنبه",
|
||||
"short_weeks": "یکشنبه|دوشنبه|سهشنبه|چهارشنبه|پنجشنبه|جمعه|شنبه",
|
||||
"seasons": "بهار|تابستان|پاییز|زمستان",
|
||||
"constellations": "قوچ|گاو نر|دو پیکر|خرچنگ|شیر|خوشه|ترازو|عقرب|کماندار|بز|آبریز|ماهی",
|
||||
"year": "1 سال|%d سال",
|
||||
"month": "1 ماه|%d ماه",
|
||||
"week": "1 هفته|%d هفته",
|
||||
"day": "1 روز|%d روز",
|
||||
"hour": "1 ساعت|%d ساعت",
|
||||
"minute": "1 دقیقه|%d دقیقه",
|
||||
"second": "1 ثانیه|%d ثانیه",
|
||||
"now": "همین الان",
|
||||
"ago": "%s پیش",
|
||||
"from_now": "در %s",
|
||||
"before": "%s قبل",
|
||||
"after": "%s بعد"
|
||||
}
|
||||
21
vendor/github.com/dromara/carbon/v2/lang/fr.json
generated
vendored
Normal file
21
vendor/github.com/dromara/carbon/v2/lang/fr.json
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "French",
|
||||
"months": "Janvier|Février|Mars|Avril|Mai|Juin|Juillet|Août|Septembre|Octobre|Novembre|Décembre",
|
||||
"short_months": "Janv|Févr|Mars|Avril|Mai|Juin|Juil|Août|Sept|Oct|Nov|Déc",
|
||||
"weeks": "Dimanche|Lundi|Mardi|Mercredi|Jeudi|Vendredi|Samedi",
|
||||
"short_weeks": "Dim|Lun|Mar|Mer|Jeu|Ven|Sam",
|
||||
"seasons": "Le Printemps|L’été|L’Automne|L’Hiver",
|
||||
"constellations": "Bélier|Taureau|Gémeaux|Cancer|Lion|Vierge|Balance|Scorpion|Sagittaire|Capricorne|Verseau|Poissons",
|
||||
"year": "1 an|%d ans",
|
||||
"month": "1 mois|%d mois",
|
||||
"week": "1 semaine|%d semaines",
|
||||
"day": "1 jour|%d jours",
|
||||
"hour": "1 heure|%d heures",
|
||||
"minute": "1 minute|%d minutes",
|
||||
"second": "1 seconde|%d secondes",
|
||||
"now": "maintenant",
|
||||
"ago": "il y a %s",
|
||||
"from_now": "%s à partir de maintenant",
|
||||
"before": "avant %s",
|
||||
"after": "après %s"
|
||||
}
|
||||
21
vendor/github.com/dromara/carbon/v2/lang/hi.json
generated
vendored
Normal file
21
vendor/github.com/dromara/carbon/v2/lang/hi.json
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "Hindi",
|
||||
"months": "जनवरी|फ़रवरी|मार्च|अप्रैल|मई|जून|जुलाई|अगस्त|सितंबर|अक्टूबर|नवंबर|दिसंबर",
|
||||
"short_months": "जन|फ़र|मार्च|अप्रैल|मई|जून|जुलाई|अगस्त|सितंबर|अक्टूबर|नवंबर|दिसंबर",
|
||||
"weeks": "रविवार|सोमवार|मंगलवार|बुधवार|गुरुवार|शुक्रवार|शनिवार",
|
||||
"short_weeks": "रवि|सोम|मंगल|बुध|गुरु|शुक्र|शनि",
|
||||
"seasons": "वसंत|ग्रीष्म|पतझड़|शीत",
|
||||
"constellations": "मेष|वृषभ|मिथुन|कर्क|सिंह|कन्या|तुला|वृश्चिक|धनु|मकर|कुंभ|मीन",
|
||||
"year": "1 वर्ष|%d वर्ष",
|
||||
"month": "1 महीना|%d महीने",
|
||||
"week": "1 सप्ताह|%d सप्ताह",
|
||||
"day": "1 दिन|%d दिन",
|
||||
"hour": "1 घंटा|%d घंटे",
|
||||
"minute": "1 मिनट|%d मिनट",
|
||||
"second": "1 सेकंड|%d सेकंड",
|
||||
"now": "अभी",
|
||||
"ago": "%s पहले",
|
||||
"from_now": "%s बाद",
|
||||
"before": "%s पहले",
|
||||
"after": "%s बाद"
|
||||
}
|
||||
21
vendor/github.com/dromara/carbon/v2/lang/hu.json
generated
vendored
Normal file
21
vendor/github.com/dromara/carbon/v2/lang/hu.json
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "Hungarian",
|
||||
"months": "január|február|március|április|május|június|július|augusztus|szeptember|október|november|december",
|
||||
"short_months": "jan.|febr.|márc.|ápr.|máj.|jún.|júl.|aug.|szept.|okt.|nov.|dec.",
|
||||
"weeks": "Vasárnap|Hétfő|Kedd|Szerda|Csütörtök|Péntek|Szombat",
|
||||
"short_weeks": "Vas|Hét|Ke|Sze|Csü|Pé|Szo",
|
||||
"seasons": "Tavasz|Nyár|Ősz|Tél",
|
||||
"constellations": "Kos|Bika|Ikrek|Rák|Oroszlán|Szűz|Mérleg|Skorpió|Nyilas|Bak|Vízöntő|Halak",
|
||||
"year": "1 év|%d év",
|
||||
"month": "1 hónap|%d hónap",
|
||||
"week": "1 hét|%d hét",
|
||||
"day": "1 nap|%d nap",
|
||||
"hour": "1 óra|%d óra",
|
||||
"minute": "1 perc|%d perc",
|
||||
"second": "1 másodperc|%d másodperc",
|
||||
"now": "most",
|
||||
"ago": "%s",
|
||||
"from_now": "%s múlva",
|
||||
"before": "%s korábban",
|
||||
"after": "%s később"
|
||||
}
|
||||
21
vendor/github.com/dromara/carbon/v2/lang/id.json
generated
vendored
Normal file
21
vendor/github.com/dromara/carbon/v2/lang/id.json
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "Indonesian",
|
||||
"months": "Januari|Februari|Maret|April|Mei|Juni|Juli|Agustus|September|Oktober|November|Desember",
|
||||
"short_months": "Jan|Feb|Mar|Apr|Mei|Jun|Jul|Agt|Sep|Okt|Nov|Des",
|
||||
"weeks": "Minggu|Senin|Selasa|Rabu|Kamis|Jumaat|Sabtu",
|
||||
"short_weeks": "Min|Sen|Sel|Rab|Kam|Jum|Sab",
|
||||
"seasons": "Musim Semi|Musim Panas|Musim Gugur|Musim Salju",
|
||||
"constellations": "Aries|Taurus|Gemini|Cancer|Leo|Virgo|Libra|Scorpio|Sagitarius|Capricorn|Aquarius|Pisces",
|
||||
"year": "1 tahun|%d tahun",
|
||||
"month": "1 bulan|%d bulan",
|
||||
"week": "1 minggu|%d minggu",
|
||||
"day": "1 hari|%d hari",
|
||||
"hour": "1 jam|%d jam",
|
||||
"minute": "1 menit|%d menit",
|
||||
"second": "1 detik|%d detik",
|
||||
"now": "baru saja",
|
||||
"ago": "%s yang lalu",
|
||||
"from_now": "%s dari sekarang",
|
||||
"before": "%s sebelum",
|
||||
"after": "%s sesudah"
|
||||
}
|
||||
20
vendor/github.com/dromara/carbon/v2/lang/it.json
generated
vendored
Normal file
20
vendor/github.com/dromara/carbon/v2/lang/it.json
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"name": "Italian",
|
||||
"months": "Gennaio|Febbraio|Marzo|Aprile|Maggio|Giugno|Luglio|Agosto|Settembre|Ottobre|Novembre|Dicembre",
|
||||
"short_months": "Gen|Feb|Mar|Apr|Mag|Giu|Lug|Ago|Set|Ott|Nov|Dic",
|
||||
"weeks": "Domenica|Lunedí|Martedí|Mercoledí|Giovedí|Venerdí|Sabato",
|
||||
"short_weeks": "Dom|Lun|Mar|Mer|Gio|Ven|Sab",
|
||||
"seasons": "Primavera|Estate|Autunno|Inverno",
|
||||
"year": "1 anno|%d anni",
|
||||
"month": "1 mese|%d mesi",
|
||||
"week": "1 settimana|%d settimane",
|
||||
"day": "1 giorno|%d giorni",
|
||||
"hour": "1 ora|%d ore",
|
||||
"minute": "1 minuto|%d minuti",
|
||||
"second": "1 secondo|%d secondi",
|
||||
"now": "proprio ora",
|
||||
"ago": "%s fa",
|
||||
"from_now": "%s da adesso",
|
||||
"before": "%s prima",
|
||||
"after": "%s dopo"
|
||||
}
|
||||
21
vendor/github.com/dromara/carbon/v2/lang/jp.json
generated
vendored
Normal file
21
vendor/github.com/dromara/carbon/v2/lang/jp.json
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "Japanese",
|
||||
"months": "1月|2月|3月|4月|5月|6月|7月|8月|9月|10月|11月|12月",
|
||||
"short_months": "1月|2月|3月|4月|5月|6月|7月|8月|9月|10月|11月|12月",
|
||||
"weeks": "日曜日|月曜日|火曜日|水曜日|木曜日|金曜日|土曜日",
|
||||
"short_weeks": "日|月|火|水|木|金|土",
|
||||
"seasons": "春|夏|秋|冬",
|
||||
"constellations": "おひつじ座|おうし座|ふたご座|かに座|しし座|おとめ座|てんびん座|さそり座|いて座|やぎ座|みずがめ座|うお座",
|
||||
"year": "%d 年",
|
||||
"month": "%d ヶ月",
|
||||
"week": "%d 週間",
|
||||
"day": "%d 日",
|
||||
"hour": "%d 時間",
|
||||
"minute": "%d 分",
|
||||
"second": "%d 秒",
|
||||
"now": "現在",
|
||||
"ago": "%s前",
|
||||
"from_now": "%s後",
|
||||
"before": "%s前",
|
||||
"after": "%s後"
|
||||
}
|
||||
21
vendor/github.com/dromara/carbon/v2/lang/kr.json
generated
vendored
Normal file
21
vendor/github.com/dromara/carbon/v2/lang/kr.json
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "Korean",
|
||||
"months": "일월|이월|삼월|사월|오월|유월|칠월|팔월|구월|시월|십일월|십이월",
|
||||
"short_months": "1월|2월|3월|4월|5월|6월|7월|8월|9월|10월|11월|12월",
|
||||
"weeks": "일요일|월요일|화요일|수요일|목요일|금요일|토요일",
|
||||
"short_weeks": "일요일|월요일|화요일|수요일|목요일|금요일|토요일",
|
||||
"seasons": "봄|여름|가을|겨울",
|
||||
"constellations": "양자리|황소자리|쌍둥이자리|게자리|사자자리|처녀자리|천칭자리|전갈자리|사수자리|염소자리|물병자리|물고기자리",
|
||||
"year": "%d 년",
|
||||
"month": "%d 개월",
|
||||
"week": "%d 주",
|
||||
"day": "%d 일",
|
||||
"hour": "%d 시간",
|
||||
"minute": "%d 분",
|
||||
"second": "%d 초",
|
||||
"now": "방금",
|
||||
"ago": "%s앞",
|
||||
"from_now": "%s후",
|
||||
"before": "%s전",
|
||||
"after": "%s후"
|
||||
}
|
||||
21
vendor/github.com/dromara/carbon/v2/lang/ms-MY.json
generated
vendored
Normal file
21
vendor/github.com/dromara/carbon/v2/lang/ms-MY.json
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "Bahasa Malaysia",
|
||||
"months": "Januari|Februari|Mac|April|Mei|Jun|Julai|Ogos|September|Oktober|November|Disember",
|
||||
"short_months": "Jan|Feb|Mac|Apr|Mei|Jun|Jul|Ogs|Sep|Okt|Nov|Dis",
|
||||
"weeks": "Ahad|Isnin|Selasa|Rabu|Khamis|Jumaat|Sabtu",
|
||||
"short_weeks": "Ahd|Isn|Sel|Rab|Kha|Jum|Sab",
|
||||
"seasons": "Musim Bunga|Musim Panas|Musim Luruh|Musim Sejuk",
|
||||
"constellations": "Aries|Taurus|Gemini|Cancer|Leo|Virgo|Libra|Scorpio|Sagittarius|Capricorn|Aquarius|Pisces",
|
||||
"year": "1 tahun|%d tahun",
|
||||
"month": "1 bulan|%d bulan",
|
||||
"week": "1 minggu|%d minggu",
|
||||
"day": "1 hari|%d hari",
|
||||
"hour": "1 jam|%d jam",
|
||||
"minute": "1 minit|%d minit",
|
||||
"second": "1 saat|%d saat",
|
||||
"now": "baru tadi",
|
||||
"ago": "%s lalu",
|
||||
"from_now": "%s dari sekarang",
|
||||
"before": "sebelum %s",
|
||||
"after": "selepas %s"
|
||||
}
|
||||
21
vendor/github.com/dromara/carbon/v2/lang/nl.json
generated
vendored
Normal file
21
vendor/github.com/dromara/carbon/v2/lang/nl.json
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "Dutch",
|
||||
"months": "januari|februari|maart|april|mei|juni|juli|augustus|september|oktober|november|december",
|
||||
"short_months": "jan|feb|mrt|apr|mei|jun|jul|aug|sep|okt|nov|dec",
|
||||
"weeks": "Zondag|Maandag|Dinsdag|Woensdag|Donderdag|Vrijdag|Zaterdag|Zondag",
|
||||
"short_weeks": "zo|ma|di|wo|do|vr|za",
|
||||
"seasons": "Lente|Zomer|Herfst|Winter",
|
||||
"constellations": "Ram|Stier|Tweelingen|Kreeft|Leeuw|Maagd|Weegschaal|Schorpioen|Boogschutter|Steenbok|Waterman|Vissen",
|
||||
"year": "1 jaar|%d jaren",
|
||||
"month": "1 maand|%d maanden",
|
||||
"week": "1 week|%d weken",
|
||||
"day": "1 dag|%d dagen",
|
||||
"hour": "1 uur|%d uren",
|
||||
"minute": "1 minuut|%d minuten",
|
||||
"second": "1 seconde|%d seconden",
|
||||
"now": "zojuist",
|
||||
"ago": "%s geleden",
|
||||
"from_now": "%s vanaf nu",
|
||||
"before": "%s voor",
|
||||
"after": "%s na"
|
||||
}
|
||||
21
vendor/github.com/dromara/carbon/v2/lang/pl.json
generated
vendored
Normal file
21
vendor/github.com/dromara/carbon/v2/lang/pl.json
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "Polish",
|
||||
"months": "stycznia|lutego|marca|kwietnia|maja|czerwca|lipca|sierpnia|września|października|listopada|grudnia",
|
||||
"short_months": "sty|lut|mar|kwi|maj|cze|lip|sie|wrz|paź|lis|gru",
|
||||
"weeks": "niedziela|poniedziałek|wtorek|środa|czwartek|piątek|sobota",
|
||||
"short_weeks": "ndz|pon|wt|śr|czw|pt|sob",
|
||||
"seasons": "sprężyna|lato|jesień|zima",
|
||||
"constellations": "baran|byk|bliźnięta|rak|lew|dziewica|waga|skorpion|strzelec|koziorożec|wodnik|ryby",
|
||||
"year": "1 rok|2 lata|%d lat",
|
||||
"month": "1 miesiąc|2 miesiące|%d miesięcy",
|
||||
"week": "1 tydzień|2 tygodnie|%d tygodni",
|
||||
"day": "1 dzień|%d dni",
|
||||
"hour": "1 godzina|2 godziny|%d godzin",
|
||||
"minute": "1 minuta|2 minuty|%d minut",
|
||||
"second": "1 sekunda|2 sekundy|%d sekund",
|
||||
"now": "teraz",
|
||||
"ago": "%s temu",
|
||||
"from_now": "%s po",
|
||||
"before": "%s przed",
|
||||
"after": "%s po"
|
||||
}
|
||||
21
vendor/github.com/dromara/carbon/v2/lang/pt.json
generated
vendored
Normal file
21
vendor/github.com/dromara/carbon/v2/lang/pt.json
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "Portuguese",
|
||||
"months": "Janeiro|Fevereiro|Março|Abril|Maio|Junho|Julho|Agosto|Setembro|Outubro|Novembro|Dezembro",
|
||||
"short_months": "Jan|Fev|Mar|Abr|Maio|Jun|Jul|Ago|Set|Out|Nov|Dez",
|
||||
"weeks": "Domingo|Segunda-feira|Terça-feira|Quarta-feira|Quinta-feira|Sexta-feira|Sábado",
|
||||
"short_weeks": "Dom|Seg|Ter|Qua|Qui|Sex|Sab",
|
||||
"seasons": "Primavera|Verão|Outono|Inverno",
|
||||
"constellations": "Áries|Touro|Gêmeos|Câncer|Leão|Virgem|Libra|Escorpião|Sagitário|Capricórnio|Aquário|Peixes",
|
||||
"year": "1 ano|%d anos",
|
||||
"month": "1 mês|%d meses",
|
||||
"week": "1 semana|%d semanas",
|
||||
"day": "1 dia|%d dias",
|
||||
"hour": "1 hora|%d horas",
|
||||
"minute": "1 minuto|%d minutos",
|
||||
"second": "1 segundo|%d segundos",
|
||||
"now": "agora",
|
||||
"ago": "%s atrás",
|
||||
"from_now": "%s a partir de agora",
|
||||
"before": "%s antes",
|
||||
"after": "%s depois"
|
||||
}
|
||||
21
vendor/github.com/dromara/carbon/v2/lang/ro.json
generated
vendored
Normal file
21
vendor/github.com/dromara/carbon/v2/lang/ro.json
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "Romanian",
|
||||
"months": "Ianuarie|Februarie|Martie|Aprilie|Mai|Iunie|Iulie|August|Septembrie|Octombrie|Noiembrie|Decembrie",
|
||||
"short_months": "Ian|Feb|Mar|Apr|Mai|Iun|Iul|Aug|Sep|Oct|Noi|Dec",
|
||||
"weeks": "Duminică|Luni|Marți|Miercuri|Joi|Vineri|Sîmbătă",
|
||||
"short_weeks": "Dum|Lun|Mar|Mie|Joi|Vin|Sîm",
|
||||
"seasons": "Primăvara|Vara|Toamna|Iarna",
|
||||
"constellations": "Berbec|Taur|Gemeni|Rac|Leu|Fecioară|Balanță|Scorpion|Săgetător|Capricorn|Vărsător|Pești",
|
||||
"year": "1 an|%d ani",
|
||||
"month": "1 lună|%d luni",
|
||||
"week": "1 săptămînă|%d săptămîni",
|
||||
"day": "1 zi|%d zile",
|
||||
"hour": "1 oră|%d ore",
|
||||
"minute": "1 minută|%d minute",
|
||||
"second": "1 secundă|%d secunde",
|
||||
"now": "chiar acum",
|
||||
"ago": "%s în urmă",
|
||||
"from_now": "%s de acum",
|
||||
"before": "%s înainte",
|
||||
"after": "%s după"
|
||||
}
|
||||
21
vendor/github.com/dromara/carbon/v2/lang/ru.json
generated
vendored
Normal file
21
vendor/github.com/dromara/carbon/v2/lang/ru.json
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "Russian",
|
||||
"months": "Январь|Февраль|Март|Апрель|Май|Июнь|Июль|Август|Сентябрь|Октябрь|Ноябрь|Декабрь",
|
||||
"short_months": "Янв|Фев|Мар|Апр|Май|Июн|Июл|Авг|Сен|Окт|Ноя|Дек",
|
||||
"weeks": "Воскресенье|Понедельник|Вторник|Среда|Четверг|Пятница|Суббота",
|
||||
"short_weeks": "Вс|Пн|Вт|Ср|Чт|Пт|Сб",
|
||||
"seasons": "Весна|Лето|Осень|Зима",
|
||||
"constellations": "Овен|Телец|Близнецы|Рак|Лев|Дева|Весы|Скорпион|Стрелец|Козерог|Водолей|Рыбы",
|
||||
"year": "1 год|2 года|3 года|4 года|%d лет",
|
||||
"month": "1 месяц|2 месяца|3 месяца|4 месяца|%d месяцев",
|
||||
"week": "1 неделя|2 недели|3 недели|4 недели|%d недель",
|
||||
"day": "1 день|2 дня|3 дня|4 дня|%d дней",
|
||||
"hour": "1 час|2 часа|3 часа|4 часа|%d часов",
|
||||
"minute": "1 минуту|2 минуты|3 минуты|4 минуты|%d минут",
|
||||
"second": "1 секунда|2 секунды|3 секунды|4 секунды|%d секунд",
|
||||
"now": "сейчас",
|
||||
"ago": "%s назад",
|
||||
"from_now": "через %s",
|
||||
"before": "за %s до",
|
||||
"after": "через %s после"
|
||||
}
|
||||
21
vendor/github.com/dromara/carbon/v2/lang/se.json
generated
vendored
Normal file
21
vendor/github.com/dromara/carbon/v2/lang/se.json
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "Swedish",
|
||||
"months": "Januari|Februari|Mars|April|Maj|Juni|Juli|Augusti|September|Oktober|November|December",
|
||||
"short_months": "Jan|Feb|Mars|April|Maj|Juni|Juli|Aug|Sep|Okt|Nov|Dec",
|
||||
"weeks": "Söndag|Måndag|Tisdag|Onsdag|Torsdag|Fredag|Lördag",
|
||||
"short_weeks": "Sön|Mån|Tis|Ons|Tors|Fre|Lör",
|
||||
"seasons": "Vår|Sommar|Höst|Vinter",
|
||||
"constellations": "Väduren|Oxen|Tvillingarna|Kräftan|Lejonet|Jungfrun|Vågen|Skorpionen|Skytten|Stenbocken|Vattumannen|Fiskarna",
|
||||
"year": "1 år|%d år",
|
||||
"month": "1 månad|%d månader",
|
||||
"week": "1 vecka|%d veckor",
|
||||
"day": "1 dag|%d dagar",
|
||||
"hour": "1 timme|%d timmar",
|
||||
"minute": "1 minut|%d minuter",
|
||||
"second": "1 sekund|%d sekunder",
|
||||
"now": "just nu",
|
||||
"ago": "%s sedan",
|
||||
"from_now": "%s fr.o.m. nu",
|
||||
"before": "%s innan",
|
||||
"after": "%s efter"
|
||||
}
|
||||
21
vendor/github.com/dromara/carbon/v2/lang/th.json
generated
vendored
Normal file
21
vendor/github.com/dromara/carbon/v2/lang/th.json
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "Thailand",
|
||||
"months": "มกราคม|กุมภาพันธ์|มีนาคม|เมษายน|พฤษภาคม|มิถุนายน|กรกฎาคม|สิงหาคม|กันยายน|ตุลาคม|พฤศจิกายน|ธันวาคม",
|
||||
"short_months": "ม.ค.|ก.พ.|มี.ค.|เม.ย.|พ.ค.|มิ.ย.|ก.ค.|ส.ค.|ก.ย.|ต.ค.|พ.ย.|ธ.ค.",
|
||||
"weeks": "อาทิตย์|จันทร์|อังคาร|พุธ|พฤหัสบดี|ศุกร์|เสาร์",
|
||||
"short_weeks": "อา.|จ.|อัง.|พ.|พฤ.|ศ.|ส.",
|
||||
"seasons": "ฤดูใบไม้ผลิ|ฤดูร้อน|ฤดูใบไม้ร่วง|ฤดูหนาว",
|
||||
"constellations": "เมษ|พฤษภ|เมถุน|กรกฎ|สิงห์|กันย์|ตุลย์|พิจิก|ธนู|มังกร|กุมภ์|มีน",
|
||||
"year": "1 ปี|%d ปี",
|
||||
"month": "1 เดือน|%d เดือน",
|
||||
"week": "1 สัปดาห์|%d สัปดาห์",
|
||||
"day": "1 วัน|%d วัน",
|
||||
"hour": "1 ชั่วโมง|%d ชั่วโมง",
|
||||
"minute": "1 นาที|%d นาที",
|
||||
"second": "1 วินาที|%d วินาที",
|
||||
"now": "ไม่กี่วินาทีที่แล้ว",
|
||||
"ago": "%s ที่แล้ว",
|
||||
"from_now": "อีก %s",
|
||||
"before": "%s ก่อน",
|
||||
"after": "%s หลังจากนี้"
|
||||
}
|
||||
21
vendor/github.com/dromara/carbon/v2/lang/tr.json
generated
vendored
Normal file
21
vendor/github.com/dromara/carbon/v2/lang/tr.json
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "Turkish",
|
||||
"months": "Ocak|Şubat|Mart|Nisan|Mayıs|Haziran|Temmuz|Ağustos|Eylül|Ekim|Kasım|Aralık",
|
||||
"short_months": "Oca|Şub|Mar|Nis|May|Haz|Tem|Ağu|Eyl|Eki|Kas|Ara",
|
||||
"weeks": "Pazar|Pazartesi|Salı|Çarşamba|Perşembe|Cuma|Cumartesi",
|
||||
"short_weeks": "Paz|Pts|Sal|Çrş|Per|Cum|Cts",
|
||||
"seasons": "İlkbahar|Yaz|Sonbahar|Kış",
|
||||
"constellations": "Koç|Boğa|İkizler|Yengeç|Aslan|Başak|Terazi|Akrep|Yay|Oğlak|Kova|Balık",
|
||||
"year": "bir yıl|%d yıl",
|
||||
"month": "bir ay|%d ay",
|
||||
"week": "bir hafta|%d hafta",
|
||||
"day": "bir gün|%d gün",
|
||||
"hour": "bir saat|%d saat",
|
||||
"minute": "bir dakika|%d dakika",
|
||||
"second": "bir saniye|%d saniye",
|
||||
"now": "az önce",
|
||||
"ago": "%s evvel",
|
||||
"from_now": "şu andan itibaren %s sonra",
|
||||
"before": "%s önce",
|
||||
"after": "%s sonra"
|
||||
}
|
||||
21
vendor/github.com/dromara/carbon/v2/lang/uk.json
generated
vendored
Normal file
21
vendor/github.com/dromara/carbon/v2/lang/uk.json
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "Ukrainian",
|
||||
"months": "січня|лютого|березня|квітня|травня|червня|липня|серпня|вересня|жовтня|листопада|грудня",
|
||||
"short_months": "січ|лют|бер|квіт|трав|черв|лип|серп|вер|жовт|лист|груд",
|
||||
"weeks": "неділя|понеділок|вівторок|середа|четвер|п’ятниця|субота",
|
||||
"short_weeks": "ндл|пнд|втр|срд|чтв|птн|сбт",
|
||||
"seasons": "Весна|Літо|Осінь|Зима",
|
||||
"constellations": "Овен|Телець|Близнюки|Рак|Лев|Діва|Терези|Скорпіон|Стрілець|Козоріг|Водолій|Риби",
|
||||
"year": "рік|2 роки|3 роки|4 роки|%d років",
|
||||
"month": "місяць|2 місяці|3 місяці|4 місяці|%d місяців",
|
||||
"week": "tиждень|2 тижні|3 тижні|4 тижні|%d тижнів",
|
||||
"day": "день|2 дні|3 дні|4 дні|%d днів",
|
||||
"hour": "1 година|2 години|3 години|4 години|%d годин",
|
||||
"minute": "1 хвилина|2 хвилини|3 хвилини|4 хвилини|%d хвилин",
|
||||
"second": "1 секунда|2 секунди|3 секунди|4 секунди|%d секунд",
|
||||
"now": "зараз",
|
||||
"ago": "%s тому",
|
||||
"from_now": "за %s",
|
||||
"before": "%s до",
|
||||
"after": "%s після"
|
||||
}
|
||||
21
vendor/github.com/dromara/carbon/v2/lang/vi.json
generated
vendored
Normal file
21
vendor/github.com/dromara/carbon/v2/lang/vi.json
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "VietNamese",
|
||||
"months": "Tháng Một|Tháng Hai|Tháng Ba|Tháng Tư|Tháng Năm|Tháng Sáu|Tháng Bảy|Tháng Tám|Tháng Chín|Tháng Mười|Tháng Mười Một|Tháng Mười Hai",
|
||||
"short_months": "Giêng|Hai|Ba|Bốn|Năm|Sáu|Bảy|Tám|Chìn|Mười|Một|Chạp",
|
||||
"weeks": "Chủ Nhật|Thứ Hai|Thứ Ba|Thứ Tư|Thứ Năm|Thứ Sáu|Thứ Bảy",
|
||||
"short_weeks": "CN|Hai|Ba|Tư|Năm|Sáu|Bảy",
|
||||
"seasons": "Xuân|Hè|Thu|Đông",
|
||||
"constellations": "Bạch Dương|Kim Ngưu|Song Tử|Cự Giải|Sư Tử|Xử Nữ|Thiên Bình|Bọ Cạp|Nhân Mã|Ma Kết|Bảo Bình|Song Ngư",
|
||||
"year": "%d năm",
|
||||
"month": "%d tháng",
|
||||
"week": "%d tuần",
|
||||
"day": "%d ngày",
|
||||
"hour": "%d giờ",
|
||||
"minute": "%d phút",
|
||||
"second": "%d giây",
|
||||
"now": "vừa xong",
|
||||
"ago": "%s trước",
|
||||
"from_now": "%s từ bây giờ",
|
||||
"before": "%s trước",
|
||||
"after": "%s sau"
|
||||
}
|
||||
21
vendor/github.com/dromara/carbon/v2/lang/zh-CN.json
generated
vendored
Normal file
21
vendor/github.com/dromara/carbon/v2/lang/zh-CN.json
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "Simplified Chinese",
|
||||
"months": "一月|二月|三月|四月|五月|六月|七月|八月|九月|十月|十一月|十二月",
|
||||
"short_months": "1月|2月|3月|4月|5月|6月|7月|8月|9月|10月|11月|12月",
|
||||
"weeks": "星期日|星期一|星期二|星期三|星期四|星期五|星期六",
|
||||
"short_weeks": "周日|周一|周二|周三|周四|周五|周六",
|
||||
"seasons": "春季|夏季|秋季|冬季",
|
||||
"constellations": "白羊座|金牛座|双子座|巨蟹座|狮子座|处女座|天秤座|天蝎座|射手座|摩羯座|水瓶座|双鱼座",
|
||||
"year": "%d 年",
|
||||
"month": "%d 个月",
|
||||
"week": "%d 周",
|
||||
"day": "%d 天",
|
||||
"hour": "%d 小时",
|
||||
"minute": "%d 分钟",
|
||||
"second": "%d 秒",
|
||||
"now": "刚刚",
|
||||
"ago": "%s前",
|
||||
"from_now": "%s后",
|
||||
"before": "%s前",
|
||||
"after": "%s后"
|
||||
}
|
||||
21
vendor/github.com/dromara/carbon/v2/lang/zh-TW.json
generated
vendored
Normal file
21
vendor/github.com/dromara/carbon/v2/lang/zh-TW.json
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "Traditional Chinese",
|
||||
"months": "一月|二月|三月|四月|五月|六月|七月|八月|九月|十月|十一月|十二月",
|
||||
"short_months": "1月|2月|3月|4月|5月|6月|7月|8月|9月|10月|11月|12月",
|
||||
"weeks": "星期日|星期一|星期二|星期三|星期四|星期五|星期六",
|
||||
"short_weeks": "週日|週一|週二|週三|週四|週五|週六",
|
||||
"seasons": "春季|夏季|秋季|冬季",
|
||||
"constellations": "白羊座|金牛座|雙子座|巨蟹座|獅子座|處女座|天秤座|天蠍座|射手座|摩羯座|水瓶座|雙魚座",
|
||||
"year": "%d 年",
|
||||
"month": "%d 個月",
|
||||
"week": "%d 週",
|
||||
"day": "%d 天",
|
||||
"hour": "%d 小時",
|
||||
"minute": "%d 分鐘",
|
||||
"second": "%d 秒",
|
||||
"now": "剛剛",
|
||||
"ago": "%s前",
|
||||
"from_now": "%s後",
|
||||
"before": "%s前",
|
||||
"after": "%s後"
|
||||
}
|
||||
109
vendor/github.com/dromara/carbon/v2/language.go
generated
vendored
Normal file
109
vendor/github.com/dromara/carbon/v2/language.go
generated
vendored
Normal file
@@ -0,0 +1,109 @@
|
||||
package carbon
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
)
|
||||
|
||||
//go:embed lang
|
||||
var fs embed.FS
|
||||
|
||||
var (
|
||||
// invalid locale error
|
||||
// 无效的区域错误
|
||||
invalidLocaleError = func(locale string) error {
|
||||
return fmt.Errorf("invalid locale file %q, please make sure the json file exists and is valid", locale)
|
||||
}
|
||||
)
|
||||
|
||||
// Language defines a Language struct.
|
||||
// 定义 Language 结构体
|
||||
type Language struct {
|
||||
dir string
|
||||
locale string
|
||||
resources map[string]string
|
||||
Error error
|
||||
rw *sync.RWMutex
|
||||
}
|
||||
|
||||
// NewLanguage returns a new Language instance.
|
||||
// 初始化 Language 结构体
|
||||
func NewLanguage() *Language {
|
||||
return &Language{
|
||||
dir: "lang/",
|
||||
locale: defaultLocale,
|
||||
resources: make(map[string]string),
|
||||
rw: new(sync.RWMutex),
|
||||
}
|
||||
}
|
||||
|
||||
// SetLanguage sets language.
|
||||
// 设置语言对象
|
||||
func SetLanguage(lang *Language) Carbon {
|
||||
c := NewCarbon()
|
||||
lang.SetLocale(lang.locale)
|
||||
c.lang, c.Error = lang, lang.Error
|
||||
return c
|
||||
}
|
||||
|
||||
// SetLocale sets language locale.
|
||||
// 设置区域
|
||||
func (lang *Language) SetLocale(locale string) *Language {
|
||||
lang.rw.Lock()
|
||||
defer lang.rw.Unlock()
|
||||
|
||||
if len(lang.resources) != 0 {
|
||||
return lang
|
||||
}
|
||||
lang.locale = locale
|
||||
fileName := lang.dir + locale + ".json"
|
||||
bytes, err := fs.ReadFile(fileName)
|
||||
if err != nil {
|
||||
lang.Error = invalidLocaleError(fileName)
|
||||
return lang
|
||||
}
|
||||
_ = json.Unmarshal(bytes, &lang.resources)
|
||||
return lang
|
||||
}
|
||||
|
||||
// SetResources sets language resources.
|
||||
// 设置资源
|
||||
func (lang *Language) SetResources(resources map[string]string) *Language {
|
||||
lang.rw.Lock()
|
||||
defer lang.rw.Unlock()
|
||||
|
||||
if len(lang.resources) == 0 {
|
||||
lang.resources = resources
|
||||
return lang
|
||||
}
|
||||
for k, v := range resources {
|
||||
if _, ok := lang.resources[k]; ok {
|
||||
lang.resources[k] = v
|
||||
}
|
||||
}
|
||||
return lang
|
||||
}
|
||||
|
||||
// returns a translated string.
|
||||
// 翻译转换
|
||||
func (lang *Language) translate(unit string, value int64) string {
|
||||
if len(lang.resources) == 0 {
|
||||
lang.SetLocale(defaultLocale)
|
||||
}
|
||||
slice := strings.Split(lang.resources[unit], "|")
|
||||
number := getAbsValue(value)
|
||||
if len(slice) == 1 {
|
||||
return strings.Replace(slice[0], "%d", strconv.FormatInt(value, 10), 1)
|
||||
}
|
||||
if int64(len(slice)) <= number {
|
||||
return strings.Replace(slice[len(slice)-1], "%d", strconv.FormatInt(value, 10), 1)
|
||||
}
|
||||
if !strings.Contains(slice[number-1], "%d") && value < 0 {
|
||||
return "-" + slice[number-1]
|
||||
}
|
||||
return strings.Replace(slice[number-1], "%d", strconv.FormatInt(value, 10), 1)
|
||||
}
|
||||
892
vendor/github.com/dromara/carbon/v2/outputer.go
generated
vendored
Normal file
892
vendor/github.com/dromara/carbon/v2/outputer.go
generated
vendored
Normal file
@@ -0,0 +1,892 @@
|
||||
package carbon
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// String implements the interface Stringer for Carbon struct.
|
||||
// 实现 Stringer 接口
|
||||
func (c Carbon) String() string {
|
||||
return c.Layout(c.layout, c.Location())
|
||||
}
|
||||
|
||||
// GoString implements fmt.GoStringer and formats c to be printed in Go source code.
|
||||
// 实现 fmt.GoStringer 接口,并格式化 c 以在 Go 源代码中打印
|
||||
func (c Carbon) GoString() string {
|
||||
if c.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
return c.StdTime().GoString()
|
||||
}
|
||||
|
||||
// ToString outputs a string in "2006-01-02 15:04:05.999999999 -0700 MST" layout.
|
||||
// 输出 "2006-01-02 15:04:05.999999999 -0700 MST" 格式字符串
|
||||
func (c Carbon) ToString(timezone ...string) string {
|
||||
if c.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
return c.StdTime().String()
|
||||
}
|
||||
|
||||
// ToMonthString outputs a string in month layout like "January", i18n is supported.
|
||||
// 输出完整月份字符串,支持i18n
|
||||
func (c Carbon) ToMonthString(timezone ...string) string {
|
||||
if c.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
if len(c.lang.resources) == 0 {
|
||||
c.lang.SetLocale(defaultLocale)
|
||||
}
|
||||
c.lang.rw.RLock()
|
||||
defer c.lang.rw.RUnlock()
|
||||
if resources, ok := c.lang.resources["months"]; ok {
|
||||
slice := strings.Split(resources, "|")
|
||||
if len(slice) == MonthsPerYear {
|
||||
return slice[c.Month()-1]
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// ToShortMonthString outputs a string in short month layout like "Jan", i18n is supported.
|
||||
// 输出缩写月份字符串,支持i18n
|
||||
func (c Carbon) ToShortMonthString(timezone ...string) string {
|
||||
if c.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
if len(c.lang.resources) == 0 {
|
||||
c.lang.SetLocale(defaultLocale)
|
||||
}
|
||||
c.lang.rw.RLock()
|
||||
defer c.lang.rw.RUnlock()
|
||||
if resources, ok := c.lang.resources["short_months"]; ok {
|
||||
slice := strings.Split(resources, "|")
|
||||
if len(slice) == MonthsPerYear {
|
||||
return slice[c.Month()-1]
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// ToWeekString outputs a string in week layout like "Sunday", i18n is supported.
|
||||
// 输出完整星期字符串,支持i18n
|
||||
func (c Carbon) ToWeekString(timezone ...string) string {
|
||||
if c.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
if len(c.lang.resources) == 0 {
|
||||
c.lang.SetLocale(defaultLocale)
|
||||
}
|
||||
c.lang.rw.RLock()
|
||||
defer c.lang.rw.RUnlock()
|
||||
if resources, ok := c.lang.resources["weeks"]; ok {
|
||||
slice := strings.Split(resources, "|")
|
||||
if len(slice) == DaysPerWeek {
|
||||
return slice[c.DayOfWeek()%DaysPerWeek]
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// ToShortWeekString outputs a string in short week layout like "Sun", i18n is supported.
|
||||
// 输出缩写星期字符串,支持i18n
|
||||
func (c Carbon) ToShortWeekString(timezone ...string) string {
|
||||
if c.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
if len(c.lang.resources) == 0 {
|
||||
c.lang.SetLocale(defaultLocale)
|
||||
}
|
||||
c.lang.rw.RLock()
|
||||
defer c.lang.rw.RUnlock()
|
||||
if resources, ok := c.lang.resources["short_weeks"]; ok {
|
||||
slice := strings.Split(resources, "|")
|
||||
if len(slice) == DaysPerWeek {
|
||||
return slice[c.DayOfWeek()%DaysPerWeek]
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// ToDayDateTimeString outputs a string in "Mon, Jan 2, 2006 3:04 PM" layout.
|
||||
// 输出 "Mon, Jan 2, 2006 3:04 PM" 格式字符串
|
||||
func (c Carbon) ToDayDateTimeString(timezone ...string) string {
|
||||
if c.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
return c.StdTime().Format(DayDateTimeLayout)
|
||||
}
|
||||
|
||||
// ToDateTimeString outputs a string in "2006-01-02 15:04:05" layout.
|
||||
// 输出 "2006-01-02 15:04:05" 格式字符串
|
||||
func (c Carbon) ToDateTimeString(timezone ...string) string {
|
||||
if c.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
return c.StdTime().Format(DateTimeLayout)
|
||||
}
|
||||
|
||||
// ToDateTimeMilliString outputs a string in "2006-01-02 15:04:05.999" layout.
|
||||
// 输出 "2006-01-02 15:04:05.999" 格式字符串
|
||||
func (c Carbon) ToDateTimeMilliString(timezone ...string) string {
|
||||
if c.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
return c.StdTime().Format(DateTimeMilliLayout)
|
||||
}
|
||||
|
||||
// ToDateTimeMicroString outputs a string in "2006-01-02 15:04:05.999999" layout.
|
||||
// 输出 "2006-01-02 15:04:05.999999" 格式字符串
|
||||
func (c Carbon) ToDateTimeMicroString(timezone ...string) string {
|
||||
if c.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
return c.StdTime().Format(DateTimeMicroLayout)
|
||||
}
|
||||
|
||||
// ToDateTimeNanoString outputs a string in "2006-01-02 15:04:05.999999999" layout.
|
||||
// 输出 "2006-01-02 15:04:05.999999999" 格式字符串
|
||||
func (c Carbon) ToDateTimeNanoString(timezone ...string) string {
|
||||
if c.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
return c.StdTime().Format(DateTimeNanoLayout)
|
||||
}
|
||||
|
||||
// ToShortDateTimeString outputs a string in "20060102150405" layout.
|
||||
// 输出 "20060102150405" 格式字符串
|
||||
func (c Carbon) ToShortDateTimeString(timezone ...string) string {
|
||||
if c.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
return c.StdTime().Format(ShortDateTimeLayout)
|
||||
}
|
||||
|
||||
// ToShortDateTimeMilliString outputs a string in "20060102150405.999" layout.
|
||||
// 输出 "20060102150405.999" 格式字符串
|
||||
func (c Carbon) ToShortDateTimeMilliString(timezone ...string) string {
|
||||
if c.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
return c.StdTime().Format(ShortDateTimeMilliLayout)
|
||||
}
|
||||
|
||||
// ToShortDateTimeMicroString outputs a string in "20060102150405.999999" layout.
|
||||
// 输出 "20060102150405.999999" 格式字符串
|
||||
func (c Carbon) ToShortDateTimeMicroString(timezone ...string) string {
|
||||
if c.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
return c.StdTime().Format(ShortDateTimeMicroLayout)
|
||||
}
|
||||
|
||||
// ToShortDateTimeNanoString outputs a string in "20060102150405.999999999" layout.
|
||||
// 输出 "20060102150405.999999999" 格式字符串
|
||||
func (c Carbon) ToShortDateTimeNanoString(timezone ...string) string {
|
||||
if c.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
return c.StdTime().Format(ShortDateTimeNanoLayout)
|
||||
}
|
||||
|
||||
// ToDateString outputs a string in "2006-01-02" layout.
|
||||
// 输出 "2006-01-02" 格式字符串
|
||||
func (c Carbon) ToDateString(timezone ...string) string {
|
||||
if c.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
return c.StdTime().Format(DateLayout)
|
||||
}
|
||||
|
||||
// ToDateMilliString outputs a string in "2006-01-02.999" layout.
|
||||
// 输出 "2006-01-02.999" 格式字符串
|
||||
func (c Carbon) ToDateMilliString(timezone ...string) string {
|
||||
if c.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
return c.StdTime().Format(DateMilliLayout)
|
||||
}
|
||||
|
||||
// ToDateMicroString outputs a string in "2006-01-02.999999" layout.
|
||||
// 输出 "2006-01-02.999999" 格式字符串
|
||||
func (c Carbon) ToDateMicroString(timezone ...string) string {
|
||||
if c.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
return c.StdTime().Format(DateMicroLayout)
|
||||
}
|
||||
|
||||
// ToDateNanoString outputs a string in "2006-01-02.999999999" layout.
|
||||
// 输出 "2006-01-02.999999999" 格式字符串
|
||||
func (c Carbon) ToDateNanoString(timezone ...string) string {
|
||||
if c.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
return c.StdTime().Format(DateNanoLayout)
|
||||
}
|
||||
|
||||
// ToShortDateString outputs a string in "20060102" layout.
|
||||
// 输出 "20060102" 格式字符串
|
||||
func (c Carbon) ToShortDateString(timezone ...string) string {
|
||||
if c.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
return c.StdTime().Format(ShortDateLayout)
|
||||
}
|
||||
|
||||
// ToShortDateMilliString outputs a string in "20060102.999" layout.
|
||||
// 输出 "20060102.999" 格式字符串
|
||||
func (c Carbon) ToShortDateMilliString(timezone ...string) string {
|
||||
if c.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
return c.StdTime().Format(ShortDateMilliLayout)
|
||||
}
|
||||
|
||||
// ToShortDateMicroString outputs a string in "20060102.999999" layout.
|
||||
// 输出 "20060102.999999" 格式字符串
|
||||
func (c Carbon) ToShortDateMicroString(timezone ...string) string {
|
||||
if c.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
return c.StdTime().Format(ShortDateMicroLayout)
|
||||
}
|
||||
|
||||
// ToShortDateNanoString outputs a string in "20060102.999999999" layout.
|
||||
// 输出 "20060102.999999999" 格式字符串
|
||||
func (c Carbon) ToShortDateNanoString(timezone ...string) string {
|
||||
if c.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
return c.StdTime().Format(ShortDateNanoLayout)
|
||||
}
|
||||
|
||||
// ToTimeString outputs a string in "15:04:05" layout.
|
||||
// 输出 "15:04:05" 格式字符串
|
||||
func (c Carbon) ToTimeString(timezone ...string) string {
|
||||
if c.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
return c.StdTime().Format(TimeLayout)
|
||||
}
|
||||
|
||||
// ToTimeMilliString outputs a string in "15:04:05.999" layout.
|
||||
// 输出 "15:04:05.999" 格式字符串
|
||||
func (c Carbon) ToTimeMilliString(timezone ...string) string {
|
||||
if c.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
return c.StdTime().Format(TimeMilliLayout)
|
||||
}
|
||||
|
||||
// ToTimeMicroString outputs a string in "15:04:05.999999" layout.
|
||||
// 输出 "15:04:05.999999" 格式字符串
|
||||
func (c Carbon) ToTimeMicroString(timezone ...string) string {
|
||||
if c.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
return c.StdTime().Format(TimeMicroLayout)
|
||||
}
|
||||
|
||||
// ToTimeNanoString outputs a string in "15:04:05.999999999" layout.
|
||||
// 输出 "15:04:05.999999999" 格式字符串
|
||||
func (c Carbon) ToTimeNanoString(timezone ...string) string {
|
||||
if c.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
return c.StdTime().Format(TimeNanoLayout)
|
||||
}
|
||||
|
||||
// ToShortTimeString outputs a string in "150405" layout.
|
||||
// 输出 "150405" 格式字符串
|
||||
func (c Carbon) ToShortTimeString(timezone ...string) string {
|
||||
if c.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
return c.StdTime().Format(ShortTimeLayout)
|
||||
}
|
||||
|
||||
// ToShortTimeMilliString outputs a string in "150405.999" layout.
|
||||
// 输出 "150405.999" 格式字符串
|
||||
func (c Carbon) ToShortTimeMilliString(timezone ...string) string {
|
||||
if c.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
return c.StdTime().Format(ShortTimeMilliLayout)
|
||||
}
|
||||
|
||||
// ToShortTimeMicroString outputs a string in "150405.999999" layout.
|
||||
// 输出 "150405.999999" 格式字符串
|
||||
func (c Carbon) ToShortTimeMicroString(timezone ...string) string {
|
||||
if c.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
return c.StdTime().Format(ShortTimeMicroLayout)
|
||||
}
|
||||
|
||||
// ToShortTimeNanoString outputs a string in "150405.999999999" layout.
|
||||
// 输出 "150405.999999999" 格式字符串
|
||||
func (c Carbon) ToShortTimeNanoString(timezone ...string) string {
|
||||
if c.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
return c.StdTime().Format(ShortTimeNanoLayout)
|
||||
}
|
||||
|
||||
// ToAtomString outputs a string in "2006-01-02T15:04:05Z07:00" layout.
|
||||
// 输出 "2006-01-02T15:04:05Z07:00" 格式字符串
|
||||
func (c Carbon) ToAtomString(timezone ...string) string {
|
||||
if c.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
return c.StdTime().Format(AtomLayout)
|
||||
}
|
||||
|
||||
// ToAnsicString outputs a string in "Mon Jan _2 15:04:05 2006" layout.
|
||||
// 输出 "Mon Jan _2 15:04:05 2006" 格式字符串
|
||||
func (c Carbon) ToAnsicString(timezone ...string) string {
|
||||
if c.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
return c.StdTime().Format(ANSICLayout)
|
||||
}
|
||||
|
||||
// ToCookieString outputs a string in "Monday, 02-Jan-2006 15:04:05 MST" layout.
|
||||
// 输出 "Monday, 02-Jan-2006 15:04:05 MST" 格式字符串
|
||||
func (c Carbon) ToCookieString(timezone ...string) string {
|
||||
if c.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
return c.StdTime().Format(CookieLayout)
|
||||
}
|
||||
|
||||
// ToRssString outputs a string in "Mon, 02 Jan 2006 15:04:05 -0700" format.
|
||||
// 输出 "Mon, 02 Jan 2006 15:04:05 -0700" 格式字符串
|
||||
func (c Carbon) ToRssString(timezone ...string) string {
|
||||
if c.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
return c.StdTime().Format(RssLayout)
|
||||
}
|
||||
|
||||
// ToW3cString outputs a string in "2006-01-02T15:04:05Z07:00" layout.
|
||||
// 输出 "2006-01-02T15:04:05Z07:00" 格式字符串
|
||||
func (c Carbon) ToW3cString(timezone ...string) string {
|
||||
if c.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
return c.StdTime().Format(W3cLayout)
|
||||
}
|
||||
|
||||
// ToUnixDateString outputs a string in "Mon Jan _2 15:04:05 MST 2006" layout.
|
||||
// 输出 "Mon Jan _2 15:04:05 MST 2006" 格式字符串
|
||||
func (c Carbon) ToUnixDateString(timezone ...string) string {
|
||||
if c.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
return c.StdTime().Format(UnixDateLayout)
|
||||
}
|
||||
|
||||
// ToRubyDateString outputs a string in "Mon Jan 02 15:04:05 -0700 2006" layout.
|
||||
// 输出 "Mon Jan 02 15:04:05 -0700 2006" 格式字符串
|
||||
func (c Carbon) ToRubyDateString(timezone ...string) string {
|
||||
if c.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
return c.StdTime().Format(RubyDateLayout)
|
||||
}
|
||||
|
||||
// ToKitchenString outputs a string in "3:04PM" layout.
|
||||
// 输出 "3:04PM" 格式字符串
|
||||
func (c Carbon) ToKitchenString(timezone ...string) string {
|
||||
if c.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
return c.StdTime().Format(KitchenLayout)
|
||||
}
|
||||
|
||||
// ToIso8601String outputs a string in "2006-01-02T15:04:05-07:00" layout.
|
||||
// 输出 "2006-01-02T15:04:05-07:00" 格式字符串
|
||||
func (c Carbon) ToIso8601String(timezone ...string) string {
|
||||
if c.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
return c.StdTime().Format(ISO8601Layout)
|
||||
}
|
||||
|
||||
// ToIso8601MilliString outputs a string in "2006-01-02T15:04:05.999-07:00" layout.
|
||||
// 输出 "2006-01-02T15:04:05.999-07:00" 格式字符串
|
||||
func (c Carbon) ToIso8601MilliString(timezone ...string) string {
|
||||
if c.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
return c.StdTime().Format(ISO8601MilliLayout)
|
||||
}
|
||||
|
||||
// ToIso8601MicroString outputs a string in "2006-01-02T15:04:05.999999-07:00" layout.
|
||||
// 输出 "2006-01-02T15:04:05.999999-07:00" 格式字符串
|
||||
func (c Carbon) ToIso8601MicroString(timezone ...string) string {
|
||||
if c.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
return c.StdTime().Format(ISO8601MicroLayout)
|
||||
}
|
||||
|
||||
// ToIso8601NanoString outputs a string in "2006-01-02T15:04:05.999999999-07:00" layout.
|
||||
// 输出 "2006-01-02T15:04:05.999999999-07:00" 格式字符串
|
||||
func (c Carbon) ToIso8601NanoString(timezone ...string) string {
|
||||
if c.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
return c.StdTime().Format(ISO8601NanoLayout)
|
||||
}
|
||||
|
||||
// ToIso8601ZuluString outputs a string in "2006-01-02T15:04:05Z" layout.
|
||||
// 输出 "2006-01-02T15:04:05Z" 格式字符串
|
||||
func (c Carbon) ToIso8601ZuluString(timezone ...string) string {
|
||||
if c.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
return c.StdTime().Format(ISO8601ZuluLayout)
|
||||
}
|
||||
|
||||
// ToIso8601ZuluMilliString outputs a string in "2006-01-02T15:04:05.999Z" layout.
|
||||
// 输出 "2006-01-02T15:04:05.999Z" 格式字符串
|
||||
func (c Carbon) ToIso8601ZuluMilliString(timezone ...string) string {
|
||||
if c.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
return c.StdTime().Format(ISO8601ZuluMilliLayout)
|
||||
}
|
||||
|
||||
// ToIso8601ZuluMicroString outputs a string in "2006-01-02T15:04:05.999999Z" layout.
|
||||
// 输出 "2006-01-02T15:04:05.999999Z" 格式字符串
|
||||
func (c Carbon) ToIso8601ZuluMicroString(timezone ...string) string {
|
||||
if c.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
return c.StdTime().Format(ISO8601ZuluMicroLayout)
|
||||
}
|
||||
|
||||
// ToIso8601ZuluNanoString outputs a string in "2006-01-02T15:04:05.999999999Z" layout.
|
||||
// 输出 "2006-01-02T15:04:05.999999999Z" 格式字符串
|
||||
func (c Carbon) ToIso8601ZuluNanoString(timezone ...string) string {
|
||||
if c.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
return c.StdTime().Format(ISO8601ZuluNanoLayout)
|
||||
}
|
||||
|
||||
// ToRfc822String outputs a string in "02 Jan 06 15:04 MST" layout.
|
||||
// 输出 "02 Jan 06 15:04 MST" 格式字符串
|
||||
func (c Carbon) ToRfc822String(timezone ...string) string {
|
||||
if c.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
return c.StdTime().Format(RFC822Layout)
|
||||
}
|
||||
|
||||
// ToRfc822zString outputs a string in "02 Jan 06 15:04 -0700" layout.
|
||||
// 输出 "02 Jan 06 15:04 -0700" 格式字符串
|
||||
func (c Carbon) ToRfc822zString(timezone ...string) string {
|
||||
if c.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
return c.StdTime().Format(RFC822ZLayout)
|
||||
}
|
||||
|
||||
// ToRfc850String outputs a string in "Monday, 02-Jan-06 15:04:05 MST" layout.
|
||||
// 输出 "Monday, 02-Jan-06 15:04:05 MST" 格式字符串
|
||||
func (c Carbon) ToRfc850String(timezone ...string) string {
|
||||
if c.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
return c.StdTime().Format(RFC850Layout)
|
||||
}
|
||||
|
||||
// ToRfc1036String outputs a string in "Mon, 02 Jan 06 15:04:05 -0700" layout.
|
||||
// 输出 "Mon, 02 Jan 06 15:04:05 -0700" 格式字符串
|
||||
func (c Carbon) ToRfc1036String(timezone ...string) string {
|
||||
if c.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
return c.StdTime().Format(RFC1036Layout)
|
||||
}
|
||||
|
||||
// ToRfc1123String outputs a string in "Mon, 02 Jan 2006 15:04:05 MST" layout.
|
||||
// 输出 "Mon, 02 Jan 2006 15:04:05 MST" 格式字符串
|
||||
func (c Carbon) ToRfc1123String(timezone ...string) string {
|
||||
if c.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
return c.StdTime().Format(RFC1123Layout)
|
||||
}
|
||||
|
||||
// ToRfc1123zString outputs a string in "Mon, 02 Jan 2006 15:04:05 -0700" layout.
|
||||
// 输出 "Mon, 02 Jan 2006 15:04:05 -0700" 格式字符串
|
||||
func (c Carbon) ToRfc1123zString(timezone ...string) string {
|
||||
if c.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
return c.StdTime().Format(RFC1123ZLayout)
|
||||
}
|
||||
|
||||
// ToRfc2822String outputs a string in "Mon, 02 Jan 2006 15:04:05 -0700" layout.
|
||||
// 输出 "Mon, 02 Jan 2006 15:04:05 -0700" 格式字符串
|
||||
func (c Carbon) ToRfc2822String(timezone ...string) string {
|
||||
if c.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
return c.StdTime().Format(RFC2822Layout)
|
||||
}
|
||||
|
||||
// ToRfc3339String outputs a string in "2006-01-02T15:04:05Z07:00" layout.
|
||||
// 输出 "2006-01-02T15:04:05Z07:00" 格式字符串
|
||||
func (c Carbon) ToRfc3339String(timezone ...string) string {
|
||||
if c.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
return c.StdTime().Format(RFC3339Layout)
|
||||
}
|
||||
|
||||
// ToRfc3339MilliString outputs a string in "2006-01-02T15:04:05.999Z07:00" layout.
|
||||
// 输出 "2006-01-02T15:04:05.999Z07:00" 格式字符串
|
||||
func (c Carbon) ToRfc3339MilliString(timezone ...string) string {
|
||||
if c.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
return c.StdTime().Format(RFC3339MilliLayout)
|
||||
}
|
||||
|
||||
// ToRfc3339MicroString outputs a string in "2006-01-02T15:04:05.999999Z07:00" layout.
|
||||
// 输出 "2006-01-02T15:04:05.999999Z07:00" 格式字符串
|
||||
func (c Carbon) ToRfc3339MicroString(timezone ...string) string {
|
||||
if c.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
return c.StdTime().Format(RFC3339MicroLayout)
|
||||
}
|
||||
|
||||
// ToRfc3339NanoString outputs a string in "2006-01-02T15:04:05.999999999Z07:00" layout.
|
||||
// 输出 "2006-01-02T15:04:05.999999999Z07:00" 格式字符串
|
||||
func (c Carbon) ToRfc3339NanoString(timezone ...string) string {
|
||||
if c.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
return c.StdTime().Format(RFC3339NanoLayout)
|
||||
}
|
||||
|
||||
// ToRfc7231String outputs a string in "Mon, 02 Jan 2006 15:04:05 GMT" layout.
|
||||
// 输出 "Mon, 02 Jan 2006 15:04:05 GMT" 格式字符串
|
||||
func (c Carbon) ToRfc7231String(timezone ...string) string {
|
||||
if c.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
return c.StdTime().Format(RFC7231Layout)
|
||||
}
|
||||
|
||||
// ToFormattedDateString outputs a string in "Jan 2, 2006" layout.
|
||||
// 输出 "Jan 2, 2006" 格式字符串
|
||||
func (c Carbon) ToFormattedDateString(timezone ...string) string {
|
||||
if c.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
return c.StdTime().Format(FormattedDateLayout)
|
||||
}
|
||||
|
||||
// ToFormattedDayDateString outputs a string in "Mon, Jan 2, 2006" layout.
|
||||
// 输出 "Jan 2, 2006" 格式字符串
|
||||
func (c Carbon) ToFormattedDayDateString(timezone ...string) string {
|
||||
if c.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
return c.StdTime().Format(FormattedDayDateLayout)
|
||||
}
|
||||
|
||||
// Layout outputs a string by layout.
|
||||
// 输出指定布局模板的时间字符串
|
||||
func (c Carbon) Layout(layout string, timezone ...string) string {
|
||||
if c.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
return c.StdTime().Format(layout)
|
||||
}
|
||||
|
||||
// Format outputs a string by format.
|
||||
// 输出指定格式模板的时间字符串
|
||||
func (c Carbon) Format(format string, timezone ...string) string {
|
||||
if c.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
buffer := bytes.NewBuffer(nil)
|
||||
for i := 0; i < len(format); i++ {
|
||||
if layout, ok := formats[format[i]]; ok {
|
||||
// support for i18n specific symbols
|
||||
switch format[i] {
|
||||
case 'l': // week, such as Monday
|
||||
buffer.WriteString(c.ToWeekString())
|
||||
case 'D': // short week, such as Mon
|
||||
buffer.WriteString(c.ToShortWeekString())
|
||||
case 'F': // month, such as January
|
||||
buffer.WriteString(c.ToMonthString())
|
||||
case 'M': // short month, such as Jan
|
||||
buffer.WriteString(c.ToShortMonthString())
|
||||
case 'U': // timestamp with second, such as 1596604455
|
||||
buffer.WriteString(strconv.FormatInt(c.Timestamp(), 10))
|
||||
case 'V': // timestamp with millisecond, such as 1596604455000
|
||||
buffer.WriteString(strconv.FormatInt(c.TimestampMilli(), 10))
|
||||
case 'X': // timestamp with microsecond, such as 1596604455000000
|
||||
buffer.WriteString(strconv.FormatInt(c.TimestampMicro(), 10))
|
||||
case 'Z': // timestamp with nanoseconds, such as 1596604455000000000
|
||||
buffer.WriteString(strconv.FormatInt(c.TimestampNano(), 10))
|
||||
default: // common symbols
|
||||
buffer.WriteString(c.StdTime().Format(layout))
|
||||
}
|
||||
} else {
|
||||
switch format[i] {
|
||||
case '\\': // raw output, no parse
|
||||
buffer.WriteByte(format[i+1])
|
||||
i++
|
||||
continue
|
||||
case 'W': // week number of the year in ISO-8601 format, ranging from 01-52
|
||||
week := fmt.Sprintf("%02d", c.WeekOfYear())
|
||||
buffer.WriteString(week)
|
||||
case 'N': // day of the week as a number in ISO-8601 format, ranging from 01-7
|
||||
week := fmt.Sprintf("%02d", c.DayOfWeek())
|
||||
buffer.WriteString(week)
|
||||
case 'S': // abbreviated suffix for the day of the month, such as st, nd, rd, th
|
||||
suffix := "th"
|
||||
switch c.Day() {
|
||||
case 1, 21, 31:
|
||||
suffix = "st"
|
||||
case 2, 22:
|
||||
suffix = "nd"
|
||||
case 3, 23:
|
||||
suffix = "rd"
|
||||
}
|
||||
buffer.WriteString(suffix)
|
||||
case 'L': // whether it is a leap year, if it is a leap year, it is 1, otherwise it is 0
|
||||
if c.IsLeapYear() {
|
||||
buffer.WriteString("1")
|
||||
} else {
|
||||
buffer.WriteString("0")
|
||||
}
|
||||
case 'G': // 24-hour format, no padding, ranging from 0-23
|
||||
buffer.WriteString(strconv.Itoa(c.Hour()))
|
||||
case 'v': // current millisecond, such as 999
|
||||
s := c.Layout(".999")
|
||||
buffer.WriteString(strings.Trim(s, "."))
|
||||
case 'u': // current microsecond, such as 999999
|
||||
s := c.Layout(".999999")
|
||||
buffer.WriteString(strings.Trim(s, "."))
|
||||
case 'x': // current nanosecond, such as 999999999
|
||||
s := c.Layout(".999999999")
|
||||
buffer.WriteString(strings.Trim(s, "."))
|
||||
case 'w': // day of the week represented by the number, ranging from 0-6
|
||||
buffer.WriteString(strconv.Itoa(c.DayOfWeek() - 1))
|
||||
case 't': // number of days in the month, ranging from 28-31
|
||||
buffer.WriteString(strconv.Itoa(c.DaysInMonth()))
|
||||
case 'z': // day of the year, ranging from 0-365
|
||||
buffer.WriteString(strconv.Itoa(c.DayOfYear() - 1))
|
||||
case 'e': // current location, such as UTC,GMT,Atlantic/Azores
|
||||
buffer.WriteString(c.Location())
|
||||
case 'Q': // current quarter, ranging from 1-4
|
||||
buffer.WriteString(strconv.Itoa(c.Quarter()))
|
||||
case 'C': // current century, ranging from 0-99
|
||||
buffer.WriteString(strconv.Itoa(c.Century()))
|
||||
default:
|
||||
buffer.WriteByte(format[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
return buffer.String()
|
||||
}
|
||||
104
vendor/github.com/dromara/carbon/v2/parser.go
generated
vendored
Normal file
104
vendor/github.com/dromara/carbon/v2/parser.go
generated
vendored
Normal file
@@ -0,0 +1,104 @@
|
||||
package carbon
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Parse parses a standard time string as a Carbon instance.
|
||||
// 将标准格式时间字符串解析成 Carbon 实例
|
||||
func (c Carbon) Parse(value string, timezone ...string) Carbon {
|
||||
if len(value) == 0 {
|
||||
c.Error = invalidValueError(value)
|
||||
return c
|
||||
}
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
switch value {
|
||||
case "now":
|
||||
return c.Now(timezone...)
|
||||
case "yesterday":
|
||||
return c.Yesterday(timezone...)
|
||||
case "tomorrow":
|
||||
return c.Tomorrow(timezone...)
|
||||
}
|
||||
for _, layout := range layouts {
|
||||
t, err := time.ParseInLocation(layout, value, c.loc)
|
||||
if err == nil {
|
||||
c.time = t
|
||||
return c
|
||||
}
|
||||
}
|
||||
c.Error = invalidValueError(value)
|
||||
return c
|
||||
}
|
||||
|
||||
// Parse parses a standard time string as a Carbon instance.
|
||||
// 将标准时间字符串解析成 Carbon 实例
|
||||
func Parse(value string, timezone ...string) Carbon {
|
||||
return NewCarbon().Parse(value, timezone...)
|
||||
}
|
||||
|
||||
// ParseByFormat parses a time string as a Carbon instance by format.
|
||||
// 通过格式模板将时间字符串解析成 Carbon 实例
|
||||
func (c Carbon) ParseByFormat(value, format string, timezone ...string) Carbon {
|
||||
carbon := c.ParseByLayout(value, format2layout(format), timezone...)
|
||||
if carbon.Error != nil {
|
||||
carbon.Error = invalidFormatError(value, format)
|
||||
}
|
||||
return carbon
|
||||
}
|
||||
|
||||
// ParseByFormat parses a time string as a Carbon instance by format.
|
||||
// 通过格式模板将时间字符串解析成 Carbon 实例
|
||||
func ParseByFormat(value, format string, timezone ...string) Carbon {
|
||||
return NewCarbon().ParseByFormat(value, format, timezone...)
|
||||
}
|
||||
|
||||
// ParseByLayout parses a time string as a Carbon instance by layout.
|
||||
// 通过布局模板将时间字符串解析成 Carbon 实例
|
||||
func (c Carbon) ParseByLayout(value, layout string, timezone ...string) Carbon {
|
||||
if len(value) == 0 {
|
||||
c.Error = invalidValueError(value)
|
||||
return c
|
||||
}
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
if c.Error != nil {
|
||||
return c
|
||||
}
|
||||
if len(layout) == 0 {
|
||||
layout = defaultLayout
|
||||
}
|
||||
if layout == "timestamp" {
|
||||
timestamp, _ := strconv.ParseInt(value, 10, 64)
|
||||
return c.CreateFromTimestamp(timestamp)
|
||||
}
|
||||
if layout == "timestampMilli" {
|
||||
timestamp, _ := strconv.ParseInt(value, 10, 64)
|
||||
return c.CreateFromTimestampMilli(timestamp)
|
||||
}
|
||||
if layout == "timestampMicro" {
|
||||
timestamp, _ := strconv.ParseInt(value, 10, 64)
|
||||
return c.CreateFromTimestampMicro(timestamp)
|
||||
}
|
||||
if layout == "timestampNano" {
|
||||
timestamp, _ := strconv.ParseInt(value, 10, 64)
|
||||
return c.CreateFromTimestampNano(timestamp)
|
||||
}
|
||||
tt, err := time.ParseInLocation(layout, value, c.loc)
|
||||
if err != nil {
|
||||
c.Error = invalidLayoutError(value, layout)
|
||||
return c
|
||||
}
|
||||
c.time = tt
|
||||
return c
|
||||
}
|
||||
|
||||
// ParseByLayout parses a time string as a Carbon instance by layout.
|
||||
// 通过布局模板将时间字符串解析成 Carbon 实例
|
||||
func ParseByLayout(value, layout string, timezone ...string) Carbon {
|
||||
return NewCarbon().ParseByLayout(value, layout, timezone...)
|
||||
}
|
||||
131
vendor/github.com/dromara/carbon/v2/season.go
generated
vendored
Normal file
131
vendor/github.com/dromara/carbon/v2/season.go
generated
vendored
Normal file
@@ -0,0 +1,131 @@
|
||||
package carbon
|
||||
|
||||
import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
var seasons = []struct {
|
||||
month, index int
|
||||
}{
|
||||
{3, 0}, // spring
|
||||
{4, 0}, // spring
|
||||
{5, 0}, // spring
|
||||
{6, 1}, // summer
|
||||
{7, 1}, // summer
|
||||
{8, 1}, // summer
|
||||
{9, 2}, // autumn
|
||||
{10, 2}, // autumn
|
||||
{11, 2}, // autumn
|
||||
{12, 3}, // winter
|
||||
{1, 3}, // winter
|
||||
{2, 3}, // winter
|
||||
}
|
||||
|
||||
// Season gets season name according to the meteorological division method like "Spring", i18n is supported.
|
||||
// 获取当前季节(以气象划分),支持i18n
|
||||
func (c Carbon) Season() string {
|
||||
if c.Error != nil {
|
||||
return ""
|
||||
}
|
||||
if len(c.lang.resources) == 0 {
|
||||
c.lang.SetLocale(defaultLocale)
|
||||
}
|
||||
index := -1
|
||||
month := c.Month()
|
||||
for i := 0; i < len(seasons); i++ {
|
||||
season := seasons[i]
|
||||
if month == season.month {
|
||||
index = season.index
|
||||
}
|
||||
}
|
||||
c.lang.rw.RLock()
|
||||
defer c.lang.rw.RUnlock()
|
||||
if resources, ok := c.lang.resources["seasons"]; ok {
|
||||
slice := strings.Split(resources, "|")
|
||||
if len(slice) == QuartersPerYear {
|
||||
return slice[index]
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// StartOfSeason returns a Carbon instance for start of the season.
|
||||
// 本季节开始时间
|
||||
func (c Carbon) StartOfSeason() Carbon {
|
||||
if c.Error != nil {
|
||||
return c
|
||||
}
|
||||
year, month, _ := c.Date()
|
||||
if month == 1 || month == 2 {
|
||||
return c.create(year-1, 12, 1, 0, 0, 0, 0)
|
||||
}
|
||||
return c.create(year, month/3*3, 1, 0, 0, 0, 0)
|
||||
}
|
||||
|
||||
// EndOfSeason returns a Carbon instance for end of the season.
|
||||
// 本季节结束时间
|
||||
func (c Carbon) EndOfSeason() Carbon {
|
||||
if c.Error != nil {
|
||||
return c
|
||||
}
|
||||
year, month, _ := c.Date()
|
||||
if month == 1 || month == 2 {
|
||||
return c.create(year, 3, 0, 23, 59, 59, 999999999)
|
||||
}
|
||||
if month == 12 {
|
||||
return c.create(year+1, 3, 0, 23, 59, 59, 999999999)
|
||||
}
|
||||
return c.create(year, month/3*3+3, 0, 23, 59, 59, 999999999)
|
||||
}
|
||||
|
||||
// IsSpring reports whether is spring.
|
||||
// 是否是春季
|
||||
func (c Carbon) IsSpring() bool {
|
||||
if c.Error != nil {
|
||||
return false
|
||||
}
|
||||
month := c.Month()
|
||||
if month == 3 || month == 4 || month == 5 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// IsSummer reports whether is summer.
|
||||
// 是否是夏季
|
||||
func (c Carbon) IsSummer() bool {
|
||||
if c.Error != nil {
|
||||
return false
|
||||
}
|
||||
month := c.Month()
|
||||
if month == 6 || month == 7 || month == 8 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// IsAutumn reports whether is autumn.
|
||||
// 是否是秋季
|
||||
func (c Carbon) IsAutumn() bool {
|
||||
if c.Error != nil {
|
||||
return false
|
||||
}
|
||||
month := c.Month()
|
||||
if month == 9 || month == 10 || month == 11 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// IsWinter reports whether is winter.
|
||||
// 是否是冬季
|
||||
func (c Carbon) IsWinter() bool {
|
||||
if c.Error != nil {
|
||||
return false
|
||||
}
|
||||
month := c.Month()
|
||||
if month == 12 || month == 1 || month == 2 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
302
vendor/github.com/dromara/carbon/v2/setter.go
generated
vendored
Normal file
302
vendor/github.com/dromara/carbon/v2/setter.go
generated
vendored
Normal file
@@ -0,0 +1,302 @@
|
||||
package carbon
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// SetWeekStartsAt sets start day of the week.
|
||||
// 设置一周的开始日期
|
||||
func (c Carbon) SetWeekStartsAt(day string) Carbon {
|
||||
if c.Error != nil {
|
||||
return c
|
||||
}
|
||||
if weekday, ok := weekdays[day]; ok {
|
||||
c.weekStartsAt = weekday
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
// SetWeekStartsAt sets start day of the week.
|
||||
// 设置一周的开始日期
|
||||
func SetWeekStartsAt(day string) Carbon {
|
||||
return NewCarbon().SetWeekStartsAt(day)
|
||||
}
|
||||
|
||||
// SetTimezone sets timezone.
|
||||
// 设置时区
|
||||
func (c Carbon) SetTimezone(name string) Carbon {
|
||||
if c.Error != nil {
|
||||
return c
|
||||
}
|
||||
c.loc, c.Error = getLocationByTimezone(name)
|
||||
return c
|
||||
}
|
||||
|
||||
// SetTimezone sets timezone.
|
||||
// 设置时区
|
||||
func SetTimezone(name string) Carbon {
|
||||
return NewCarbon().SetTimezone(name)
|
||||
}
|
||||
|
||||
// SetLocation sets location.
|
||||
// 设置地区
|
||||
func (c Carbon) SetLocation(loc *time.Location) Carbon {
|
||||
if c.Error != nil {
|
||||
return c
|
||||
}
|
||||
if loc == nil {
|
||||
c.Error = invalidLocationError()
|
||||
}
|
||||
c.loc = loc
|
||||
return c
|
||||
}
|
||||
|
||||
// SetLocation sets location.
|
||||
// 设置地区
|
||||
func SetLocation(loc *time.Location) Carbon {
|
||||
return NewCarbon().SetLocation(loc)
|
||||
}
|
||||
|
||||
// SetLocale sets locale.
|
||||
// 设置语言区域
|
||||
func (c Carbon) SetLocale(locale string) Carbon {
|
||||
if c.Error != nil {
|
||||
return c
|
||||
}
|
||||
c.lang.SetLocale(locale)
|
||||
c.Error = c.lang.Error
|
||||
return c
|
||||
}
|
||||
|
||||
// SetLocale sets locale.
|
||||
// 设置语言区域
|
||||
func SetLocale(locale string) Carbon {
|
||||
c := NewCarbon()
|
||||
c.lang.SetLocale(locale)
|
||||
c.Error = c.lang.Error
|
||||
return c
|
||||
}
|
||||
|
||||
// SetDateTime sets year, month, day, hour, minute and second.
|
||||
// 设置年、月、日、时、分、秒
|
||||
func (c Carbon) SetDateTime(year, month, day, hour, minute, second int) Carbon {
|
||||
if c.Error != nil {
|
||||
return c
|
||||
}
|
||||
return c.create(year, month, day, hour, minute, second, c.Nanosecond())
|
||||
}
|
||||
|
||||
// SetDateTimeMilli sets year, month, day, hour, minute, second and millisecond.
|
||||
// 设置年、月、日、时、分、秒、毫秒
|
||||
func (c Carbon) SetDateTimeMilli(year, month, day, hour, minute, second, millisecond int) Carbon {
|
||||
if c.Error != nil {
|
||||
return c
|
||||
}
|
||||
return c.create(year, month, day, hour, minute, second, millisecond*1e6)
|
||||
}
|
||||
|
||||
// SetDateTimeMicro sets year, month, day, hour, minute, second and microsecond.
|
||||
// 设置年、月、日、时、分、秒、微秒
|
||||
func (c Carbon) SetDateTimeMicro(year, month, day, hour, minute, second, microsecond int) Carbon {
|
||||
if c.Error != nil {
|
||||
return c
|
||||
}
|
||||
return c.create(year, month, day, hour, minute, second, microsecond*1e3)
|
||||
}
|
||||
|
||||
// SetDateTimeNano sets year, month, day, hour, minute, second and nanosecond.
|
||||
// 设置年、月、日、时、分、秒、纳秒
|
||||
func (c Carbon) SetDateTimeNano(year, month, day, hour, minute, second, nanosecond int) Carbon {
|
||||
if c.Error != nil {
|
||||
return c
|
||||
}
|
||||
return c.create(year, month, day, hour, minute, second, nanosecond)
|
||||
}
|
||||
|
||||
// SetDate sets year, month and day.
|
||||
// 设置年、月、日
|
||||
func (c Carbon) SetDate(year, month, day int) Carbon {
|
||||
if c.Error != nil {
|
||||
return c
|
||||
}
|
||||
hour, minute, second := c.Time()
|
||||
return c.create(year, month, day, hour, minute, second, c.Nanosecond())
|
||||
}
|
||||
|
||||
// SetDateMilli sets year, month, day and millisecond.
|
||||
// 设置年、月、日、毫秒
|
||||
func (c Carbon) SetDateMilli(year, month, day, millisecond int) Carbon {
|
||||
if c.Error != nil {
|
||||
return c
|
||||
}
|
||||
hour, minute, second := c.Time()
|
||||
return c.create(year, month, day, hour, minute, second, millisecond*1e6)
|
||||
}
|
||||
|
||||
// SetDateMicro sets year, month, day and microsecond.
|
||||
// 设置年、月、日、微秒
|
||||
func (c Carbon) SetDateMicro(year, month, day, microsecond int) Carbon {
|
||||
if c.Error != nil {
|
||||
return c
|
||||
}
|
||||
hour, minute, second := c.Time()
|
||||
return c.create(year, month, day, hour, minute, second, microsecond*1e3)
|
||||
}
|
||||
|
||||
// SetDateNano sets year, month, day and nanosecond.
|
||||
// 设置年、月、日、纳秒
|
||||
func (c Carbon) SetDateNano(year, month, day, nanosecond int) Carbon {
|
||||
if c.Error != nil {
|
||||
return c
|
||||
}
|
||||
hour, minute, second := c.Time()
|
||||
return c.create(year, month, day, hour, minute, second, nanosecond)
|
||||
}
|
||||
|
||||
// SetTime sets hour, minute and second.
|
||||
// 设置时、分、秒
|
||||
func (c Carbon) SetTime(hour, minute, second int) Carbon {
|
||||
if c.Error != nil {
|
||||
return c
|
||||
}
|
||||
year, month, day := c.Date()
|
||||
return c.create(year, month, day, hour, minute, second, c.Nanosecond())
|
||||
}
|
||||
|
||||
// SetTimeMilli sets hour, minute, second and millisecond.
|
||||
// 设置时、分、秒、毫秒
|
||||
func (c Carbon) SetTimeMilli(hour, minute, second, millisecond int) Carbon {
|
||||
if c.Error != nil {
|
||||
return c
|
||||
}
|
||||
year, month, day := c.Date()
|
||||
return c.create(year, month, day, hour, minute, second, millisecond*1e6)
|
||||
}
|
||||
|
||||
// SetTimeMicro sets hour, minute, second and microsecond.
|
||||
// 设置时、分、秒、微秒
|
||||
func (c Carbon) SetTimeMicro(hour, minute, second, microsecond int) Carbon {
|
||||
if c.Error != nil {
|
||||
return c
|
||||
}
|
||||
year, month, day := c.Date()
|
||||
return c.create(year, month, day, hour, minute, second, microsecond*1e3)
|
||||
}
|
||||
|
||||
// SetTimeNano sets hour, minute, second and nanosecond.
|
||||
// 设置、时、分、秒、纳秒
|
||||
func (c Carbon) SetTimeNano(hour, minute, second, nanosecond int) Carbon {
|
||||
if c.Error != nil {
|
||||
return c
|
||||
}
|
||||
year, month, day := c.Date()
|
||||
return c.create(year, month, day, hour, minute, second, nanosecond)
|
||||
}
|
||||
|
||||
// SetYear sets year.
|
||||
// 设置年份
|
||||
func (c Carbon) SetYear(year int) Carbon {
|
||||
if c.Error != nil {
|
||||
return c
|
||||
}
|
||||
_, month, day, hour, minute, second := c.DateTime()
|
||||
return c.create(year, month, day, hour, minute, second, c.Nanosecond())
|
||||
}
|
||||
|
||||
// SetYearNoOverflow sets year without overflowing month.
|
||||
// 设置年份(月份不溢出)
|
||||
func (c Carbon) SetYearNoOverflow(year int) Carbon {
|
||||
if c.Error != nil {
|
||||
return c
|
||||
}
|
||||
return c.AddYearsNoOverflow(year - c.Year())
|
||||
}
|
||||
|
||||
// SetMonth sets month.
|
||||
// 设置月份
|
||||
func (c Carbon) SetMonth(month int) Carbon {
|
||||
if c.Error != nil {
|
||||
return c
|
||||
}
|
||||
year, _, day, hour, minute, second := c.DateTime()
|
||||
return c.create(year, month, day, hour, minute, second, c.Nanosecond())
|
||||
}
|
||||
|
||||
// SetMonthNoOverflow sets month without overflowing month.
|
||||
// 设置月份(月份不溢出)
|
||||
func (c Carbon) SetMonthNoOverflow(month int) Carbon {
|
||||
if c.Error != nil {
|
||||
return c
|
||||
}
|
||||
return c.AddMonthsNoOverflow(month - c.Month())
|
||||
}
|
||||
|
||||
// SetDay sets day.
|
||||
// 设置日期
|
||||
func (c Carbon) SetDay(day int) Carbon {
|
||||
if c.Error != nil {
|
||||
return c
|
||||
}
|
||||
year, month, _, hour, minute, second := c.DateTime()
|
||||
return c.create(year, month, day, hour, minute, second, c.Nanosecond())
|
||||
}
|
||||
|
||||
// SetHour sets hour.
|
||||
// 设置小时
|
||||
func (c Carbon) SetHour(hour int) Carbon {
|
||||
if c.Error != nil {
|
||||
return c
|
||||
}
|
||||
year, month, day, _, minute, second := c.DateTime()
|
||||
return c.create(year, month, day, hour, minute, second, c.Nanosecond())
|
||||
}
|
||||
|
||||
// SetMinute sets minute.
|
||||
// 设置分钟
|
||||
func (c Carbon) SetMinute(minute int) Carbon {
|
||||
if c.Error != nil {
|
||||
return c
|
||||
}
|
||||
year, month, day, hour, _, second := c.DateTime()
|
||||
return c.create(year, month, day, hour, minute, second, c.Nanosecond())
|
||||
}
|
||||
|
||||
// SetSecond sets second.
|
||||
// 设置秒数
|
||||
func (c Carbon) SetSecond(second int) Carbon {
|
||||
if c.Error != nil {
|
||||
return c
|
||||
}
|
||||
year, month, day, hour, minute, _ := c.DateTime()
|
||||
return c.create(year, month, day, hour, minute, second, c.Nanosecond())
|
||||
}
|
||||
|
||||
// SetMillisecond sets millisecond.
|
||||
// 设置毫秒
|
||||
func (c Carbon) SetMillisecond(millisecond int) Carbon {
|
||||
if c.Error != nil {
|
||||
return c
|
||||
}
|
||||
year, month, day, hour, minute, second := c.DateTime()
|
||||
return c.create(year, month, day, hour, minute, second, millisecond*1e6)
|
||||
}
|
||||
|
||||
// SetMicrosecond sets microsecond.
|
||||
// 设置微秒
|
||||
func (c Carbon) SetMicrosecond(microsecond int) Carbon {
|
||||
if c.Error != nil {
|
||||
return c
|
||||
}
|
||||
year, month, day, hour, minute, second := c.DateTime()
|
||||
return c.create(year, month, day, hour, minute, second, microsecond*1e3)
|
||||
}
|
||||
|
||||
// SetNanosecond sets nanosecond.
|
||||
// 设置纳秒
|
||||
func (c Carbon) SetNanosecond(nanosecond int) Carbon {
|
||||
if c.Error != nil {
|
||||
return c
|
||||
}
|
||||
year, month, day, hour, minute, second := c.DateTime()
|
||||
return c.create(year, month, day, hour, minute, second, nanosecond)
|
||||
}
|
||||
19
vendor/github.com/dromara/carbon/v2/test.go
generated
vendored
Normal file
19
vendor/github.com/dromara/carbon/v2/test.go
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
package carbon
|
||||
|
||||
// SetTestNow sets a test Carbon instance (real or mock) to be returned when a "now" instance is created.
|
||||
// 设置当前测试时间
|
||||
func (c *Carbon) SetTestNow(carbon Carbon) {
|
||||
c.testNow, c.loc = carbon.TimestampNano(), carbon.loc
|
||||
}
|
||||
|
||||
// UnSetTestNow clears a test Carbon instance (real or mock) to be returned when a "now" instance is created.
|
||||
// 清除当前测试时间
|
||||
func (c *Carbon) UnSetTestNow() {
|
||||
c.testNow = 0
|
||||
}
|
||||
|
||||
// IsSetTestNow report whether there is testing time now.
|
||||
// 是否设置过当前测试时间
|
||||
func (c Carbon) IsSetTestNow() bool {
|
||||
return c.testNow > 0
|
||||
}
|
||||
585
vendor/github.com/dromara/carbon/v2/traveler.go
generated
vendored
Normal file
585
vendor/github.com/dromara/carbon/v2/traveler.go
generated
vendored
Normal file
@@ -0,0 +1,585 @@
|
||||
package carbon
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// Now returns a Carbon instance for now.
|
||||
// 当前
|
||||
func (c Carbon) Now(timezone ...string) Carbon {
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
if c.Error != nil {
|
||||
return c
|
||||
}
|
||||
if c.IsSetTestNow() {
|
||||
now := CreateFromTimestampNano(c.testNow, c.Location())
|
||||
now.testNow = c.testNow
|
||||
return now
|
||||
}
|
||||
c.time = time.Now().In(c.loc)
|
||||
return c
|
||||
}
|
||||
|
||||
// Now returns a Carbon instance for now.
|
||||
// 当前
|
||||
func Now(timezone ...string) Carbon {
|
||||
return NewCarbon().Now(timezone...)
|
||||
}
|
||||
|
||||
// Tomorrow returns a Carbon instance for tomorrow.
|
||||
// 明天
|
||||
func (c Carbon) Tomorrow(timezone ...string) Carbon {
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
if c.Error != nil {
|
||||
return c
|
||||
}
|
||||
if !c.IsZero() {
|
||||
return c.AddDay()
|
||||
}
|
||||
return c.Now().AddDay()
|
||||
}
|
||||
|
||||
// Tomorrow returns a Carbon instance for tomorrow.
|
||||
// 明天
|
||||
func Tomorrow(timezone ...string) Carbon {
|
||||
return NewCarbon().Tomorrow(timezone...)
|
||||
}
|
||||
|
||||
// Yesterday returns a Carbon instance for yesterday.
|
||||
// 昨天
|
||||
func (c Carbon) Yesterday(timezone ...string) Carbon {
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
if c.Error != nil {
|
||||
return c
|
||||
}
|
||||
if !c.IsZero() {
|
||||
return c.SubDay()
|
||||
}
|
||||
return c.Now().SubDay()
|
||||
}
|
||||
|
||||
// Yesterday returns a Carbon instance for yesterday.
|
||||
// 昨天
|
||||
func Yesterday(timezone ...string) Carbon {
|
||||
return NewCarbon().Yesterday(timezone...)
|
||||
}
|
||||
|
||||
// AddDuration adds one duration.
|
||||
// 按照时长增加时间,支持整数/浮点数和符号ns(纳秒)、us(微妙)、ms(毫秒)、s(秒)、m(分钟)、h(小时)的组合
|
||||
func (c Carbon) AddDuration(duration string) Carbon {
|
||||
if c.IsInvalid() {
|
||||
return c
|
||||
}
|
||||
td, err := parseByDuration(duration)
|
||||
c.time, c.Error = c.StdTime().Add(td), err
|
||||
return c
|
||||
}
|
||||
|
||||
// SubDuration subtracts one duration.
|
||||
// 按照时长减少时间,支持整数/浮点数和符号ns(纳秒)、us(微妙)、ms(毫秒)、s(秒)、m(分钟)、h(小时)的组合
|
||||
func (c Carbon) SubDuration(duration string) Carbon {
|
||||
return c.AddDuration("-" + duration)
|
||||
}
|
||||
|
||||
// AddCenturies adds some centuries.
|
||||
// N个世纪后
|
||||
func (c Carbon) AddCenturies(centuries int) Carbon {
|
||||
return c.AddYears(centuries * YearsPerCentury)
|
||||
}
|
||||
|
||||
// AddCenturiesNoOverflow adds some centuries without overflowing month.
|
||||
// N个世纪后(月份不溢出)
|
||||
func (c Carbon) AddCenturiesNoOverflow(centuries int) Carbon {
|
||||
return c.AddYearsNoOverflow(centuries * YearsPerCentury)
|
||||
}
|
||||
|
||||
// AddCentury adds one century.
|
||||
// 1个世纪后
|
||||
func (c Carbon) AddCentury() Carbon {
|
||||
return c.AddCenturies(1)
|
||||
}
|
||||
|
||||
// AddCenturyNoOverflow adds one century without overflowing month.
|
||||
// 1个世纪后(月份不溢出)
|
||||
func (c Carbon) AddCenturyNoOverflow() Carbon {
|
||||
return c.AddCenturiesNoOverflow(1)
|
||||
}
|
||||
|
||||
// SubCenturies subtracts some centuries.
|
||||
// N个世纪前
|
||||
func (c Carbon) SubCenturies(centuries int) Carbon {
|
||||
return c.SubYears(centuries * YearsPerCentury)
|
||||
}
|
||||
|
||||
// SubCenturiesNoOverflow subtracts some centuries without overflowing month.
|
||||
// N个世纪前(月份不溢出)
|
||||
func (c Carbon) SubCenturiesNoOverflow(centuries int) Carbon {
|
||||
return c.SubYearsNoOverflow(centuries * YearsPerCentury)
|
||||
}
|
||||
|
||||
// SubCentury subtracts one century.
|
||||
// 1个世纪前
|
||||
func (c Carbon) SubCentury() Carbon {
|
||||
return c.SubCenturies(1)
|
||||
}
|
||||
|
||||
// SubCenturyNoOverflow subtracts one century without overflowing month.
|
||||
// 1个世纪前(月份不溢出)
|
||||
func (c Carbon) SubCenturyNoOverflow() Carbon {
|
||||
return c.SubCenturiesNoOverflow(1)
|
||||
}
|
||||
|
||||
// AddDecades adds some decades.
|
||||
// N个年代后
|
||||
func (c Carbon) AddDecades(decades int) Carbon {
|
||||
return c.AddYears(decades * YearsPerDecade)
|
||||
}
|
||||
|
||||
// AddDecadesNoOverflow adds some decades without overflowing month.
|
||||
// N个年代后(月份不溢出)
|
||||
func (c Carbon) AddDecadesNoOverflow(decades int) Carbon {
|
||||
return c.AddYearsNoOverflow(decades * YearsPerDecade)
|
||||
}
|
||||
|
||||
// AddDecade adds one decade.
|
||||
// 1个年代后
|
||||
func (c Carbon) AddDecade() Carbon {
|
||||
return c.AddDecades(1)
|
||||
}
|
||||
|
||||
// AddDecadeNoOverflow adds one decade without overflowing month.
|
||||
// 1个年代后(月份不溢出)
|
||||
func (c Carbon) AddDecadeNoOverflow() Carbon {
|
||||
return c.AddDecadesNoOverflow(1)
|
||||
}
|
||||
|
||||
// SubDecades subtracts some decades.
|
||||
// N个年代后
|
||||
func (c Carbon) SubDecades(decades int) Carbon {
|
||||
return c.SubYears(decades * YearsPerDecade)
|
||||
}
|
||||
|
||||
// SubDecadesNoOverflow subtracts some decades without overflowing month.
|
||||
// N个年代后(月份不溢出)
|
||||
func (c Carbon) SubDecadesNoOverflow(decades int) Carbon {
|
||||
return c.SubYearsNoOverflow(decades * YearsPerDecade)
|
||||
}
|
||||
|
||||
// SubDecade subtracts one decade.
|
||||
// 1个年代后
|
||||
func (c Carbon) SubDecade() Carbon {
|
||||
return c.SubDecades(1)
|
||||
}
|
||||
|
||||
// SubDecadeNoOverflow subtracts one decade without overflowing month.
|
||||
// 1个年代后(月份不溢出)
|
||||
func (c Carbon) SubDecadeNoOverflow() Carbon {
|
||||
return c.SubDecadesNoOverflow(1)
|
||||
}
|
||||
|
||||
// AddYears adds some years.
|
||||
// N年后
|
||||
func (c Carbon) AddYears(years int) Carbon {
|
||||
if c.IsInvalid() {
|
||||
return c
|
||||
}
|
||||
c.time = c.StdTime().AddDate(years, 0, 0)
|
||||
return c
|
||||
}
|
||||
|
||||
// AddYearsNoOverflow adds some years without overflowing month.
|
||||
// N年后(月份不溢出)
|
||||
func (c Carbon) AddYearsNoOverflow(years int) Carbon {
|
||||
if c.IsInvalid() {
|
||||
return c
|
||||
}
|
||||
nanosecond := c.Nanosecond()
|
||||
year, month, day, hour, minute, second := c.DateTime()
|
||||
// 获取N年后本月的最后一天
|
||||
lastYear, lastMonth, lastDay := c.create(year+years, month+1, 0, hour, minute, second, nanosecond).Date()
|
||||
if day > lastDay {
|
||||
day = lastDay
|
||||
}
|
||||
return c.create(lastYear, lastMonth, day, hour, minute, second, nanosecond)
|
||||
}
|
||||
|
||||
// AddYear adds one year.
|
||||
// 1年后
|
||||
func (c Carbon) AddYear() Carbon {
|
||||
return c.AddYears(1)
|
||||
}
|
||||
|
||||
// AddYearNoOverflow adds one year without overflowing month.
|
||||
// 1年后(月份不溢出)
|
||||
func (c Carbon) AddYearNoOverflow() Carbon {
|
||||
return c.AddYearsNoOverflow(1)
|
||||
}
|
||||
|
||||
// SubYears subtracts some years.
|
||||
// N年前
|
||||
func (c Carbon) SubYears(years int) Carbon {
|
||||
if c.IsInvalid() {
|
||||
return c
|
||||
}
|
||||
return c.AddYears(-years)
|
||||
}
|
||||
|
||||
// SubYearsNoOverflow subtracts some years without overflowing month.
|
||||
// N年前(月份不溢出)
|
||||
func (c Carbon) SubYearsNoOverflow(years int) Carbon {
|
||||
return c.AddYearsNoOverflow(-years)
|
||||
}
|
||||
|
||||
// SubYear subtracts one year.
|
||||
// 1年前
|
||||
func (c Carbon) SubYear() Carbon {
|
||||
return c.SubYears(1)
|
||||
}
|
||||
|
||||
// SubYearNoOverflow subtracts one year without overflowing month.
|
||||
// 1年前(月份不溢出)
|
||||
func (c Carbon) SubYearNoOverflow() Carbon {
|
||||
return c.SubYearsNoOverflow(1)
|
||||
}
|
||||
|
||||
// AddQuarters adds some quarters
|
||||
// N个季度后
|
||||
func (c Carbon) AddQuarters(quarters int) Carbon {
|
||||
return c.AddMonths(quarters * MonthsPerQuarter)
|
||||
}
|
||||
|
||||
// AddQuartersNoOverflow adds quarters without overflowing month.
|
||||
// N个季度后(月份不溢出)
|
||||
func (c Carbon) AddQuartersNoOverflow(quarters int) Carbon {
|
||||
return c.AddMonthsNoOverflow(quarters * MonthsPerQuarter)
|
||||
}
|
||||
|
||||
// AddQuarter adds one quarter
|
||||
// 1个季度后
|
||||
func (c Carbon) AddQuarter() Carbon {
|
||||
return c.AddQuarters(1)
|
||||
}
|
||||
|
||||
// AddQuarterNoOverflow adds one quarter without overflowing month.
|
||||
// 1个季度后(月份不溢出)
|
||||
func (c Carbon) AddQuarterNoOverflow() Carbon {
|
||||
return c.AddQuartersNoOverflow(1)
|
||||
}
|
||||
|
||||
// SubQuarters subtracts some quarters.
|
||||
// N个季度前
|
||||
func (c Carbon) SubQuarters(quarters int) Carbon {
|
||||
return c.AddQuarters(-quarters)
|
||||
}
|
||||
|
||||
// SubQuartersNoOverflow subtracts some quarters without overflowing month.
|
||||
// N个季度前(月份不溢出)
|
||||
func (c Carbon) SubQuartersNoOverflow(quarters int) Carbon {
|
||||
return c.AddMonthsNoOverflow(-quarters * MonthsPerQuarter)
|
||||
}
|
||||
|
||||
// SubQuarter subtracts one quarter.
|
||||
// 1个季度前
|
||||
func (c Carbon) SubQuarter() Carbon {
|
||||
return c.SubQuarters(1)
|
||||
}
|
||||
|
||||
// SubQuarterNoOverflow subtracts one quarter without overflowing month.
|
||||
// 1个季度前(月份不溢出)
|
||||
func (c Carbon) SubQuarterNoOverflow() Carbon {
|
||||
return c.SubQuartersNoOverflow(1)
|
||||
}
|
||||
|
||||
// AddMonths adds some months.
|
||||
// N个月后
|
||||
func (c Carbon) AddMonths(months int) Carbon {
|
||||
if c.IsInvalid() {
|
||||
return c
|
||||
}
|
||||
c.time = c.StdTime().AddDate(0, months, 0)
|
||||
return c
|
||||
}
|
||||
|
||||
// AddMonthsNoOverflow adds some months without overflowing month.
|
||||
// N个月后(月份不溢出)
|
||||
func (c Carbon) AddMonthsNoOverflow(months int) Carbon {
|
||||
if c.IsInvalid() {
|
||||
return c
|
||||
}
|
||||
nanosecond := c.Nanosecond()
|
||||
year, month, day, hour, minute, second := c.DateTime()
|
||||
// 获取N月后的最后一天
|
||||
lastYear, lastMonth, lastDay := c.create(year, month+months+1, 0, hour, minute, second, nanosecond).Date()
|
||||
if day > lastDay {
|
||||
day = lastDay
|
||||
}
|
||||
return c.create(lastYear, lastMonth, day, hour, minute, second, nanosecond)
|
||||
}
|
||||
|
||||
// AddMonth adds one month.
|
||||
// 1个月后
|
||||
func (c Carbon) AddMonth() Carbon {
|
||||
return c.AddMonths(1)
|
||||
}
|
||||
|
||||
// AddMonthNoOverflow adds one month without overflowing month.
|
||||
// 1个月后(月份不溢出)
|
||||
func (c Carbon) AddMonthNoOverflow() Carbon {
|
||||
return c.AddMonthsNoOverflow(1)
|
||||
}
|
||||
|
||||
// SubMonths subtracts some months.
|
||||
// N个月前
|
||||
func (c Carbon) SubMonths(months int) Carbon {
|
||||
return c.AddMonths(-months)
|
||||
}
|
||||
|
||||
// SubMonthsNoOverflow subtracts some months without overflowing month.
|
||||
// N个月前(月份不溢出)
|
||||
func (c Carbon) SubMonthsNoOverflow(months int) Carbon {
|
||||
return c.AddMonthsNoOverflow(-months)
|
||||
}
|
||||
|
||||
// SubMonth subtracts one month.
|
||||
// 1个月前
|
||||
func (c Carbon) SubMonth() Carbon {
|
||||
return c.SubMonths(1)
|
||||
}
|
||||
|
||||
// SubMonthNoOverflow subtracts one month without overflowing month.
|
||||
// 1个月前(月份不溢出)
|
||||
func (c Carbon) SubMonthNoOverflow() Carbon {
|
||||
return c.SubMonthsNoOverflow(1)
|
||||
}
|
||||
|
||||
// AddWeeks adds some weeks.
|
||||
// N周后
|
||||
func (c Carbon) AddWeeks(weeks int) Carbon {
|
||||
return c.AddDays(weeks * DaysPerWeek)
|
||||
}
|
||||
|
||||
// AddWeek adds one week.
|
||||
// 1周后
|
||||
func (c Carbon) AddWeek() Carbon {
|
||||
return c.AddWeeks(1)
|
||||
}
|
||||
|
||||
// SubWeeks subtracts some weeks.
|
||||
// N周前
|
||||
func (c Carbon) SubWeeks(weeks int) Carbon {
|
||||
return c.SubDays(weeks * DaysPerWeek)
|
||||
}
|
||||
|
||||
// SubWeek subtracts one week.
|
||||
// 1周前
|
||||
func (c Carbon) SubWeek() Carbon {
|
||||
return c.SubWeeks(1)
|
||||
}
|
||||
|
||||
// AddDays adds some days.
|
||||
// N天后
|
||||
func (c Carbon) AddDays(days int) Carbon {
|
||||
if c.IsInvalid() {
|
||||
return c
|
||||
}
|
||||
c.time = c.StdTime().AddDate(0, 0, days)
|
||||
return c
|
||||
}
|
||||
|
||||
// AddDay adds one day.
|
||||
// 1天后
|
||||
func (c Carbon) AddDay() Carbon {
|
||||
return c.AddDays(1)
|
||||
}
|
||||
|
||||
// SubDays subtracts some days.
|
||||
// N天前
|
||||
func (c Carbon) SubDays(days int) Carbon {
|
||||
return c.AddDays(-days)
|
||||
}
|
||||
|
||||
// SubDay subtracts one day.
|
||||
// 1天前
|
||||
func (c Carbon) SubDay() Carbon {
|
||||
return c.SubDays(1)
|
||||
}
|
||||
|
||||
// AddHours adds some hours.
|
||||
// N小时后
|
||||
func (c Carbon) AddHours(hours int) Carbon {
|
||||
if c.IsInvalid() {
|
||||
return c
|
||||
}
|
||||
td := time.Duration(hours) * time.Hour
|
||||
c.time = c.StdTime().Add(td)
|
||||
return c
|
||||
}
|
||||
|
||||
// AddHour adds one hour.
|
||||
// 1小时后
|
||||
func (c Carbon) AddHour() Carbon {
|
||||
return c.AddHours(1)
|
||||
}
|
||||
|
||||
// SubHours subtracts some hours.
|
||||
// N小时前
|
||||
func (c Carbon) SubHours(hours int) Carbon {
|
||||
return c.AddHours(-hours)
|
||||
}
|
||||
|
||||
// SubHour subtracts one hour.
|
||||
// 1小时前
|
||||
func (c Carbon) SubHour() Carbon {
|
||||
return c.SubHours(1)
|
||||
}
|
||||
|
||||
// AddMinutes adds some minutes.
|
||||
// N分钟后
|
||||
func (c Carbon) AddMinutes(minutes int) Carbon {
|
||||
if c.IsInvalid() {
|
||||
return c
|
||||
}
|
||||
td := time.Duration(minutes) * time.Minute
|
||||
c.time = c.StdTime().Add(td)
|
||||
return c
|
||||
}
|
||||
|
||||
// AddMinute adds one minute.
|
||||
// 1分钟后
|
||||
func (c Carbon) AddMinute() Carbon {
|
||||
return c.AddMinutes(1)
|
||||
}
|
||||
|
||||
// SubMinutes subtracts some minutes.
|
||||
// N分钟前
|
||||
func (c Carbon) SubMinutes(minutes int) Carbon {
|
||||
return c.AddMinutes(-minutes)
|
||||
}
|
||||
|
||||
// SubMinute subtracts one minute.
|
||||
// 1分钟前
|
||||
func (c Carbon) SubMinute() Carbon {
|
||||
return c.SubMinutes(1)
|
||||
}
|
||||
|
||||
// AddSeconds adds some seconds.
|
||||
// N秒钟后
|
||||
func (c Carbon) AddSeconds(seconds int) Carbon {
|
||||
if c.IsInvalid() {
|
||||
return c
|
||||
}
|
||||
td := time.Duration(seconds) * time.Second
|
||||
c.time = c.StdTime().Add(td)
|
||||
return c
|
||||
}
|
||||
|
||||
// AddSecond adds one second.
|
||||
// 1秒钟后
|
||||
func (c Carbon) AddSecond() Carbon {
|
||||
return c.AddSeconds(1)
|
||||
}
|
||||
|
||||
// SubSeconds subtracts some seconds.
|
||||
// N秒钟前
|
||||
func (c Carbon) SubSeconds(seconds int) Carbon {
|
||||
return c.AddSeconds(-seconds)
|
||||
}
|
||||
|
||||
// SubSecond subtracts one second.
|
||||
// 1秒钟前
|
||||
func (c Carbon) SubSecond() Carbon {
|
||||
return c.SubSeconds(1)
|
||||
}
|
||||
|
||||
// AddMilliseconds adds some milliseconds.
|
||||
// N毫秒后
|
||||
func (c Carbon) AddMilliseconds(milliseconds int) Carbon {
|
||||
if c.IsInvalid() {
|
||||
return c
|
||||
}
|
||||
td := time.Duration(milliseconds) * time.Millisecond
|
||||
c.time = c.StdTime().Add(td)
|
||||
return c
|
||||
}
|
||||
|
||||
// AddMillisecond adds one millisecond.
|
||||
// 1毫秒后
|
||||
func (c Carbon) AddMillisecond() Carbon {
|
||||
return c.AddMilliseconds(1)
|
||||
}
|
||||
|
||||
// SubMilliseconds subtracts some milliseconds.
|
||||
// N毫秒前
|
||||
func (c Carbon) SubMilliseconds(milliseconds int) Carbon {
|
||||
return c.AddMilliseconds(-milliseconds)
|
||||
}
|
||||
|
||||
// SubMillisecond subtracts one millisecond.
|
||||
// 1毫秒前
|
||||
func (c Carbon) SubMillisecond() Carbon {
|
||||
return c.SubMilliseconds(1)
|
||||
}
|
||||
|
||||
// AddMicroseconds adds some microseconds.
|
||||
// N微秒后
|
||||
func (c Carbon) AddMicroseconds(microseconds int) Carbon {
|
||||
if c.IsInvalid() {
|
||||
return c
|
||||
}
|
||||
td := time.Duration(microseconds) * time.Microsecond
|
||||
c.time = c.StdTime().Add(td)
|
||||
return c
|
||||
}
|
||||
|
||||
// AddMicrosecond adds one microsecond.
|
||||
// 1微秒后
|
||||
func (c Carbon) AddMicrosecond() Carbon {
|
||||
return c.AddMicroseconds(1)
|
||||
}
|
||||
|
||||
// SubMicroseconds subtracts some microseconds.
|
||||
// N微秒前
|
||||
func (c Carbon) SubMicroseconds(microseconds int) Carbon {
|
||||
return c.AddMicroseconds(-microseconds)
|
||||
}
|
||||
|
||||
// SubMicrosecond subtracts one microsecond.
|
||||
// 1微秒前
|
||||
func (c Carbon) SubMicrosecond() Carbon {
|
||||
return c.SubMicroseconds(1)
|
||||
}
|
||||
|
||||
// AddNanoseconds adds some nanoseconds.
|
||||
// N纳秒后
|
||||
func (c Carbon) AddNanoseconds(nanoseconds int) Carbon {
|
||||
if c.IsInvalid() {
|
||||
return c
|
||||
}
|
||||
td := time.Duration(nanoseconds) * time.Nanosecond
|
||||
c.time = c.StdTime().Add(td)
|
||||
return c
|
||||
}
|
||||
|
||||
// AddNanosecond adds one nanosecond.
|
||||
// 1纳秒后
|
||||
func (c Carbon) AddNanosecond() Carbon {
|
||||
return c.AddNanoseconds(1)
|
||||
}
|
||||
|
||||
// SubNanoseconds subtracts some nanoseconds.
|
||||
// N纳秒前
|
||||
func (c Carbon) SubNanoseconds(nanoseconds int) Carbon {
|
||||
return c.AddNanoseconds(-nanoseconds)
|
||||
}
|
||||
|
||||
// SubNanosecond subtracts one nanosecond.
|
||||
// 1纳秒前
|
||||
func (c Carbon) SubNanosecond() Carbon {
|
||||
return c.SubNanoseconds(1)
|
||||
}
|
||||
Reference in New Issue
Block a user