github.com/gogf/gf/v2@v2.7.4/os/gtime/gtime_sql.go (about)

     1  package gtime
     2  
     3  import (
     4  	"database/sql/driver"
     5  )
     6  
     7  // Scan implements interface used by Scan in package database/sql for Scanning value
     8  // from database to local golang variable.
     9  func (t *Time) Scan(value interface{}) error {
    10  	if t == nil {
    11  		return nil
    12  	}
    13  	newTime := New(value)
    14  	*t = *newTime
    15  	return nil
    16  }
    17  
    18  // Value is the interface providing the Value method for package database/sql/driver
    19  // for retrieving value from golang variable to database.
    20  func (t *Time) Value() (driver.Value, error) {
    21  	if t == nil {
    22  		return nil, nil
    23  	}
    24  	if t.IsZero() {
    25  		return nil, nil
    26  	}
    27  
    28  	if t.Year() == 0 {
    29  		// Only time.
    30  		return t.Format("15:04:05"), nil
    31  	}
    32  
    33  	return t.Time, nil
    34  }