FiscalWeekQuarterProvider Class
Definition
Provides quarter boundary logic for a week-based retail fiscal calendar using a configurable FiscalWeekPattern (5-4-4, 4-5-4, or 4-4-5 week distribution).
public sealed class FiscalWeekQuarterProvider : IQuarterDefinitionProvider
- Inheritance
-
FiscalWeekQuarterProvider
- Implements
- Inherited Members
- Extension Methods
Remarks
This provider describes a recurring fiscal calendar rule. Each quarter consists of exactly 13 weeks, divided into three fiscal periods according to the FiscalWeekPattern supplied at construction. Quarters are defined as contiguous 13-week blocks measured from the fiscal year start:
- Q1Weeks 1-13
- Q2Weeks 14-26
- Q3Weeks 27-39
- Q4Weeks 40-52 (or 40-53 in a 53-week year)
The FiscalWeekPattern controls how the 13 weeks within each quarter are divided into three fiscal periods (fiscal months). It does not affect quarter start or end boundaries, but is exposed via the Pattern property for consumers that require intra-quarter period logic.
A fiscal year may contain a 53rd week when the span between the computed fiscal year start and the equivalent start in the following year exceeds 364 days. In a 53-week year, the extra week is always appended to Q4.
The fiscal week start day is governed by the DayOfWeek supplied to the constructor. Year-specific
values - the fiscal year start date, whether a given year contains 53 weeks, and quarter boundaries - are computed
on demand from either an explicit fiscalYear argument or from the input date itself.
Constructors
FiscalWeekQuarterProvider(int, DayOfWeek, bool, bool, FiscalWeekPattern)
Initializes a new instance of the FiscalWeekQuarterProvider class using the specified anchor month and alignment options.
public FiscalWeekQuarterProvider(int month, DayOfWeek dayOfWeek = DayOfWeek.Saturday, bool isFiscalYearEnd = true, bool useNearestDayOfWeek = true, FiscalWeekPattern pattern = FiscalWeekPattern.Weeks445)
Parameters
monthintThe calendar month (1-12) of the fiscal year anchor.
dayOfWeekDayOfWeekThe day of the week on which each fiscal week begins. Common values are Sunday and Saturday. Defaults to Saturday.
isFiscalYearEndboolWhen true,
monthidentifies the fiscal year's closing month, and the actual fiscal start month is the one that follows. When false,monthidentifies the fiscal year's opening month directly. Defaults to true.useNearestDayOfWeekbooltrue to align the fiscal year start to the occurrence of
dayOfWeeknearest to the computed anchor date; false to align it to the occurrence ofdayOfWeekon or before the computed anchor date. Defaults to true.patternFiscalWeekPatternThe week distribution pattern applied to the three fiscal periods within each quarter. Defaults to Weeks445.
Remarks
The fiscal year start for a given fiscalYear is derived from the first day of the anchor month in that
year, then aligned to the configured fiscal week start day using one of two strategies:
-
When
useNearestDayOfWeekis true, the start date is aligned to the occurrence ofdayOfWeeknearest to the computed anchor date. -
When
useNearestDayOfWeekis false, the start date is aligned to the occurrence ofdayOfWeekon or before the computed anchor date.
When isFiscalYearEnd is true, the anchor is the first day of the month
following month. The fiscal year still begins on the occurrence of
dayOfWeek selected by useNearestDayOfWeek, so the fiscal week boundary
always coincides with dayOfWeek.
Exceptions
- ArgumentOutOfRangeException
Thrown when
monthis not in the range 1-12, -or-dayOfWeekis not a defined DayOfWeek value, -or-patternis not a defined FiscalWeekPattern value.
Properties
Pattern
Gets the week distribution pattern applied to the three fiscal periods within each quarter.
public FiscalWeekPattern Pattern { get; }
Property Value
- FiscalWeekPattern
One of the FiscalWeekPattern values that describes how the 13 weeks of each quarter are divided into fiscal periods.
Methods
GetFiscalYear(DateOnly)
Returns the fiscal year that contains the supplied DateOnly.
public 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.
public 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.
public 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.
public 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.
public 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.
public 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.
public 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.
public 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.
public 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.
public 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.
public 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.
public 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.
public 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.
public bool Is53WeekFiscalYear(int fiscalYear)
Parameters
fiscalYearintThe fiscal year to test.
Returns
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |