* Store local time zone as UTC and do not throw validation error when stored time zone is different * Additional fixes when switching between date time editors with and without time zone * Additional fixes * Ensure that an update is triggered when the expected value does not match the stored value This will happen when switching between editors (with and without time zone) or switching between a specific time zone to the editor's local time zone. * Fix inconsistencies with null and undefined * Fix inconsistencies between date/time provided to the client and returned in the value converter (when switching between editors) * Fix unit tests and small bug * Adjust integration test * Small improvement * Update test data * Adjust logic so that time zone offsets are updated every time the date value changes * Do not pre-select time zone when switching between unspecified and time zone editors
35 lines
1.3 KiB
C#
35 lines
1.3 KiB
C#
using Microsoft.Extensions.Logging;
|
|
using Umbraco.Cms.Core.Models.PublishedContent;
|
|
using Umbraco.Cms.Core.Serialization;
|
|
|
|
namespace Umbraco.Cms.Core.PropertyEditors.ValueConverters;
|
|
|
|
/// <summary>
|
|
/// Provides a property value converter for date only datetime property editors.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// This is one of four property value converters derived from <see cref="DateTimeValueConverterBase"/> and storing their
|
|
/// value as JSON with timezone information.
|
|
/// </remarks>
|
|
public class DateOnlyValueConverter : DateTimeValueConverterBase
|
|
{
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="DateOnlyValueConverter"/> class.
|
|
/// </summary>
|
|
public DateOnlyValueConverter(IJsonSerializer jsonSerializer, ILogger<DateOnlyValueConverter> logger)
|
|
: base(jsonSerializer, logger)
|
|
{
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public override bool IsConverter(IPublishedPropertyType propertyType)
|
|
=> propertyType.EditorAlias == Constants.PropertyEditors.Aliases.DateOnly;
|
|
|
|
/// <inheritdoc />
|
|
public override Type GetPropertyValueType(IPublishedPropertyType propertyType) => typeof(DateOnly?);
|
|
|
|
/// <inheritdoc/>
|
|
protected override object ConvertToObject(DateTimeDto dateTimeDto)
|
|
=> DateOnly.FromDateTime(dateTimeDto.Date.DateTime);
|
|
}
|