2024-04-16 18:29:40 +00:00
|
|
|
using System.Text.RegularExpressions;
|
2023-08-13 17:26:49 +01:00
|
|
|
|
2024-04-16 18:29:40 +00:00
|
|
|
namespace LootDumpProcessor.Utils;
|
2023-08-13 17:26:49 +01:00
|
|
|
|
2025-01-11 11:50:02 +03:00
|
|
|
public static partial class FileDateParser
|
2023-08-13 17:26:49 +01:00
|
|
|
{
|
2025-01-11 11:50:02 +03:00
|
|
|
private static readonly Regex FileDateRegex = GetRegex();
|
2023-08-13 17:26:49 +01:00
|
|
|
|
|
|
|
public static bool TryParseFileDate(string fileName, out DateTime? date)
|
|
|
|
{
|
|
|
|
date = null;
|
2025-01-11 11:50:02 +03:00
|
|
|
if (!FileDateRegex.IsMatch(fileName)) return false;
|
|
|
|
|
|
|
|
var match = FileDateRegex.Match(fileName);
|
2023-08-13 17:26:49 +01:00
|
|
|
var year = match.Groups[1].Value;
|
|
|
|
var month = match.Groups[2].Value;
|
|
|
|
var day = match.Groups[3].Value;
|
|
|
|
var hour = match.Groups[4].Value;
|
2025-01-11 11:50:02 +03:00
|
|
|
var minutes = match.Groups[5].Value;
|
|
|
|
var seconds = match.Groups[6].Value;
|
2023-08-13 17:26:49 +01:00
|
|
|
date = new DateTime(
|
|
|
|
int.Parse(year),
|
|
|
|
int.Parse(month),
|
|
|
|
int.Parse(day),
|
|
|
|
int.Parse(hour),
|
2025-01-11 11:50:02 +03:00
|
|
|
int.Parse(minutes),
|
|
|
|
int.Parse(seconds)
|
2023-08-13 17:26:49 +01:00
|
|
|
);
|
|
|
|
return true;
|
|
|
|
}
|
2025-01-11 11:50:02 +03:00
|
|
|
|
|
|
|
[GeneratedRegex(".*([0-9]{4})[-]([0-9]{2})[-]([0-9]{2})[_]([0-9]{2})[-]([0-9]{2})[-]([0-9]{2}).*")]
|
|
|
|
private static partial Regex GetRegex();
|
2023-08-13 17:26:49 +01:00
|
|
|
}
|