Skip to content
This repository has been archived by the owner on Sep 3, 2023. It is now read-only.

Commit

Permalink
fix: parse date with ru local
Browse files Browse the repository at this point in the history
  • Loading branch information
FrediKats committed Sep 16, 2022
1 parent a248bcd commit 3072995
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
using Kysect.Shreks.Common.Exceptions;
using Kysect.Shreks.Core.Models;
using Kysect.Shreks.Core.Submissions;
using Kysect.Shreks.Core.Tools;
using Microsoft.Extensions.Logging;
using System.Globalization;

namespace Kysect.Shreks.Application.Commands.Commands;

Expand Down Expand Up @@ -32,10 +34,7 @@ public UpdateCommand(int submissionCode, double? ratingPercent, double? extraPoi

public DateOnly GetDate()
{
if (!DateOnly.TryParse(DateStr, out DateOnly date))
throw new InvalidUserInputException($"Cannot parse input date ({DateStr} as date. Ensure that you use correct format.");

return date;
return RuCultureDate.Parse(DateStr);
}

public async Task<Submission> ExecuteAsync(SubmissionContext context, ILogger logger, CancellationToken cancellationToken)
Expand Down
15 changes: 15 additions & 0 deletions Source/Domain/Kysect.Shreks.Core/Tools/RuCultureDate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Kysect.Shreks.Common.Exceptions;
using System.Globalization;

namespace Kysect.Shreks.Core.Tools;

public class RuCultureDate
{
public static DateOnly Parse(string? value)
{
if (!DateOnly.TryParse(value, CultureInfo.GetCultureInfo("ru-Ru"), DateTimeStyles.None, out DateOnly date))
throw new InvalidUserInputException($"Cannot parse input date ({value} as date. Ensure that you use correct format.");

return date;
}
}

0 comments on commit 3072995

Please sign in to comment.