mirror of
https://github.com/tribufu/ServerManagers
synced 2026-05-06 15:17:34 +00:00
asm: add NewYear setting
This commit is contained in:
parent
c9e6f2ec26
commit
70ed633bc0
4 changed files with 158 additions and 1 deletions
|
|
@ -0,0 +1,35 @@
|
|||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Markup;
|
||||
|
||||
namespace ServerManagerTool.Common.Converters
|
||||
{
|
||||
public class DateTimeToStringConverter : MarkupExtension, IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
DateTime datetime = (DateTime)value;
|
||||
if (datetime == DateTime.MinValue)
|
||||
return "";
|
||||
|
||||
return datetime.ToString("yyyy.MM.dd HH:mm:ss");
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is null || value.ToString() == string.Empty)
|
||||
return DateTime.MinValue;
|
||||
|
||||
if (!DateTime.TryParse(value.ToString(), out DateTime datetime))
|
||||
return DateTime.MinValue;
|
||||
|
||||
return datetime;
|
||||
}
|
||||
|
||||
public override object ProvideValue(IServiceProvider serviceProvider)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
using ServerManagerTool.Common.Extensions;
|
||||
using System;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace ServerManagerTool.Common.ValidationRules
|
||||
{
|
||||
public class DateTimeValidationRule : ValidationRule
|
||||
{
|
||||
private static readonly DateTime MinUnixDate = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
|
||||
private static readonly DateTime MaxUnixDate = new DateTime(2038, 1, 19, 3, 14, 7, 0, DateTimeKind.Utc);
|
||||
|
||||
public override ValidationResult Validate(object value, System.Globalization.CultureInfo cultureInfo)
|
||||
{
|
||||
string strDateTime = (string)value;
|
||||
|
||||
if (strDateTime.IsEmpty())
|
||||
{
|
||||
return new ValidationResult(true, null);
|
||||
}
|
||||
|
||||
if (!DateTime.TryParse(strDateTime, out DateTime datetime))
|
||||
{
|
||||
return new ValidationResult(false, "Invalid Date. Date must be formatted as yyyy.mm.dd hh:mm:ss");
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
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