github.com/blend/go-sdk@v1.20220411.3/timeutil/beginning_of_month_test.go (about) 1 /* 2 3 Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 6 */ 7 8 package timeutil 9 10 import ( 11 "fmt" 12 "testing" 13 "time" 14 15 "github.com/blend/go-sdk/assert" 16 ) 17 18 func TestBeginningOfMonth(t *testing.T) { 19 assert := assert.New(t) 20 21 testCases := [...]struct { 22 Input time.Time 23 Expected time.Time 24 }{ 25 {Input: time.Date(2019, 9, 9, 17, 59, 44, 0, time.UTC), Expected: time.Date(2019, 9, 1, 0, 0, 0, 0, time.UTC)}, 26 {Input: time.Date(2019, 9, 1, 0, 0, 0, 0, time.UTC), Expected: time.Date(2019, 9, 1, 0, 0, 0, 0, time.UTC)}, 27 {Input: time.Date(2019, 9, 30, 23, 59, 59, 0, time.UTC), Expected: time.Date(2019, 9, 1, 0, 0, 0, 0, time.UTC)}, 28 } 29 30 for _, tc := range testCases { 31 assert.InTimeDelta( 32 tc.Expected, 33 BeginningOfMonth(tc.Input), 34 time.Second, 35 fmt.Sprintf("input: %v expected: %v", tc.Input, tc.Expected), 36 ) 37 } 38 }