Skip to content

Commit 36e0af2

Browse files
committed
[IMP] web: accurate relative dates and rename RemainingDaysField
Luxon is not very accurate when the field is close to today: If today is Apr 30, so a deadline set to May 1 will be displayed as "Next month". In practice, it is not wrong, but it is not very accurate. The widget name 'RemainingDaysField' was misleading as it implies a focus on future countdowns, whereas the widget is also used for past dates. task-6175442
1 parent 86f0ea6 commit 36e0af2

2 files changed

Lines changed: 18 additions & 9 deletions

File tree

content/applications/studio/fields.rst

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ Date (`date`)
190190

191191
The :guilabel:`Date` field is used to select a date on a calendar.
192192

193-
- :guilabel:`Remaining Days`: the remaining number of days before the selected date is displayed
193+
- :guilabel:`Relative Date`: the remaining number of days before the selected date is displayed
194194
(e.g., *In 5 days*), based on the current date. This field should be set to :guilabel:`Read only`.
195195

196196
.. example::
@@ -255,12 +255,13 @@ To add a date range:
255255
.. image:: fields/date-time-examples.png
256256
:alt: Examples of Date & Time fields with different widgets
257257

258-
Remaining Days (`remaining_days`)
259-
*********************************
258+
Relative Date (`relative_date`)
259+
*******************************
260260

261-
The :guilabel:`Remaining Days` widget displays the remaining number of days before the selected date
262-
(e.g., *In 5 days*), based on the current date and time. This field should be set to :guilabel:`Read
263-
only`.
261+
The :guilabel:`Relative Date` widget displays displays a human-readable relative calendar string
262+
computed from the difference between the field value and today (e.g. *"yesterday"*, *"today"*,
263+
*"in 3 days"*, *"next month"*). The exact format depends on the magnitude of the difference.
264+
This field should be set to :guilabel:`Readonly`.
264265

265266
.. _studio/fields/simple-fields-checkbox:
266267

content/developer/reference/frontend/javascript_reference.rst

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -808,10 +808,18 @@ Date Range (`daterange`)
808808
809809
<field name="start_date" widget="daterange" options="{'end_date_field': 'end_date'}" />
810810
811-
Remaining Days (`remaining_days`)
811+
Relative Date (`relative_date`)
812812
This widget can be used on date and datetime fields. In readonly, it displays
813-
the delta (in days) between the value of the field and today. The widget turns
814-
into a regular date or datetime field in edit mode.
813+
a human-readable relative calendar string computed from the difference between
814+
the field value and today (e.g. *"yesterday"*, *"today"*, *"in 3 days"*,
815+
*"next month"*). The exact format depends on the magnitude of the difference:
816+
817+
- Within ±30 days: the unit is forced to *days* (e.g. *"in 5 days"*, *"3 days ago"*).
818+
- Between 31 and 99 days: Luxon picks the most appropriate unit automatically
819+
(e.g. *"next month"*, *"2 months ago"*).
820+
- Beyond ±99 days: the widget falls back to the formatted date string.
821+
822+
In edit mode the widget falls back to a regular date/datetime field.
815823

816824
- Supported field types: `date`, `datetime`
817825

0 commit comments

Comments
 (0)