Documentation
¶
Overview ¶
Package period holds the subscription module's calendar rules: the time units that size a subscription term and the traffic reset cycles of a plan. It is the one place these rules live; the calendar reset, renewals, the refund quote and the owner's next-reset display all ask it.
A Calendar evaluates the rules in one time zone whatever zone a time value carries (a value read from the database comes in the driver's zone), so "the 15th" is the same day for every caller. Production code uses App(), the application zone of pkg/timeutil.
Index ¶
- Variables
- type Calendar
- func (c Calendar) CycleAt(cycle Cycle, start, now time.Time) (from, to time.Time, ok bool)
- func (c Calendar) DayStart(t time.Time) time.Time
- func (c Calendar) LastReset(cycle Cycle, start, at time.Time) (last time.Time, ok bool)
- func (c Calendar) Location() *time.Location
- func (c Calendar) NextReset(cycle Cycle, start, now time.Time) (next time.Time, ok bool)
- func (c Calendar) ResetBetween(cycle Cycle, start, from, to time.Time) bool
- func (c Calendar) ResetsOn(cycle Cycle, start, day time.Time) bool
- func (c Calendar) TermEnd(unit Unit, quantity int64, start time.Time) (time.Time, error)
- type Cycle
- type Unit
Constants ¶
This section is empty.
Variables ¶
var ErrUnknownUnit = errors.New("unknown subscription time unit")
ErrUnknownUnit rejects a time unit no rule knows. A term computed from one used to end where it started: a subscription expired on arrival.
Functions ¶
This section is empty.
Types ¶
type Calendar ¶
type Calendar struct {
// contains filtered or unexported fields
}
Calendar evaluates the rules in one time zone.
func (Calendar) CycleAt ¶
CycleAt returns the reset cycle containing now: from the last reset at or before now up to the next one. ok is false when the cycle never resets.
func (Calendar) LastReset ¶
LastReset returns the most recent reset of cycle at or before at, at the start of its day, for a subscription that started at start. ok is false when the cycle never resets. It is the reset a subscription is owed when no run has reset it for that day yet.
func (Calendar) NextReset ¶
NextReset returns the first reset of cycle after now, at the start of its day, for a subscription that started at start. ok is false when the cycle never resets.
func (Calendar) ResetBetween ¶
ResetBetween reports whether cycle has a reset day on any date from from's day through to's day, both included.
func (Calendar) ResetsOn ¶
ResetsOn reports whether day, any instant of it, is a reset day of cycle for a subscription that started at start.
type Cycle ¶
type Cycle int64
Cycle is a plan's calendar traffic reset rule, its reset_cycle.
const ( // CycleNone has no calendar reset: the traffic quota lasts the term. CycleNone Cycle = 0 // CycleFirstOfMonth resets on the 1st of every month. CycleFirstOfMonth Cycle = 1 // CycleMonthly resets every month on the start day, or on the month's // last day when the month is shorter. CycleMonthly Cycle = 2 // CycleYearly resets every year on the start date; a Feb 29 start resets // on Feb 28 in common years. CycleYearly Cycle = 3 )