-
Notifications
You must be signed in to change notification settings - Fork 1
/
date_test.go
58 lines (47 loc) · 1.83 KB
/
date_test.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
package journalskill_test
import (
"time"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/petergtz/alexa-journal"
"github.com/rickb777/date"
)
var _ = Describe("Date", func() {
It("works", func() {
dayDate, monthDate, dateType := DateFrom("2019-01-XX")
Expect(dateType).To(BeEquivalentTo(MonthDate))
Expect(dayDate.IsZero()).To(BeTrue())
Expect(monthDate).To(Equal("2019-01"))
dayDate, monthDate, dateType = DateFrom("2019-01")
Expect(dateType).To(BeEquivalentTo(MonthDate))
Expect(dayDate.IsZero()).To(BeTrue())
Expect(monthDate).To(Equal("2019-01"))
dayDate, monthDate, dateType = DateFrom("2019-01-01")
Expect(dateType).To(BeEquivalentTo(DayDate))
Expect(dayDate).To(Equal(date.New(2019, time.January, 1)))
Expect(monthDate).To(BeEmpty())
dayDate, monthDate, dateType = DateFrom("")
Expect(dateType).To(BeEquivalentTo(Invalid))
Expect(dayDate.IsZero()).To(BeTrue())
Expect(monthDate).To(BeEmpty())
dayDate, monthDate, dateType = DateFrom("2017-XX-XX")
Expect(dateType).To(BeEquivalentTo(YearDate))
Expect(dayDate.IsZero()).To(BeTrue())
Expect(monthDate).To(BeEmpty())
dayDate, monthDate, dateType = DateFrom("XXXX-XX-27")
Expect(dateType).To(BeEquivalentTo(DayDate))
Expect(dayDate.Day()).To(Equal(27))
Expect(dayDate.Month()).To(Equal(date.Today().Month()))
Expect(dayDate.Year()).To(Equal(date.Today().Year()))
Expect(monthDate).To(BeEmpty())
dayDate, monthDate, dateType = DateFrom("XX19-12-08")
Expect(dateType).To(BeEquivalentTo(DayDate))
Expect(dayDate).To(Equal(date.New(2019, time.December, 8)))
Expect(monthDate).To(BeEmpty())
dayDate, monthDate, dateType = DateFrom("XXXX-XX-02")
Expect(dateType).To(BeEquivalentTo(DayDate))
today := time.Now()
Expect(dayDate).To(Equal(date.New(today.Year(), today.Month(), 2)))
Expect(monthDate).To(BeEmpty())
})
})