c.time.In(c.loc->c.ToStdTime()

This commit is contained in:
Peleus 2023-09-06 14:34:51 +08:00
parent b64c8c7b9c
commit 5033c8ea57
4 changed files with 87 additions and 87 deletions

View File

@ -189,7 +189,7 @@ func (c Carbon) IsMonday() bool {
if c.IsInvalid() {
return false
}
return c.time.In(c.loc).Weekday() == time.Monday
return c.ToStdTime().Weekday() == time.Monday
}
// IsTuesday reports whether is Tuesday.
@ -198,7 +198,7 @@ func (c Carbon) IsTuesday() bool {
if c.IsInvalid() {
return false
}
return c.time.In(c.loc).Weekday() == time.Tuesday
return c.ToStdTime().Weekday() == time.Tuesday
}
// IsWednesday reports whether is Wednesday.
@ -207,7 +207,7 @@ func (c Carbon) IsWednesday() bool {
if c.IsInvalid() {
return false
}
return c.time.In(c.loc).Weekday() == time.Wednesday
return c.ToStdTime().Weekday() == time.Wednesday
}
// IsThursday reports whether is Thursday.
@ -216,7 +216,7 @@ func (c Carbon) IsThursday() bool {
if c.IsInvalid() {
return false
}
return c.time.In(c.loc).Weekday() == time.Thursday
return c.ToStdTime().Weekday() == time.Thursday
}
// IsFriday reports whether is Friday.
@ -225,7 +225,7 @@ func (c Carbon) IsFriday() bool {
if c.IsInvalid() {
return false
}
return c.time.In(c.loc).Weekday() == time.Friday
return c.ToStdTime().Weekday() == time.Friday
}
// IsSaturday reports whether is Saturday.
@ -234,7 +234,7 @@ func (c Carbon) IsSaturday() bool {
if c.IsInvalid() {
return false
}
return c.time.In(c.loc).Weekday() == time.Saturday
return c.ToStdTime().Weekday() == time.Saturday
}
// IsSunday reports whether is Sunday.
@ -243,7 +243,7 @@ func (c Carbon) IsSunday() bool {
if c.IsInvalid() {
return false
}
return c.time.In(c.loc).Weekday() == time.Sunday
return c.ToStdTime().Weekday() == time.Sunday
}
// IsWeekday reports whether is weekday.

View File

@ -31,7 +31,7 @@ func (c Carbon) MonthOfYear() int {
if c.IsInvalid() {
return 0
}
return int(c.time.In(c.loc).Month())
return int(c.ToStdTime().Month())
}
// DayOfYear gets day of year like 365.
@ -40,7 +40,7 @@ func (c Carbon) DayOfYear() int {
if c.IsInvalid() {
return 0
}
return c.time.In(c.loc).YearDay()
return c.ToStdTime().YearDay()
}
// DayOfMonth gets day of month like 30.
@ -49,7 +49,7 @@ func (c Carbon) DayOfMonth() int {
if c.IsInvalid() {
return 0
}
return c.time.In(c.loc).Day()
return c.ToStdTime().Day()
}
// DayOfWeek gets day of week like 6.
@ -58,7 +58,7 @@ func (c Carbon) DayOfWeek() int {
if c.IsInvalid() {
return 0
}
day := int(c.time.In(c.loc).Weekday())
day := int(c.ToStdTime().Weekday())
if day == 0 {
return DaysPerWeek
}
@ -71,7 +71,7 @@ func (c Carbon) WeekOfYear() int {
if c.IsInvalid() {
return 0
}
_, week := c.time.In(c.loc).ISOWeek()
_, week := c.ToStdTime().ISOWeek()
return week
}
@ -136,7 +136,7 @@ func (c Carbon) Date() (year, month, day int) {
return
}
var tm time.Month
year, tm, day = c.time.In(c.loc).Date()
year, tm, day = c.ToStdTime().Date()
return year, int(tm), day
}
@ -176,7 +176,7 @@ func (c Carbon) Time() (hour, minute, second int) {
if c.IsInvalid() {
return
}
return c.time.In(c.loc).Clock()
return c.ToStdTime().Clock()
}
// TimeMilli gets current hour, minute, second and millisecond like 13, 14, 15, 999.
@ -233,7 +233,7 @@ func (c Carbon) Year() int {
if c.IsInvalid() {
return 0
}
return c.time.In(c.loc).Year()
return c.ToStdTime().Year()
}
// Quarter gets current quarter like 3.
@ -283,7 +283,7 @@ func (c Carbon) Hour() int {
if c.IsInvalid() {
return 0
}
return c.time.In(c.loc).Hour()
return c.ToStdTime().Hour()
}
// Minute gets current minute like 14.
@ -292,7 +292,7 @@ func (c Carbon) Minute() int {
if c.IsInvalid() {
return 0
}
return c.time.In(c.loc).Minute()
return c.ToStdTime().Minute()
}
// Second gets current second like 15.
@ -301,7 +301,7 @@ func (c Carbon) Second() int {
if c.IsInvalid() {
return 0
}
return c.time.In(c.loc).Second()
return c.ToStdTime().Second()
}
// Millisecond gets current millisecond like 999.
@ -310,7 +310,7 @@ func (c Carbon) Millisecond() int {
if c.IsInvalid() {
return 0
}
return c.time.In(c.loc).Nanosecond() / 1e6
return c.ToStdTime().Nanosecond() / 1e6
}
// Microsecond gets current microsecond like 999999.
@ -319,7 +319,7 @@ func (c Carbon) Microsecond() int {
if c.IsInvalid() {
return 0
}
return c.time.In(c.loc).Nanosecond() / 1e3
return c.ToStdTime().Nanosecond() / 1e3
}
// Nanosecond gets current nanosecond like 999999999.
@ -328,7 +328,7 @@ func (c Carbon) Nanosecond() int {
if c.IsInvalid() {
return 0
}
return c.time.In(c.loc).Nanosecond()
return c.ToStdTime().Nanosecond()
}
// Timestamp gets timestamp with second like 1596604455.
@ -337,7 +337,7 @@ func (c Carbon) Timestamp() int64 {
if c.IsInvalid() {
return 0
}
return c.time.In(c.loc).Unix()
return c.ToStdTime().Unix()
}
// TimestampMilli gets timestamp with millisecond like 1596604455000.
@ -346,7 +346,7 @@ func (c Carbon) TimestampMilli() int64 {
if c.IsInvalid() {
return 0
}
t := c.time.In(c.loc)
t := c.ToStdTime()
return t.Unix()*1e3 + int64(t.Nanosecond())/1e6
}
@ -356,7 +356,7 @@ func (c Carbon) TimestampMicro() int64 {
if c.IsInvalid() {
return 0
}
t := c.time.In(c.loc)
t := c.ToStdTime()
return t.Unix()*1e6 + int64(t.Nanosecond())/1e3
}
@ -366,7 +366,7 @@ func (c Carbon) TimestampNano() int64 {
if c.IsInvalid() {
return 0
}
return c.time.In(c.loc).UnixNano()
return c.ToStdTime().UnixNano()
}
// Location gets location name like "PRC".
@ -378,14 +378,14 @@ func (c Carbon) Location() string {
// Timezone gets timezone name like "CST".
// 获取时区
func (c Carbon) Timezone() string {
name, _ := c.time.In(c.loc).Zone()
name, _ := c.ToStdTime().Zone()
return name
}
// Offset gets offset seconds from the UTC timezone like 28800.
// 获取距离UTC时区的偏移量单位秒
func (c Carbon) Offset() int {
_, offset := c.time.In(c.loc).Zone()
_, offset := c.ToStdTime().Zone()
return offset
}

View File

@ -23,7 +23,7 @@ func (c Carbon) ToString(timezone ...string) string {
if c.IsInvalid() {
return ""
}
return c.time.In(c.loc).String()
return c.ToStdTime().String()
}
// ToMonthString outputs a string in month layout like "January", i18n is supported.
@ -119,7 +119,7 @@ func (c Carbon) ToDayDateTimeString(timezone ...string) string {
if c.IsInvalid() {
return ""
}
return c.time.In(c.loc).Format(DayDateTimeLayout)
return c.ToStdTime().Format(DayDateTimeLayout)
}
// ToDateTimeString outputs a string in "2006-01-02 15:04:05" layout.
@ -131,7 +131,7 @@ func (c Carbon) ToDateTimeString(timezone ...string) string {
if c.IsInvalid() {
return ""
}
return c.time.In(c.loc).Format(DateTimeLayout)
return c.ToStdTime().Format(DateTimeLayout)
}
// ToDateTimeMilliString outputs a string in "2006-01-02 15:04:05.999" layout.
@ -143,7 +143,7 @@ func (c Carbon) ToDateTimeMilliString(timezone ...string) string {
if c.IsInvalid() {
return ""
}
return c.time.In(c.loc).Format(DateTimeMilliLayout)
return c.ToStdTime().Format(DateTimeMilliLayout)
}
// ToDateTimeMicroString outputs a string in "2006-01-02 15:04:05.999999" layout.
@ -155,7 +155,7 @@ func (c Carbon) ToDateTimeMicroString(timezone ...string) string {
if c.IsInvalid() {
return ""
}
return c.time.In(c.loc).Format(DateTimeMicroLayout)
return c.ToStdTime().Format(DateTimeMicroLayout)
}
// ToDateTimeNanoString outputs a string in "2006-01-02 15:04:05.999999999" layout.
@ -167,7 +167,7 @@ func (c Carbon) ToDateTimeNanoString(timezone ...string) string {
if c.IsInvalid() {
return ""
}
return c.time.In(c.loc).Format(DateTimeNanoLayout)
return c.ToStdTime().Format(DateTimeNanoLayout)
}
// ToShortDateTimeString outputs a string in "20060102150405" layout.
@ -179,7 +179,7 @@ func (c Carbon) ToShortDateTimeString(timezone ...string) string {
if c.IsInvalid() {
return ""
}
return c.time.In(c.loc).Format(ShortDateTimeLayout)
return c.ToStdTime().Format(ShortDateTimeLayout)
}
// ToShortDateTimeMilliString outputs a string in "20060102150405.999" layout.
@ -191,7 +191,7 @@ func (c Carbon) ToShortDateTimeMilliString(timezone ...string) string {
if c.IsInvalid() {
return ""
}
return c.time.In(c.loc).Format(ShortDateTimeMilliLayout)
return c.ToStdTime().Format(ShortDateTimeMilliLayout)
}
// ToShortDateTimeMicroString outputs a string in "20060102150405.999999" layout.
@ -203,7 +203,7 @@ func (c Carbon) ToShortDateTimeMicroString(timezone ...string) string {
if c.IsInvalid() {
return ""
}
return c.time.In(c.loc).Format(ShortDateTimeMicroLayout)
return c.ToStdTime().Format(ShortDateTimeMicroLayout)
}
// ToShortDateTimeNanoString outputs a string in "20060102150405.999999999" layout.
@ -215,7 +215,7 @@ func (c Carbon) ToShortDateTimeNanoString(timezone ...string) string {
if c.IsInvalid() {
return ""
}
return c.time.In(c.loc).Format(ShortDateTimeNanoLayout)
return c.ToStdTime().Format(ShortDateTimeNanoLayout)
}
// ToDateString outputs a string in "2006-01-02" layout.
@ -227,7 +227,7 @@ func (c Carbon) ToDateString(timezone ...string) string {
if c.IsInvalid() {
return ""
}
return c.time.In(c.loc).Format(DateLayout)
return c.ToStdTime().Format(DateLayout)
}
// ToDateMilliString outputs a string in "2006-01-02.999" layout.
@ -239,7 +239,7 @@ func (c Carbon) ToDateMilliString(timezone ...string) string {
if c.IsInvalid() {
return ""
}
return c.time.In(c.loc).Format(DateMilliLayout)
return c.ToStdTime().Format(DateMilliLayout)
}
// ToDateMicroString outputs a string in "2006-01-02.999999" layout.
@ -251,7 +251,7 @@ func (c Carbon) ToDateMicroString(timezone ...string) string {
if c.IsInvalid() {
return ""
}
return c.time.In(c.loc).Format(DateMicroLayout)
return c.ToStdTime().Format(DateMicroLayout)
}
// ToDateNanoString outputs a string in "2006-01-02.999999999" layout.
@ -263,7 +263,7 @@ func (c Carbon) ToDateNanoString(timezone ...string) string {
if c.IsInvalid() {
return ""
}
return c.time.In(c.loc).Format(DateNanoLayout)
return c.ToStdTime().Format(DateNanoLayout)
}
// ToShortDateString outputs a string in "20060102" layout.
@ -275,7 +275,7 @@ func (c Carbon) ToShortDateString(timezone ...string) string {
if c.IsInvalid() {
return ""
}
return c.time.In(c.loc).Format(ShortDateLayout)
return c.ToStdTime().Format(ShortDateLayout)
}
// ToShortDateMilliString outputs a string in "20060102.999" layout.
@ -287,7 +287,7 @@ func (c Carbon) ToShortDateMilliString(timezone ...string) string {
if c.IsInvalid() {
return ""
}
return c.time.In(c.loc).Format(ShortDateMilliLayout)
return c.ToStdTime().Format(ShortDateMilliLayout)
}
// ToShortDateMicroString outputs a string in "20060102.999999" layout.
@ -299,7 +299,7 @@ func (c Carbon) ToShortDateMicroString(timezone ...string) string {
if c.IsInvalid() {
return ""
}
return c.time.In(c.loc).Format(ShortDateMicroLayout)
return c.ToStdTime().Format(ShortDateMicroLayout)
}
// ToShortDateNanoString outputs a string in "20060102.999999999" layout.
@ -311,7 +311,7 @@ func (c Carbon) ToShortDateNanoString(timezone ...string) string {
if c.IsInvalid() {
return ""
}
return c.time.In(c.loc).Format(ShortDateNanoLayout)
return c.ToStdTime().Format(ShortDateNanoLayout)
}
// ToTimeString outputs a string in "15:04:05" layout.
@ -323,7 +323,7 @@ func (c Carbon) ToTimeString(timezone ...string) string {
if c.IsInvalid() {
return ""
}
return c.time.In(c.loc).Format(TimeLayout)
return c.ToStdTime().Format(TimeLayout)
}
// ToTimeMilliString outputs a string in "15:04:05.999" layout.
@ -335,7 +335,7 @@ func (c Carbon) ToTimeMilliString(timezone ...string) string {
if c.IsInvalid() {
return ""
}
return c.time.In(c.loc).Format(TimeMilliLayout)
return c.ToStdTime().Format(TimeMilliLayout)
}
// ToTimeMicroString outputs a string in "15:04:05.999999" layout.
@ -347,7 +347,7 @@ func (c Carbon) ToTimeMicroString(timezone ...string) string {
if c.IsInvalid() {
return ""
}
return c.time.In(c.loc).Format(TimeMicroLayout)
return c.ToStdTime().Format(TimeMicroLayout)
}
// ToTimeNanoString outputs a string in "15:04:05.999999999" layout.
@ -359,7 +359,7 @@ func (c Carbon) ToTimeNanoString(timezone ...string) string {
if c.IsInvalid() {
return ""
}
return c.time.In(c.loc).Format(TimeNanoLayout)
return c.ToStdTime().Format(TimeNanoLayout)
}
// ToShortTimeString outputs a string in "150405" layout.
@ -371,7 +371,7 @@ func (c Carbon) ToShortTimeString(timezone ...string) string {
if c.IsInvalid() {
return ""
}
return c.time.In(c.loc).Format(ShortTimeLayout)
return c.ToStdTime().Format(ShortTimeLayout)
}
// ToShortTimeMilliString outputs a string in "150405.999" layout.
@ -383,7 +383,7 @@ func (c Carbon) ToShortTimeMilliString(timezone ...string) string {
if c.IsInvalid() {
return ""
}
return c.time.In(c.loc).Format(ShortTimeMilliLayout)
return c.ToStdTime().Format(ShortTimeMilliLayout)
}
// ToShortTimeMicroString outputs a string in "150405.999999" layout.
@ -395,7 +395,7 @@ func (c Carbon) ToShortTimeMicroString(timezone ...string) string {
if c.IsInvalid() {
return ""
}
return c.time.In(c.loc).Format(ShortTimeMicroLayout)
return c.ToStdTime().Format(ShortTimeMicroLayout)
}
// ToShortTimeNanoString outputs a string in "150405.999999999" layout.
@ -407,7 +407,7 @@ func (c Carbon) ToShortTimeNanoString(timezone ...string) string {
if c.IsInvalid() {
return ""
}
return c.time.In(c.loc).Format(ShortTimeNanoLayout)
return c.ToStdTime().Format(ShortTimeNanoLayout)
}
// ToAtomString outputs a string in "2006-01-02T15:04:05Z07:00" layout.
@ -425,7 +425,7 @@ func (c Carbon) ToANSICString(timezone ...string) string {
if c.IsInvalid() {
return ""
}
return c.time.In(c.loc).Format(ANSICLayout)
return c.ToStdTime().Format(ANSICLayout)
}
// ToCookieString outputs a string in "Monday, 02-Jan-2006 15:04:05 MST" layout.
@ -437,7 +437,7 @@ func (c Carbon) ToCookieString(timezone ...string) string {
if c.IsInvalid() {
return ""
}
return c.time.In(c.loc).Format(CookieLayout)
return c.ToStdTime().Format(CookieLayout)
}
// ToRssString outputs a string in "Mon, 02 Jan 2006 15:04:05 -0700" format.
@ -449,7 +449,7 @@ func (c Carbon) ToRssString(timezone ...string) string {
if c.IsInvalid() {
return ""
}
return c.time.In(c.loc).Format(RssLayout)
return c.ToStdTime().Format(RssLayout)
}
// ToW3cString outputs a string in "2006-01-02T15:04:05Z07:00" layout.
@ -467,7 +467,7 @@ func (c Carbon) ToUnixDateString(timezone ...string) string {
if c.IsInvalid() {
return ""
}
return c.time.In(c.loc).Format(UnixDateLayout)
return c.ToStdTime().Format(UnixDateLayout)
}
// ToRubyDateString outputs a string in "Mon Jan 02 15:04:05 -0700 2006" layout.
@ -479,7 +479,7 @@ func (c Carbon) ToRubyDateString(timezone ...string) string {
if c.IsInvalid() {
return ""
}
return c.time.In(c.loc).Format(RubyDateLayout)
return c.ToStdTime().Format(RubyDateLayout)
}
// ToKitchenString outputs a string in "3:04PM" layout.
@ -491,7 +491,7 @@ func (c Carbon) ToKitchenString(timezone ...string) string {
if c.IsInvalid() {
return ""
}
return c.time.In(c.loc).Format(KitchenLayout)
return c.ToStdTime().Format(KitchenLayout)
}
// ToIso8601String outputs a string in "2006-01-02T15:04:05-07:00" layout.
@ -503,7 +503,7 @@ func (c Carbon) ToIso8601String(timezone ...string) string {
if c.IsInvalid() {
return ""
}
return c.time.In(c.loc).Format(ISO8601Layout)
return c.ToStdTime().Format(ISO8601Layout)
}
// ToIso8601MilliString outputs a string in "2006-01-02T15:04:05.999-07:00" layout.
@ -515,7 +515,7 @@ func (c Carbon) ToIso8601MilliString(timezone ...string) string {
if c.IsInvalid() {
return ""
}
return c.time.In(c.loc).Format(ISO8601MilliLayout)
return c.ToStdTime().Format(ISO8601MilliLayout)
}
// ToIso8601MicroString outputs a string in "2006-01-02T15:04:05.999999-07:00" layout.
@ -527,7 +527,7 @@ func (c Carbon) ToIso8601MicroString(timezone ...string) string {
if c.IsInvalid() {
return ""
}
return c.time.In(c.loc).Format(ISO8601MicroLayout)
return c.ToStdTime().Format(ISO8601MicroLayout)
}
// ToIso8601NanoString outputs a string in "2006-01-02T15:04:05.999999999-07:00" layout.
@ -539,7 +539,7 @@ func (c Carbon) ToIso8601NanoString(timezone ...string) string {
if c.IsInvalid() {
return ""
}
return c.time.In(c.loc).Format(ISO8601NanoLayout)
return c.ToStdTime().Format(ISO8601NanoLayout)
}
// ToRfc822String outputs a string in "02 Jan 06 15:04 MST" layout.
@ -551,7 +551,7 @@ func (c Carbon) ToRfc822String(timezone ...string) string {
if c.IsInvalid() {
return ""
}
return c.time.In(c.loc).Format(RFC822Layout)
return c.ToStdTime().Format(RFC822Layout)
}
// ToRfc822zString outputs a string in "02 Jan 06 15:04 -0700" layout.
@ -563,7 +563,7 @@ func (c Carbon) ToRfc822zString(timezone ...string) string {
if c.IsInvalid() {
return ""
}
return c.time.In(c.loc).Format(RFC822ZLayout)
return c.ToStdTime().Format(RFC822ZLayout)
}
// ToRfc850String outputs a string in "Monday, 02-Jan-06 15:04:05 MST" layout.
@ -575,7 +575,7 @@ func (c Carbon) ToRfc850String(timezone ...string) string {
if c.IsInvalid() {
return ""
}
return c.time.In(c.loc).Format(RFC850Layout)
return c.ToStdTime().Format(RFC850Layout)
}
// ToRfc1036String outputs a string in "Mon, 02 Jan 06 15:04:05 -0700" layout.
@ -587,7 +587,7 @@ func (c Carbon) ToRfc1036String(timezone ...string) string {
if c.IsInvalid() {
return ""
}
return c.time.In(c.loc).Format(RFC1036Layout)
return c.ToStdTime().Format(RFC1036Layout)
}
// ToRfc1123String outputs a string in "Mon, 02 Jan 2006 15:04:05 MST" layout.
@ -599,7 +599,7 @@ func (c Carbon) ToRfc1123String(timezone ...string) string {
if c.IsInvalid() {
return ""
}
return c.time.In(c.loc).Format(RFC1123Layout)
return c.ToStdTime().Format(RFC1123Layout)
}
// ToRfc1123zString outputs a string in "Mon, 02 Jan 2006 15:04:05 -0700" layout.
@ -611,7 +611,7 @@ func (c Carbon) ToRfc1123zString(timezone ...string) string {
if c.IsInvalid() {
return ""
}
return c.time.In(c.loc).Format(RFC1123ZLayout)
return c.ToStdTime().Format(RFC1123ZLayout)
}
// ToRfc2822String outputs a string in "Mon, 02 Jan 2006 15:04:05 -0700" layout.
@ -623,7 +623,7 @@ func (c Carbon) ToRfc2822String(timezone ...string) string {
if c.IsInvalid() {
return ""
}
return c.time.In(c.loc).Format(RFC2822Layout)
return c.ToStdTime().Format(RFC2822Layout)
}
// ToRfc3339String outputs a string in "2006-01-02T15:04:05Z07:00" layout.
@ -635,7 +635,7 @@ func (c Carbon) ToRfc3339String(timezone ...string) string {
if c.IsInvalid() {
return ""
}
return c.time.In(c.loc).Format(RFC3339Layout)
return c.ToStdTime().Format(RFC3339Layout)
}
// ToRfc3339MilliString outputs a string in "2006-01-02T15:04:05.999Z07:00" layout.
@ -647,7 +647,7 @@ func (c Carbon) ToRfc3339MilliString(timezone ...string) string {
if c.IsInvalid() {
return ""
}
return c.time.In(c.loc).Format(RFC3339MilliLayout)
return c.ToStdTime().Format(RFC3339MilliLayout)
}
// ToRfc3339MicroString outputs a string in "2006-01-02T15:04:05.999999Z07:00" layout.
@ -659,7 +659,7 @@ func (c Carbon) ToRfc3339MicroString(timezone ...string) string {
if c.IsInvalid() {
return ""
}
return c.time.In(c.loc).Format(RFC3339MicroLayout)
return c.ToStdTime().Format(RFC3339MicroLayout)
}
// ToRfc3339NanoString outputs a string in "2006-01-02T15:04:05.999999999Z07:00" layout.
@ -671,7 +671,7 @@ func (c Carbon) ToRfc3339NanoString(timezone ...string) string {
if c.IsInvalid() {
return ""
}
return c.time.In(c.loc).Format(RFC3339NanoLayout)
return c.ToStdTime().Format(RFC3339NanoLayout)
}
// ToRfc7231String outputs a string in "Mon, 02 Jan 2006 15:04:05 GMT" layout.
@ -683,7 +683,7 @@ func (c Carbon) ToRfc7231String(timezone ...string) string {
if c.IsInvalid() {
return ""
}
return c.time.In(c.loc).Format(RFC7231Layout)
return c.ToStdTime().Format(RFC7231Layout)
}
// ToLayoutString outputs a string by layout.
@ -695,7 +695,7 @@ func (c Carbon) ToLayoutString(layout string, timezone ...string) string {
if c.IsInvalid() {
return ""
}
return c.time.In(c.loc).Format(layout)
return c.ToStdTime().Format(layout)
}
// Layout outputs a string by layout, it is shorthand for ToLayoutString.
@ -727,7 +727,7 @@ func (c Carbon) ToFormatString(format string, timezone ...string) string {
case 'M': // short month, such as Jan
buffer.WriteString(c.ToShortMonthString())
default: // common symbols
buffer.WriteString(c.time.In(c.loc).Format(layout))
buffer.WriteString(c.ToStdTime().Format(layout))
}
} else {
switch format[i] {

View File

@ -81,7 +81,7 @@ func (c Carbon) AddDuration(duration string) Carbon {
return c
}
td, err := parseByDuration(duration)
c.time, c.Error = c.time.In(c.loc).Add(td), err
c.time, c.Error = c.ToStdTime().Add(td), err
return c
}
@ -193,7 +193,7 @@ func (c Carbon) AddYears(years int) Carbon {
if c.IsInvalid() {
return c
}
c.time = c.time.In(c.loc).AddDate(years, 0, 0)
c.time = c.ToStdTime().AddDate(years, 0, 0)
return c
}
@ -306,7 +306,7 @@ func (c Carbon) AddMonths(months int) Carbon {
if c.IsInvalid() {
return c
}
c.time = c.time.In(c.loc).AddDate(0, months, 0)
c.time = c.ToStdTime().AddDate(0, months, 0)
return c
}
@ -392,7 +392,7 @@ func (c Carbon) AddDays(days int) Carbon {
if c.IsInvalid() {
return c
}
c.time = c.time.In(c.loc).AddDate(0, 0, days)
c.time = c.ToStdTime().AddDate(0, 0, days)
return c
}
@ -421,7 +421,7 @@ func (c Carbon) AddHours(hours int) Carbon {
return c
}
td := time.Duration(hours) * time.Hour
c.time = c.time.In(c.loc).Add(td)
c.time = c.ToStdTime().Add(td)
return c
}
@ -450,7 +450,7 @@ func (c Carbon) AddMinutes(minutes int) Carbon {
return c
}
td := time.Duration(minutes) * time.Minute
c.time = c.time.In(c.loc).Add(td)
c.time = c.ToStdTime().Add(td)
return c
}
@ -479,7 +479,7 @@ func (c Carbon) AddSeconds(seconds int) Carbon {
return c
}
td := time.Duration(seconds) * time.Second
c.time = c.time.In(c.loc).Add(td)
c.time = c.ToStdTime().Add(td)
return c
}
@ -508,7 +508,7 @@ func (c Carbon) AddMilliseconds(milliseconds int) Carbon {
return c
}
td := time.Duration(milliseconds) * time.Millisecond
c.time = c.time.In(c.loc).Add(td)
c.time = c.ToStdTime().Add(td)
return c
}
@ -537,7 +537,7 @@ func (c Carbon) AddMicroseconds(microseconds int) Carbon {
return c
}
td := time.Duration(microseconds) * time.Microsecond
c.time = c.time.In(c.loc).Add(td)
c.time = c.ToStdTime().Add(td)
return c
}
@ -566,7 +566,7 @@ func (c Carbon) AddNanoseconds(nanoseconds int) Carbon {
return c
}
td := time.Duration(nanoseconds) * time.Nanosecond
c.time = c.time.In(c.loc).Add(td)
c.time = c.ToStdTime().Add(td)
return c
}