为避免New()和Now()混淆,将New()方法改回NewCarbon()方法

This commit is contained in:
gouguoyin 2021-07-13 23:18:34 +08:00
parent ac6e6126e9
commit 17617f9b8e
5 changed files with 17 additions and 17 deletions

View File

@ -63,7 +63,7 @@ func (c Carbon) Lunar() (l lunar) {
return
}
// 计算距离1900年1月31日相差的天数
offset := int(c.DiffInDaysWithAbs(Parse("1900-01-31")))
offset := int(c.DiffInDaysWithAbs(CreateFromDateTime(minYear, 1, 31, 0, 0, 0)))
for l.year = minYear; l.year <= maxYear && offset > 0; l.year++ {
daysInYear = l.getDaysInYear()
offset -= daysInYear

View File

@ -145,14 +145,14 @@ type Carbon struct {
Error error
}
// New 新建 Carbon 结构体
func New() Carbon {
// NewCarbon 新建 Carbon 结构体
func NewCarbon() Carbon {
return Carbon{Loc: time.Local, Lang: NewLanguage()}
}
// Time2Carbon 将 time.Time 转换成 Carbon
func Time2Carbon(tt time.Time) Carbon {
c := New()
c := NewCarbon()
c.Time = tt
return c
}
@ -170,7 +170,7 @@ func (c Carbon) Now() Carbon {
// Now 当前(默认时区)
func Now() Carbon {
return New().Now()
return NewCarbon().Now()
}
// Tomorrow 明天
@ -185,7 +185,7 @@ func (c Carbon) Tomorrow() Carbon {
// Tomorrow 明天(默认时区)
func Tomorrow() Carbon {
return New().Tomorrow()
return NewCarbon().Tomorrow()
}
// Yesterday 昨天
@ -200,5 +200,5 @@ func (c Carbon) Yesterday() Carbon {
// Yesterday 昨天(默认时区)
func Yesterday() Carbon {
return New().Yesterday()
return NewCarbon().Yesterday()
}

View File

@ -26,7 +26,7 @@ func (c Carbon) CreateFromTimestamp(timestamp int64) Carbon {
// CreateFromTimestamp 从时间戳创建 Carbon 实例(默认时区)
func CreateFromTimestamp(timestamp int64) Carbon {
return New().CreateFromTimestamp(timestamp)
return NewCarbon().CreateFromTimestamp(timestamp)
}
// CreateFromDateTime 从年月日时分秒创建 Carbon 实例
@ -37,7 +37,7 @@ func (c Carbon) CreateFromDateTime(year int, month int, day int, hour int, minut
// CreateFromDateTime 从年月日时分秒创建 Carbon 实例(默认时区)
func CreateFromDateTime(year int, month int, day int, hour int, minute int, second int) Carbon {
return New().CreateFromDateTime(year, month, day, hour, minute, second)
return NewCarbon().CreateFromDateTime(year, month, day, hour, minute, second)
}
// CreateFromDate 从年月日创建 Carbon 实例
@ -49,7 +49,7 @@ func (c Carbon) CreateFromDate(year int, month int, day int) Carbon {
// CreateFromDate 从年月日创建 Carbon 实例(默认时区)
func CreateFromDate(year int, month int, day int) Carbon {
return New().CreateFromDate(year, month, day)
return NewCarbon().CreateFromDate(year, month, day)
}
// CreateFromTime 从时分秒创建 Carbon 实例
@ -61,5 +61,5 @@ func (c Carbon) CreateFromTime(hour int, minute int, second int) Carbon {
// CreateFromTime 从时分秒创建 Carbon 实例(默认时区)
func CreateFromTime(hour int, minute int, second int) Carbon {
return New().CreateFromTime(hour, minute, second)
return NewCarbon().CreateFromTime(hour, minute, second)
}

View File

@ -35,7 +35,7 @@ func (c Carbon) Parse(value string) Carbon {
// Parse 将标准格式时间字符串解析成 Carbon 实例(默认时区)
func Parse(value string) Carbon {
return New().Parse(value)
return NewCarbon().Parse(value)
}
// ParseByFormat 将特殊格式时间字符串解析成 Carbon 实例
@ -49,7 +49,7 @@ func (c Carbon) ParseByFormat(value string, format string) Carbon {
// ParseByFormat 将特殊格式时间字符串解析成 Carbon 实例(默认时区)
func ParseByFormat(value string, format string) Carbon {
return New().ParseByFormat(value, format)
return NewCarbon().ParseByFormat(value, format)
}
// ParseByLayout 将布局时间字符串解析成 Carbon 实例
@ -67,5 +67,5 @@ func (c Carbon) ParseByLayout(value string, layout string) Carbon {
// ParseByLayout 将布局时间字符串解析成 Carbon 实例(默认时区)
func ParseByLayout(value string, layout string) Carbon {
return New().ParseByLayout(value, layout)
return NewCarbon().ParseByLayout(value, layout)
}

View File

@ -12,7 +12,7 @@ func (c Carbon) SetTimezone(name string) Carbon {
// SetTimezone 设置时区
func SetTimezone(name string) Carbon {
return New().SetTimezone(name)
return NewCarbon().SetTimezone(name)
}
// SetLanguage 设置语言对象
@ -29,7 +29,7 @@ func (c Carbon) SetLanguage(lang *Language) Carbon {
// SetLanguage 设置语言对象
func SetLanguage(lang *Language) Carbon {
c := New()
c := NewCarbon()
err := lang.SetLocale(lang.locale)
c.Lang = lang
c.Error = err
@ -44,7 +44,7 @@ func (c Carbon) SetLocale(locale string) Carbon {
// SetLocale 设置语言区域
func SetLocale(locale string) Carbon {
c := New()
c := NewCarbon()
c.Error = c.Lang.SetLocale(locale)
return c
}