// Go MySQL Driver - A MySQL-Driver for Go's database/sql package
//
// Copyright 2013 The Go-MySQL-Driver Authors. All rights reserved.
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at http://mozilla.org/MPL/2.0/.

package mysql

import (
	
	
	
	
)

// NullTime represents a time.Time that may be NULL.
// NullTime implements the Scanner interface so
// it can be used as a scan destination:
//
//	var nt NullTime
//	err := db.QueryRow("SELECT time FROM foo WHERE id=?", id).Scan(&nt)
//	...
//	if nt.Valid {
//	   // use nt.Time
//	} else {
//	   // NULL value
//	}
//
// # This NullTime implementation is not driver-specific
//
// Deprecated: NullTime doesn't honor the loc DSN parameter.
// NullTime.Scan interprets a time as UTC, not the loc DSN parameter.
// Use sql.NullTime instead.
type NullTime sql.NullTime

// Scan implements the Scanner interface.
// The value type must be time.Time or string / []byte (formatted time-string),
// otherwise Scan fails.
func ( *NullTime) ( interface{}) ( error) {
	if  == nil {
		.Time, .Valid = time.Time{}, false
		return
	}

	switch v := .(type) {
	case time.Time:
		.Time, .Valid = , true
		return
	case []byte:
		.Time,  = parseDateTime(, time.UTC)
		.Valid = ( == nil)
		return
	case string:
		.Time,  = parseDateTime([]byte(), time.UTC)
		.Valid = ( == nil)
		return
	}

	.Valid = false
	return fmt.Errorf("Can't convert %T to time.Time", )
}

// Value implements the driver Valuer interface.
func ( NullTime) () (driver.Value, error) {
	if !.Valid {
		return nil, nil
	}
	return .Time, nil
}