Skip to content

proposal: time: add Compare #62642

@ianlancetaylor

Description

@ianlancetaylor

We have a method time.Time.Compare, but we don't have a plain time.Compare function. The latter would be useful as an argument to functions like slices.SortFunc or slices.BinarySearchFunc. I propose

// Compare returns an integer comparing two times.
// If a is before b, it returns -1;
// if a is after b, it returns +1; if they're the same, it returns 0.
func Compare(a, b time.Time) int {
	return a.Compare(b)
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions