~mendelmaleh/pfin

ref: parallel pfin/parser/util/date.go -rw-r--r-- 521 bytes
95ffe938Mendel E Parallelize directory parsing 6 months ago
                                                                                
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
package util

import "time"

// DateISO implements the encoding.TextUnmarshaler interface to unmarshal from an ISO8601 date
type DateISO struct {
	time.Time
}

func (d *DateISO) UnmarshalText(data []byte) error {
	t, err := time.Parse("2006-01-02", string(data))
	if err != nil {
		return err
	}

	d.Time = t
	return nil
}

type DateUS struct {
	time.Time
}

func (d *DateUS) UnmarshalText(data []byte) error {
	t, err := time.Parse("01/02/2006", string(data))
	if err != nil {
		return err
	}

	d.Time = t
	return nil
}