improve package gtime

This commit is contained in:
John 2020-11-26 22:40:55 +08:00
parent 43ecfc7484
commit 3485ba2a5d
5 changed files with 8 additions and 5 deletions

View File

@ -158,7 +158,7 @@ type DB interface {
// ===========================================================================
mappingAndFilterData(schema, table string, data map[string]interface{}, filter bool) (map[string]interface{}, error)
convertValue(fieldValue interface{}, fieldType string) interface{}
convertDatabaseValueToLocalValue(fieldValue interface{}, fieldType string) interface{}
rowsToResult(rows *sql.Rows) (Result, error)
}

View File

@ -785,7 +785,7 @@ func (c *Core) rowsToResult(rows *sql.Rows) (Result, error) {
if value == nil {
row[columnNames[i]] = gvar.New(nil)
} else {
row[columnNames[i]] = gvar.New(c.DB.convertValue(value, columnTypes[i]))
row[columnNames[i]] = gvar.New(c.DB.convertDatabaseValueToLocalValue(value, columnTypes[i]))
}
}
records = append(records, row)

View File

@ -22,9 +22,9 @@ import (
"github.com/gogf/gf/util/gconv"
)
// convertValue automatically checks and converts field value from database type
// convertDatabaseValueToLocalValue automatically checks and converts field value from database type
// to golang variable type.
func (c *Core) convertValue(fieldValue interface{}, fieldType string) interface{} {
func (c *Core) convertDatabaseValueToLocalValue(fieldValue interface{}, fieldType string) interface{} {
// If there's no type retrieved, it returns the <fieldValue> directly
// to use its original data type, as <fieldValue> is type of interface{}.
if fieldType == "" {

View File

@ -333,7 +333,6 @@ func StrToTime(str string, format ...string) (*Time, error) {
if year <= 0 {
return nil, errors.New("invalid time string:" + str)
}
// It finally converts all time to UTC time zone.
return NewFromTime(time.Date(year, time.Month(month), day, hour, min, sec, nsec, local)), nil
}

View File

@ -31,6 +31,10 @@ func New(param ...interface{}) *Time {
return NewFromTime(r)
case *time.Time:
return NewFromTime(*r)
case Time:
return &r
case *Time:
return r
case string:
return NewFromStr(r)
case []byte: