New Upstream Release - golang-github-bep-clock

Ready changes

Summary

Merged new upstream version: 0.5.0 (was: 0.3.0).

Resulting package

Built on 2022-12-14T05:17 (took 3m38s)

The resulting binary packages can be installed (if you have the apt repository enabled) by running one of:

apt install -t fresh-releases golang-github-bep-clock-dev

Lintian Result

Diff

diff --git a/README.md b/README.md
index 0d28648..6071631 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
-[![Tests on Linux, MacOS and Windows](https://github.com/bep/clock/workflows/Test/badge.svg)](https://github.com/bep/clock/actions?query=workflow:Test)
-[![Go Report Card](https://goreportcard.com/badge/github.com/bep/clock)](https://goreportcard.com/report/github.com/bep/clock)
-[![GoDoc](https://godoc.org/github.com/bep/clock?status.svg)](https://godoc.org/github.com/bep/clock)
+[![Tests on Linux, MacOS and Windows](https://github.com/bep/clocks/workflows/Test/badge.svg)](https://github.com/bep/clocks/actions?query=workflow:Test)
+[![Go Report Card](https://goreportcard.com/badge/github.com/bep/clocks)](https://goreportcard.com/report/github.com/bep/clocks)
+[![GoDoc](https://godoc.org/github.com/bep/clocks?status.svg)](https://godoc.org/github.com/bep/clocks)
 
 This package provides a _ticking clock_ that allows you to set the start time. It also provides a system clock, both implementing this interface:
 
diff --git a/clock.go b/clock.go
index 2b75f20..bb188ca 100644
--- a/clock.go
+++ b/clock.go
@@ -1,9 +1,13 @@
-package clock
+package clocks
 
 import (
 	"time"
 )
 
+// TimeCupFinalNorway1976 is the start time in UTC for the final match of the 1976 Norwegian Football Cup.
+// This is typically used in tests where you need a historic time with a special meaning.
+var TimeCupFinalNorway1976 = time.Date(1976, time.October, 24, 12, 15, 2, 127686412, time.UTC)
+
 // Clock provides the sub set of methods in time.Time that this package provides.
 type Clock interface {
 	Now() time.Time
@@ -33,7 +37,6 @@ func (c *clock) Now() time.Time {
 // Since returns the time elapsed since t.
 func (c *clock) Since(t time.Time) time.Duration {
 	return c.Now().Sub(t)
-
 }
 
 // Until returns the duration until t.
@@ -54,8 +57,7 @@ func System() Clock {
 	return goClock
 }
 
-type systemClock struct {
-}
+type systemClock struct{}
 
 func (c *systemClock) Now() time.Time {
 	return time.Now()
@@ -72,3 +74,30 @@ func (c *systemClock) Until(t time.Time) time.Duration {
 func (c *systemClock) Offset() time.Duration {
 	return 0
 }
+
+// Fixed returns a Clock that always returns the given time.
+func Fixed(t time.Time) Clock {
+	return &fixedClock{t: t}
+}
+
+// fixedClock is a Clock that always returns the same time.
+type fixedClock struct {
+	t time.Time
+}
+
+func (c *fixedClock) Now() time.Time {
+	return c.t
+}
+
+func (c *fixedClock) Since(t time.Time) time.Duration {
+	return c.Now().Sub(t)
+}
+
+func (c *fixedClock) Until(t time.Time) time.Duration {
+	return t.Sub(c.Now())
+}
+
+// Offset returns the offset of this clock relative to the system clock.
+func (c *fixedClock) Offset() time.Duration {
+	return time.Since(c.t)
+}
diff --git a/clock_test.go b/clock_test.go
index a3b952b..9dd5441 100644
--- a/clock_test.go
+++ b/clock_test.go
@@ -1,6 +1,7 @@
-package clock
+package clocks
 
 import (
+	"math"
 	"testing"
 	"time"
 
@@ -12,7 +13,9 @@ const timeLayout = "2006-01-02-15:04:05"
 
 var durationEq = qt.CmpEquals(
 	cmp.Comparer(func(x, y time.Duration) bool {
-		return x.Truncate(1*time.Second) == y.Truncate(1*time.Second)
+		xs := math.RoundToEven(float64(x) / float64(time.Second))
+		ys := math.RoundToEven(float64(y) / float64(time.Second))
+		return xs == ys
 	}),
 )
 
@@ -46,7 +49,6 @@ func TestClock(t *testing.T) {
 
 		clock := Start(time.Now().Add(5010 * time.Millisecond))
 		c.Assert(clock.Offset(), durationEq, time.Duration(5*time.Second))
-
 	})
 
 	c.Run("Since", func(c *qt.C) {
@@ -67,7 +69,6 @@ func TestClock(t *testing.T) {
 		then := clock.Now().Add(3010 * time.Millisecond)
 		c.Assert(clock.Until(then), durationEq, time.Duration(3*time.Second))
 	})
-
 }
 
 func TestSystemClock(t *testing.T) {
@@ -79,6 +80,21 @@ func TestSystemClock(t *testing.T) {
 	c.Assert(System().Since(time.Now().Add(-10*time.Hour)), durationEq, time.Since(time.Now().Add(-10*time.Hour)))
 	c.Assert(System().Until(time.Now().Add(10*time.Hour)), durationEq, time.Until(time.Now().Add(10*time.Hour)))
 	c.Assert(System().Offset(), qt.Equals, time.Duration(0))
+}
+
+func TestFixedClock(t *testing.T) {
+	t.Parallel()
+
+	c := qt.New(t)
+
+	fixed := Fixed(TimeCupFinalNorway1976)
+	fiveSecondsLater := Fixed(TimeCupFinalNorway1976.Add(5 * time.Second))
+	fiveSecondsBefore := Fixed(TimeCupFinalNorway1976.Add(-5 * time.Second))
+
+	c.Assert(toString(fixed.Now()), qt.Equals, toString(TimeCupFinalNorway1976))
+	c.Assert(fixed.Offset() > 0, qt.IsTrue)
+	c.Assert(fixed.Since(fiveSecondsBefore.Now()), durationEq, time.Duration(5*time.Second))
+	c.Assert(fixed.Until(fiveSecondsLater.Now()), durationEq, time.Duration(5*time.Second))
 
 }
 
diff --git a/debian/changelog b/debian/changelog
index a56f8ab..ddaaa5d 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+golang-github-bep-clock (0.5.0-1) UNRELEASED; urgency=low
+
+  * New upstream release.
+
+ -- Debian Janitor <janitor@jelmer.uk>  Wed, 14 Dec 2022 05:13:51 -0000
+
 golang-github-bep-clock (0.3.0-2) unstable; urgency=medium
 
   * Source-only upload for migration to testing
diff --git a/go.mod b/go.mod
index 8f1198f..07fc5e8 100644
--- a/go.mod
+++ b/go.mod
@@ -1,4 +1,4 @@
-module github.com/bep/clock
+module github.com/bep/clocks
 
 go 1.18
 

Debdiff

File lists identical (after any substitutions)

No differences were encountered in the control files

More details

Full run details