2016-08-10 14:02:31 +00:00
|
|
|
|
using System;
|
|
|
|
|
|
2017-01-08 07:54:09 +00:00
|
|
|
|
namespace PKHeX.Core
|
2016-08-10 14:02:31 +00:00
|
|
|
|
{
|
|
|
|
|
public static partial class Util
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Determines whether or not the given date components are valid.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="year">The year of the date of which to check the validity.</param>
|
|
|
|
|
/// <param name="month">The month of the date of which to check the validity.</param>
|
|
|
|
|
/// <param name="day">The day of the date of which to check the validity.</param>
|
|
|
|
|
/// <returns>A boolean indicating whether or not the date is valid.</returns>
|
|
|
|
|
public static bool IsDateValid(int year, int month, int day)
|
|
|
|
|
{
|
2016-08-11 00:54:12 +00:00
|
|
|
|
return !(year <= 0 || year > DateTime.MaxValue.Year || month < 1 || month > 12 || day < 1 || day > DateTime.DaysInMonth(year, month));
|
2016-08-10 14:02:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Determines whether or not the given date components are valid.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="year">The year of the date of which to check the validity.</param>
|
|
|
|
|
/// <param name="month">The month of the date of which to check the validity.</param>
|
|
|
|
|
/// <param name="day">The day of the date of which to check the validity.</param>
|
|
|
|
|
/// <returns>A boolean indicating whether or not the date is valid.</returns>
|
|
|
|
|
public static bool IsDateValid(uint year, uint month, uint day)
|
|
|
|
|
{
|
2016-08-10 14:24:40 +00:00
|
|
|
|
return year < int.MaxValue && month < int.MaxValue && day < int.MaxValue && IsDateValid((int)year, (int)month, (int)day);
|
2016-08-10 14:02:31 +00:00
|
|
|
|
}
|
2019-09-16 05:12:32 +00:00
|
|
|
|
|
2020-12-22 01:17:56 +00:00
|
|
|
|
private static readonly DateTime Epoch2000 = new(2000, 1, 1);
|
2020-06-17 02:46:22 +00:00
|
|
|
|
private const int SecondsPerDay = 60*60*24; // 86400
|
2019-09-16 05:12:32 +00:00
|
|
|
|
|
|
|
|
|
public static int GetSecondsFrom2000(DateTime date, DateTime time)
|
|
|
|
|
{
|
|
|
|
|
int seconds = (int)(date - Epoch2000).TotalSeconds;
|
2020-06-17 02:46:22 +00:00
|
|
|
|
seconds -= seconds % SecondsPerDay;
|
2019-09-16 05:12:32 +00:00
|
|
|
|
seconds += (int)(time - Epoch2000).TotalSeconds;
|
|
|
|
|
return seconds;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void GetDateTime2000(uint seconds, out DateTime date, out DateTime time)
|
|
|
|
|
{
|
|
|
|
|
date = Epoch2000.AddSeconds(seconds);
|
2020-06-17 02:46:22 +00:00
|
|
|
|
time = Epoch2000.AddSeconds(seconds % SecondsPerDay);
|
2019-09-16 05:12:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string ConvertDateValueToString(int value, int secondsBias = -1)
|
|
|
|
|
{
|
|
|
|
|
string tip = string.Empty;
|
2020-06-17 02:46:22 +00:00
|
|
|
|
if (value >= SecondsPerDay)
|
|
|
|
|
tip += (value / SecondsPerDay) + "d ";
|
2019-09-16 05:12:32 +00:00
|
|
|
|
tip += new DateTime(0).AddSeconds(value).ToString("HH:mm:ss");
|
|
|
|
|
if (secondsBias >= 0)
|
|
|
|
|
tip += Environment.NewLine + $"Date: {Epoch2000.AddSeconds(value + secondsBias)}";
|
|
|
|
|
return tip;
|
|
|
|
|
}
|
2016-08-10 14:02:31 +00:00
|
|
|
|
}
|
|
|
|
|
}
|