timex

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 12, 2026 License: MIT Imports: 1 Imported by: 0

README

timex 包 Package

timex 提供可注入的 Clock 契约、真实时钟、固定时钟和测试用 fake 时钟。

Use FixedClock or FakeClock in deterministic tests instead of reading wall clock time directly.

Documentation

Overview

Package timex 提供可注入时钟和确定性假时钟。

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Clock

type Clock interface{ Now() time.Time }

Clock provides injectable time access.

type FakeClock

type FakeClock struct {
	// contains filtered or unexported fields
}

FakeClock is a deterministic mutable clock for tests.

func NewFakeClock

func NewFakeClock(now time.Time) *FakeClock

func (*FakeClock) Advance

func (c *FakeClock) Advance(d time.Duration)

func (*FakeClock) Now

func (c *FakeClock) Now() time.Time

type FixedClock

type FixedClock struct {
	// contains filtered or unexported fields
}

FixedClock always returns the configured time.

func NewFixedClock

func NewFixedClock(now time.Time) FixedClock
Example
package main

import (
	"time"

	"github.com/ZoneCNH/kernel/timex"
)

func main() {
	fixed := time.Date(2026, 6, 1, 0, 0, 0, 0, time.UTC)
	_ = timex.NewFixedClock(fixed).Now()
}

func (FixedClock) Now

func (c FixedClock) Now() time.Time

type RealClock

type RealClock struct{}

RealClock reads the system clock.

func NewRealClock

func NewRealClock() RealClock

func (RealClock) Now

func (RealClock) Now() time.Time

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL