Skip to content

Commit 010d47c

Browse files
Fixes U4-2822 Datepicker throws "Specified cast is not valid" when saving through API
1 parent 173ac65 commit 010d47c

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

src/Umbraco.Core/Models/Rdbms/PropertyDataDto.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ public object GetValue
6565
return Date.Value;
6666
}
6767

68-
if(!string.IsNullOrEmpty(VarChar))
68+
if(string.IsNullOrEmpty(VarChar) == false)
6969
{
7070
return VarChar;
7171
}
7272

73-
if(!string.IsNullOrEmpty(Text))
73+
if(string.IsNullOrEmpty(Text) == false)
7474
{
7575
return Text;
7676
}

src/umbraco.editorControls/datepicker/DateData.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,17 @@ public DateData(cms.businesslogic.datatype.BaseDataType DataType) : base(DataTyp
1111

1212
public override System.Xml.XmlNode ToXMl(System.Xml.XmlDocument d)
1313
{
14-
if (Value != null && Value.ToString() != "")
15-
return d.CreateTextNode(((DateTime) Value).ToString("s"));
16-
else
17-
return d.CreateTextNode("");
14+
if (Value != null && Value.ToString() != "")
15+
{
16+
if(Value is DateTime)
17+
return d.CreateTextNode(((DateTime) Value).ToString("s"));
18+
19+
DateTime convertedDate;
20+
if (DateTime.TryParse(Value.ToString(), out convertedDate))
21+
return d.CreateTextNode(convertedDate.ToString("s"));
22+
}
23+
24+
return d.CreateTextNode("");
1825
}
1926

2027
public override void MakeNew(int PropertyId)

0 commit comments

Comments
 (0)