1/* 2Copyright 2014 SAP SE 3 4Licensed under the Apache License, Version 2.0 (the "License"); 5you may not use this file except in compliance with the License. 6You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10Unless required by applicable law or agreed to in writing, software 11distributed under the License is distributed on an "AS IS" BASIS, 12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13See the License for the specific language governing permissions and 14limitations under the License. 15*/ 16 17package driver 18 19import ( 20 "database/sql/driver" 21 "time" 22) 23 24// NullTime represents an time.Time that may be null. 25// NullTime implements the Scanner interface so 26// it can be used as a scan destination, similar to NullString. 27type NullTime struct { 28 Time time.Time 29 Valid bool // Valid is true if Time is not NULL 30} 31 32// Scan implements the Scanner interface. 33func (n *NullTime) Scan(value interface{}) error { 34 n.Time, n.Valid = value.(time.Time) 35 return nil 36} 37 38// Value implements the driver Valuer interface. 39func (n NullTime) Value() (driver.Value, error) { 40 if !n.Valid { 41 return nil, nil 42 } 43 return n.Time, nil 44} 45