-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtype.go
77 lines (59 loc) · 1.55 KB
/
type.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package equifax
import (
"encoding/xml"
"time"
)
const timeEquifaxFormat = "02.01.2006 15:04:05"
const dateEquifaxFormat = "02.01.2006"
const strEmpty = "EMPTY"
const Null = "NULL"
var emptyDateDefault = time.Date(1900, 1, 1, 0, 0, 0, 0, time.Local)
type EmptyString string
func (t EmptyString) getValue() string {
if t == "" {
return strEmpty
}
return (string)(t)
}
func (t EmptyString) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
e.EncodeElement(t.getValue(), start)
return nil
}
func (t EmptyString) MarshalCSV() (string, error) {
return t.getValue(), nil
}
type Time struct {
time.Time
}
func (et *Time) getValue() string {
return et.Format(timeEquifaxFormat)
}
func (et *Time) MarshalCSV() (string, error) {
return et.getValue(), nil
}
func (et *Time) MarshalXMLAttr(name xml.Name) (xml.Attr, error) {
return xml.Attr{Name: name, Value: et.getValue()}, nil
}
func (et *Time) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
e.EncodeElement(et.getValue(), start)
return nil
}
type Date struct {
time.Time
}
func (et *Date) getValue() string {
if et.IsZero() {
return ""
}
return et.Format(dateEquifaxFormat)
}
func (et *Date) MarshalCSV() (string, error) {
return et.getValue(), nil
}
func (et *Date) MarshalXMLAttr(name xml.Name) (xml.Attr, error) {
return xml.Attr{Name: name, Value: et.getValue()}, nil
}
func (et *Date) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
e.EncodeElement(et.getValue(), start)
return nil
}