Skip to content

Instantly share code, notes, and snippets.

@meysampg
Created July 27, 2020 14:12
Show Gist options
  • Save meysampg/fce78508943063ab661a35a6cb98538f to your computer and use it in GitHub Desktop.
Save meysampg/fce78508943063ab661a35a6cb98538f to your computer and use it in GitHub Desktop.
More readable to compare times
import (
"time"
"github.com/stretchr/testify/assert"
)
func compareTimes(t assert.TestingT, expected, actual [2]time.Time) {
assertTruefTime(t, "start", expected[0], actual[0])
assertTruefTime(t, "end", expected[1], actual[1])
}
func assertTruefTime(t assert.TestingT, when string, expected, actual time.Time) {
assert.Truef(t, expected.Equal(actual), "%s: expected[%s] != actual[%s]", when, expected, actual)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment