Skip to content

Commit

Permalink
Add extra check if this is a sortable date on import parsing of dates.
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinJump committed Oct 12, 2023
1 parent ec3c834 commit 1adb4b5
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions uSync8.ContentEdition/Mapping/Mappers/DateMapper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Globalization;

using Umbraco.Core.Services;

Expand Down Expand Up @@ -36,8 +37,16 @@ private string GetFormattedDateFromValue(object value)
{
return date.ToString("s");
}

// try and read it exactly, as a sortable date.
var culture = new CultureInfo("en-US");
if (DateTime.TryParseExact(value.ToString(), "s", culture, DateTimeStyles.None, out date))
{
return date.ToString("s");
}
else if (DateTime.TryParse(value.ToString(), out date))
{
// when we are coming from Umbraco it might be the date is parse-able.
return date.ToString("s");
}

Expand Down

0 comments on commit 1adb4b5

Please sign in to comment.