Class DateOnlyExtensions
- Namespace
- Payetools.Common.Extensions
- Assembly
- Payetools.Common.dll
Extension methods for instances of DateOnly.
public static class DateOnlyExtensions
- Inheritance
-
DateOnlyExtensions
- Inherited Members
Methods
AgeAt(DateOnly, DateOnly)
Calculates the age of a person on a certain date based on the supplied date of birth. Takes account of leap years, using the convention that someone born on 29th February in a leap year is not legally one year older until 1st March of a non-leap year.
public static int AgeAt(this DateOnly dateOfBirth, DateOnly date)
Parameters
Returns
- int
Age of the individual in years (as an integer).
Remarks
This code is not guaranteed to be correct for non-UK locales, as some countries have skipped certain dates within living memory.
OrIfEarlier(DateOnly, DateOnly)
Returns the earlier of two dates.
public static DateOnly OrIfEarlier(this DateOnly date, DateOnly other)
Parameters
Returns
- DateOnly
The earlier of the two dates.
OrIfLater(DateOnly, DateOnly)
Returns the later of two dates.
public static DateOnly OrIfLater(this DateOnly date, DateOnly other)
Parameters
Returns
- DateOnly
The later of the two dates.
ToMiddayUtcDateTime(DateOnly)
Provides an equivalent DateTime to the supplied DateOnly with the time portion set to midday (12:00:00) UTC. This is used to minimise the possibility of dates being misinterpreted as the next or previous day due to the use of non-UTC timezones.
public static DateTime ToMiddayUtcDateTime(this DateOnly date)
Parameters
date
DateOnlyDateOnly to convert to DateTime.
Returns
- DateTime
DateTime instance with the same date as the supplied DateOnly and time portion set to 12:00:00 UTC.
ToPayDate(DateOnly, PayFrequency)
Converts the supplied DateOnly to a PayDate based on the specified PayFrequency.
public static PayDate ToPayDate(this DateOnly date, PayFrequency payFrequency)
Parameters
date
DateOnlyDate to obtain PayDate for.
payFrequency
PayFrequencyApplicable pay frequency for this pay date.
Returns
- PayDate
PayDate for the supplied date and pay frequency.
ToTaxYearEnding(DateOnly)
Gets the TaxYearEnding value for the supplied DateOnly.
public static TaxYearEnding ToTaxYearEnding(this DateOnly date)
Parameters
Returns
- TaxYearEnding
Relevant TaxYearEnding for the supplied date.
Exceptions
- ArgumentOutOfRangeException
Thrown if the supplied date is outside the supported set of dates for this library.
ToUk(DateOnly)
Returns the date as a string in UK format (dd/mm/yyyy).
public static string ToUk(this DateOnly date)
Parameters
date
DateOnlyDate to get string representation for.
Returns
- string
UK format date string.