mirror of
https://gitee.com/dromara/carbon.git
synced 2024-11-30 03:07:36 +08:00
更新版本号,部分将要弃用方法增加 Deprecated 标识
This commit is contained in:
parent
120abc76d4
commit
e9ec23b511
20
carbon.go
20
carbon.go
@ -14,7 +14,7 @@ import (
|
||||
|
||||
// Version current version
|
||||
// 当前版本号
|
||||
const Version = "2.2.3"
|
||||
const Version = "2.2.4"
|
||||
|
||||
// timezone constants
|
||||
// 时区常量
|
||||
@ -192,8 +192,18 @@ func NewCarbon() Carbon {
|
||||
return Carbon{weekStartsAt: time.Sunday, loc: time.Local, lang: NewLanguage()}
|
||||
}
|
||||
|
||||
// CreateFromStdTime creates a Carbon instance from standard time.Time.
|
||||
// 从标准的 time.Time 创建 Carbon 实例
|
||||
func CreateFromStdTime(tt time.Time) Carbon {
|
||||
c := NewCarbon()
|
||||
c.time = tt
|
||||
c.loc = tt.Location()
|
||||
return c
|
||||
}
|
||||
|
||||
// FromStdTime converts standard time.Time to Carbon.
|
||||
// 将标准 time.Time 转换成 Carbon
|
||||
// Deprecated: It will be removed in the future, CreateFromStdTime is recommended.
|
||||
// 将标准 time.Time 转换成 Carbon,未来将移除,推荐使用 CreateFromStdTime
|
||||
func FromStdTime(tt time.Time) Carbon {
|
||||
c := NewCarbon()
|
||||
c.time = tt
|
||||
@ -207,13 +217,15 @@ func (c Carbon) ToStdTime() time.Time {
|
||||
return c.time.In(c.loc)
|
||||
}
|
||||
|
||||
// Time2Carbon converts standard time.Time to Carbon, will be removed in the future, recommended use FromStdTime
|
||||
// Time2Carbon converts standard time.Time to Carbon.
|
||||
// Deprecated: It will be removed in the future, FromStdTime is recommended.
|
||||
// 将标准 time.Time 转换成 Carbon,未来将移除,推荐使用 FromStdTime
|
||||
func Time2Carbon(tt time.Time) Carbon {
|
||||
return FromStdTime(tt)
|
||||
}
|
||||
|
||||
// Carbon2Time converts Carbon to standard time.Time, will be removed in the future, recommended use ToStdTime
|
||||
// Carbon2Time converts Carbon to standard time.Time.
|
||||
// Deprecated: It will be removed in the future, ToStdTime is recommended.
|
||||
// 将 Carbon 转换成标准 time.Time,未来将移除,推荐使用 ToStdTime
|
||||
func (c Carbon) Carbon2Time() time.Time {
|
||||
return c.ToStdTime()
|
||||
|
@ -7,6 +7,14 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestCarbon_CreateFromStdTime(t *testing.T) {
|
||||
loc, _ := time.LoadLocation("Asia/Shanghai")
|
||||
tt := time.Now().In(loc)
|
||||
expected := tt.Format(DateTimeLayout)
|
||||
actual := CreateFromStdTime(tt).ToDateTimeString()
|
||||
assert.Equal(t, expected, actual)
|
||||
}
|
||||
|
||||
func TestCarbon_FromStdTime(t *testing.T) {
|
||||
loc, _ := time.LoadLocation("Asia/Shanghai")
|
||||
tt := time.Now().In(loc)
|
||||
|
Loading…
Reference in New Issue
Block a user