-
Notifications
You must be signed in to change notification settings - Fork 0
/
time_test.go
49 lines (38 loc) · 1.1 KB
/
time_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
package gossamer
import (
"bytes"
"encoding/json"
"github.com/stretchr/testify/assert"
"testing"
"time"
)
func TestTimePeriod(t *testing.T) {
var tp *TimePeriod
var err error
tp = NewDefaultTimePeriod()
assert.NotNil(t, tp)
assert.True(t, tp.From().IsZero())
assert.True(t, tp.To().IsZero())
tp.FromTime = time.Now()
assert.False(t, tp.From().IsZero())
tp.ToTime = time.Now()
assert.False(t, tp.To().IsZero())
tp = NewDefaultTimePeriod()
tp.FromTime, err = time.Parse(STD_TIME_FORMAT_INSTANT, "2014-03-01T13:00:00+08:00")
assert.Nil(t, err)
buf := new(bytes.Buffer)
encoder := json.NewEncoder(buf)
err = encoder.Encode(tp)
assert.Nil(t, err)
assert.Equal(t, string(buf.String()), "\"2014-03-01T13:00:00+08:00\"\n")
buf = new(bytes.Buffer)
encoder = json.NewEncoder(buf)
tp.ToTime, err = time.Parse(STD_TIME_FORMAT_INSTANT, "2015-03-01T13:00:00+08:00")
err = encoder.Encode(tp)
assert.Nil(t, err)
assert.Equal(t, string(buf.String()), "\"2014-03-01T13:00:00.00Z/2015-03-01T13:00:00.00Z\"\n")
}
func TestTimeInstant(t *testing.T) {
ti := NewTimeInstant(time.Now())
assert.NotNil(t, ti)
}