9709d09b15
PR Checks / test-and-build (pull_request) Successful in 30m45s
- Remove legacy DiscordNewSessionCommand/Handler and their tests. - Rename /newsession-wizard to /newsession. - Add shared pool capacity step before Format/Location. - Render Format and Location in Discord wizard; Location uses a modal. - Propagate Format, JoinLink and LocationAddress in BuildCommand. - Publish created sessions through existing IPlatformMessenger pipeline. - Update README, version bump to 3.11.1, sync compose/deploy/NavMenu.
46 lines
1.6 KiB
C#
46 lines
1.6 KiB
C#
using System.Globalization;
|
|
|
|
namespace GmRelay.DiscordBot.Features.Sessions;
|
|
|
|
public sealed record TimeParseResult(bool IsSuccess, DateTimeOffset Value, string? Error);
|
|
|
|
public static class DiscordTimeParser
|
|
{
|
|
private static readonly TimeSpan MoscowOffset = TimeSpan.FromHours(3);
|
|
|
|
public static TimeParseResult ParseTimeInput(string input)
|
|
{
|
|
var trimmed = input.Trim();
|
|
|
|
if (DateTime.TryParseExact(
|
|
trimmed,
|
|
"yyyy-MM-dd HH:mm",
|
|
CultureInfo.InvariantCulture,
|
|
DateTimeStyles.None,
|
|
out var dt1))
|
|
{
|
|
var offset = new DateTimeOffset(dt1, MoscowOffset).ToUniversalTime();
|
|
if (offset < DateTimeOffset.UtcNow)
|
|
return new TimeParseResult(false, default, "Дата находится в прошлом.");
|
|
|
|
return new TimeParseResult(true, offset, null);
|
|
}
|
|
|
|
if (DateTime.TryParseExact(
|
|
trimmed,
|
|
"dd.MM.yyyy HH:mm",
|
|
CultureInfo.InvariantCulture,
|
|
DateTimeStyles.None,
|
|
out var dt2))
|
|
{
|
|
var offset = new DateTimeOffset(dt2, MoscowOffset).ToUniversalTime();
|
|
if (offset < DateTimeOffset.UtcNow)
|
|
return new TimeParseResult(false, default, "Дата находится в прошлом.");
|
|
|
|
return new TimeParseResult(true, offset, null);
|
|
}
|
|
|
|
return new TimeParseResult(false, default, "Некорректный формат даты. Используйте YYYY-MM-DD HH:mm или DD.MM.YYYY HH:mm");
|
|
}
|
|
}
|