Class TimeProviderExtensions
- Namespace
- System
- Assembly
- Arc4u.dll
Provides a set of static methods extending the TimeProvider class.
They work in the LocalTimeZone of the provider, which is the time zone of the application with a ZonedTimeProvider.
public static class TimeProviderExtensions
- Inheritance
-
TimeProviderExtensions
- Inherited Members
Methods
GetDaylightChanges(TimeProvider, int)
Gets the start and the end of the daylight saving time of the LocalTimeZone in year.
See GetDaylightChanges(TimeZoneInfo, int).
public static DaylightTime? GetDaylightChanges(this TimeProvider timeProvider, int year)
Parameters
timeProviderTimeProviderThe time provider.
yearintThe year.
Returns
- DaylightTime
The daylight saving period, or null when the time zone does not both enter and leave the daylight saving time in
year.
Exceptions
- ArgumentNullException
timeProvideris null.- ArgumentOutOfRangeException
yearis not between 1 and 9999.
GetDueTimeOfDay(TimeProvider, TimeSpan)
Gets the time to wait from now until the next occurrence of timeOfDay in the LocalTimeZone,
taking the changes of the daylight saving time into account. Typically used as the due time of a daily timer.
public static TimeSpan GetDueTimeOfDay(this TimeProvider timeProvider, TimeSpan timeOfDay)
Parameters
timeProviderTimeProviderThe time provider.
timeOfDayTimeSpanThe wall-clock time of the day. A time skipped when the clocks go forward is moved forward by the gap (02:30 becomes 03:30); a time that happens twice when the clocks go back is the first of the two.
Returns
- TimeSpan
The time to wait, Zero when
timeOfDayis now or negative, or negative one (-1) millisecond (no start) whentimeOfDayis greater than one day.
Examples
// Run every day at 02:00 in the time zone of the application.
var timer = timeProvider.CreateTimer(_ => Purge(), null, timeProvider.GetDueTimeOfDay(TimeSpan.FromHours(2)), Timeout.InfiniteTimeSpan);
Exceptions
- ArgumentNullException
timeProvideris null.