-
Notifications
You must be signed in to change notification settings - Fork 808
Document the new Date Time property editors #7431
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 16 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
b067b9c
Added documentation for new 'Date Time (with Time Zone)' property editor
lauraneto fbe9855
Added documentation for new 'Date Time (Unspecified)' property editor
lauraneto 7e0d4f3
Added documentation for new 'Date Only' property editor
lauraneto 995b8e4
Added documentation for new 'Time Only' property editor
lauraneto b0b942a
Updated code samples
lauraneto 9ad68fb
Small adjustments
lauraneto 49be45c
Small adjustments following the linter feedback
lauraneto 096780c
Placed the new date time editors in their own folder. Additional adjuβ¦
lauraneto 9453fbb
Add new documents to the navigation
lauraneto 9417e64
Adjust the date time editor page to display the different types as a β¦
lauraneto 2a04b62
Move the new pages in the navigation next to the current DateTime
lauraneto 48bbf54
Additional adjustments. Removed page about non existing 'Date' properβ¦
lauraneto 2e2f1a4
Merge branch 'main' into cms/new-date-time-property-editors
lauraneto 347e674
Add a hint to the existing Date Time property editor pointing to the β¦
lauraneto fddf579
Merge branch 'main' into cms/new-date-time-property-editors
lauraneto 65a452b
Move changes to the new 17 folder
lauraneto 7d1cd93
Update 17/umbraco-cms/fundamentals/backoffice/property-editors/built-β¦
eshanrnh b042048
Update 17/umbraco-cms/fundamentals/backoffice/property-editors/built-β¦
eshanrnh 523aaf9
Update 17/umbraco-cms/fundamentals/backoffice/property-editors/built-β¦
eshanrnh 340e9c1
Update 17/umbraco-cms/fundamentals/backoffice/property-editors/built-β¦
eshanrnh 7630452
Update 17/umbraco-cms/fundamentals/backoffice/property-editors/built-β¦
eshanrnh f1a2ced
Update 17/umbraco-cms/fundamentals/backoffice/property-editors/built-β¦
eshanrnh d6c6342
Update 17/umbraco-cms/fundamentals/backoffice/property-editors/built-β¦
eshanrnh 1b583c1
Update 17/umbraco-cms/fundamentals/backoffice/property-editors/built-β¦
eshanrnh 2eb914b
Update 17/umbraco-cms/fundamentals/backoffice/property-editors/built-β¦
eshanrnh ff1aa35
Update 17/umbraco-cms/fundamentals/backoffice/property-editors/built-β¦
eshanrnh a45495c
Update 17/umbraco-cms/fundamentals/backoffice/property-editors/built-β¦
eshanrnh a851ebc
Update 17/umbraco-cms/fundamentals/backoffice/property-editors/built-β¦
eshanrnh f5280ae
Update 17/umbraco-cms/fundamentals/backoffice/property-editors/built-β¦
eshanrnh 8b58f66
Update 17/umbraco-cms/fundamentals/backoffice/property-editors/built-β¦
eshanrnh ddd0aac
Update 17/umbraco-cms/fundamentals/backoffice/property-editors/built-β¦
eshanrnh 152dac8
Added redirect for date.md
eshanrnh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
...e/property-editors/built-in-umbraco-property-editors/date-time-editor/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Date Time Editors | ||
|
||
The Date Time property editors provide interfaces for selecting dates, times, and time zones. Each editor is designed for specific use cases, from basic date selection to comprehensive date/time handling with time zone support. | ||
|
||
{% hint style="info" %} | ||
These property editors supersede the [Date Time](../date-time.md) property editor, offering more focused functionality and specific return types (like `DateOnly`, `TimeOnly`, `DateTime`, or `DateTimeOffset`). You can switch from the legacy Date Time editor by changing your properties to use the new editors. | ||
{% endhint %} | ||
|
||
Umbraco CMS currently ships with four Date Time editors: | ||
|
||
| Editor | Purpose | Use Cases | Return Type | Preview | | ||
|--------|---------|-----------|-------------|---------| | ||
| [Date Only](date-only.md) | Date selection | Birthdays, deadlines, event dates | `DateOnly` |  | | ||
| [Time Only](time-only.md) | Time selection | Business hours, schedules, time-based events | `TimeOnly` |  | | ||
| [Date Time (with Time Zone)](date-time-with-time-zone.md) | Full date, time, and timezone support | International apps, timezone-aware scheduling | `DateTimeOffset` |  | | ||
eshanrnh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| [Date Time (Unspecified)](date-time-unspecified.md) | Date and time without a defined time zone | Local events, compatibility with [Date Time](../date-time.md) | `DateTime` |  | |
110 changes: 110 additions & 0 deletions
110
...roperty-editors/built-in-umbraco-property-editors/date-time-editor/date-only.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
# Date Only | ||
|
||
`Schema Alias: Umbraco.DateOnly` | ||
|
||
`UI Alias: Umb.PropertyEditorUi.DateOnlyPicker` | ||
|
||
`Returns: DateOnly?` | ||
|
||
The Date Only property editor provides an interface for selecting dates without time or time zone information. It focuses purely on date selection and returns `DateOnly` values. | ||
eshanrnh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
## Configuration | ||
You can configure this property editor in the same way as any standard property editor, using the *Data Types* admin interface. | ||
|
||
To set up a property using this editor, create a new *Data Type* and select **Date Only** from the list of available property editors. | ||
|
||
This editor has no configuration options. | ||
|
||
## Editing experience | ||
|
||
### Adding or editing a value | ||
|
||
You will be presented with a date input. | ||
|
||
 | ||
|
||
## Rendering | ||
|
||
The value returned will have the type `DateOnly?`. | ||
|
||
### Display the value | ||
|
||
With Models Builder: | ||
```csharp | ||
@Model.EventDate | ||
``` | ||
|
||
Without Models Builder: | ||
```csharp | ||
@Model.Value<DateOnly?>("eventDate") | ||
``` | ||
|
||
## Add values programmatically | ||
|
||
This property editor stores values as a JSON object. The object contains the date as an ISO 8601 string with midnight time and UTC offset. | ||
|
||
### Storage format | ||
|
||
The property editor stores values in this JSON format: | ||
```json | ||
{ | ||
"date": "2025-01-01T00:00:00+00:00" | ||
} | ||
``` | ||
|
||
The property editor handles date-only values. Time is set to 00:00:00 and offset to +00:00 for storage consistency. These time components are ignored in Date Only context. | ||
eshanrnh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
1. Create a C# model that matches the JSON schema. | ||
|
||
```csharp | ||
using System.Text.Json.Serialization; | ||
|
||
namespace UmbracoProject; | ||
|
||
public class DateOnlyValue | ||
{ | ||
/// <summary> | ||
/// The date value, represented as a <see cref="DateTimeOffset"/> for storage compatibility. | ||
/// </summary> | ||
[JsonPropertyName("date")] | ||
public DateTimeOffset Date { get; init; } | ||
} | ||
``` | ||
2. Convert your existing date value to `DateTimeOffset` for storage. | ||
|
||
If you have a `DateOnly`: | ||
```csharp | ||
DateOnly dateOnly = DateOnly.FromDateTime(DateTime.Today); // Your existing DateOnly value | ||
DateTimeOffset dateTimeOffset = dateOnly.ToDateTime(TimeOnly.MinValue); | ||
``` | ||
|
||
If you have a `DateTime`: | ||
```csharp | ||
DateTime dateTime = DateTime.Today; // Your existing DateTime value | ||
DateOnly dateOnly = DateOnly.FromDateTime(dateTime); | ||
DateTimeOffset dateTimeOffset = dateOnly.ToDateTime(TimeOnly.MinValue); | ||
``` | ||
|
||
3. Create an instance of the class with the `DateTimeOffset` value. | ||
```csharp | ||
DateOnlyValue value = new DateOnlyValue | ||
{ | ||
Date = dateTimeOffset | ||
}; | ||
``` | ||
|
||
4. Inject the `IJsonSerializer` and use it to serialize the object. | ||
```csharp | ||
string jsonValue = _jsonSerializer.Serialize(value); | ||
``` | ||
|
||
5. Inject the `IContentService` to retrieve and update the value of a property of the desired content item. | ||
```csharp | ||
IContent content = _contentService.GetById(contentKey) ?? throw new Exception("Content not found"); | ||
|
||
// Set the value of the property with alias 'eventDate'. | ||
content.SetValue("eventDate", jsonValue); | ||
|
||
// Save the change | ||
_contentService.Save(content); | ||
``` |
115 changes: 115 additions & 0 deletions
115
...ors/built-in-umbraco-property-editors/date-time-editor/date-time-unspecified.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
# Date Time (Unspecified) | ||
|
||
`Schema Alias: Umbraco.DateTimeUnspecified` | ||
|
||
`UI Alias: Umb.PropertyEditorUi.DateTimePicker` | ||
|
||
`Returns: DateTime?` | ||
|
||
The Date Time (Unspecified) property editor provides a comprehensive interface for selecting dates and times. It excludes time zone information. | ||
eshanrnh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
## Configuration | ||
You can configure this property editor in the same way as any standard property editor, using the *Data Types* admin interface. | ||
|
||
To set up a property using this editor, create a new *Data Type* and select **Date Time (unspecified)** from the list of available property editors. | ||
eshanrnh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
You will see the configuration options as shown below. | ||
|
||
 | ||
|
||
- **Time format** - Specifies the level of precision for time values shown and stored by the editor. | ||
|
||
### Time format | ||
|
||
- **HH:mm** - Displays hours and minutes (e.g., `14:30`). | ||
Suitable for most general use cases. | ||
 | ||
- **HH:mm:ss** - Displays hours, minutes, and seconds (e.g., `14:30:45`). | ||
Use this when you need more precise timing. | ||
 | ||
|
||
## Editing experience | ||
|
||
### Adding or editing a value | ||
|
||
You will be presented with a date and time input. This editor focuses only on the date and time components, unlike the time zone version. | ||
|
||
 | ||
|
||
## Rendering | ||
|
||
The value returned will have the type `DateTime?`. | ||
|
||
### Display the value | ||
|
||
With Models Builder: | ||
```csharp | ||
@Model.EventDateTime.Value | ||
``` | ||
|
||
Without Models Builder: | ||
```csharp | ||
@Model.Value<DateTime?>("eventDateTime") | ||
``` | ||
|
||
## Add values programmatically | ||
|
||
This property editor stores values as a JSON object. The object contains the date as an ISO 8601 string. | ||
|
||
### Storage format | ||
|
||
The property editor stores values in this JSON format: | ||
```json | ||
{ | ||
"date": "2025-01-01T00:00:00+00:00" | ||
} | ||
``` | ||
|
||
The property editor handles unspecified date times with no time zone information. The value is stored with offset +00:00 for consistency. The offset is ignored unless you replace this editor with the Date Time (with time zone) version. | ||
eshanrnh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
1. Create a C# model that matches the JSON schema. | ||
|
||
```csharp | ||
using System.Text.Json.Serialization; | ||
|
||
namespace UmbracoProject; | ||
|
||
public class DateTimeUnspecified | ||
{ | ||
/// <summary> | ||
/// The date and time value, represented as a <see cref="DateTimeOffset"/> for storage compatibility. | ||
/// </summary> | ||
[JsonPropertyName("date")] | ||
public DateTimeOffset Date { get; init; } | ||
} | ||
``` | ||
|
||
2. Convert your existing DateTime value to `DateTimeOffset` for storage. | ||
```csharp | ||
DateTime dateTime = DateTime.Now; // Your existing DateTime value | ||
DateTimeOffset dateTimeOffset = dateTime; // Explicit conversion | ||
``` | ||
|
||
3. Create an instance of the class with the `DateTimeOffset` value. | ||
```csharp | ||
var value = new DateTimeUnspecified | ||
{ | ||
Date = dateTimeOffset | ||
}; | ||
``` | ||
|
||
4. Inject the `IJsonSerializer` and use it to serialize the object. | ||
```csharp | ||
string jsonValue = _jsonSerializer.Serialize(value); | ||
``` | ||
|
||
5. Inject the `IContentService` to retrieve and update the value of a property of the desired content item. | ||
```csharp | ||
IContent content = _contentService.GetById(contentKey) ?? throw new Exception("Content not found"); | ||
|
||
// Set the value of the property with alias 'eventDateTime'. | ||
content.SetValue("eventDateTime", jsonValue); | ||
|
||
// Save the change | ||
_contentService.Save(content); | ||
``` |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.