package pgtype

import (
	
	
	
	
	

	
)
Time represents the PostgreSQL time type. The PostgreSQL time is a time of day without time zone. Time is represented as the number of microseconds since midnight in the same way that PostgreSQL does. Other time and date types in pgtype can use time.Time as the underlying representation. However, pgtype.Time type cannot due to needing to handle 24:00:00. time.Time converts that to 00:00:00 on the following day.
type Time struct {
	Microseconds int64 // Number of microseconds since midnight
	Status       Status
}
Set converts src into a Time and stores in dst.
func ( *Time) ( interface{}) error {
	if  == nil {
		* = Time{Status: Null}
		return nil
	}

	if ,  := .(interface{ () interface{} });  {
		 := .()
		if  !=  {
			return .()
		}
	}

	switch value := .(type) {
	case time.Time:
		 := int64(.Hour())*microsecondsPerHour +
			int64(.Minute())*microsecondsPerMinute +
			int64(.Second())*microsecondsPerSecond +
			int64(.Nanosecond())/1000
		* = Time{Microseconds: , Status: Present}
	case *time.Time:
		if  == nil {
			* = Time{Status: Null}
		} else {
			return .(*)
		}
	default:
		if ,  := underlyingTimeType();  {
			return .()
		}
		return fmt.Errorf("cannot convert %v to Time", )
	}

	return nil
}

func ( Time) () interface{} {
	switch .Status {
	case Present:
		return .Microseconds
	case Null:
		return nil
	default:
		return .Status
	}
}

func ( *Time) ( interface{}) error {
	switch .Status {
	case Present:
		switch v := .(type) {
24:00:00 is max allowed time in PostgreSQL, but time.Time will normalize that to 00:00:00 the next day.
			var  int64 = 24*60*60*1000000 - 1
			if .Microseconds >  {
				return fmt.Errorf("%d microseconds cannot be represented as time.Time", .Microseconds)
			}

			 := .Microseconds
			 :=  / microsecondsPerHour
			 -=  * microsecondsPerHour
			 :=  / microsecondsPerMinute
			 -=  * microsecondsPerMinute
			 :=  / microsecondsPerSecond
			 -=  * microsecondsPerSecond
			 :=  * 1000
			* = time.Date(2000, 1, 1, int(), int(), int(), int(), time.UTC)
			return nil
		default:
			if ,  := GetAssignToDstType();  {
				return .()
			}
			return fmt.Errorf("unable to assign to %T", )
		}
	case Null:
		return NullAssignTo()
	}

	return fmt.Errorf("cannot decode %#v into %T", , )
}
DecodeText decodes from src into dst.
func ( *Time) ( *ConnInfo,  []byte) error {
	if  == nil {
		* = Time{Status: Null}
		return nil
	}

	 := string()

	if len() < 8 {
		return fmt.Errorf("cannot decode %v into Time", )
	}

	,  := strconv.ParseInt([0:2], 10, 64)
	if  != nil {
		return fmt.Errorf("cannot decode %v into Time", )
	}
	 :=  * microsecondsPerHour

	,  := strconv.ParseInt([3:5], 10, 64)
	if  != nil {
		return fmt.Errorf("cannot decode %v into Time", )
	}
	 +=  * microsecondsPerMinute

	,  := strconv.ParseInt([6:8], 10, 64)
	if  != nil {
		return fmt.Errorf("cannot decode %v into Time", )
	}
	 +=  * microsecondsPerSecond

	if len() > 9 {
		 := [9:]
		,  := strconv.ParseInt(, 10, 64)
		if  != nil {
			return fmt.Errorf("cannot decode %v into Time", )
		}

		for  := len();  < 6; ++ {
			 *= 10
		}

		 += 
	}

	* = Time{Microseconds: , Status: Present}

	return nil
}
DecodeBinary decodes from src into dst.
func ( *Time) ( *ConnInfo,  []byte) error {
	if  == nil {
		* = Time{Status: Null}
		return nil
	}

	if len() != 8 {
		return fmt.Errorf("invalid length for time: %v", len())
	}

	 := int64(binary.BigEndian.Uint64())
	* = Time{Microseconds: , Status: Present}

	return nil
}
EncodeText writes the text encoding of src into w.
func ( Time) ( *ConnInfo,  []byte) ([]byte, error) {
	switch .Status {
	case Null:
		return nil, nil
	case Undefined:
		return nil, errUndefined
	}

	 := .Microseconds
	 :=  / microsecondsPerHour
	 -=  * microsecondsPerHour
	 :=  / microsecondsPerMinute
	 -=  * microsecondsPerMinute
	 :=  / microsecondsPerSecond
	 -=  * microsecondsPerSecond

	 := fmt.Sprintf("%02d:%02d:%02d.%06d", , , , )

	return append(, ...), nil
}
EncodeBinary writes the binary encoding of src into w. If src.Time is not in the UTC time zone it returns an error.
func ( Time) ( *ConnInfo,  []byte) ([]byte, error) {
	switch .Status {
	case Null:
		return nil, nil
	case Undefined:
		return nil, errUndefined
	}

	return pgio.AppendInt64(, .Microseconds), nil
}
Scan implements the database/sql Scanner interface.
func ( *Time) ( interface{}) error {
	if  == nil {
		* = Time{Status: Null}
		return nil
	}

	switch src := .(type) {
	case string:
		return .DecodeText(nil, []byte())
	case []byte:
		 := make([]byte, len())
		copy(, )
		return .DecodeText(nil, )
	case time.Time:
		return .Set()
	}

	return fmt.Errorf("cannot scan %T", )
}
Value implements the database/sql/driver Valuer interface.
func ( Time) () (driver.Value, error) {
	return EncodeValueText()