github.com/keys-pub/mattermost-server@v4.10.10+incompatible/utils/time_test.go (about)

     1  // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
     2  // See License.txt for license information.
     3  
     4  package utils
     5  
     6  import (
     7  	"testing"
     8  	"time"
     9  )
    10  
    11  var format = "2006-01-02 15:04:05.000000000"
    12  
    13  func TestMillisFromTime(t *testing.T) {
    14  	input, _ := time.Parse(format, "2015-01-01 12:34:00.000000000")
    15  	actual := MillisFromTime(input)
    16  	expected := int64(1420115640000)
    17  
    18  	if actual != expected {
    19  		t.Fatalf("TestMillisFromTime failed, %v=%v", expected, actual)
    20  	}
    21  }
    22  
    23  func TestYesterday(t *testing.T) {
    24  	actual := Yesterday()
    25  	expected := time.Now().AddDate(0, 0, -1)
    26  
    27  	if actual.Year() != expected.Year() || actual.Day() != expected.Day() || actual.Month() != expected.Month() {
    28  		t.Fatalf("TestYesterday failed, %v=%v", expected, actual)
    29  	}
    30  }
    31  
    32  func TestStartOfDay(t *testing.T) {
    33  	input, _ := time.Parse(format, "2015-01-01 12:34:00.000000000")
    34  	actual := StartOfDay(input)
    35  	expected, _ := time.Parse(format, "2015-01-01 00:00:00.000000000")
    36  
    37  	if actual != expected {
    38  		t.Fatalf("TestStartOfDay failed, %v=%v", expected, actual)
    39  	}
    40  }
    41  
    42  func TestEndOfDay(t *testing.T) {
    43  	input, _ := time.Parse(format, "2015-01-01 12:34:00.000000000")
    44  	actual := EndOfDay(input)
    45  	expected, _ := time.Parse(format, "2015-01-01 23:59:59.999999999")
    46  
    47  	if actual != expected {
    48  		t.Fatalf("TestEndOfDay failed, %v=%v", expected, actual)
    49  	}
    50  }