Table of Contents


Quarter and DateRange Classes

Overview

The Quarter class represents a fiscal or calendar quarter with defined start and end dates. It provides a simple way to work with quarterly date ranges in your application.

The DateRange class extends Quarter to add validation capabilities for date range operations.


Classes

Quarter

Represents a quarter period with start and end dates.

Properties

PropertyTypeDescription
StartDateTimeThe start date of the quarter
EndDateTimeThe end date of the quarter

DateRange

Extends Quarter to provide validated date range functionality.

Properties

PropertyTypeDescription
StartDateTimeThe start date of the date range (inherited)
EndDateTimeThe end date of the date range (inherited)
IsValidboolIndicates whether the date range is valid

Usage Examples

Creating a Quarter

var q1 = new Quarter
{
    Start = new DateTime(2025, 1, 1),
    End = new DateTime(2025, 3, 31)
};

Creating a Validated Date Range

var dateRange = new DateRange
{
    Start = new DateTime(2025, 1, 1),
    End = new DateTime(2025, 12, 31),
    IsValid = true
};

if (dateRange.IsValid)
{
    // Process the date range
    Console.WriteLine($"Range: {dateRange.Start:d} to {dateRange.End:d}");
}

Checking Quarter Duration

var quarter = new Quarter
{
    Start = new DateTime(2025, 4, 1),
    End = new DateTime(2025, 6, 30)
};

var duration = quarter.End - quarter.Start;
SystemInfo.Debug($"Quarter duration: {duration.TotalDays} days");

Common Use Cases

  • Fiscal Reporting: Define quarterly periods for financial reports
  • Date Filtering: Filter data by quarter in queries or reports
  • Period Validation: Use DateRange to validate user-selected date ranges
  • Time-based Operations: Calculate metrics or aggregations by quarter

Notes

💡 Note: The Quarter class does not enforce that the date range represents exactly one quarter (90-92 days). You can use it to represent any start/end date pair.
💡 Note: The DateRange.IsValid property should be set explicitly based on your validation logic (e.g., ensuring Start < End).
âš  Warning: Neither class performs automatic validation. You must implement validation logic in your business layer to ensure dates are properly ordered and within acceptable bounds.