Skip to content

Commit fd88cce

Browse files
committed
Field default values of DateOnly/TimeOnly support
1 parent 376d78a commit fd88cce

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

Orm/Xtensive.Orm/Orm/Building/Builders/ValueTypeBuilder.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2011-2020 Xtensive LLC.
1+
// Copyright (C) 2011-2020 Xtensive LLC.
22
// This code is distributed under MIT license terms.
33
// See the License.txt file in the project root for more information.
44
// Created by: Denis Krjuchkov
@@ -58,6 +58,22 @@ private static object AdjustValue(string fieldName, Type fieldType, object value
5858
timespan = TimeSpan.FromTicks(ticks);
5959
return timespan;
6060
}
61+
#if NET6_0_OR_GREATER //DO_DATEONLY
62+
63+
if (valueType == WellKnownTypes.TimeOnly) {
64+
if (value is string timeOnlyString && !TimeOnly.TryParse(timeOnlyString, out var timeOnly)) {
65+
throw FailToParseValue(fieldName, timeOnlyString);
66+
}
67+
return timeOnly;
68+
}
69+
70+
if (valueType == WellKnownTypes.DateOnly) {
71+
if (value is string dateOnlyString && !DateOnly.TryParse(dateOnlyString, out var dateOnly)) {
72+
throw FailToParseValue(fieldName, dateOnlyString);
73+
}
74+
return dateOnly;
75+
}
76+
#endif
6177

6278
return Convert.ChangeType(value, valueType);
6379
}

0 commit comments

Comments
 (0)