<commit_before>package clock

import (
	"time"
)

// A replaceable clock interface. Alternative implementations can run faster than real time.
type Clock interface {
	Now() time.Time
	NewTimer(d time.Duration) *time.Timer
}

var clock Clock = NewClock()

type realClock struct {
}

func GetClock() Clock {
	return clock
}

func SetClock(c Clock) {
	clock = c
}

func NewClock() Clock {
	return &realClock{}
}

func (c *realClock) Now() time.Time {
	return time.Now()
}

func (c *realClock) NewTimer(d time.Duration) *time.Timer {
	return time.NewTimer(d)
}

type simulatedClock struct {
	epoch     time.Time
	epochDiff time.Duration
	speedup   int
}

const DEFAULT_EPOCH_DIFF = 86400 * 365 * 10

// Answer a clock in which real time after the epoch time is sped up by the specified amount.
func NewSimulatedClock(epoch time.Time, speedup int, epochDiff time.Duration) Clock {
	return &simulatedClock{
		epoch:     epoch,
		speedup:   speedup,
		epochDiff: epochDiff,
	}
}

func (c *simulatedClock) Now() time.Time {
	return c.simulatedTime(time.Now())
}

func (c *simulatedClock) simulatedTime(realTime time.Time) time.Time {
	return c.epoch.Add(realTime.Sub(c.epoch) * time.Duration(c.speedup)).Add(-c.epochDiff)
}

func (c *simulatedClock) NewTimer(d time.Duration) *time.Timer {
	t := time.NewTimer(d / time.Duration(c.speedup))
	ch := make(chan time.Time)
	pseudo := &time.Timer{
		C: ch,
	}
	go func() {
		t := <-t.C
		ch <- c.simulatedTime(t)
	}()
	return pseudo
}<commit_msg>Start sim clock at epoch<commit_after>package clock

import (
	"time"
)

// A replaceable clock interface. Alternative implementations can run faster than real time.
type Clock interface {
	Now() time.Time
	NewTimer(d time.Duration) *time.Timer
}

var clock Clock = NewClock()

type realClock struct {
}

func GetClock() Clock {
	return clock
}

func SetClock(c Clock) {
	clock = c
}

func NewClock() Clock {
	return &realClock{}
}

func (c *realClock) Now() time.Time {
	return time.Now()
}

func (c *realClock) NewTimer(d time.Duration) *time.Timer {
	return time.NewTimer(d)
}

type simulatedClock struct {
	realEpoch time.Time
	epoch     time.Time
	speedup   int
}

// Answer a clock in which real time after the epoch time is sped up by the specified amount.
func NewSimulatedClock(epoch time.Time, speedup int) Clock {
	return &simulatedClock{
		epoch:     epoch,
		speedup:   speedup,
		realEpoch: time.Now(),
	}
}

func (c *simulatedClock) Now() time.Time {
	return c.simulatedTime(time.Now())
}

func (c *simulatedClock) simulatedTime(realTime time.Time) time.Time {
	return c.epoch.Add(realTime.Sub(c.realEpoch) * time.Duration(c.speedup))
}

func (c *simulatedClock) NewTimer(d time.Duration) *time.Timer {
	t := time.NewTimer(d / time.Duration(c.speedup))
	ch := make(chan time.Time)
	pseudo := &time.Timer{
		C: ch,
	}
	go func() {
		t := <-t.C
		ch <- c.simulatedTime(t)
	}()
	return pseudo
}
{'fraction_non_alphanumeric': 0.12430747922437674, 'fraction_numerical': 0.0034626038781163434, 'mean_word_length': 3.921635434412266, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '862145', 'n_tokens_mistral': 1068, 'n_tokens_neox': 1036, 'n_words': 295}