Table of Contents

Class WeeklySchedule

Namespace
Trellis.Primitives
Assembly
Trellis.Primitives.dll

Immutable weekly availability in an IANA time zone, evaluated against local wall-clock time.

public sealed class WeeklySchedule : ValueObject, IComparable<ValueObject>, IComparable, IEquatable<ValueObject>
Inheritance
WeeklySchedule
Implements
Inherited Members
Extension Methods

Remarks

Empty means always closed. Periods are copied and sorted Sunday-first; overlapping periods are rejected, but touching periods are retained. Equality includes the resolved time-zone identifier and sorted period components, not equivalence of covered instants or zone aliases. Use a DTO for JSON and persistence; this type has no direct EF materialization contract.

Properties

Periods

Gets a read-only snapshot of periods sorted by local start within the week.

public IReadOnlyList<WeeklyPeriod> Periods { get; }

Property Value

IReadOnlyList<WeeklyPeriod>

TimeZoneId

Gets the resolved IANA identifier. Equivalent aliases are not unified.

public string TimeZoneId { get; }

Property Value

string

Methods

Contains(DayOfWeek, TimeOnly)

Checks membership of a local day and clock time without applying a time-zone conversion.

public bool Contains(DayOfWeek day, TimeOnly time)

Parameters

day DayOfWeek

A defined day of the week.

time TimeOnly

Local clock time, with full tick precision.

Returns

bool

Whether a start-inclusive, end-exclusive period contains that local time.

Exceptions

ArgumentOutOfRangeException

The day is undefined.

Create(string, IReadOnlyList<WeeklyPeriod>)

Creates a schedule from trusted input.

public static WeeklySchedule Create(string timeZoneId, IReadOnlyList<WeeklyPeriod> periods)

Parameters

timeZoneId string

An IANA ID resolvable on this system.

periods IReadOnlyList<WeeklyPeriod>

Non-overlapping periods; empty means always closed.

Returns

WeeklySchedule

The validated schedule.

Exceptions

InvalidOperationException

The time zone or periods are invalid.

GetEqualityComponents(ref EqualityComponents)

When overridden in a derived class, adds the components that define equality for this value object.

protected override void GetEqualityComponents(ref EqualityComponents components)

Parameters

components EqualityComponents

The sink that collects this value object's equality components.

Examples

protected override void GetEqualityComponents(ref EqualityComponents components)
{
    components.Add(Street);
    components.Add(City);
    components.Add(PostalCode);
}

Remarks

This method is used by Equals(ValueObject?), GetHashCode(), and CompareTo(ValueObject?) to determine equality and ordering. Components must be added in a consistent order.

Guidelines:

  • Add all properties that define the value object's identity
  • For derived classes, call base.GetEqualityComponents(ref components) first
  • Add components in a consistent, deterministic order
  • Do not allocate: the sink exists so comparisons stay allocation-free

IsActiveAt(DateTimeOffset)

Checks whether the schedule is active at an absolute instant.

public bool IsActiveAt(DateTimeOffset instant)

Parameters

instant DateTimeOffset

An instant; its supplied offset does not select the schedule's zone.

Returns

bool

Whether the corresponding local wall-clock time belongs to a period.

Remarks

Both occurrences of repeated clock times match the same weekly periods. Skipped clock times have no corresponding instant. This is a pure in-memory query, not SQL translation or job scheduling; no current clock is read.

TryCreate(string?, IReadOnlyList<WeeklyPeriod>?, string?)

Validates an IANA time-zone ID and a collection of non-overlapping periods.

public static Result<WeeklySchedule> TryCreate(string? timeZoneId, IReadOnlyList<WeeklyPeriod>? periods, string? fieldName = null)

Parameters

timeZoneId string

An IANA ID resolvable on this system, including UTC. Surrounding whitespace is trimmed.

periods IReadOnlyList<WeeklyPeriod>

Periods to copy. Empty is valid; a null collection or null element is invalid.

fieldName string

Optional owner name or JSON Pointer for nested errors.

Returns

Result<WeeklySchedule>

A schedule or accumulated time-zone and period validation failures.

Remarks

Windows-only IDs are rejected. Resolution uses the host's installed time-zone data; the resolved rules are retained by this instance. No arbitrary period-count limit is imposed.