histwin

package
v0.41.28 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package histwin carries the free plan's history window in a request context.

A free account (Rivolt Pro, Sprint 14) sees drives, charges and statements from the first day of the calendar month Months back (UTC): one cutoff for all three, so the window is the current month and the twelve before it. The window lives only in the context of a request that a windowed route's middleware has stamped: background jobs (the recorder, recaps, the statement email), repairs, the export and every other context carry none, so they see everything. The stores (drives, charges) narrow their reads when a window is present; nothing here deletes or hides a row from storage.

It has no dependencies so the stores can import it.

Index

Constants

View Source
const Months = 12

Months is how many calendar months before the current one the free window reaches back.

Variables

View Source
var ErrOutside = errors.New("histwin: outside the free history window")

ErrOutside is returned by a single-row read (a drive or charge by id) of a row older than the window. The row exists; the free plan does not show it.

Functions

func Allows

func Allows(ctx context.Context, t time.Time) bool

Allows reports whether a row that started at t is inside the window in ctx (always, when there is none).

func Clamp

func Clamp(ctx context.Context, from time.Time) time.Time

Clamp raises a client-supplied lower bound to the window: the result is never earlier than the window's start. A zero from means "no lower bound" and becomes the window's start.

func Since

func Since(ctx context.Context) (time.Time, bool)

Since is the window's oldest start time in ctx, if a window applies.

func With

func With(ctx context.Context, w W) context.Context

With returns ctx carrying w.

Types

type W

type W struct {
	// Since is the oldest start time a drive, charge or other timed row may have to be shown: the first instant of the calendar month
	// Months back (UTC). Clients show it as free_from.
	Since time.Time
	// MoneyFrom is the same cutoff for the Money statements (a statement month is whole, so it is a month start).
	MoneyFrom time.Time
	// Days is the window's length in days at the moment it was made (it changes through the month), for clients that show a number.
	Days int
}

W is a window. The zero value is no window.

func Free

func Free(now time.Time) W

Free is the free plan's window at now.

func From

func From(ctx context.Context) (W, bool)

From is the window in ctx, if any.

Jump to

Keyboard shortcuts

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