mirror of
https://github.com/tribufu/ServerManagers
synced 2026-05-06 15:17:34 +00:00
asm: update NewYear to nullable value
This commit is contained in:
parent
70ed633bc0
commit
a14ee7c108
4 changed files with 32 additions and 33 deletions
|
|
@ -1,30 +1,30 @@
|
|||
using System;
|
||||
using ServerManagerTool.Common.Model;
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Markup;
|
||||
|
||||
namespace ServerManagerTool.Common.Converters
|
||||
{
|
||||
public class DateTimeToStringConverter : MarkupExtension, IValueConverter
|
||||
public class NullableDateTimeToStringConverter : MarkupExtension, IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
DateTime datetime = (DateTime)value;
|
||||
if (datetime == DateTime.MinValue)
|
||||
return "";
|
||||
if (value != null && value is NullableValue<DateTime> && ((NullableValue<DateTime>)value).Value != DateTime.MinValue)
|
||||
return ((NullableValue<DateTime>)value).Value.ToString("yyyy.MM.dd HH:mm:ss");
|
||||
|
||||
return datetime.ToString("yyyy.MM.dd HH:mm:ss");
|
||||
return "";
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is null || value.ToString() == string.Empty)
|
||||
return DateTime.MinValue;
|
||||
return (new NullableValue<DateTime>());
|
||||
|
||||
if (!DateTime.TryParse(value.ToString(), out DateTime datetime))
|
||||
return DateTime.MinValue;
|
||||
return (new NullableValue<DateTime>());
|
||||
|
||||
return datetime;
|
||||
return (new NullableValue<DateTime>(datetime));
|
||||
}
|
||||
|
||||
public override object ProvideValue(IServiceProvider serviceProvider)
|
||||
|
|
@ -23,17 +23,16 @@ namespace ServerManagerTool.Common.ValidationRules
|
|||
return new ValidationResult(false, "Invalid Date. Date must be formatted as yyyy.mm.dd hh:mm:ss");
|
||||
}
|
||||
|
||||
if (datetime.ToUniversalTime() <= MinUnixDate)
|
||||
if (datetime.ToUniversalTime() < MinUnixDate)
|
||||
{
|
||||
return new ValidationResult(false, $"Invalid Date. The Date must be after {MinUnixDate.ToLocalTime().ToString("yyyy.MM.dd HH:mm:ss")}");
|
||||
}
|
||||
|
||||
if (datetime.ToUniversalTime() >= MaxUnixDate)
|
||||
if (datetime.ToUniversalTime() > MaxUnixDate)
|
||||
{
|
||||
return new ValidationResult(false, $"Invalid Date. The Date must be before {MaxUnixDate.ToLocalTime().ToString("yyyy.MM.dd HH:mm:ss")}");
|
||||
}
|
||||
|
||||
|
||||
return new ValidationResult(true, null);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue