Skip to content

Commit 2f7727a

Browse files
committed
Fixes: U4-3894 Date picker with time resets to "måndag januari 1, 0001" on Republish entire site
1 parent 5a9874b commit 2f7727a

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/Umbraco.Core/PropertyEditors/ValueConverters/DatePickerValueConverter.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,14 @@ public override object ConvertDataToSource(PublishedPropertyType propertyType, o
2626
if (source == null) return DateTime.MinValue;
2727

2828
// in XML a DateTime is: string - format "yyyy-MM-ddTHH:mm:ss"
29+
// Actually, not always sometimes it is formatted in UTC style with 'Z' suffixed on the end but that is due to this bug:
30+
// http://issues.umbraco.org/issue/U4-4145, http://issues.umbraco.org/issue/U4-3894
31+
// We should just be using TryConvertTo instead.
2932
var sourceString = source as string;
3033
if (sourceString != null)
3134
{
32-
DateTime value;
33-
return DateTime.TryParseExact(sourceString, "yyyy-MM-ddTHH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.None, out value)
34-
? value
35-
: DateTime.MinValue;
35+
var attempt = sourceString.TryConvertTo<DateTime>();
36+
return attempt.Success == false ? DateTime.MinValue : attempt.Result;
3637
}
3738

3839
// in the database a DateTime is: DateTime
@@ -47,7 +48,7 @@ public override object ConvertDataToSource(PublishedPropertyType propertyType, o
4748
public override object ConvertSourceToXPath(PublishedPropertyType propertyType, object source, bool preview)
4849
{
4950
// source should come from ConvertSource and be a DateTime already
50-
return XmlConvert.ToString((DateTime) source, "yyyy-MM-ddTHH:mm:ss");
51+
return XmlConvert.ToString((DateTime)source, XmlDateTimeSerializationMode.Unspecified);
5152
}
5253
}
5354
}

0 commit comments

Comments
 (0)