2021-02-18 14:32:31 +08:00
|
|
|
package carbon
|
|
|
|
|
2021-07-19 09:55:28 +08:00
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
)
|
2021-02-18 14:32:31 +08:00
|
|
|
|
2021-07-28 15:18:05 +08:00
|
|
|
// SetTimezone set timezone
|
|
|
|
// 设置时区
|
2021-02-18 14:32:31 +08:00
|
|
|
func (c Carbon) SetTimezone(name string) Carbon {
|
2021-03-25 18:59:38 +08:00
|
|
|
loc, err := getLocationByTimezone(name)
|
|
|
|
c.Loc = loc
|
|
|
|
c.Error = err
|
2021-02-18 14:32:31 +08:00
|
|
|
return c
|
|
|
|
}
|
|
|
|
|
2021-07-28 15:18:05 +08:00
|
|
|
// SetTimezone set timezone
|
|
|
|
// 设置时区
|
2021-02-18 14:32:31 +08:00
|
|
|
func SetTimezone(name string) Carbon {
|
2021-07-13 23:18:34 +08:00
|
|
|
return NewCarbon().SetTimezone(name)
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
|
2021-07-31 13:34:52 +08:00
|
|
|
// SetLanguage set language
|
|
|
|
// 设置语言对象
|
2021-02-18 14:32:31 +08:00
|
|
|
func (c Carbon) SetLanguage(lang *Language) Carbon {
|
2021-07-19 09:55:28 +08:00
|
|
|
c.Lang = lang
|
2021-02-18 14:32:31 +08:00
|
|
|
return c
|
|
|
|
}
|
|
|
|
|
2021-07-28 15:18:05 +08:00
|
|
|
// SetLanguage set language
|
|
|
|
// 设置语言对象
|
2021-02-18 14:32:31 +08:00
|
|
|
func SetLanguage(lang *Language) Carbon {
|
2021-07-13 23:18:34 +08:00
|
|
|
c := NewCarbon()
|
2021-02-18 14:32:31 +08:00
|
|
|
err := lang.SetLocale(lang.locale)
|
2021-06-17 16:21:55 +08:00
|
|
|
c.Lang = lang
|
|
|
|
c.Error = err
|
|
|
|
return c
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
|
2021-07-28 15:18:05 +08:00
|
|
|
// SetLocale set locale
|
|
|
|
// 设置语言区域
|
2021-02-18 14:32:31 +08:00
|
|
|
func (c Carbon) SetLocale(locale string) Carbon {
|
2021-07-23 11:07:13 +08:00
|
|
|
if c.IsInvalid() {
|
|
|
|
return c
|
|
|
|
}
|
2021-06-17 16:21:55 +08:00
|
|
|
c.Error = c.Lang.SetLocale(locale)
|
2021-02-18 14:32:31 +08:00
|
|
|
return c
|
|
|
|
}
|
|
|
|
|
2021-07-28 15:18:05 +08:00
|
|
|
// SetLocale set locale
|
|
|
|
// 设置语言区域
|
2021-02-18 14:32:31 +08:00
|
|
|
func SetLocale(locale string) Carbon {
|
2021-07-13 23:18:34 +08:00
|
|
|
c := NewCarbon()
|
2021-06-17 16:21:55 +08:00
|
|
|
c.Error = c.Lang.SetLocale(locale)
|
|
|
|
return c
|
|
|
|
}
|
|
|
|
|
2021-07-28 15:18:05 +08:00
|
|
|
// SetYear set year
|
|
|
|
// 设置年
|
2021-02-18 14:32:31 +08:00
|
|
|
func (c Carbon) SetYear(year int) Carbon {
|
2021-07-23 11:07:13 +08:00
|
|
|
if c.IsInvalid() {
|
|
|
|
return c
|
|
|
|
}
|
2021-04-07 15:29:43 +08:00
|
|
|
c.Time = time.Date(year, time.Month(c.Month()), c.Day(), c.Hour(), c.Minute(), c.Second(), c.Nanosecond(), c.Loc)
|
2021-02-18 14:32:31 +08:00
|
|
|
return c
|
|
|
|
}
|
|
|
|
|
2021-07-28 15:18:05 +08:00
|
|
|
// SetMonth set month
|
|
|
|
// 设置月
|
2021-02-18 14:32:31 +08:00
|
|
|
func (c Carbon) SetMonth(month int) Carbon {
|
2021-07-23 11:07:13 +08:00
|
|
|
if c.IsInvalid() {
|
|
|
|
return c
|
|
|
|
}
|
2021-04-07 15:29:43 +08:00
|
|
|
c.Time = time.Date(c.Year(), time.Month(month), c.Day(), c.Hour(), c.Minute(), c.Second(), c.Nanosecond(), c.Loc)
|
2021-02-18 14:32:31 +08:00
|
|
|
return c
|
|
|
|
}
|
|
|
|
|
2021-07-28 15:18:05 +08:00
|
|
|
// SetDay set day
|
|
|
|
// 设置日
|
2021-02-18 14:32:31 +08:00
|
|
|
func (c Carbon) SetDay(day int) Carbon {
|
2021-07-23 11:07:13 +08:00
|
|
|
if c.IsInvalid() {
|
|
|
|
return c
|
|
|
|
}
|
2021-04-07 15:29:43 +08:00
|
|
|
c.Time = time.Date(c.Year(), time.Month(c.Month()), day, c.Hour(), c.Minute(), c.Second(), c.Nanosecond(), c.Loc)
|
2021-02-18 14:32:31 +08:00
|
|
|
return c
|
|
|
|
}
|
|
|
|
|
2021-07-28 15:18:05 +08:00
|
|
|
// SetHour set hour
|
|
|
|
// 设置时
|
2021-02-18 14:32:31 +08:00
|
|
|
func (c Carbon) SetHour(hour int) Carbon {
|
2021-07-23 11:07:13 +08:00
|
|
|
if c.IsInvalid() {
|
|
|
|
return c
|
|
|
|
}
|
2021-04-07 15:29:43 +08:00
|
|
|
c.Time = time.Date(c.Year(), time.Month(c.Month()), c.Day(), hour, c.Minute(), c.Second(), c.Nanosecond(), c.Loc)
|
2021-02-18 14:32:31 +08:00
|
|
|
return c
|
|
|
|
}
|
|
|
|
|
2021-07-28 15:18:05 +08:00
|
|
|
// SetMinute set minute
|
|
|
|
// 设置分
|
2021-02-18 14:32:31 +08:00
|
|
|
func (c Carbon) SetMinute(minute int) Carbon {
|
2021-07-23 11:07:13 +08:00
|
|
|
if c.IsInvalid() {
|
|
|
|
return c
|
|
|
|
}
|
2021-04-07 15:29:43 +08:00
|
|
|
c.Time = time.Date(c.Year(), time.Month(c.Month()), c.Day(), c.Hour(), minute, c.Second(), c.Nanosecond(), c.Loc)
|
2021-02-18 14:32:31 +08:00
|
|
|
return c
|
|
|
|
}
|
|
|
|
|
2021-07-28 15:18:05 +08:00
|
|
|
// SetSecond set second
|
|
|
|
// 设置秒
|
2021-02-18 14:32:31 +08:00
|
|
|
func (c Carbon) SetSecond(second int) Carbon {
|
2021-04-07 15:29:43 +08:00
|
|
|
c.Time = time.Date(c.Year(), time.Month(c.Month()), c.Day(), c.Hour(), c.Minute(), second, c.Nanosecond(), c.Loc)
|
2021-02-18 14:32:31 +08:00
|
|
|
return c
|
|
|
|
}
|
2021-04-05 09:45:14 +08:00
|
|
|
|
2021-07-28 15:18:05 +08:00
|
|
|
// SetMillisecond set millisecond
|
|
|
|
// 设置毫秒
|
2021-04-05 10:14:44 +08:00
|
|
|
func (c Carbon) SetMillisecond(millisecond int) Carbon {
|
2021-07-23 11:07:13 +08:00
|
|
|
if c.IsInvalid() {
|
|
|
|
return c
|
|
|
|
}
|
2021-04-07 15:29:43 +08:00
|
|
|
c.Time = time.Date(c.Year(), time.Month(c.Month()), c.Day(), c.Hour(), c.Minute(), c.Second(), millisecond*1e6, c.Loc)
|
2021-04-05 10:14:44 +08:00
|
|
|
return c
|
|
|
|
}
|
|
|
|
|
2021-07-28 15:18:05 +08:00
|
|
|
// SetMicrosecond set microsecond
|
|
|
|
// 设置微秒
|
2021-04-05 10:14:44 +08:00
|
|
|
func (c Carbon) SetMicrosecond(microsecond int) Carbon {
|
2021-07-23 11:07:13 +08:00
|
|
|
if c.IsInvalid() {
|
|
|
|
return c
|
|
|
|
}
|
2021-07-19 09:55:28 +08:00
|
|
|
c.Time = time.Date(c.Year(), time.Month(c.Month()), c.Day(), c.Hour(), c.Minute(), c.Second(), microsecond*1e3, c.Loc)
|
2021-04-05 10:14:44 +08:00
|
|
|
return c
|
|
|
|
}
|
|
|
|
|
2021-07-28 15:18:05 +08:00
|
|
|
// SetNanosecond set nanosecond
|
|
|
|
// 设置纳秒
|
2021-04-05 09:45:14 +08:00
|
|
|
func (c Carbon) SetNanosecond(nanosecond int) Carbon {
|
2021-07-23 11:07:13 +08:00
|
|
|
if c.IsInvalid() {
|
|
|
|
return c
|
|
|
|
}
|
2021-04-07 15:29:43 +08:00
|
|
|
c.Time = time.Date(c.Year(), time.Month(c.Month()), c.Day(), c.Hour(), c.Minute(), c.Second(), nanosecond, c.Loc)
|
2021-04-05 09:45:14 +08:00
|
|
|
return c
|
|
|
|
}
|