summaryrefslogtreecommitdiffstats
path: root/utils/time_test.go
blob: 7d65046bf9849af1b2bbff9bc95e2a7f0cb92e6b (plain)
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
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.

package utils

import (
	"testing"
	"time"
)

var format = "2006-01-02 15:04:05.000000000"

func TestMillisFromTime(t *testing.T) {
	input, _ := time.Parse(format, "2015-01-01 12:34:00.000000000")
	actual := MillisFromTime(input)
	expected := int64(1420115640000)

	if actual != expected {
		t.Fatalf("TestMillisFromTime failed, %v=%v", expected, actual)
	}
}

func TestYesterday(t *testing.T) {
	actual := Yesterday()
	expected := time.Now().AddDate(0, 0, -1)

	if actual.Year() != expected.Year() || actual.Day() != expected.Day() || actual.Month() != expected.Month() {
		t.Fatalf("TestYesterday failed, %v=%v", expected, actual)
	}
}

func TestStartOfDay(t *testing.T) {
	input, _ := time.Parse(format, "2015-01-01 12:34:00.000000000")
	actual := StartOfDay(input)
	expected, _ := time.Parse(format, "2015-01-01 00:00:00.000000000")

	if actual != expected {
		t.Fatalf("TestStartOfDay failed, %v=%v", expected, actual)
	}
}

func TestEndOfDay(t *testing.T) {
	input, _ := time.Parse(format, "2015-01-01 12:34:00.000000000")
	actual := EndOfDay(input)
	expected, _ := time.Parse(format, "2015-01-01 23:59:59.999999999")

	if actual != expected {
		t.Fatalf("TestEndOfDay failed, %v=%v", expected, actual)
	}
}