Skip to content

proposal: time: add time.Same, time.Past and time.Future const or enum for time.Compare #57177

@Delta456

Description

@Delta456

From commit, I think we should be using an enum or const for the return type of time.Compare instead of hardcoded values. It makes the code easier to understand and maintain. This can be seen below:

// src/time/time.go
package time

const (
  Same = 0
  Past = +1
  Furue = -1
)

// ...

Example code:

package main

import (
	"fmt"
	"time"
)

func main() {
	var (
		t1 = time.Now()
		t2 = t1.Add(time.Hour)
	)
	switch t1.Compare(t2) {
	case time.Same:
		fmt.Println("same")
	case time.Past:
		fmt.Println("past")
	case time.Future:
		fmt.Println("future")
	}
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions