add short datetime string parsing support for package gtime

This commit is contained in:
John Guo 2021-02-21 22:24:51 +08:00
parent 5adde275fc
commit 285ad36e7d
2 changed files with 7 additions and 1 deletions

View File

@ -45,7 +45,7 @@ const (
// "2018/10/31 - 16:38:46"
// "2018-02-09",
// "2018.02.09",
timeRegexPattern1 = `(\d{4}[-/\.]\d{2}[-/\.]\d{2})[:\sT-]*(\d{0,2}:{0,1}\d{0,2}:{0,1}\d{0,2}){0,1}\.{0,1}(\d{0,9})([\sZ]{0,1})([\+-]{0,1})([:\d]*)`
timeRegexPattern1 = `(\d{4}[-/\.]\d{1,2}[-/\.]\d{1,2})[:\sT-]*(\d{0,2}:{0,1}\d{0,2}:{0,1}\d{0,2}){0,1}\.{0,1}(\d{0,9})([\sZ]{0,1})([\+-]{0,1})([:\d]*)`
// Regular expression2(datetime separator supports '-', '/', '.').
// Eg:

View File

@ -42,6 +42,12 @@ func Test_New(t *testing.T) {
timeTemp := gtime.New(timeNow.TimestampMicro())
t.Assert(timeTemp.Time.Format("2006-01-02 15:04:05"), timeNow.Time.Format("2006-01-02 15:04:05"))
})
// short datetime.
gtest.C(t, func(t *gtest.T) {
timeTemp := gtime.New("2021-2-9 08:01:21")
t.Assert(timeTemp.Format("Y-m-d H:i:s"), "2021-02-09 08:01:21")
t.Assert(timeTemp.Time.Format("2006-01-02 15:04:05"), "2021-02-09 08:01:21")
})
}
func Test_Nil(t *testing.T) {