Table of Contents

Class WeeklyPeriod

Namespace
Trellis.Primitives
Assembly
Trellis.Primitives.dll

An immutable, recurring local-clock interval starting on a day of the week.

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

Remarks

Intervals include their start and exclude their end. An end before the start means the following day. Equal endpoints are invalid unless created explicitly as an all-day period. TimeOnly tick precision is preserved. Use a DTO for JSON and persistence.

Properties

Day

Gets the day on which this period starts.

public DayOfWeek Day { get; }

Property Value

DayOfWeek

End

Gets the exclusive local end time, or midnight for an all-day period.

public TimeOnly End { get; }

Property Value

TimeOnly

IsAllDay

Gets whether the period covers the entire calendar day, midnight to midnight.

public bool IsAllDay { get; }

Property Value

bool

Start

Gets the inclusive local start time, or midnight for an all-day period.

public TimeOnly Start { get; }

Property Value

TimeOnly

Methods

Create(DayOfWeek, TimeOnly, TimeOnly)

Creates a period from trusted input.

public static WeeklyPeriod Create(DayOfWeek day, TimeOnly start, TimeOnly end)

Parameters

day DayOfWeek

The starting day.

start TimeOnly

Inclusive local start time.

end TimeOnly

Exclusive local end time.

Returns

WeeklyPeriod

The validated period.

Exceptions

InvalidOperationException

The day is undefined or the endpoints are equal.

CreateAllDay(DayOfWeek)

Creates an explicit all-day period from a trusted day.

public static WeeklyPeriod CreateAllDay(DayOfWeek day)

Parameters

day DayOfWeek

The day to cover.

Returns

WeeklyPeriod

The validated all-day period.

Exceptions

InvalidOperationException

The day is undefined.

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

TryCreate(DayOfWeek, TimeOnly, TimeOnly, string?)

Validates the day and unequal endpoints, accumulating independent failures.

public static Result<WeeklyPeriod> TryCreate(DayOfWeek day, TimeOnly start, TimeOnly end, string? fieldName = null)

Parameters

day DayOfWeek

The starting day, Sunday through Saturday.

start TimeOnly

Inclusive local start time.

end TimeOnly

Exclusive local end time; an earlier time means the following day.

fieldName string

Optional owner name or JSON Pointer for component errors.

Returns

Result<WeeklyPeriod>

The period, or errors under day and/or end.

TryCreateAllDay(DayOfWeek, string?)

Creates an explicit midnight-to-midnight period for one calendar day.

public static Result<WeeklyPeriod> TryCreateAllDay(DayOfWeek day, string? fieldName = null)

Parameters

day DayOfWeek

The day to cover, Sunday through Saturday.

fieldName string

Optional owner name or JSON Pointer for the day error.

Returns

Result<WeeklyPeriod>

The all-day period, or an undefined-day failure.