Repository navigation
Serializable DateTime
Ilia Petrov-Komotskii edited this page Oct 13, 2026
·
6 revisions
UTC DateTime stored as a round-trip ISO 8601 string, plus a start–end range. Inspector fields get a text row and a calendar popup. Those inspectors are Property Drawers, so they own the field; Decorators can still wrap it.
using System;
using Mane.Unity;
using UnityEngine;
public class SeasonWindow : MonoBehaviour
{
[SerializeField] private SerializableDateTime _opens;
[SerializeField] private SerializableDateTimeRange _active;
}
- Stored UTC. Invalid strings read as
DateTime.UtcNow. - Unspecified
DateTimeKindis treated as UTC. Local is converted withToUniversalTime. -
Normalizedrops seconds and smaller units. - Display format
yyyy-MM-dd HH:mm(DateTimeFormat); date-onlyyyyy-MM-dd(DateFormat). Both use the invariant culture.ToString()returns the display format.
DateTime utc = SerializableDateTime.ToUtc(local);
string iso = SerializableDateTime.FormatRoundTrip(utc);
SerializableDateTime.TryParse(iso, out DateTime parsed);
string display = SerializableDateTime.FormatDisplay(utc); // 2026-10-09 14:30
string date = SerializableDateTime.FormatDate(utc); // 2026-10-09Constructor swaps bounds if start is after end. Default range is now → a week later. StartString / EndString expose the raw ISO strings.
The inspector button opens CalendarPopup (Mane.Unity.Editor): month grid, hour/minute sliders, UTC and local labels. Range mode has Start/End toggles; picking a start switches to end.
From editor code:
using Mane.Unity.Editor;
CalendarPopup.Show(DateTime.UtcNow, dt => Debug.Log(dt));
CalendarPopup.ShowRange(range, updated => serializedObject.ApplyModifiedProperties());

openupm add com.manefunction.tools-unity