• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

go-sql-driver / mysql / 3601392501

pending completion
3601392501

push

github

GitHub
update changelog for Version 1.7 (#1376)

2932 of 3584 relevant lines covered (81.81%)

1490385.18 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

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

9
package mysql
10

11
import (
12
        "database/sql"
13
        "database/sql/driver"
14
        "fmt"
15
        "time"
16
)
17

18
// NullTime represents a time.Time that may be NULL.
19
// NullTime implements the Scanner interface so
20
// it can be used as a scan destination:
21
//
22
//        var nt NullTime
23
//        err := db.QueryRow("SELECT time FROM foo WHERE id=?", id).Scan(&nt)
24
//        ...
25
//        if nt.Valid {
26
//           // use nt.Time
27
//        } else {
28
//           // NULL value
29
//        }
30
//
31
// # This NullTime implementation is not driver-specific
32
//
33
// Deprecated: NullTime doesn't honor the loc DSN parameter.
34
// NullTime.Scan interprets a time as UTC, not the loc DSN parameter.
35
// Use sql.NullTime instead.
36
type NullTime sql.NullTime
37

38
// Scan implements the Scanner interface.
39
// The value type must be time.Time or string / []byte (formatted time-string),
40
// otherwise Scan fails.
41
func (nt *NullTime) Scan(value interface{}) (err error) {
378✔
42
        if value == nil {
378✔
43
                nt.Time, nt.Valid = time.Time{}, false
×
44
                return
×
45
        }
×
46

47
        switch v := value.(type) {
378✔
48
        case time.Time:
81✔
49
                nt.Time, nt.Valid = v, true
81✔
50
                return
81✔
51
        case []byte:
108✔
52
                nt.Time, err = parseDateTime(v, time.UTC)
108✔
53
                nt.Valid = (err == nil)
108✔
54
                return
108✔
55
        case string:
162✔
56
                nt.Time, err = parseDateTime([]byte(v), time.UTC)
162✔
57
                nt.Valid = (err == nil)
162✔
58
                return
162✔
59
        }
60

61
        nt.Valid = false
27✔
62
        return fmt.Errorf("Can't convert %T to time.Time", value)
27✔
63
}
64

65
// Value implements the driver Valuer interface.
66
func (nt NullTime) Value() (driver.Value, error) {
×
67
        if !nt.Valid {
×
68
                return nil, nil
×
69
        }
×
70
        return nt.Time, nil
×
71
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc