1// SPDX-FileCopyrightText: Amolith <amolith@secluded.site>
2//
3// SPDX-License-Identifier: AGPL-3.0-or-later
4
5package testutil
6
7import (
8 "time"
9)
10
11// SequenceClock returns the supplied times in order, repeating the final entry
12// when no more values remain.
13type SequenceClock struct {
14 Times []time.Time
15 index int
16}
17
18// Now implements timeutil.Clock semantics.
19func (c *SequenceClock) Now() time.Time {
20 if len(c.Times) == 0 {
21 return time.Now().UTC()
22 }
23 if c.index >= len(c.Times) {
24 return c.Times[len(c.Times)-1]
25 }
26 t := c.Times[c.index]
27 if c.index < len(c.Times)-1 {
28 c.index++
29 }
30 return t
31}