Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
DateTimeExtensions.cs
1using System;
2
4{
8 public static class DateTimeExtensions
9 {
15 public static DateTime? GetDateOrNullIfMinValue(this DateTime? date)
16 {
17 if (!date.HasValue)
18 return null;
19 return GetDateOrNullIfMinValue(date.Value);
20 }
21
27 public static DateTime? GetDateOrNullIfMinValue(this DateTime date)
28 {
29 if (date == DateTime.MinValue)
30 return null;
31 return date;
32 }
33
41 public static DateTime SanitizeForDatePicker(this DateTime date, DateTime safeMin, DateTime safeMax)
42 {
43 if (date <= safeMin || date == DateTime.MinValue)
44 return safeMin;
45 if (date >= safeMax || date == DateTime.MaxValue)
46 return safeMax;
47 return date;
48 }
49
59 public static DateTime? SanitizeForDatePicker(this DateTime? date, DateTime safeMin, DateTime safeMax)
60 {
61 if (!date.HasValue)
62 return null;
63
64 return date.Value.SanitizeForDatePicker(safeMin, safeMax);
65 }
66 }
67}
Extensions for the DateTime class.
static ? DateTime GetDateOrNullIfMinValue(this DateTime date)
Returns the actual date if it has a valid value, or null if it is DateTime.MinValue.
static DateTime SanitizeForDatePicker(this DateTime date, DateTime safeMin, DateTime safeMax)
Clamps a date to a safe range to avoid System.ArgumentOutOfRangeException when MAUI converts it to Sy...
static ? DateTime SanitizeForDatePicker(this DateTime? date, DateTime safeMin, DateTime safeMax)
Clamps a nullable date to a safe range, preserving null if no value is present.
static ? DateTime GetDateOrNullIfMinValue(this DateTime? date)
Returns the actual date, if it is non-null, or null if it is DateTime.MinValue.