dnote/pkg/clock/clock.go
Sung Won Cho e84e8ed2f3
Allow to rename books (#239)
* Allow to rename books

* Avoid mutating the flag variable

* Validate book name upon edit

* Write integration test

* Add missing licenses

* Mark book as dirty upon renaming so it can be synced

* Remove TODO that is no longer needed
2019-08-01 09:21:24 +10:00

66 lines
1.6 KiB
Go

/* Copyright (C) 2019 Monomax Software Pty Ltd
*
* This file is part of Dnote CLI.
*
* Dnote CLI is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Dnote CLI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Dnote CLI. If not, see <https://www.gnu.org/licenses/>.
*/
// Package clock provides an abstract layer over the standard time package
package clock
import (
"time"
)
//TODO: use mutex to avoid race
// Clock is an interface to the standard library time.
// It is used to implement a real or a mock clock. The latter is
// used in tests.
type Clock interface {
Now() time.Time
}
type clock struct{}
func (c *clock) Now() time.Time {
return time.Now()
}
// Mock is a mock instance of clock
type Mock struct {
currentTime time.Time
}
// SetNow sets the current time for the mock clock
func (c *Mock) SetNow(t time.Time) {
c.currentTime = t
}
// Now returns the current time
func (c *Mock) Now() time.Time {
return c.currentTime
}
// New returns an instance of a real clock
func New() Clock {
return &clock{}
}
// NewMock returns an instance of a mock clock
func NewMock() *Mock {
return &Mock{
currentTime: time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC),
}
}