forked from tkrajina/gpxgo
/
nullable_time.go
50 lines (41 loc) · 1 KB
/
nullable_time.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright 2013, 2014 Peter Vasil, Tomo Krajina. All
// rights reserved. Use of this source code is governed
// by a BSD-style license that can be found in the
// LICENSE file.
package gpx
import "time"
//NullableTime implements a nullable time
type NullableTime struct {
data time.Time
notNull bool
}
//Null checks if value is null
func (n *NullableTime) Null() bool {
return !n.notNull
}
//NotNull checks if value is not null
func (n *NullableTime) NotNull() bool {
return n.notNull
}
//Value returns the value
func (n *NullableTime) Value() time.Time {
return n.data
}
//SetValue sets the value
func (n *NullableTime) SetValue(data time.Time) {
n.data = data
n.notNull = true
}
//SetNull sets the value to null
func (n *NullableTime) SetNull() {
var defaultValue time.Time
n.data = defaultValue
n.notNull = false
}
//NewNullableTime creates a new NullableTime
func NewNullableTime(data time.Time) *NullableTime {
result := new(NullableTime)
result.data = data
result.notNull = true
return result
}