arturwwl
24a672be3c
Some checks failed
test mariadb / test mariadb (push) Successful in 4m53s
test cockroach / test cockroach (push) Failing after 7m13s
test mysql / test mysql (push) Successful in 5m10s
test mssql / test mssql (push) Successful in 6m0s
test mysql8 / test mysql8 (push) Successful in 5m11s
test postgres / test postgres (push) Successful in 5m49s
test tidb / test tidb (push) Successful in 5m33s
test sqlite / unit test & test sqlite (push) Successful in 7m46s
resolves #2073 Co-authored-by: arturwwl <> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Reviewed-on: #2074 Co-authored-by: arturwwl <arturwwl@noreply.gitea.com> Co-committed-by: arturwwl <arturwwl@noreply.gitea.com>
42 lines
1.9 KiB
Go
42 lines
1.9 KiB
Go
// Copyright 2021 The Xorm Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package convert
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestString2Time(t *testing.T) {
|
|
expectedLoc, err := time.LoadLocation("Asia/Shanghai")
|
|
assert.NoError(t, err)
|
|
|
|
cases := map[string]time.Time{
|
|
"2021-08-10": time.Date(2021, 8, 10, 8, 0, 0, 0, expectedLoc),
|
|
"2021-07-11 10:44:00": time.Date(2021, 7, 11, 18, 44, 0, 0, expectedLoc),
|
|
"2021-07-11 10:44:00.999": time.Date(2021, 7, 11, 18, 44, 0, 999000000, expectedLoc),
|
|
"2021-07-11 10:44:00.999999": time.Date(2021, 7, 11, 18, 44, 0, 999999000, expectedLoc),
|
|
"2021-07-11 10:44:00.999999999": time.Date(2021, 7, 11, 18, 44, 0, 999999999, expectedLoc),
|
|
"2021-06-06T22:58:20+08:00": time.Date(2021, 6, 6, 22, 58, 20, 0, expectedLoc),
|
|
"2021-06-06T22:58:20.999+08:00": time.Date(2021, 6, 6, 22, 58, 20, 999000000, expectedLoc),
|
|
"2021-06-06T22:58:20.999999+08:00": time.Date(2021, 6, 6, 22, 58, 20, 999999000, expectedLoc),
|
|
"2021-06-06T22:58:20.999999999+08:00": time.Date(2021, 6, 6, 22, 58, 20, 999999999, expectedLoc),
|
|
"2021-08-10T10:33:04Z": time.Date(2021, 8, 10, 18, 33, 0o4, 0, expectedLoc),
|
|
"2021-08-10T10:33:04.999Z": time.Date(2021, 8, 10, 18, 33, 0o4, 999000000, expectedLoc),
|
|
"2021-08-10T10:33:04.999999Z": time.Date(2021, 8, 10, 18, 33, 0o4, 999999000, expectedLoc),
|
|
"2021-08-10T10:33:04.999999999Z": time.Date(2021, 8, 10, 18, 33, 0o4, 999999999, expectedLoc),
|
|
"10:22:33": time.Date(0, 1, 1, 18, 22, 33, 0, expectedLoc),
|
|
}
|
|
for layout, tm := range cases {
|
|
t.Run(layout, func(t *testing.T) {
|
|
target, err := String2Time(layout, time.UTC, expectedLoc)
|
|
assert.NoError(t, err)
|
|
assert.EqualValues(t, tm, *target)
|
|
})
|
|
}
|
|
}
|