github.com/vnforks/kid/v5@v5.22.1-0.20200408055009-b89d99c65676/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  	"github.com/stretchr/testify/assert"
    11  )
    12  
    13  var format = "2006-01-02 15:04:05.000000000"
    14  
    15  func TestMillisFromTime(t *testing.T) {
    16  	input, _ := time.Parse(format, "2015-01-01 12:34:00.000000000")
    17  	actual := MillisFromTime(input)
    18  	expected := int64(1420115640000)
    19  
    20  	assert.Equal(t, expected, actual)
    21  }
    22  
    23  func TestYesterday(t *testing.T) {
    24  	actual := Yesterday()
    25  	expected := time.Now().AddDate(0, 0, -1)
    26  
    27  	assert.Equal(t, expected.Year(), actual.Year())
    28  	assert.Equal(t, expected.Day(), actual.Day())
    29  	assert.Equal(t, expected.Month(), actual.Month())
    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  	assert.Equal(t, expected, actual)
    38  }
    39  
    40  func TestEndOfDay(t *testing.T) {
    41  	input, _ := time.Parse(format, "2015-01-01 12:34:00.000000000")
    42  	actual := EndOfDay(input)
    43  	expected, _ := time.Parse(format, "2015-01-01 23:59:59.999999999")
    44  
    45  	assert.Equal(t, expected, actual)
    46  }