Advertisement
Guest User

Untitled

a guest
Sep 19th, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4. "fmt"
  5. "time"
  6. )
  7.  
  8. type Date string // xxx:
  9.  
  10. type NowFunc func() time.Time
  11.  
  12. func (f NowFunc) Now() time.Time {
  13. return f()
  14. }
  15.  
  16. func (f NowFunc) Today() Date {
  17. return Date(f().Format("2006/01/02"))
  18. }
  19.  
  20. type Clock interface {
  21. Now() time.Time
  22. Today() Date
  23. }
  24.  
  25. func use(clock Clock) {
  26. fmt.Println("use", clock.Today())
  27. }
  28.  
  29. func main() {
  30. use(NowFunc(func() time.Time { return time.Now() }))
  31.  
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement