Files
gods/utils/comparator.go
Paul Chesnais 14f714261f Generics migration (#237)
* Generics migration

This attempts to migrate this library in the least invasive way by preserving as
much of the original API as possible. It does not change the tests in a
meaningful way nor does it attempt to upgrade any logic that can be simplified
or improved with generics. This is purely an API migration, and still requires a
lot of additional work to be fully ready.

* Fix a few broken tests around serialization

* Add v2 suffix

* Temporarily change mod name for testing

* Rename module to /v2
2024-01-06 16:06:17 -08:00

22 lines
429 B
Go

// Copyright (c) 2015, Emir Pasic. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package utils
import "time"
type Comparator[T any] func(x, y T) int
// TimeComparator provides a basic comparison on time.Time
func TimeComparator(a, b time.Time) int {
switch {
case a.After(b):
return 1
case a.Before(b):
return -1
default:
return 0
}
}