IQuarterDefinitionProvider Interface
Definition
Defines a provider interface for custom quarter calculation logic based on DateTime or DateOnly values.
public interface IQuarterDefinitionProvider
- Extension Methods
Remarks
Implementations describe a recurring quarter rule - a fiscal or logical calendar definition that is independent of
any single year. Year-specific values, such as quarter start and end dates or whether a fiscal year contains a 53rd
week, are derived on demand from the DateTime or DateOnly input, or from an explicit
fiscalYear argument.
Example use cases include 4-4-5 calendars, academic terms, retail fiscal calendars, or historical reporting quarters that do not align with calendar or standard financial quarters.
Methods that support this interface include:
- Quarter(DateTime, IQuarterDefinitionProvider)
- FirstDateOfQuarter(DateTime, IQuarterDefinitionProvider)
- LastDateOfQuarter(DateTime, IQuarterDefinitionProvider)
- IsFirstDateOfQuarter(DateTime, IQuarterDefinitionProvider)
- IsLastDateOfQuarter(DateTime, IQuarterDefinitionProvider)
- Quarter(DateOnly, IQuarterDefinitionProvider)
- FirstDateOfQuarter(DateOnly, IQuarterDefinitionProvider)
- LastDateOfQuarter(DateOnly, IQuarterDefinitionProvider)
- IsFirstDateOfQuarter(DateOnly, IQuarterDefinitionProvider)
- IsLastDateOfQuarter(DateOnly, IQuarterDefinitionProvider)
Methods
GetFiscalYear(DateOnly)
Returns the fiscal year that contains the supplied DateOnly.
int GetFiscalYear(DateOnly dateOnly)
Parameters
dateOnlyDateOnlyThe date to identify.
Returns
- int
The fiscal year number under the provider's conventions.
Exceptions
- ArgumentOutOfRangeException
Thrown when
dateOnlycannot be mapped to any fiscal year known to the provider.
GetFiscalYear(DateTime)
Returns the fiscal year that contains the supplied DateTime.
int GetFiscalYear(DateTime dateTime)
Parameters
dateTimeDateTimeThe date to identify.
Returns
- int
The fiscal year number under the provider's conventions.
Remarks
The default implementation probes the calendar years dateTime.Year - 1, dateTime.Year, and
dateTime.Year + 1, returning the candidate whose Q1 start and Q4 end bracket dateTime
. This works for any provider whose fiscal year is contiguous and at most one calendar year away from the
observed calendar year. Implementations may override with a more efficient or more precise computation.
Exceptions
- ArgumentOutOfRangeException
Thrown when
dateTimecannot be mapped to any fiscal year known to the provider.
GetQuarter(DateOnly)
Returns the quarter number (1-4) that contains the specified DateOnly.
int GetQuarter(DateOnly dateOnly)
Parameters
Returns
- int
An integer in the range 1 to 4 representing the quarter that includes
dateOnly.
Exceptions
- ArgumentOutOfRangeException
Thrown when
dateOnlycannot be mapped to a recognized fiscal year.
GetQuarter(DateTime)
Returns the quarter number (1-4) that contains the specified DateTime.
int GetQuarter(DateTime dateTime)
Parameters
Returns
- int
An integer in the range 1 to 4 representing the quarter that includes
dateTime.
Exceptions
- ArgumentOutOfRangeException
Thrown when
dateTimecannot be mapped to a recognized fiscal year.
GetQuarterEnd(DateTime)
Returns the last day of the quarter that contains the specified DateTime.
DateTime GetQuarterEnd(DateTime dateTime)
Parameters
Returns
- DateTime
A DateTime set to midnight (00:00:00) on the final day of the quarter that includes
dateTime. The result preserves the original Kind.
Exceptions
- ArgumentOutOfRangeException
Thrown when
dateTimecannot be mapped to a recognized fiscal year.
GetQuarterEnd(int, int)
Returns the last day of the specified quarter number (1-4) within the given fiscal year.
DateTime GetQuarterEnd(int quarter, int fiscalYear)
Parameters
quarterintThe quarter number (1-4).
fiscalYearintThe fiscal year whose quarter boundary is being requested.
Returns
Exceptions
- ArgumentOutOfRangeException
Thrown when
quarteris not between 1 and 4.
GetQuarterEndDate(DateOnly)
Returns the last day of the quarter that contains the specified DateOnly.
DateOnly GetQuarterEndDate(DateOnly dateOnly)
Parameters
Returns
Exceptions
- ArgumentOutOfRangeException
Thrown when
dateOnlycannot be mapped to a recognized fiscal year.
GetQuarterEndDate(int, int)
Returns the last day of the specified quarter number (1-4) within the given fiscal year.
DateOnly GetQuarterEndDate(int quarter, int fiscalYear)
Parameters
quarterintThe quarter number (1-4).
fiscalYearintThe fiscal year whose quarter boundary is being requested.
Returns
Exceptions
- ArgumentOutOfRangeException
Thrown when
quarteris not between 1 and 4.
GetQuarterStart(DateTime)
Returns the first day of the quarter that contains the specified DateTime.
DateTime GetQuarterStart(DateTime dateTime)
Parameters
Returns
- DateTime
A DateTime set to midnight (00:00:00) on the first day of the quarter that includes
dateTime. The result preserves the original Kind.
Exceptions
- ArgumentOutOfRangeException
Thrown when
dateTimecannot be mapped to a recognized fiscal year.
GetQuarterStart(int, int)
Returns the first day of the specified quarter number (1-4) within the given fiscal year.
DateTime GetQuarterStart(int quarter, int fiscalYear)
Parameters
quarterintThe quarter number (1-4).
fiscalYearintThe fiscal year whose quarter boundary is being requested.
Returns
Exceptions
- ArgumentOutOfRangeException
Thrown when
quarteris not between 1 and 4.
GetQuarterStartDate(DateOnly)
Returns the first day of the quarter that contains the specified DateOnly.
DateOnly GetQuarterStartDate(DateOnly dateOnly)
Parameters
Returns
Exceptions
- ArgumentOutOfRangeException
Thrown when
dateOnlycannot be mapped to a recognized fiscal year.
GetQuarterStartDate(int, int)
Returns the first day of the specified quarter number (1-4) within the given fiscal year.
DateOnly GetQuarterStartDate(int quarter, int fiscalYear)
Parameters
quarterintThe quarter number (1-4).
fiscalYearintThe fiscal year whose quarter boundary is being requested.
Returns
Exceptions
- ArgumentOutOfRangeException
Thrown when
quarteris not between 1 and 4.
GetWeeksInFiscalYear(int)
Returns the total number of weeks in the specified fiscal year.
int GetWeeksInFiscalYear(int fiscalYear)
Parameters
fiscalYearintThe fiscal year to query.
Returns
- int
53 in a 53-week fiscal year; otherwise, 52.
Is53WeekFiscalYear(int)
Returns a value indicating whether the specified fiscal year contains 53 weeks rather than the standard 52.
bool Is53WeekFiscalYear(int fiscalYear)
Parameters
fiscalYearintThe fiscal year to test.
Returns
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |