This repository has been archived by the owner on Sep 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deprecate in favor of github.com/godogx/clocksteps
- Loading branch information
Showing
16 changed files
with
24 additions
and
713 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,99 +1,23 @@ | ||
package clockdog | ||
|
||
import ( | ||
"errors" | ||
"sync" | ||
"time" | ||
|
||
clock "github.com/nhatthm/go-clock" | ||
"github.com/godogx/clocksteps" | ||
) | ||
|
||
// ErrClockIsNotSet indicates that the clock must be set by either Clock.Set() or Clock.Freeze() before adding some | ||
// time.Duration into it. | ||
var ErrClockIsNotSet = errors.New("clock is not set") | ||
|
||
var _ clock.Clock = (*Clock)(nil) | ||
// | ||
// Deprecated: Use clocksteps.ErrClockIsNotSet instead. | ||
var ErrClockIsNotSet = clocksteps.ErrClockIsNotSet | ||
|
||
// Clock is a clock.Clock. | ||
type Clock struct { | ||
timestamp *time.Time | ||
mu sync.Mutex | ||
} | ||
|
||
// Now returns a fixed timestamp or time.Now(). | ||
func (c *Clock) Now() time.Time { | ||
c.mu.Lock() | ||
defer c.mu.Unlock() | ||
|
||
if c.timestamp == nil { | ||
return time.Now() | ||
} | ||
|
||
return *c.timestamp | ||
} | ||
|
||
// Set fixes the clock at a time. | ||
func (c *Clock) Set(t time.Time) { | ||
c.mu.Lock() | ||
defer c.mu.Unlock() | ||
|
||
c.timestamp = timestamp(t) | ||
} | ||
|
||
// Add adds time to the clock. | ||
func (c *Clock) Add(d time.Duration) error { | ||
c.mu.Lock() | ||
defer c.mu.Unlock() | ||
|
||
if c.timestamp == nil { | ||
return ErrClockIsNotSet | ||
} | ||
|
||
c.timestamp = timestamp(c.timestamp.Add(d)) | ||
|
||
return nil | ||
} | ||
|
||
// AddDate adds date to the clock. | ||
func (c *Clock) AddDate(years, months, days int) error { | ||
c.mu.Lock() | ||
defer c.mu.Unlock() | ||
|
||
if c.timestamp == nil { | ||
return ErrClockIsNotSet | ||
} | ||
|
||
c.timestamp = timestamp(c.timestamp.AddDate(years, months, days)) | ||
|
||
return nil | ||
} | ||
|
||
// Freeze freezes the clock. | ||
func (c *Clock) Freeze() { | ||
c.mu.Lock() | ||
defer c.mu.Unlock() | ||
|
||
c.timestamp = timestamp(time.Now()) | ||
} | ||
|
||
// Unfreeze unfreezes the clock. | ||
func (c *Clock) Unfreeze() { | ||
c.mu.Lock() | ||
defer c.mu.Unlock() | ||
|
||
c.timestamp = nil | ||
} | ||
|
||
// Clock provides clock.Clock. | ||
func (c *Clock) Clock() clock.Clock { | ||
return c | ||
} | ||
// | ||
// Deprecated: Use clocksteps.Clock instead. | ||
type Clock = clocksteps.Clock | ||
|
||
// New initiates a new Clock. | ||
// | ||
// Deprecated: Use clocksteps.New instead. | ||
func New() *Clock { | ||
return &Clock{} | ||
} | ||
|
||
func timestamp(t time.Time) *time.Time { | ||
return &t | ||
return clocksteps.New() | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
// Package clockdog provides a clock for tests with cucumber/godog. | ||
// | ||
// Deprecated: Use github.com/godogx/clocksteps instead. | ||
package clockdog |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.