Skip to content

Commit

Permalink
Move CreateFromStdTime method from carbon. go to creator. go
Browse files Browse the repository at this point in the history
  • Loading branch information
gouguoyin committed Sep 4, 2023
1 parent 5edc5a7 commit ff66ccd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
16 changes: 2 additions & 14 deletions carbon.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,23 +196,11 @@ func NewCarbon() Carbon {
return c
}

// 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.
// 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
c.loc = tt.Location()
return c
return CreateFromStdTime(tt)
}

// ToStdTime converts Carbon to standard time.Time.
Expand All @@ -225,7 +213,7 @@ func (c Carbon) ToStdTime() time.Time {
// Deprecated: It will be removed in the future, CreateFromStdTime is recommended.
// 将标准 time.Time 转换成 Carbon,未来将移除,推荐使用 CreateFromStdTime
func Time2Carbon(tt time.Time) Carbon {
return FromStdTime(tt)
return CreateFromStdTime(tt)
}

// Carbon2Time converts Carbon to standard time.Time.
Expand Down
9 changes: 9 additions & 0 deletions creator.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ import (
"time"
)

// 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
}

// CreateFromTimestamp creates a Carbon instance from a given timestamp with second.
// 从给定的秒级时间戳创建 Carbon 实例
func (c Carbon) CreateFromTimestamp(timestamp int64, timezone ...string) Carbon {
Expand Down

0 comments on commit ff66ccd

Please sign in to comment.