package utils

import (
	"context"
	"time"
)

type timestampKeyTp string

const (
	timestampCtxKey timestampKeyTp = "timestamp_key"
)

func InjectTimestampIntoCtx(ctx context.Context, t time.Time) context.Context {
	return context.WithValue(ctx, timestampCtxKey, t)
}

func GetTimestampFromContext(ctx context.Context) (time.Time, bool) {
	val := ctx.Value(timestampCtxKey)
	t, ok := val.(time.Time)
	if ok {
		return t, true
	} else {
		return time.Now(), false
	}
}
