-
Notifications
You must be signed in to change notification settings - Fork 0
/
expiration.go
43 lines (35 loc) · 871 Bytes
/
expiration.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
package finance
import (
"strconv"
"time"
)
// Expiration is a date for options expiry.
type Expiration struct {
Month string `json:"m"`
Day string `json:"d"`
Year string `json:"y"`
Date time.Time `json:",omitempty"`
}
// NewExpiration builds an expiration object from month-day-year strings.
func NewExpiration(month, day, year string) *Expiration {
e := &Expiration{
Day: day,
Month: month,
Year: year,
}
e.setDate()
return e
}
// ExpirationFromDate builds an expiration object from a proper date.
func ExpirationFromDate(date time.Time) *Expiration {
return &Expiration{
Day: strconv.Itoa(date.Day()),
Month: strconv.Itoa(int(date.Month())),
Year: strconv.Itoa(date.Year()),
Date: date,
}
}
func (exp *Expiration) setDate() {
dString := exp.Month + "/" + exp.Day + "/" + exp.Year
exp.Date = parseDate(dString)
}