github.com/acoshift/pgsql@v0.15.3/time.go (about)

     1  package pgsql
     2  
     3  import (
     4  	"database/sql"
     5  	"database/sql/driver"
     6  	"time"
     7  )
     8  
     9  // Time is the time.Time but can scan null into empty
    10  type Time struct {
    11  	time.Time
    12  }
    13  
    14  // Scan implements Scanner interface
    15  func (t *Time) Scan(src any) error {
    16  	t.Time, _ = src.(time.Time)
    17  	return nil
    18  }
    19  
    20  // Value implements Valuer interface
    21  func (t Time) Value() (driver.Value, error) {
    22  	if t.IsZero() {
    23  		return nil, nil
    24  	}
    25  	return t.Time, nil
    26  }
    27  
    28  // NullTime likes Time but wrap time.Time with scanner
    29  func NullTime(t *time.Time) interface {
    30  	driver.Valuer
    31  	sql.Scanner
    32  } {
    33  	return Null(t)
    34  }