NickvisionApps/Parabolic · error · ArgumentException

End time must be greater than or equal to start time.

Error message

End time must be greater than or equal to start time.

What it means

The TimeFrame constructor throws ArgumentException when the supplied end TimeSpan is earlier than the start TimeSpan. A TimeFrame represents a time interval, so a negative or backwards interval is meaningless and is rejected at construction time. It also silently truncates millisecond components from both bounds, but only after the ordering check.

Solutions

  1. Validate before constructing: ensure end >= start, swapping or normalizing the pair if needed.
  2. Parse user-supplied times consistently (same format/culture/timezone) so ordering comparisons are correct.
  3. If the interval is derived from a duration, construct end as start + duration and assert duration >= TimeSpan.Zero.
  4. Catch ArgumentException at the boundary and surface a user-facing message asking to correct the time range.

Example fix

// before
var frame = new TimeFrame(new TimeSpan(endHour, 0, 0), new TimeSpan(startHour, 0, 0));
// after
var start = new TimeSpan(startHour, 0, 0);
var end = new TimeSpan(endHour, 0, 0);
if (end < start) (start, end) = (end, start);
var frame = new TimeFrame(start, end);
Defensive patterns

Strategy: validation

Validate before calling

bool IsValidTimeFrame(TimeSpan start, TimeSpan end) => end >= start;
// call: if (!IsValidTimeFrame(s, e)) throw new ArgumentException("end must be >= start");

Type guard

bool HasValidOrder(TimeSpan start, TimeSpan end) => end >= start;

Try / catch

try { var frame = new TimeFrame(start, end); }
catch (ArgumentException ex) { /* prompt user to fix start/end order */ }

Prevention

When it happens

Trigger: Calling new TimeFrame(start, end) with end < Start, e.g. TimeFrame(new TimeSpan(10,0,0), new TimeSpan(9,0,0)). Also triggered when computed end values (start plus a negative duration, or values parsed from config/user input in the wrong order) are passed in unvalidated.

Common situations: Scheduling download time frames from user input where the user enters start/stop times in the wrong order; timezone or 12h/24h parsing mistakes that swap AM/PM; computing end = start - offset instead of plus.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of NickvisionApps/Parabolic@1118e6a3ab (2026-09-15). Data as JSON: /api/errors/f09c59c58df6342d. Report an issue: GitHub.

Appendix: source

Thrown at Nickvision.Parabolic.Shared/Models/TimeFrame.cs:20

namespace Nickvision.Parabolic.Shared.Models;

public class TimeFrame : IEquatable<TimeFrame>
{
    public TimeSpan Start { get; }
    public TimeSpan End { get; }

    public string StartString => $"{Start:c}";
    public string EndString => $"{End:c}";
    public TimeSpan Duration => End - Start;

    public TimeFrame(TimeSpan start, TimeSpan end)
    {
        Start = start;
        End = end;
        if (End < Start)
        {
            throw new ArgumentException("End time must be greater than or equal to start time.");
        }
        if (Start.Milliseconds > 0)
        {
            Start = new TimeSpan(Start.Hours, Start.Minutes, Start.Seconds);
        }
        if (End.Milliseconds > 0)
        {
            End = new TimeSpan(End.Hours, End.Minutes, End.Seconds);
        }
    }

    public static TimeFrame? Parse(string start, string end, TimeSpan duration)
    {
        if (string.IsNullOrEmpty(start) || string.IsNullOrEmpty(end) || duration.TotalSeconds <= 0)
        {
            return null;
        }
        var startParts = start.Split(':');

View on GitHub (pinned to 1118e6a3ab)