mirror of
https://gitee.com/johng/gf.git
synced 2024-12-02 12:17:53 +08:00
improve package gtime
This commit is contained in:
parent
43ecfc7484
commit
3485ba2a5d
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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 == "" {
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user