This repository has been archived by the owner on Jan 4, 2019. It is now read-only.
forked from abourget/slick
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathdates_test.go
67 lines (48 loc) · 1.77 KB
/
dates_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
59
60
61
62
63
64
65
66
67
package slick
import (
"testing"
"time"
"github.com/nlopes/slack"
"github.com/stretchr/testify/assert"
)
func TestShouldReturnTheNextWeekdayTime(t *testing.T) {
layout := "2006-01-02 15:04:05 -0700 MST"
now, _ := time.Parse(layout, "2018-10-23 12:00:00 +0000 UTC")
expectedTs, _ := time.Parse(layout, "2018-10-30 12:00:00 +0000 UTC")
wday, _ := NextWeekdayTime(now, time.Tuesday, 12, 0)
assert.NotZero(t, wday)
assert.Equal(t, wday, expectedTs)
}
func TestShouldReturnTheAskedWeekday(t *testing.T) {
layout := "2006-01-02 15:04:05 -0700 MST"
now, _ := time.Parse(layout, "2018-10-23 12:00:00 +0000 UTC")
wday, _ := NextWeekdayTime(now, time.Sunday, 12, 0)
assert.Equal(t, wday.Weekday(), time.Sunday)
}
func TestShouldReturnTheAskedHourAndMinute(t *testing.T) {
layout := "2006-01-02 15:04:05 -0700 MST"
now, _ := time.Parse(layout, "2018-10-23 12:00:00 +0000 UTC")
wday, _ := NextWeekdayTime(now, time.Sunday, 12, 0)
assert.Equal(t, wday.Hour(), 12)
assert.Equal(t, wday.Minute(), 0)
}
func TestShouldReturnTheDurationInNanoseconds(t *testing.T) {
layout := "2006-01-02 15:04:05 -0700 MST"
now, _ := time.Parse(layout, "2018-10-23 12:00:00 +0000 UTC")
expectedTs, _ := time.Parse(layout, "2018-10-30 12:00:00 +0000 UTC")
expectedDuration := expectedTs.Sub(now)
_, duration := NextWeekdayTime(now, time.Tuesday, 12, 0)
assert.Equal(t, duration, expectedDuration)
}
func TestShouldReturnTheUnixFromTimestamp(t *testing.T) {
slackTs := "1355517523.000005"
expectedTs := slack.JSONTime(1355517523)
unixTs := unixFromTimestamp(slackTs)
assert.Equal(t, expectedTs, unixTs)
}
func TestShouldReturnCeroIfGivenTimestampIsInvalid(t *testing.T) {
slackTs := "invalid"
expectedTs := slack.JSONTime(0)
unixTs := unixFromTimestamp(slackTs)
assert.Equal(t, expectedTs, unixTs)
}