-
-
Notifications
You must be signed in to change notification settings - Fork 239
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move deprecated methods to
deprecated.go
and deprecated_test.go
- Loading branch information
Showing
6 changed files
with
81 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// The methods in this file will be removed in the future | ||
|
||
package carbon | ||
|
||
import "time" | ||
|
||
// 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 { | ||
return CreateFromStdTime(tt) | ||
} | ||
|
||
// Time2Carbon converts standard time.Time to Carbon. | ||
// Deprecated: It will be removed in the future, CreateFromStdTime is recommended. | ||
// 将标准 time.Time 转换成 Carbon,未来将移除,推荐使用 CreateFromStdTime | ||
func Time2Carbon(tt time.Time) Carbon { | ||
return CreateFromStdTime(tt) | ||
} | ||
|
||
// 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() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package carbon | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestCarbon_FromStdTime(t *testing.T) { | ||
loc, _ := time.LoadLocation("Asia/Shanghai") | ||
tt := time.Now().In(loc) | ||
expected := tt.Format(DateTimeLayout) | ||
actual := FromStdTime(tt).ToDateTimeString() | ||
assert.Equal(t, expected, actual) | ||
} | ||
|
||
func TestCarbon_Time2Carbon(t *testing.T) { | ||
loc, _ := time.LoadLocation("Asia/Shanghai") | ||
tt := time.Now().In(loc) | ||
expected := tt.Format(DateTimeLayout) | ||
actual := Time2Carbon(tt).ToDateTimeString() | ||
assert.Equal(t, expected, actual) | ||
} | ||
|
||
func TestCarbon_Carbon2Time(t *testing.T) { | ||
expected := time.Now().Format(DateTimeLayout) | ||
actual := Now().Carbon2Time().Format(DateTimeLayout) | ||
assert.Equal(t, expected, actual) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters