@rio-cloud/uikit-mcp 1.1.10 → 1.1.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/dist/doc-metadata.json +92 -92
- package/dist/docs/components/accentBar.md +1 -1
- package/dist/docs/components/activity.md +1 -1
- package/dist/docs/components/analyticsAnalysisOverlay.md +3 -1
- package/dist/docs/components/animatedNumber.md +2 -2
- package/dist/docs/components/animatedTextReveal.md +6 -6
- package/dist/docs/components/animations.md +22 -22
- package/dist/docs/components/appHeader.md +1 -1
- package/dist/docs/components/appLayout.md +31 -65
- package/dist/docs/components/appNavigationBar.md +1 -1
- package/dist/docs/components/areaCharts.md +7 -5
- package/dist/docs/components/aspectRatioPlaceholder.md +1 -1
- package/dist/docs/components/assetTree.md +160 -142
- package/dist/docs/components/autosuggests.md +1 -1
- package/dist/docs/components/avatar.md +1 -1
- package/dist/docs/components/banner.md +2 -2
- package/dist/docs/components/barCharts.md +16 -14
- package/dist/docs/components/barList.md +9 -9
- package/dist/docs/components/basicMap.md +45 -1
- package/dist/docs/components/bottomSheet.md +1 -1
- package/dist/docs/components/button.md +1 -1
- package/dist/docs/components/buttonToolbar.md +1 -1
- package/dist/docs/components/calendarStripe.md +56 -56
- package/dist/docs/components/card.md +1 -1
- package/dist/docs/components/carousel.md +1 -1
- package/dist/docs/components/chartColors.md +3 -1
- package/dist/docs/components/chartsGettingStarted.md +3 -1
- package/dist/docs/components/chat.md +1 -1
- package/dist/docs/components/checkbox.md +3 -1
- package/dist/docs/components/circularProgress.md +5 -5
- package/dist/docs/components/clearableInput.md +1 -1
- package/dist/docs/components/collapse.md +4 -2
- package/dist/docs/components/composedCharts.md +17 -15
- package/dist/docs/components/contentLoader.md +1 -1
- package/dist/docs/components/dataTabs.md +1 -1
- package/dist/docs/components/datepickers.md +662 -660
- package/dist/docs/components/dayPicker.md +55 -5
- package/dist/docs/components/dayPickerCalendar.md +488 -468
- package/dist/docs/components/dialogs.md +1 -1
- package/dist/docs/components/divider.md +1 -1
- package/dist/docs/components/dropdowns.md +3270 -3244
- package/dist/docs/components/editableContent.md +1 -1
- package/dist/docs/components/expander.md +1 -1
- package/dist/docs/components/fade.md +1 -1
- package/dist/docs/components/fadeExpander.md +1 -1
- package/dist/docs/components/fadeUp.md +2 -2
- package/dist/docs/components/feedback.md +1 -1
- package/dist/docs/components/filePickers.md +1 -1
- package/dist/docs/components/formLabel.md +1 -1
- package/dist/docs/components/groupedItemList.md +1 -1
- package/dist/docs/components/htmlTable.md +113 -115
- package/dist/docs/components/iconList.md +3 -3
- package/dist/docs/components/imagePreloader.md +1 -1
- package/dist/docs/components/labeledElement.md +1 -1
- package/dist/docs/components/licensePlate.md +1 -1
- package/dist/docs/components/lineCharts.md +6 -4
- package/dist/docs/components/listMenu.md +1 -1
- package/dist/docs/components/loadMore.md +1 -1
- package/dist/docs/components/mainNavigation.md +1 -1
- package/dist/docs/components/mapCircle.md +1 -1
- package/dist/docs/components/mapCluster.md +3 -1
- package/dist/docs/components/mapContext.md +1 -1
- package/dist/docs/components/mapDraggableMarker.md +1 -1
- package/dist/docs/components/mapGettingStarted.md +39 -1
- package/dist/docs/components/mapInfoBubble.md +1 -1
- package/dist/docs/components/mapLayerGroup.md +1 -1
- package/dist/docs/components/mapMarker.md +3 -1
- package/dist/docs/components/mapPolygon.md +1 -1
- package/dist/docs/components/mapRoute.md +1 -1
- package/dist/docs/components/mapSettings.md +36 -9
- package/dist/docs/components/mapUtils.md +65 -2
- package/dist/docs/components/mapViewportHistory.md +287 -0
- package/dist/docs/components/multiselects.md +171 -1
- package/dist/docs/components/noData.md +1 -1
- package/dist/docs/components/notifications.md +1 -1
- package/dist/docs/components/numbercontrol.md +1 -1
- package/dist/docs/components/onboarding.md +1 -1
- package/dist/docs/components/page.md +1 -1
- package/dist/docs/components/pager.md +1 -1
- package/dist/docs/components/pieCharts.md +38 -36
- package/dist/docs/components/popover.md +1 -1
- package/dist/docs/components/position.md +1 -1
- package/dist/docs/components/radialBarCharts.md +27 -25
- package/dist/docs/components/radioCardGroup.md +1 -1
- package/dist/docs/components/radiobutton.md +3 -1
- package/dist/docs/components/releaseNotes.md +1 -1
- package/dist/docs/components/resizer.md +3 -1
- package/dist/docs/components/responsiveColumnStripe.md +3 -1
- package/dist/docs/components/responsiveVideo.md +1 -1
- package/dist/docs/components/rioglyph.md +1 -1
- package/dist/docs/components/rules.md +1 -1
- package/dist/docs/components/saveableInput.md +247 -247
- package/dist/docs/components/selects.md +168 -51
- package/dist/docs/components/sidebar.md +1 -1
- package/dist/docs/components/sliders.md +1 -1
- package/dist/docs/components/smoothScrollbars.md +3 -1
- package/dist/docs/components/spinners.md +1 -1
- package/dist/docs/components/states.md +15 -1
- package/dist/docs/components/statsWidgets.md +1 -1
- package/dist/docs/components/statusBar.md +3 -1
- package/dist/docs/components/stepButton.md +1 -1
- package/dist/docs/components/steppedProgressBars.md +1 -1
- package/dist/docs/components/subNavigation.md +1 -1
- package/dist/docs/components/supportMarker.md +1 -1
- package/dist/docs/components/svgImage.md +1 -1
- package/dist/docs/components/switch.md +3 -1
- package/dist/docs/components/table.md +1998 -221
- package/dist/docs/components/tableControls.md +51 -51
- package/dist/docs/components/tagManager.md +1 -1
- package/dist/docs/components/tags.md +1 -1
- package/dist/docs/components/teaser.md +3 -1
- package/dist/docs/components/textTruncateMiddle.md +1 -1
- package/dist/docs/components/timeline.md +1 -1
- package/dist/docs/components/timepicker.md +3 -1
- package/dist/docs/components/toggleButton.md +1 -1
- package/dist/docs/components/tooltip.md +5 -1
- package/dist/docs/components/tracker.md +1 -1
- package/dist/docs/components/virtualList.md +58 -56
- package/dist/docs/foundations.md +271 -105
- package/dist/docs/start/changelog.md +44 -212
- package/dist/docs/start/goodtoknow.md +8 -2
- package/dist/docs/start/guidelines/color-combinations.md +5 -1
- package/dist/docs/start/guidelines/custom-css.md +26 -2
- package/dist/docs/start/guidelines/custom-rioglyph.md +20 -2
- package/dist/docs/start/guidelines/formatting.md +2256 -249
- package/dist/docs/start/guidelines/iframe.md +37 -1
- package/dist/docs/start/guidelines/obfuscate-data.md +26 -2
- package/dist/docs/start/guidelines/print-css.md +16 -2
- package/dist/docs/start/guidelines/spinner.md +1 -1
- package/dist/docs/start/guidelines/state-in-url.md +1138 -11
- package/dist/docs/start/guidelines/supported-browsers.md +9 -2
- package/dist/docs/start/guidelines/writing.md +228 -2
- package/dist/docs/start/howto.md +160 -10
- package/dist/docs/start/intro.md +40 -2
- package/dist/docs/start/responsiveness.md +29 -1
- package/dist/docs/templates/ai-assistant.md +1 -1
- package/dist/docs/templates/common-table.md +55 -55
- package/dist/docs/templates/detail-views.md +2 -2
- package/dist/docs/templates/expandable-details.md +1 -1
- package/dist/docs/templates/feature-cards.md +37 -37
- package/dist/docs/templates/form-summary.md +15 -15
- package/dist/docs/templates/form-toggle.md +1 -1
- package/dist/docs/templates/list-blocks.md +137 -137
- package/dist/docs/templates/loading-progress.md +1 -1
- package/dist/docs/templates/options-panel.md +1 -1
- package/dist/docs/templates/panel-variants.md +1 -1
- package/dist/docs/templates/progress-cards.md +1 -1
- package/dist/docs/templates/progress-success.md +1 -1
- package/dist/docs/templates/settings-form.md +18 -18
- package/dist/docs/templates/stats-blocks.md +10 -10
- package/dist/docs/templates/table-panel.md +1 -1
- package/dist/docs/templates/usage-cards.md +1 -1
- package/dist/docs/utilities/classNames.md +89 -1
- package/dist/docs/utilities/deviceUtils.md +1 -1
- package/dist/docs/utilities/featureToggles.md +182 -2
- package/dist/docs/utilities/fuelTypeUtils.md +1 -1
- package/dist/docs/utilities/getTrackingAttributes.md +46 -1
- package/dist/docs/utilities/routeUtils.md +210 -2
- package/dist/docs/utilities/useAfterMount.md +1 -1
- package/dist/docs/utilities/useAutoAnimate.md +1 -1
- package/dist/docs/utilities/useAverage.md +1 -1
- package/dist/docs/utilities/useClickOutside.md +1 -1
- package/dist/docs/utilities/useClipboard.md +2 -2
- package/dist/docs/utilities/useCookies.md +1 -1
- package/dist/docs/utilities/useCount.md +1 -1
- package/dist/docs/utilities/useDarkMode.md +1 -1
- package/dist/docs/utilities/useDebugInfo.md +3 -3
- package/dist/docs/utilities/useDraggableElement.md +1 -1
- package/dist/docs/utilities/useEffectOnce.md +1 -1
- package/dist/docs/utilities/useElapsedTime.md +1 -1
- package/dist/docs/utilities/useElementSize.md +1 -1
- package/dist/docs/utilities/useEsc.md +1 -1
- package/dist/docs/utilities/useEvent.md +1 -1
- package/dist/docs/utilities/useFocusTrap.md +1 -1
- package/dist/docs/utilities/useFullscreen.md +1 -1
- package/dist/docs/utilities/useHover.md +1 -1
- package/dist/docs/utilities/useIncomingPostMessages.md +1 -1
- package/dist/docs/utilities/useInterval.md +1 -1
- package/dist/docs/utilities/useIsFocusWithin.md +1 -1
- package/dist/docs/utilities/useKey.md +1 -1
- package/dist/docs/utilities/useLocalStorage.md +1 -1
- package/dist/docs/utilities/useLocationSuggestions.md +1 -1
- package/dist/docs/utilities/useMax.md +1 -1
- package/dist/docs/utilities/useMin.md +1 -1
- package/dist/docs/utilities/useMutationObserver.md +1 -1
- package/dist/docs/utilities/useOnScreen.md +1 -1
- package/dist/docs/utilities/useOnlineStatus.md +1 -1
- package/dist/docs/utilities/usePostMessage.md +1 -1
- package/dist/docs/utilities/usePostMessageSender.md +1 -1
- package/dist/docs/utilities/usePrevious.md +111 -1
- package/dist/docs/utilities/useResizeObserver.md +1 -1
- package/dist/docs/utilities/useRioCookieConsent.md +1 -1
- package/dist/docs/utilities/useScrollPosition.md +1 -1
- package/dist/docs/utilities/useSearch.md +1 -1
- package/dist/docs/utilities/useSearchHighlight.md +1 -1
- package/dist/docs/utilities/useSorting.md +1 -1
- package/dist/docs/utilities/useStateWithValidation.md +1 -1
- package/dist/docs/utilities/useSum.md +1 -1
- package/dist/docs/utilities/useTableExport.md +61 -61
- package/dist/docs/utilities/useTableSelection.md +72 -72
- package/dist/docs/utilities/useTimeout.md +1 -1
- package/dist/docs/utilities/useToggle.md +1 -1
- package/dist/docs/utilities/useUrlState.md +1 -1
- package/dist/docs/utilities/useWindowResize.md +1 -1
- package/dist/index.mjs +174 -70
- package/dist/search-synonyms.json +214 -76
- package/dist/version.json +2 -2
- package/package.json +8 -6
- package/dist/docs/components/mapRouteGenerator.md +0 -6
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*Category:* Getting started
|
|
4
4
|
*Section:* Guidelines
|
|
5
5
|
*Source:* https://uikit.developers.rio.cloud/#/start/guidelines/formatting
|
|
6
|
-
*Captured:* 2026-
|
|
6
|
+
*Captured:* 2026-05-06T12:13:09.245Z
|
|
7
7
|
|
|
8
8
|
Having a common date formatting guide is crucial to ensure consistency, clarity, and accuracy in documentation, making it easier to understand and interpret dates correctly across different contexts.
|
|
9
9
|
|
|
@@ -34,10 +34,41 @@ Having a common date formatting guide is crucial to ensure consistency, clarity,
|
|
|
34
34
|
|
|
35
35
|
## Date formats overview
|
|
36
36
|
|
|
37
|
+
Date formats overview
|
|
38
|
+
|
|
37
39
|
This is a list of all supported langues and their respective date format showcasing also similar locales sharing the same format.
|
|
38
40
|
|
|
41
|
+
| Locale | Country | Date Format | Example |
|
|
42
|
+
| --- | --- | --- | --- |
|
|
43
|
+
| bg-BG | Bulgarian | DD.MM.YYYY | 20.05.2024 |
|
|
44
|
+
| cs-CZ | Czech | DD.MM.YYYY | 20.05.2024 |
|
|
45
|
+
| da-DK | Danish | DD-MM-YYYY | 20-05-2024 |
|
|
46
|
+
| de-DE | German | DD.MM.YYYY | 20.05.2024 |
|
|
47
|
+
| el-GR | Greek | DD/MM/YYYY | 20/05/2024 |
|
|
48
|
+
| en-GB | English UK | DD/MM/YYYY | 20/05/2024 |
|
|
49
|
+
| es-ES | Spanish | DD/MM/YYYY | 20/05/2024 |
|
|
50
|
+
| et-EE | Estonian | DD.MM.YYYY | 20.05.2024 |
|
|
51
|
+
| fi-FI | Finnish | DD.MM.YYYY | 20.05.2024 |
|
|
52
|
+
| fr-FR | French | DD/MM/YYYY | 20/05/2024 |
|
|
53
|
+
| hr-HR | Croatian | DD.MM.YYYY | 20.05.2024 |
|
|
54
|
+
| hu-HU | Hungarian | YYYY. MM. DD. | 2024. 05. 20. |
|
|
55
|
+
| it-IT | Italian | DD/MM/YYYY | 20/05/2024 |
|
|
56
|
+
| lt-LT | Lithuanian | DD-MM-YYYY | 20-05-2024 |
|
|
57
|
+
| lv-LV | Latvian | DD.MM.YYYY | 20.05.2024 |
|
|
58
|
+
| nb-NO | Norwegian Bokmål | DD.MM.YYYY | 20.05.2024 |
|
|
59
|
+
| nl-NL | Dutch | DD-MM-YYYY | 20-05-2024 |
|
|
60
|
+
| pl-PL | Polish | DD.MM.YYYY | 20.05.2024 |
|
|
61
|
+
| pt-BR | Brazilian Portuguese | DD/MM/YYYY | 20/05/2024 |
|
|
62
|
+
| pt-PT | Portuguese | DD/MM/YYYY | 20/05/2024 |
|
|
63
|
+
| ro-RO | Romanian | DD.MM.YYYY | 20.05.2024 |
|
|
64
|
+
| sk-SK | Slovak | DD.MM.YYYY | 20.05.2024 |
|
|
65
|
+
| sl-SI | Slovenian | DD.MM.YYYY | 20.05.2024 |
|
|
66
|
+
| sv-SE | Swedish | YYYY-MM-DD | 2024-05-20 |
|
|
67
|
+
|
|
39
68
|
## If nothing else is specified use the default date format: YYYY-MM-DD
|
|
40
69
|
|
|
70
|
+
If nothing else is specified use the default date format: YYYY-MM-DD
|
|
71
|
+
|
|
41
72
|
This format is defined in the ISO 8601 standard, which is maintained by the International Organization for Standardization (ISO). It's widely used for data exchange and communication because it:
|
|
42
73
|
|
|
43
74
|
- Sorts chronologically: Dates appear in order when sorted alphabetically (e.g., 2023-12-31 comes before 2024-01-01).
|
|
@@ -55,6 +86,8 @@ If nothing else is specified use the default date format otherwise use the date
|
|
|
55
86
|
|
|
56
87
|
## Avoid the American date format: MM/DD/YYYY
|
|
57
88
|
|
|
89
|
+
Avoid the American date format: MM/DD/YYYY
|
|
90
|
+
|
|
58
91
|
While there's nothing inherently wrong with the American date format (MM/DD/YYYY), it's recommended to avoid it as the default for the following reasons:
|
|
59
92
|
|
|
60
93
|
- Non-standard: It's not the international standard format defined by ISO 8601 (YYYY-MM-DD). This can lead to confusion and potential errors when exchanging data or collaborating with international teams.
|
|
@@ -68,6 +101,8 @@ Be aware that some date picker components might default to the American format (
|
|
|
68
101
|
|
|
69
102
|
## Use the Intl.DateTimeFormat to format dates for all locales
|
|
70
103
|
|
|
104
|
+
Use the Intl.DateTimeFormat to format dates for all locales
|
|
105
|
+
|
|
71
106
|
When formatting dates in React applications, you have two choices:
|
|
72
107
|
|
|
73
108
|
- Vanilla Intl.DateTimeFormat: Use the standard function.
|
|
@@ -77,10 +112,14 @@ Regardless of the chosen method (direct function or ReactIntl), you'll have acce
|
|
|
77
112
|
|
|
78
113
|
The default date and time format for the default locale "en-GB" looks like this: 27/05/2024
|
|
79
114
|
|
|
115
|
+
27/05/2024
|
|
116
|
+
|
|
80
117
|
```jsx
|
|
81
118
|
<FormattedDate value={new Date()} year='numeric' month='2-digit' day='2-digit' />
|
|
82
119
|
```
|
|
83
120
|
|
|
121
|
+
<FormattedDate value={new Date()} year='numeric' month='2-digit' day='2-digit' />
|
|
122
|
+
|
|
84
123
|
```javascript
|
|
85
124
|
const formatDate = (date, locale) => {
|
|
86
125
|
const options = {
|
|
@@ -107,339 +146,1791 @@ console.log(`Locale: ${locale}, Formatted date: ${formattedDate}`);
|
|
|
107
146
|
});
|
|
108
147
|
```
|
|
109
148
|
|
|
110
|
-
|
|
149
|
+
const
|
|
111
150
|
|
|
112
|
-
|
|
151
|
+
formatDate
|
|
113
152
|
|
|
114
|
-
|
|
115
|
-
() => {
|
|
116
|
-
const yesterday = new Date();
|
|
117
|
-
yesterday.setDate(new Date().getDate() - 1);
|
|
153
|
+
=
|
|
118
154
|
|
|
119
|
-
|
|
120
|
-
})
|
|
121
|
-
```
|
|
155
|
+
(
|
|
122
156
|
|
|
123
|
-
|
|
157
|
+
date, locale
|
|
124
158
|
|
|
125
|
-
|
|
159
|
+
)
|
|
126
160
|
|
|
127
|
-
|
|
128
|
-
- While some countries might use a 12-hour format in informal contexts, the 24-hour format is generally preferred for official communication and technical applications.
|
|
161
|
+
=>
|
|
129
162
|
|
|
130
|
-
|
|
163
|
+
{
|
|
131
164
|
|
|
132
|
-
|
|
133
|
-
<FormattedDate value={new Date()} year='numeric' month='2-digit' day='2-digit' hour='2-digit' minute='2-digit' />
|
|
134
|
-
```
|
|
165
|
+
const
|
|
135
166
|
|
|
136
|
-
|
|
137
|
-
const formatDateTime = (date, locale) => {
|
|
138
|
-
const options = {
|
|
139
|
-
year: 'numeric',
|
|
140
|
-
month: '2-digit',
|
|
141
|
-
day: '2-digit',
|
|
142
|
-
hour: '2-digit',
|
|
143
|
-
minute: '2-digit'
|
|
144
|
-
};
|
|
167
|
+
=
|
|
145
168
|
|
|
146
|
-
|
|
147
|
-
return dateTimeFormatter.format(date);
|
|
148
|
-
}
|
|
169
|
+
{
|
|
149
170
|
|
|
150
|
-
|
|
151
|
-
'bg-BG', 'cs-CZ', 'da-DK', 'el-GR', 'es-ES', 'et-EE', 'fi-FI', 'fr-FR',
|
|
152
|
-
'hr-HR', 'hu-HU', 'it-IT', 'lt-LT', 'lv-LV', 'nb-NO', 'nl-NL', 'pl-PL',
|
|
153
|
-
'pt-PT', 'ro-RO', 'sk-SK', 'sl-SI', 'sv-SE', 'de-DE', 'pt-BR', 'en-GB'
|
|
154
|
-
];
|
|
171
|
+
year
|
|
155
172
|
|
|
156
|
-
|
|
173
|
+
:
|
|
157
174
|
|
|
158
|
-
|
|
159
|
-
const formattedDateTime = formatDateTime(today, locale);
|
|
160
|
-
console.log(`Locale: ${locale}, Formatted date time: ${formattedDateTime}`);
|
|
161
|
-
});
|
|
162
|
-
```
|
|
175
|
+
'numeric'
|
|
163
176
|
|
|
164
|
-
|
|
177
|
+
,
|
|
165
178
|
|
|
166
|
-
|
|
179
|
+
month
|
|
167
180
|
|
|
168
|
-
|
|
169
|
-
- Thursday, 23 May 2024
|
|
170
|
-
- 12 Feb - 16 Feb 2024
|
|
181
|
+
:
|
|
171
182
|
|
|
172
|
-
|
|
173
|
-
() => {
|
|
174
|
-
const yesterday = new Date();
|
|
175
|
-
yesterday.setDate(new Date().getDate() - 1);
|
|
183
|
+
'2-digit'
|
|
176
184
|
|
|
177
|
-
|
|
178
|
-
<>
|
|
179
|
-
{'Today, '}
|
|
180
|
-
<FormattedDate value={new Date()} year='numeric' month='short' day='numeric' />
|
|
181
|
-
<br />
|
|
182
|
-
<FormattedDate value={yesterday} year='numeric' month='short' day='numeric' weekday='long' />
|
|
183
|
-
</>
|
|
184
|
-
);
|
|
185
|
-
})
|
|
186
|
-
```
|
|
185
|
+
,
|
|
187
186
|
|
|
188
|
-
|
|
189
|
-
function formatDateWithWeekday(date) {
|
|
190
|
-
const today = new Date();
|
|
191
|
-
const isToday =
|
|
192
|
-
today.getDate() === date.getDate() &&
|
|
193
|
-
today.getMonth() === date.getMonth() &&
|
|
194
|
-
today.getFullYear() === date.getFullYear();
|
|
187
|
+
day
|
|
195
188
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
year: 'numeric',
|
|
200
|
-
weekday: isToday ? undefined : 'long',
|
|
201
|
-
};
|
|
189
|
+
:
|
|
190
|
+
|
|
191
|
+
'2-digit'
|
|
202
192
|
|
|
203
|
-
const dateTimeFormatter = new Intl.DateTimeFormat('en-GB', options);
|
|
204
|
-
return isToday ? `Today, ${dateTimeFormatter.format(date)}` : dateTimeFormatter.format(date);
|
|
205
193
|
}
|
|
206
194
|
|
|
207
|
-
|
|
208
|
-
const today = new Date();
|
|
209
|
-
const formattedDate = formatDateWithWeekday(today);
|
|
210
|
-
console.log(formattedDate);
|
|
195
|
+
;
|
|
211
196
|
|
|
212
|
-
|
|
213
|
-
const yesterday = new Date();
|
|
214
|
-
yesterday.setDate(today.getDate() - 1); // Subtract 1 day from today
|
|
215
|
-
const formattedDateYesterday = formatDateWithWeekday(yesterday);
|
|
216
|
-
console.log(formattedDateYesterday);
|
|
217
|
-
```
|
|
197
|
+
const
|
|
218
198
|
|
|
219
|
-
|
|
199
|
+
=
|
|
220
200
|
|
|
221
|
-
|
|
201
|
+
new
|
|
222
202
|
|
|
223
|
-
|
|
224
|
-
() => {
|
|
225
|
-
const yesterday = new Date();
|
|
226
|
-
yesterday.setDate(new Date().getDate() - 1);
|
|
203
|
+
Intl.DateTimeFormat
|
|
227
204
|
|
|
228
|
-
|
|
229
|
-
<>
|
|
230
|
-
<FormattedDate value={yesterday} month='short' day='numeric' />
|
|
231
|
-
{' - '}
|
|
232
|
-
<FormattedDate value={new Date()} year='numeric' month='short' day='numeric' />
|
|
233
|
-
</>
|
|
234
|
-
);
|
|
235
|
-
})
|
|
236
|
-
```
|
|
205
|
+
(
|
|
237
206
|
|
|
238
|
-
|
|
239
|
-
function formatDateRange(startDate, endDate) {
|
|
240
|
-
if (!(startDate instanceof Date) || !(endDate instanceof Date)) {
|
|
241
|
-
throw new Error("Invalid input. Please provide valid Date objects.");
|
|
242
|
-
}
|
|
207
|
+
,
|
|
243
208
|
|
|
244
|
-
|
|
245
|
-
day: 'numeric',
|
|
246
|
-
month: 'short'
|
|
247
|
-
});
|
|
209
|
+
)
|
|
248
210
|
|
|
249
|
-
|
|
250
|
-
day: 'numeric',
|
|
251
|
-
month: 'short',
|
|
252
|
-
year: 'numeric'
|
|
253
|
-
});
|
|
211
|
+
;
|
|
254
212
|
|
|
255
|
-
|
|
256
|
-
|
|
213
|
+
return
|
|
214
|
+
|
|
215
|
+
.
|
|
216
|
+
|
|
217
|
+
format
|
|
218
|
+
|
|
219
|
+
(
|
|
220
|
+
|
|
221
|
+
)
|
|
222
|
+
|
|
223
|
+
;
|
|
257
224
|
|
|
258
|
-
return `${formattedStartDate} - ${formattedEndDate}`;
|
|
259
225
|
}
|
|
260
226
|
|
|
261
|
-
|
|
262
|
-
const startDate = new Date(2024, 1, 12); // Feb 12, 2024
|
|
263
|
-
const endDate = new Date(2024, 1, 16); // Feb 16, 2024
|
|
227
|
+
const
|
|
264
228
|
|
|
265
|
-
|
|
266
|
-
console.log("Formatted Date Range:", formattedRange);
|
|
267
|
-
```
|
|
229
|
+
=
|
|
268
230
|
|
|
269
|
-
|
|
231
|
+
[
|
|
270
232
|
|
|
271
|
-
|
|
233
|
+
'bg-BG'
|
|
272
234
|
|
|
273
|
-
|
|
274
|
-
- 2h 32min
|
|
275
|
-
- 45min
|
|
235
|
+
,
|
|
276
236
|
|
|
277
|
-
|
|
237
|
+
'cs-CZ'
|
|
278
238
|
|
|
279
|
-
|
|
280
|
-
- 3m 20s
|
|
281
|
-
- 10s
|
|
239
|
+
,
|
|
282
240
|
|
|
283
|
-
|
|
241
|
+
'da-DK'
|
|
284
242
|
|
|
285
|
-
|
|
286
|
-
<FormattedNumber value={2} />h <FormattedNumber value={45} />min
|
|
287
|
-
```
|
|
243
|
+
,
|
|
288
244
|
|
|
289
|
-
|
|
245
|
+
'el-GR'
|
|
290
246
|
|
|
291
|
-
|
|
292
|
-
- "1 month ago"
|
|
293
|
-
- "7 days ago"
|
|
294
|
-
- "In 2 hours"
|
|
295
|
-
- "Now" or "Just now" (for events within the last minute)
|
|
247
|
+
,
|
|
296
248
|
|
|
297
|
-
-
|
|
298
|
-
- Counting down to an upcoming event
|
|
299
|
-
- Indicating how recently an item was updated
|
|
300
|
-
- Benefits
|
|
301
|
-
- Clear and concise for recent events Easy for users to understand the time difference
|
|
249
|
+
'es-ES'
|
|
302
250
|
|
|
303
|
-
|
|
304
|
-
- Easy for users to understand the time difference
|
|
251
|
+
,
|
|
305
252
|
|
|
306
|
-
|
|
253
|
+
'et-EE'
|
|
307
254
|
|
|
308
|
-
|
|
255
|
+
,
|
|
309
256
|
|
|
310
|
-
|
|
311
|
-
<FormattedRelativeTime value={0} numeric='auto' updateIntervalInSeconds={1} />
|
|
312
|
-
```
|
|
257
|
+
'fi-FI'
|
|
313
258
|
|
|
314
|
-
|
|
315
|
-
- "Yesterday, 10:39"
|
|
316
|
-
- "Today, 12:17"
|
|
317
|
-
- "Tomorrow"
|
|
318
|
-
- "Last week"
|
|
319
|
-
- "Next Friday"
|
|
320
|
-
- "In 3 days"
|
|
259
|
+
,
|
|
321
260
|
|
|
322
|
-
-
|
|
323
|
-
- Highlighting recent activity within a timeframe (e.g., "Top posts from the past week")
|
|
324
|
-
- Providing deadlines or due dates in a user-friendly way
|
|
325
|
-
- Benefits
|
|
326
|
-
- Intuitive understanding for users familiar with common timeframes Reduces mental calculations for interpreting absolute dates
|
|
261
|
+
'fr-FR'
|
|
327
262
|
|
|
328
|
-
|
|
329
|
-
- Reduces mental calculations for interpreting absolute dates
|
|
263
|
+
,
|
|
330
264
|
|
|
331
|
-
|
|
265
|
+
'hr-HR'
|
|
332
266
|
|
|
333
|
-
|
|
334
|
-
- Use absolute formats: When precise timestamps are crucial, or for long time spans where relative terms become ambiguous.
|
|
267
|
+
,
|
|
335
268
|
|
|
336
|
-
|
|
269
|
+
'hu-HU'
|
|
337
270
|
|
|
338
|
-
|
|
339
|
-
<FormattedRelativeTime value={0} numeric='auto' updateIntervalInSeconds={1} />
|
|
340
|
-
```
|
|
271
|
+
,
|
|
341
272
|
|
|
342
|
-
-
|
|
343
|
-
- Level of detail: You might need to adjust the granularity of relative formats. For example, "3 weeks ago" might be more appropriate than "21 days ago" depending on the context.
|
|
273
|
+
'it-IT'
|
|
344
274
|
|
|
345
|
-
|
|
275
|
+
,
|
|
346
276
|
|
|
347
|
-
|
|
277
|
+
'lt-LT'
|
|
348
278
|
|
|
349
|
-
|
|
279
|
+
,
|
|
350
280
|
|
|
351
|
-
|
|
281
|
+
'lv-LV'
|
|
352
282
|
|
|
353
|
-
|
|
283
|
+
,
|
|
354
284
|
|
|
355
|
-
|
|
285
|
+
'nb-NO'
|
|
356
286
|
|
|
357
|
-
|
|
287
|
+
,
|
|
358
288
|
|
|
359
|
-
|
|
289
|
+
'nl-NL'
|
|
360
290
|
|
|
361
|
-
|
|
291
|
+
,
|
|
362
292
|
|
|
363
|
-
|
|
293
|
+
'pl-PL'
|
|
364
294
|
|
|
365
|
-
|
|
366
|
-
- Secondary display: Include the GMT offset in smaller text or tooltips to provide additional context
|
|
295
|
+
,
|
|
367
296
|
|
|
368
|
-
|
|
297
|
+
'pt-PT'
|
|
369
298
|
|
|
370
|
-
|
|
299
|
+
,
|
|
371
300
|
|
|
372
|
-
|
|
301
|
+
'ro-RO'
|
|
373
302
|
|
|
374
|
-
|
|
303
|
+
,
|
|
375
304
|
|
|
376
|
-
|
|
305
|
+
'sk-SK'
|
|
377
306
|
|
|
378
|
-
|
|
307
|
+
,
|
|
379
308
|
|
|
380
|
-
|
|
309
|
+
'sl-SI'
|
|
381
310
|
|
|
382
|
-
|
|
383
|
-
- Assumption Day 15/08/2024, in 64 days
|
|
311
|
+
,
|
|
384
312
|
|
|
385
|
-
|
|
313
|
+
'sv-SE'
|
|
386
314
|
|
|
387
|
-
|
|
315
|
+
,
|
|
388
316
|
|
|
389
|
-
|
|
317
|
+
'de-DE'
|
|
390
318
|
|
|
391
|
-
|
|
319
|
+
,
|
|
392
320
|
|
|
393
|
-
-
|
|
394
|
-
- Consistent use of delimiters Ensure the consistent use of decimal and thousand separators as per the locale’s conventions
|
|
395
|
-
- Handling edge cases Be aware of edge cases like negative numbers, very large numbers, and numbers with many decimal places
|
|
396
|
-
- Use libraries Utilize libraries like ReactIntl to handle number formatting, which provides built-in support for multiple locales and ensures correctness
|
|
321
|
+
'pt-BR'
|
|
397
322
|
|
|
398
|
-
|
|
399
|
-
const NumberFormattingExample = () => {
|
|
400
|
-
const number = 1234567.89;
|
|
323
|
+
,
|
|
401
324
|
|
|
402
|
-
|
|
403
|
-
<IntlProvider locale="de-DE">
|
|
404
|
-
<FormattedNumber value={number} />
|
|
405
|
-
</IntlProvider>
|
|
406
|
-
);
|
|
407
|
-
};
|
|
408
|
-
```
|
|
325
|
+
'en-GB'
|
|
409
326
|
|
|
410
|
-
|
|
327
|
+
]
|
|
411
328
|
|
|
412
|
-
|
|
329
|
+
;
|
|
413
330
|
|
|
414
|
-
|
|
331
|
+
const
|
|
415
332
|
|
|
416
|
-
|
|
333
|
+
=
|
|
417
334
|
|
|
418
|
-
|
|
419
|
-
<FormattedNumber
|
|
420
|
-
value={123.0}
|
|
421
|
-
minimumFractionDigits={0}
|
|
422
|
-
maximumFractionDigits={2}
|
|
423
|
-
style='unit'
|
|
424
|
-
unit='kilometer'
|
|
425
|
-
/>
|
|
426
|
-
```
|
|
335
|
+
new
|
|
427
336
|
|
|
428
|
-
|
|
337
|
+
Date
|
|
429
338
|
|
|
430
|
-
|
|
339
|
+
(
|
|
431
340
|
|
|
432
|
-
|
|
341
|
+
)
|
|
433
342
|
|
|
434
|
-
|
|
343
|
+
;
|
|
435
344
|
|
|
436
|
-
|
|
345
|
+
.
|
|
437
346
|
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
347
|
+
forEach
|
|
348
|
+
|
|
349
|
+
(
|
|
350
|
+
|
|
351
|
+
locale
|
|
352
|
+
|
|
353
|
+
=>
|
|
354
|
+
|
|
355
|
+
{
|
|
356
|
+
|
|
357
|
+
const
|
|
358
|
+
|
|
359
|
+
=
|
|
360
|
+
|
|
361
|
+
formatDate
|
|
362
|
+
|
|
363
|
+
(
|
|
364
|
+
|
|
365
|
+
,
|
|
366
|
+
|
|
367
|
+
)
|
|
368
|
+
|
|
369
|
+
;
|
|
370
|
+
|
|
371
|
+
.
|
|
372
|
+
|
|
373
|
+
log
|
|
374
|
+
|
|
375
|
+
(
|
|
376
|
+
|
|
377
|
+
`Locale: ${locale}, Formatted date: ${formattedDate}`
|
|
378
|
+
|
|
379
|
+
)
|
|
380
|
+
|
|
381
|
+
;
|
|
382
|
+
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
)
|
|
386
|
+
|
|
387
|
+
;
|
|
388
|
+
|
|
389
|
+
**Formatting a date range**
|
|
390
|
+
|
|
391
|
+
For formatting a time range use the ReactIntl FormattedDateTimeRange component. Note that for dates in headlines or in sections, there is a dedicated format rule listed below.
|
|
392
|
+
|
|
393
|
+
```jsx
|
|
394
|
+
() => {
|
|
395
|
+
const yesterday = new Date();
|
|
396
|
+
yesterday.setDate(new Date().getDate() - 1);
|
|
397
|
+
|
|
398
|
+
return <FormattedDateTimeRange from={yesterday} to={new Date()} />;
|
|
399
|
+
})
|
|
400
|
+
```
|
|
401
|
+
|
|
402
|
+
(
|
|
403
|
+
|
|
404
|
+
)
|
|
405
|
+
|
|
406
|
+
=>
|
|
407
|
+
|
|
408
|
+
{
|
|
409
|
+
|
|
410
|
+
const
|
|
411
|
+
|
|
412
|
+
=
|
|
413
|
+
|
|
414
|
+
new
|
|
415
|
+
|
|
416
|
+
Date
|
|
417
|
+
|
|
418
|
+
(
|
|
419
|
+
|
|
420
|
+
)
|
|
421
|
+
|
|
422
|
+
;
|
|
423
|
+
|
|
424
|
+
.
|
|
425
|
+
|
|
426
|
+
setDate
|
|
427
|
+
|
|
428
|
+
(
|
|
429
|
+
|
|
430
|
+
new
|
|
431
|
+
|
|
432
|
+
Date
|
|
433
|
+
|
|
434
|
+
(
|
|
435
|
+
|
|
436
|
+
)
|
|
437
|
+
|
|
438
|
+
.
|
|
439
|
+
|
|
440
|
+
getDate
|
|
441
|
+
|
|
442
|
+
(
|
|
443
|
+
|
|
444
|
+
)
|
|
445
|
+
|
|
446
|
+
-
|
|
447
|
+
|
|
448
|
+
1
|
|
449
|
+
|
|
450
|
+
)
|
|
451
|
+
|
|
452
|
+
;
|
|
453
|
+
|
|
454
|
+
return
|
|
455
|
+
|
|
456
|
+
<FormattedDateTimeRange from={yesterday} to={new Date()} />
|
|
457
|
+
|
|
458
|
+
;
|
|
459
|
+
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
)
|
|
463
|
+
|
|
464
|
+
## Date and time format
|
|
465
|
+
|
|
466
|
+
Date and time format
|
|
467
|
+
|
|
468
|
+
None of the mentioned locales use a 12-hour format by default according to common usage. Here's a breakdown:
|
|
469
|
+
|
|
470
|
+
- All the listed locales (including en-GB) typically use the 24-hour format for displaying time.
|
|
471
|
+
- While some countries might use a 12-hour format in informal contexts, the 24-hour format is generally preferred for official communication and technical applications.
|
|
472
|
+
|
|
473
|
+
The default date and time format looks like this: 27/05/2024, 11:17
|
|
474
|
+
|
|
475
|
+
27/05/2024, 11:17
|
|
476
|
+
|
|
477
|
+
```jsx
|
|
478
|
+
<FormattedDate value={new Date()} year='numeric' month='2-digit' day='2-digit' hour='2-digit' minute='2-digit' />
|
|
479
|
+
```
|
|
480
|
+
|
|
481
|
+
<FormattedDate value={new Date()} year='numeric' month='2-digit' day='2-digit' hour='2-digit' minute='2-digit' />
|
|
482
|
+
|
|
483
|
+
```javascript
|
|
484
|
+
const formatDateTime = (date, locale) => {
|
|
485
|
+
const options = {
|
|
486
|
+
year: 'numeric',
|
|
487
|
+
month: '2-digit',
|
|
488
|
+
day: '2-digit',
|
|
489
|
+
hour: '2-digit',
|
|
490
|
+
minute: '2-digit'
|
|
491
|
+
};
|
|
492
|
+
|
|
493
|
+
const dateTimeFormatter = new Intl.DateTimeFormat(locale, options);
|
|
494
|
+
return dateTimeFormatter.format(date);
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
const locales = [
|
|
498
|
+
'bg-BG', 'cs-CZ', 'da-DK', 'el-GR', 'es-ES', 'et-EE', 'fi-FI', 'fr-FR',
|
|
499
|
+
'hr-HR', 'hu-HU', 'it-IT', 'lt-LT', 'lv-LV', 'nb-NO', 'nl-NL', 'pl-PL',
|
|
500
|
+
'pt-PT', 'ro-RO', 'sk-SK', 'sl-SI', 'sv-SE', 'de-DE', 'pt-BR', 'en-GB'
|
|
501
|
+
];
|
|
502
|
+
|
|
503
|
+
const today = new Date();
|
|
504
|
+
|
|
505
|
+
locales.forEach(locale => {
|
|
506
|
+
const formattedDateTime = formatDateTime(today, locale);
|
|
507
|
+
console.log(`Locale: ${locale}, Formatted date time: ${formattedDateTime}`);
|
|
508
|
+
});
|
|
509
|
+
```
|
|
510
|
+
|
|
511
|
+
const
|
|
512
|
+
|
|
513
|
+
formatDateTime
|
|
514
|
+
|
|
515
|
+
=
|
|
516
|
+
|
|
517
|
+
(
|
|
518
|
+
|
|
519
|
+
date, locale
|
|
520
|
+
|
|
521
|
+
)
|
|
522
|
+
|
|
523
|
+
=>
|
|
524
|
+
|
|
525
|
+
{
|
|
526
|
+
|
|
527
|
+
const
|
|
528
|
+
|
|
529
|
+
=
|
|
530
|
+
|
|
531
|
+
{
|
|
532
|
+
|
|
533
|
+
year
|
|
534
|
+
|
|
535
|
+
:
|
|
536
|
+
|
|
537
|
+
'numeric'
|
|
538
|
+
|
|
539
|
+
,
|
|
540
|
+
|
|
541
|
+
month
|
|
542
|
+
|
|
543
|
+
:
|
|
544
|
+
|
|
545
|
+
'2-digit'
|
|
546
|
+
|
|
547
|
+
,
|
|
548
|
+
|
|
549
|
+
day
|
|
550
|
+
|
|
551
|
+
:
|
|
552
|
+
|
|
553
|
+
'2-digit'
|
|
554
|
+
|
|
555
|
+
,
|
|
556
|
+
|
|
557
|
+
hour
|
|
558
|
+
|
|
559
|
+
:
|
|
560
|
+
|
|
561
|
+
'2-digit'
|
|
562
|
+
|
|
563
|
+
,
|
|
564
|
+
|
|
565
|
+
minute
|
|
566
|
+
|
|
567
|
+
:
|
|
568
|
+
|
|
569
|
+
'2-digit'
|
|
570
|
+
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
;
|
|
574
|
+
|
|
575
|
+
const
|
|
576
|
+
|
|
577
|
+
=
|
|
578
|
+
|
|
579
|
+
new
|
|
580
|
+
|
|
581
|
+
Intl.DateTimeFormat
|
|
582
|
+
|
|
583
|
+
(
|
|
584
|
+
|
|
585
|
+
,
|
|
586
|
+
|
|
587
|
+
)
|
|
588
|
+
|
|
589
|
+
;
|
|
590
|
+
|
|
591
|
+
return
|
|
592
|
+
|
|
593
|
+
.
|
|
594
|
+
|
|
595
|
+
format
|
|
596
|
+
|
|
597
|
+
(
|
|
598
|
+
|
|
599
|
+
)
|
|
600
|
+
|
|
601
|
+
;
|
|
602
|
+
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
const
|
|
606
|
+
|
|
607
|
+
=
|
|
608
|
+
|
|
609
|
+
[
|
|
610
|
+
|
|
611
|
+
'bg-BG'
|
|
612
|
+
|
|
613
|
+
,
|
|
614
|
+
|
|
615
|
+
'cs-CZ'
|
|
616
|
+
|
|
617
|
+
,
|
|
618
|
+
|
|
619
|
+
'da-DK'
|
|
620
|
+
|
|
621
|
+
,
|
|
622
|
+
|
|
623
|
+
'el-GR'
|
|
624
|
+
|
|
625
|
+
,
|
|
626
|
+
|
|
627
|
+
'es-ES'
|
|
628
|
+
|
|
629
|
+
,
|
|
630
|
+
|
|
631
|
+
'et-EE'
|
|
632
|
+
|
|
633
|
+
,
|
|
634
|
+
|
|
635
|
+
'fi-FI'
|
|
636
|
+
|
|
637
|
+
,
|
|
638
|
+
|
|
639
|
+
'fr-FR'
|
|
640
|
+
|
|
641
|
+
,
|
|
642
|
+
|
|
643
|
+
'hr-HR'
|
|
644
|
+
|
|
645
|
+
,
|
|
646
|
+
|
|
647
|
+
'hu-HU'
|
|
648
|
+
|
|
649
|
+
,
|
|
650
|
+
|
|
651
|
+
'it-IT'
|
|
652
|
+
|
|
653
|
+
,
|
|
654
|
+
|
|
655
|
+
'lt-LT'
|
|
656
|
+
|
|
657
|
+
,
|
|
658
|
+
|
|
659
|
+
'lv-LV'
|
|
660
|
+
|
|
661
|
+
,
|
|
662
|
+
|
|
663
|
+
'nb-NO'
|
|
664
|
+
|
|
665
|
+
,
|
|
666
|
+
|
|
667
|
+
'nl-NL'
|
|
668
|
+
|
|
669
|
+
,
|
|
670
|
+
|
|
671
|
+
'pl-PL'
|
|
672
|
+
|
|
673
|
+
,
|
|
674
|
+
|
|
675
|
+
'pt-PT'
|
|
676
|
+
|
|
677
|
+
,
|
|
678
|
+
|
|
679
|
+
'ro-RO'
|
|
680
|
+
|
|
681
|
+
,
|
|
682
|
+
|
|
683
|
+
'sk-SK'
|
|
684
|
+
|
|
685
|
+
,
|
|
686
|
+
|
|
687
|
+
'sl-SI'
|
|
688
|
+
|
|
689
|
+
,
|
|
690
|
+
|
|
691
|
+
'sv-SE'
|
|
692
|
+
|
|
693
|
+
,
|
|
694
|
+
|
|
695
|
+
'de-DE'
|
|
696
|
+
|
|
697
|
+
,
|
|
698
|
+
|
|
699
|
+
'pt-BR'
|
|
700
|
+
|
|
701
|
+
,
|
|
702
|
+
|
|
703
|
+
'en-GB'
|
|
704
|
+
|
|
705
|
+
]
|
|
706
|
+
|
|
707
|
+
;
|
|
708
|
+
|
|
709
|
+
const
|
|
710
|
+
|
|
711
|
+
=
|
|
712
|
+
|
|
713
|
+
new
|
|
714
|
+
|
|
715
|
+
Date
|
|
716
|
+
|
|
717
|
+
(
|
|
718
|
+
|
|
719
|
+
)
|
|
720
|
+
|
|
721
|
+
;
|
|
722
|
+
|
|
723
|
+
.
|
|
724
|
+
|
|
725
|
+
forEach
|
|
726
|
+
|
|
727
|
+
(
|
|
728
|
+
|
|
729
|
+
locale
|
|
730
|
+
|
|
731
|
+
=>
|
|
732
|
+
|
|
733
|
+
{
|
|
734
|
+
|
|
735
|
+
const
|
|
736
|
+
|
|
737
|
+
=
|
|
738
|
+
|
|
739
|
+
formatDateTime
|
|
740
|
+
|
|
741
|
+
(
|
|
742
|
+
|
|
743
|
+
,
|
|
744
|
+
|
|
745
|
+
)
|
|
746
|
+
|
|
747
|
+
;
|
|
748
|
+
|
|
749
|
+
.
|
|
750
|
+
|
|
751
|
+
log
|
|
752
|
+
|
|
753
|
+
(
|
|
754
|
+
|
|
755
|
+
`Locale: ${locale}, Formatted date time: ${formattedDateTime}`
|
|
756
|
+
|
|
757
|
+
)
|
|
758
|
+
|
|
759
|
+
;
|
|
760
|
+
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
)
|
|
764
|
+
|
|
765
|
+
;
|
|
766
|
+
|
|
767
|
+
## Formatting dates for headlines and sections
|
|
768
|
+
|
|
769
|
+
Formatting dates for headlines and sections
|
|
770
|
+
|
|
771
|
+
When formatting a date or a date range for a headline or a section, use the following format including the weekday if it's not today. If the date is today, add the word "today" instead of the weekday.
|
|
772
|
+
|
|
773
|
+
- Today, 24 May 2024
|
|
774
|
+
- Thursday, 23 May 2024
|
|
775
|
+
- 12 Feb - 16 Feb 2024
|
|
776
|
+
|
|
777
|
+
```jsx
|
|
778
|
+
() => {
|
|
779
|
+
const yesterday = new Date();
|
|
780
|
+
yesterday.setDate(new Date().getDate() - 1);
|
|
781
|
+
|
|
782
|
+
return (
|
|
783
|
+
<>
|
|
784
|
+
{'Today, '}
|
|
785
|
+
<FormattedDate value={new Date()} year='numeric' month='short' day='numeric' />
|
|
786
|
+
<br />
|
|
787
|
+
<FormattedDate value={yesterday} year='numeric' month='short' day='numeric' weekday='long' />
|
|
788
|
+
</>
|
|
789
|
+
);
|
|
790
|
+
})
|
|
791
|
+
```
|
|
792
|
+
|
|
793
|
+
(
|
|
794
|
+
|
|
795
|
+
)
|
|
796
|
+
|
|
797
|
+
=>
|
|
798
|
+
|
|
799
|
+
{
|
|
800
|
+
|
|
801
|
+
const
|
|
802
|
+
|
|
803
|
+
=
|
|
804
|
+
|
|
805
|
+
new
|
|
806
|
+
|
|
807
|
+
Date
|
|
808
|
+
|
|
809
|
+
(
|
|
810
|
+
|
|
811
|
+
)
|
|
812
|
+
|
|
813
|
+
;
|
|
814
|
+
|
|
815
|
+
.
|
|
816
|
+
|
|
817
|
+
setDate
|
|
818
|
+
|
|
819
|
+
(
|
|
820
|
+
|
|
821
|
+
new
|
|
822
|
+
|
|
823
|
+
Date
|
|
824
|
+
|
|
825
|
+
(
|
|
826
|
+
|
|
827
|
+
)
|
|
828
|
+
|
|
829
|
+
.
|
|
830
|
+
|
|
831
|
+
getDate
|
|
832
|
+
|
|
833
|
+
(
|
|
834
|
+
|
|
835
|
+
)
|
|
836
|
+
|
|
837
|
+
-
|
|
838
|
+
|
|
839
|
+
1
|
|
840
|
+
|
|
841
|
+
)
|
|
842
|
+
|
|
843
|
+
;
|
|
844
|
+
|
|
845
|
+
return
|
|
846
|
+
|
|
847
|
+
(
|
|
848
|
+
|
|
849
|
+
<>
|
|
850
|
+
|
|
851
|
+
{
|
|
852
|
+
|
|
853
|
+
'Today, '
|
|
854
|
+
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
<FormattedDate value={new Date()} year='numeric' month='short' day='numeric' />
|
|
858
|
+
|
|
859
|
+
<br />
|
|
860
|
+
|
|
861
|
+
<FormattedDate value={yesterday} year='numeric' month='short' day='numeric' weekday='long' />
|
|
862
|
+
|
|
863
|
+
</>
|
|
864
|
+
|
|
865
|
+
)
|
|
866
|
+
|
|
867
|
+
;
|
|
868
|
+
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
)
|
|
872
|
+
|
|
873
|
+
```javascript
|
|
874
|
+
function formatDateWithWeekday(date) {
|
|
875
|
+
const today = new Date();
|
|
876
|
+
const isToday =
|
|
877
|
+
today.getDate() === date.getDate() &&
|
|
878
|
+
today.getMonth() === date.getMonth() &&
|
|
879
|
+
today.getFullYear() === date.getFullYear();
|
|
880
|
+
|
|
881
|
+
const options = {
|
|
882
|
+
day: 'numeric',
|
|
883
|
+
month: 'short',
|
|
884
|
+
year: 'numeric',
|
|
885
|
+
weekday: isToday ? undefined : 'long',
|
|
886
|
+
};
|
|
887
|
+
|
|
888
|
+
const dateTimeFormatter = new Intl.DateTimeFormat('en-GB', options);
|
|
889
|
+
return isToday ? `Today, ${dateTimeFormatter.format(date)}` : dateTimeFormatter.format(date);
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
// Example for today
|
|
893
|
+
const today = new Date();
|
|
894
|
+
const formattedDate = formatDateWithWeekday(today);
|
|
895
|
+
console.log(formattedDate);
|
|
896
|
+
|
|
897
|
+
// Example for yesterday
|
|
898
|
+
const yesterday = new Date();
|
|
899
|
+
yesterday.setDate(today.getDate() - 1); // Subtract 1 day from today
|
|
900
|
+
const formattedDateYesterday = formatDateWithWeekday(yesterday);
|
|
901
|
+
console.log(formattedDateYesterday);
|
|
902
|
+
```
|
|
903
|
+
|
|
904
|
+
function
|
|
905
|
+
|
|
906
|
+
formatDateWithWeekday
|
|
907
|
+
|
|
908
|
+
(
|
|
909
|
+
|
|
910
|
+
date
|
|
911
|
+
|
|
912
|
+
)
|
|
913
|
+
|
|
914
|
+
{
|
|
915
|
+
|
|
916
|
+
const
|
|
917
|
+
|
|
918
|
+
=
|
|
919
|
+
|
|
920
|
+
new
|
|
921
|
+
|
|
922
|
+
Date
|
|
923
|
+
|
|
924
|
+
(
|
|
925
|
+
|
|
926
|
+
)
|
|
927
|
+
|
|
928
|
+
;
|
|
929
|
+
|
|
930
|
+
const
|
|
931
|
+
|
|
932
|
+
=
|
|
933
|
+
|
|
934
|
+
.
|
|
935
|
+
|
|
936
|
+
getDate
|
|
937
|
+
|
|
938
|
+
(
|
|
939
|
+
|
|
940
|
+
)
|
|
941
|
+
|
|
942
|
+
===
|
|
943
|
+
|
|
944
|
+
.
|
|
945
|
+
|
|
946
|
+
getDate
|
|
947
|
+
|
|
948
|
+
(
|
|
949
|
+
|
|
950
|
+
)
|
|
951
|
+
|
|
952
|
+
&&
|
|
953
|
+
|
|
954
|
+
.
|
|
955
|
+
|
|
956
|
+
getMonth
|
|
957
|
+
|
|
958
|
+
(
|
|
959
|
+
|
|
960
|
+
)
|
|
961
|
+
|
|
962
|
+
===
|
|
963
|
+
|
|
964
|
+
.
|
|
965
|
+
|
|
966
|
+
getMonth
|
|
967
|
+
|
|
968
|
+
(
|
|
969
|
+
|
|
970
|
+
)
|
|
971
|
+
|
|
972
|
+
&&
|
|
973
|
+
|
|
974
|
+
.
|
|
975
|
+
|
|
976
|
+
getFullYear
|
|
977
|
+
|
|
978
|
+
(
|
|
979
|
+
|
|
980
|
+
)
|
|
981
|
+
|
|
982
|
+
===
|
|
983
|
+
|
|
984
|
+
.
|
|
985
|
+
|
|
986
|
+
getFullYear
|
|
987
|
+
|
|
988
|
+
(
|
|
989
|
+
|
|
990
|
+
)
|
|
991
|
+
|
|
992
|
+
;
|
|
993
|
+
|
|
994
|
+
const
|
|
995
|
+
|
|
996
|
+
=
|
|
997
|
+
|
|
998
|
+
{
|
|
999
|
+
|
|
1000
|
+
day
|
|
1001
|
+
|
|
1002
|
+
:
|
|
1003
|
+
|
|
1004
|
+
'numeric'
|
|
1005
|
+
|
|
1006
|
+
,
|
|
1007
|
+
|
|
1008
|
+
month
|
|
1009
|
+
|
|
1010
|
+
:
|
|
1011
|
+
|
|
1012
|
+
'short'
|
|
1013
|
+
|
|
1014
|
+
,
|
|
1015
|
+
|
|
1016
|
+
year
|
|
1017
|
+
|
|
1018
|
+
:
|
|
1019
|
+
|
|
1020
|
+
'numeric'
|
|
1021
|
+
|
|
1022
|
+
,
|
|
1023
|
+
|
|
1024
|
+
weekday
|
|
1025
|
+
|
|
1026
|
+
:
|
|
1027
|
+
|
|
1028
|
+
?
|
|
1029
|
+
|
|
1030
|
+
undefined
|
|
1031
|
+
|
|
1032
|
+
:
|
|
1033
|
+
|
|
1034
|
+
'long'
|
|
1035
|
+
|
|
1036
|
+
,
|
|
1037
|
+
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
;
|
|
1041
|
+
|
|
1042
|
+
const
|
|
1043
|
+
|
|
1044
|
+
=
|
|
1045
|
+
|
|
1046
|
+
new
|
|
1047
|
+
|
|
1048
|
+
Intl.DateTimeFormat
|
|
1049
|
+
|
|
1050
|
+
(
|
|
1051
|
+
|
|
1052
|
+
'en-GB'
|
|
1053
|
+
|
|
1054
|
+
,
|
|
1055
|
+
|
|
1056
|
+
)
|
|
1057
|
+
|
|
1058
|
+
;
|
|
1059
|
+
|
|
1060
|
+
return
|
|
1061
|
+
|
|
1062
|
+
?
|
|
1063
|
+
|
|
1064
|
+
`Today, ${dateTimeFormatter.format(date)}`
|
|
1065
|
+
|
|
1066
|
+
:
|
|
1067
|
+
|
|
1068
|
+
.
|
|
1069
|
+
|
|
1070
|
+
format
|
|
1071
|
+
|
|
1072
|
+
(
|
|
1073
|
+
|
|
1074
|
+
)
|
|
1075
|
+
|
|
1076
|
+
;
|
|
1077
|
+
|
|
1078
|
+
}
|
|
1079
|
+
|
|
1080
|
+
// Example for today
|
|
1081
|
+
|
|
1082
|
+
const
|
|
1083
|
+
|
|
1084
|
+
=
|
|
1085
|
+
|
|
1086
|
+
new
|
|
1087
|
+
|
|
1088
|
+
Date
|
|
1089
|
+
|
|
1090
|
+
(
|
|
1091
|
+
|
|
1092
|
+
)
|
|
1093
|
+
|
|
1094
|
+
;
|
|
1095
|
+
|
|
1096
|
+
const
|
|
1097
|
+
|
|
1098
|
+
=
|
|
1099
|
+
|
|
1100
|
+
formatDateWithWeekday
|
|
1101
|
+
|
|
1102
|
+
(
|
|
1103
|
+
|
|
1104
|
+
)
|
|
1105
|
+
|
|
1106
|
+
;
|
|
1107
|
+
|
|
1108
|
+
.
|
|
1109
|
+
|
|
1110
|
+
log
|
|
1111
|
+
|
|
1112
|
+
(
|
|
1113
|
+
|
|
1114
|
+
)
|
|
1115
|
+
|
|
1116
|
+
;
|
|
1117
|
+
|
|
1118
|
+
// Example for yesterday
|
|
1119
|
+
|
|
1120
|
+
const
|
|
1121
|
+
|
|
1122
|
+
=
|
|
1123
|
+
|
|
1124
|
+
new
|
|
1125
|
+
|
|
1126
|
+
Date
|
|
1127
|
+
|
|
1128
|
+
(
|
|
1129
|
+
|
|
1130
|
+
)
|
|
1131
|
+
|
|
1132
|
+
;
|
|
1133
|
+
|
|
1134
|
+
.
|
|
1135
|
+
|
|
1136
|
+
setDate
|
|
1137
|
+
|
|
1138
|
+
(
|
|
1139
|
+
|
|
1140
|
+
.
|
|
1141
|
+
|
|
1142
|
+
getDate
|
|
1143
|
+
|
|
1144
|
+
(
|
|
1145
|
+
|
|
1146
|
+
)
|
|
1147
|
+
|
|
1148
|
+
-
|
|
1149
|
+
|
|
1150
|
+
1
|
|
1151
|
+
|
|
1152
|
+
)
|
|
1153
|
+
|
|
1154
|
+
;
|
|
1155
|
+
|
|
1156
|
+
// Subtract 1 day from today
|
|
1157
|
+
|
|
1158
|
+
const
|
|
1159
|
+
|
|
1160
|
+
=
|
|
1161
|
+
|
|
1162
|
+
formatDateWithWeekday
|
|
1163
|
+
|
|
1164
|
+
(
|
|
1165
|
+
|
|
1166
|
+
)
|
|
1167
|
+
|
|
1168
|
+
;
|
|
1169
|
+
|
|
1170
|
+
.
|
|
1171
|
+
|
|
1172
|
+
log
|
|
1173
|
+
|
|
1174
|
+
(
|
|
1175
|
+
|
|
1176
|
+
)
|
|
1177
|
+
|
|
1178
|
+
;
|
|
1179
|
+
|
|
1180
|
+
**Formatting a date range for headlines**
|
|
1181
|
+
|
|
1182
|
+
When the date rage has the same year for both dates, omit the year for the first date so it looks like this: 27 May - 28 May 2024
|
|
1183
|
+
|
|
1184
|
+
```jsx
|
|
1185
|
+
() => {
|
|
1186
|
+
const yesterday = new Date();
|
|
1187
|
+
yesterday.setDate(new Date().getDate() - 1);
|
|
1188
|
+
|
|
1189
|
+
return (
|
|
1190
|
+
<>
|
|
1191
|
+
<FormattedDate value={yesterday} month='short' day='numeric' />
|
|
1192
|
+
{' - '}
|
|
1193
|
+
<FormattedDate value={new Date()} year='numeric' month='short' day='numeric' />
|
|
1194
|
+
</>
|
|
1195
|
+
);
|
|
1196
|
+
})
|
|
1197
|
+
```
|
|
1198
|
+
|
|
1199
|
+
(
|
|
1200
|
+
|
|
1201
|
+
)
|
|
1202
|
+
|
|
1203
|
+
=>
|
|
1204
|
+
|
|
1205
|
+
{
|
|
1206
|
+
|
|
1207
|
+
const
|
|
1208
|
+
|
|
1209
|
+
=
|
|
1210
|
+
|
|
1211
|
+
new
|
|
1212
|
+
|
|
1213
|
+
Date
|
|
1214
|
+
|
|
1215
|
+
(
|
|
1216
|
+
|
|
1217
|
+
)
|
|
1218
|
+
|
|
1219
|
+
;
|
|
1220
|
+
|
|
1221
|
+
.
|
|
1222
|
+
|
|
1223
|
+
setDate
|
|
1224
|
+
|
|
1225
|
+
(
|
|
1226
|
+
|
|
1227
|
+
new
|
|
1228
|
+
|
|
1229
|
+
Date
|
|
1230
|
+
|
|
1231
|
+
(
|
|
1232
|
+
|
|
1233
|
+
)
|
|
1234
|
+
|
|
1235
|
+
.
|
|
1236
|
+
|
|
1237
|
+
getDate
|
|
1238
|
+
|
|
1239
|
+
(
|
|
1240
|
+
|
|
1241
|
+
)
|
|
1242
|
+
|
|
1243
|
+
-
|
|
1244
|
+
|
|
1245
|
+
1
|
|
1246
|
+
|
|
1247
|
+
)
|
|
1248
|
+
|
|
1249
|
+
;
|
|
1250
|
+
|
|
1251
|
+
return
|
|
1252
|
+
|
|
1253
|
+
(
|
|
1254
|
+
|
|
1255
|
+
<>
|
|
1256
|
+
|
|
1257
|
+
<FormattedDate value={yesterday} month='short' day='numeric' />
|
|
1258
|
+
|
|
1259
|
+
{
|
|
1260
|
+
|
|
1261
|
+
' - '
|
|
1262
|
+
|
|
1263
|
+
}
|
|
1264
|
+
|
|
1265
|
+
<FormattedDate value={new Date()} year='numeric' month='short' day='numeric' />
|
|
1266
|
+
|
|
1267
|
+
</>
|
|
1268
|
+
|
|
1269
|
+
)
|
|
1270
|
+
|
|
1271
|
+
;
|
|
1272
|
+
|
|
1273
|
+
}
|
|
1274
|
+
|
|
1275
|
+
)
|
|
1276
|
+
|
|
1277
|
+
```javascript
|
|
1278
|
+
function formatDateRange(startDate, endDate) {
|
|
1279
|
+
if (!(startDate instanceof Date) || !(endDate instanceof Date)) {
|
|
1280
|
+
throw new Error("Invalid input. Please provide valid Date objects.");
|
|
1281
|
+
}
|
|
1282
|
+
|
|
1283
|
+
const startDateFormatter = new Intl.DateTimeFormat('en-GB', {
|
|
1284
|
+
day: 'numeric',
|
|
1285
|
+
month: 'short'
|
|
1286
|
+
});
|
|
1287
|
+
|
|
1288
|
+
const endDateFormatter = new Intl.DateTimeFormat('en-GB', {
|
|
1289
|
+
day: 'numeric',
|
|
1290
|
+
month: 'short',
|
|
1291
|
+
year: 'numeric'
|
|
1292
|
+
});
|
|
1293
|
+
|
|
1294
|
+
const formattedStartDate = startDateFormatter.format(startDate);
|
|
1295
|
+
const formattedEndDate = endDateFormatter.format(endDate);
|
|
1296
|
+
|
|
1297
|
+
return `${formattedStartDate} - ${formattedEndDate}`;
|
|
1298
|
+
}
|
|
1299
|
+
|
|
1300
|
+
// Example usage
|
|
1301
|
+
const startDate = new Date(2024, 1, 12); // Feb 12, 2024
|
|
1302
|
+
const endDate = new Date(2024, 1, 16); // Feb 16, 2024
|
|
1303
|
+
|
|
1304
|
+
const formattedRange = formatDateRange(startDate, endDate);
|
|
1305
|
+
console.log("Formatted Date Range:", formattedRange);
|
|
1306
|
+
```
|
|
1307
|
+
|
|
1308
|
+
function
|
|
1309
|
+
|
|
1310
|
+
formatDateRange
|
|
1311
|
+
|
|
1312
|
+
(
|
|
1313
|
+
|
|
1314
|
+
startDate, endDate
|
|
1315
|
+
|
|
1316
|
+
)
|
|
1317
|
+
|
|
1318
|
+
{
|
|
1319
|
+
|
|
1320
|
+
if
|
|
1321
|
+
|
|
1322
|
+
(
|
|
1323
|
+
|
|
1324
|
+
!
|
|
1325
|
+
|
|
1326
|
+
(
|
|
1327
|
+
|
|
1328
|
+
instanceof
|
|
1329
|
+
|
|
1330
|
+
Date
|
|
1331
|
+
|
|
1332
|
+
)
|
|
1333
|
+
|
|
1334
|
+
||
|
|
1335
|
+
|
|
1336
|
+
!
|
|
1337
|
+
|
|
1338
|
+
(
|
|
1339
|
+
|
|
1340
|
+
instanceof
|
|
1341
|
+
|
|
1342
|
+
Date
|
|
1343
|
+
|
|
1344
|
+
)
|
|
1345
|
+
|
|
1346
|
+
)
|
|
1347
|
+
|
|
1348
|
+
{
|
|
1349
|
+
|
|
1350
|
+
throw
|
|
1351
|
+
|
|
1352
|
+
new
|
|
1353
|
+
|
|
1354
|
+
Error
|
|
1355
|
+
|
|
1356
|
+
(
|
|
1357
|
+
|
|
1358
|
+
"Invalid input. Please provide valid Date objects."
|
|
1359
|
+
|
|
1360
|
+
)
|
|
1361
|
+
|
|
1362
|
+
;
|
|
1363
|
+
|
|
1364
|
+
}
|
|
1365
|
+
|
|
1366
|
+
const
|
|
1367
|
+
|
|
1368
|
+
=
|
|
1369
|
+
|
|
1370
|
+
new
|
|
1371
|
+
|
|
1372
|
+
Intl.DateTimeFormat
|
|
1373
|
+
|
|
1374
|
+
(
|
|
1375
|
+
|
|
1376
|
+
'en-GB'
|
|
1377
|
+
|
|
1378
|
+
,
|
|
1379
|
+
|
|
1380
|
+
{
|
|
1381
|
+
|
|
1382
|
+
day
|
|
1383
|
+
|
|
1384
|
+
:
|
|
1385
|
+
|
|
1386
|
+
'numeric'
|
|
1387
|
+
|
|
1388
|
+
,
|
|
1389
|
+
|
|
1390
|
+
month
|
|
1391
|
+
|
|
1392
|
+
:
|
|
1393
|
+
|
|
1394
|
+
'short'
|
|
1395
|
+
|
|
1396
|
+
}
|
|
1397
|
+
|
|
1398
|
+
)
|
|
1399
|
+
|
|
1400
|
+
;
|
|
1401
|
+
|
|
1402
|
+
const
|
|
1403
|
+
|
|
1404
|
+
=
|
|
1405
|
+
|
|
1406
|
+
new
|
|
1407
|
+
|
|
1408
|
+
Intl.DateTimeFormat
|
|
1409
|
+
|
|
1410
|
+
(
|
|
1411
|
+
|
|
1412
|
+
'en-GB'
|
|
1413
|
+
|
|
1414
|
+
,
|
|
1415
|
+
|
|
1416
|
+
{
|
|
1417
|
+
|
|
1418
|
+
day
|
|
1419
|
+
|
|
1420
|
+
:
|
|
1421
|
+
|
|
1422
|
+
'numeric'
|
|
1423
|
+
|
|
1424
|
+
,
|
|
1425
|
+
|
|
1426
|
+
month
|
|
1427
|
+
|
|
1428
|
+
:
|
|
1429
|
+
|
|
1430
|
+
'short'
|
|
1431
|
+
|
|
1432
|
+
,
|
|
1433
|
+
|
|
1434
|
+
year
|
|
1435
|
+
|
|
1436
|
+
:
|
|
1437
|
+
|
|
1438
|
+
'numeric'
|
|
1439
|
+
|
|
1440
|
+
}
|
|
1441
|
+
|
|
1442
|
+
)
|
|
1443
|
+
|
|
1444
|
+
;
|
|
1445
|
+
|
|
1446
|
+
const
|
|
1447
|
+
|
|
1448
|
+
=
|
|
1449
|
+
|
|
1450
|
+
.
|
|
1451
|
+
|
|
1452
|
+
format
|
|
1453
|
+
|
|
1454
|
+
(
|
|
1455
|
+
|
|
1456
|
+
)
|
|
1457
|
+
|
|
1458
|
+
;
|
|
1459
|
+
|
|
1460
|
+
const
|
|
1461
|
+
|
|
1462
|
+
=
|
|
1463
|
+
|
|
1464
|
+
.
|
|
1465
|
+
|
|
1466
|
+
format
|
|
1467
|
+
|
|
1468
|
+
(
|
|
1469
|
+
|
|
1470
|
+
)
|
|
1471
|
+
|
|
1472
|
+
;
|
|
1473
|
+
|
|
1474
|
+
return
|
|
1475
|
+
|
|
1476
|
+
`${formattedStartDate} - ${formattedEndDate}`
|
|
1477
|
+
|
|
1478
|
+
;
|
|
1479
|
+
|
|
1480
|
+
}
|
|
1481
|
+
|
|
1482
|
+
// Example usage
|
|
1483
|
+
|
|
1484
|
+
const
|
|
1485
|
+
|
|
1486
|
+
=
|
|
1487
|
+
|
|
1488
|
+
new
|
|
1489
|
+
|
|
1490
|
+
Date
|
|
1491
|
+
|
|
1492
|
+
(
|
|
1493
|
+
|
|
1494
|
+
2024
|
|
1495
|
+
|
|
1496
|
+
,
|
|
1497
|
+
|
|
1498
|
+
1
|
|
1499
|
+
|
|
1500
|
+
,
|
|
1501
|
+
|
|
1502
|
+
12
|
|
1503
|
+
|
|
1504
|
+
)
|
|
1505
|
+
|
|
1506
|
+
;
|
|
1507
|
+
|
|
1508
|
+
// Feb 12, 2024
|
|
1509
|
+
|
|
1510
|
+
const
|
|
1511
|
+
|
|
1512
|
+
=
|
|
1513
|
+
|
|
1514
|
+
new
|
|
1515
|
+
|
|
1516
|
+
Date
|
|
1517
|
+
|
|
1518
|
+
(
|
|
1519
|
+
|
|
1520
|
+
2024
|
|
1521
|
+
|
|
1522
|
+
,
|
|
1523
|
+
|
|
1524
|
+
1
|
|
1525
|
+
|
|
1526
|
+
,
|
|
1527
|
+
|
|
1528
|
+
16
|
|
1529
|
+
|
|
1530
|
+
)
|
|
1531
|
+
|
|
1532
|
+
;
|
|
1533
|
+
|
|
1534
|
+
// Feb 16, 2024
|
|
1535
|
+
|
|
1536
|
+
const
|
|
1537
|
+
|
|
1538
|
+
=
|
|
1539
|
+
|
|
1540
|
+
formatDateRange
|
|
1541
|
+
|
|
1542
|
+
(
|
|
1543
|
+
|
|
1544
|
+
,
|
|
1545
|
+
|
|
1546
|
+
)
|
|
1547
|
+
|
|
1548
|
+
;
|
|
1549
|
+
|
|
1550
|
+
.
|
|
1551
|
+
|
|
1552
|
+
log
|
|
1553
|
+
|
|
1554
|
+
(
|
|
1555
|
+
|
|
1556
|
+
"Formatted Date Range:"
|
|
1557
|
+
|
|
1558
|
+
,
|
|
1559
|
+
|
|
1560
|
+
)
|
|
1561
|
+
|
|
1562
|
+
;
|
|
1563
|
+
|
|
1564
|
+
## Format durations
|
|
1565
|
+
|
|
1566
|
+
Format durations
|
|
1567
|
+
|
|
1568
|
+
Use relative date and time formatting to help the understand quickly when an event happened or when a message has been sent:
|
|
1569
|
+
|
|
1570
|
+
- 3 days
|
|
1571
|
+
- 2h 32min
|
|
1572
|
+
- 45min
|
|
1573
|
+
|
|
1574
|
+
Best for: Short durations where hours and minutes are the most relevant unit.
|
|
1575
|
+
|
|
1576
|
+
- 3d
|
|
1577
|
+
- 3m 20s
|
|
1578
|
+
- 10s
|
|
1579
|
+
|
|
1580
|
+
Best for: When space is limited, and clarity is still maintained. Example: In a compact playlist view displaying track lengths.
|
|
1581
|
+
|
|
1582
|
+
```jsx
|
|
1583
|
+
<FormattedNumber value={2} />h <FormattedNumber value={45} />min
|
|
1584
|
+
```
|
|
1585
|
+
|
|
1586
|
+
<FormattedNumber value={2} />
|
|
1587
|
+
|
|
1588
|
+
<FormattedNumber value={45} />
|
|
1589
|
+
|
|
1590
|
+
See more information in the section "Formatting units with numbers"
|
|
1591
|
+
|
|
1592
|
+
## Relative date and time
|
|
1593
|
+
|
|
1594
|
+
Relative date and time
|
|
1595
|
+
|
|
1596
|
+
- "5 minutes ago"
|
|
1597
|
+
- "1 month ago"
|
|
1598
|
+
- "7 days ago"
|
|
1599
|
+
- "In 2 hours"
|
|
1600
|
+
- "Now" or "Just now" (for events within the last minute)
|
|
1601
|
+
|
|
1602
|
+
- Displaying when a notification arrived or a message was sent
|
|
1603
|
+
- Counting down to an upcoming event
|
|
1604
|
+
- Indicating how recently an item was updated
|
|
1605
|
+
- Benefits
|
|
1606
|
+
- Clear and concise for recent events Easy for users to understand the time difference
|
|
1607
|
+
|
|
1608
|
+
- Clear and concise for recent events
|
|
1609
|
+
- Easy for users to understand the time difference
|
|
1610
|
+
|
|
1611
|
+
Using a relative time is simple by using the ReactIntl FormattedRelativeTime component.
|
|
1612
|
+
|
|
1613
|
+
Example: now
|
|
1614
|
+
|
|
1615
|
+
```jsx
|
|
1616
|
+
<FormattedRelativeTime value={0} numeric='auto' updateIntervalInSeconds={1} />
|
|
1617
|
+
```
|
|
1618
|
+
|
|
1619
|
+
<FormattedRelativeTime value={0} numeric='auto' updateIntervalInSeconds={1} />
|
|
1620
|
+
|
|
1621
|
+
- "Yesterday"
|
|
1622
|
+
- "Yesterday, 10:39"
|
|
1623
|
+
- "Today, 12:17"
|
|
1624
|
+
- "Tomorrow"
|
|
1625
|
+
- "Last week"
|
|
1626
|
+
- "Next Friday"
|
|
1627
|
+
- "In 3 days"
|
|
1628
|
+
|
|
1629
|
+
- Displaying upcoming or past calendar events
|
|
1630
|
+
- Highlighting recent activity within a timeframe (e.g., "Top posts from the past week")
|
|
1631
|
+
- Providing deadlines or due dates in a user-friendly way
|
|
1632
|
+
- Benefits
|
|
1633
|
+
- Intuitive understanding for users familiar with common timeframes Reduces mental calculations for interpreting absolute dates
|
|
1634
|
+
|
|
1635
|
+
- Intuitive understanding for users familiar with common timeframes
|
|
1636
|
+
- Reduces mental calculations for interpreting absolute dates
|
|
1637
|
+
|
|
1638
|
+
The choice between relative and absolute formats depends on the context and desired level of precision:
|
|
1639
|
+
|
|
1640
|
+
- Use relative formats: When the time difference or date proximity is more important than the exact timestamp. Example: "Your flight departs in 2 hours" is more relevant than "Your flight departs at 14:30".
|
|
1641
|
+
- Use absolute formats: When precise timestamps are crucial, or for long time spans where relative terms become ambiguous.
|
|
1642
|
+
|
|
1643
|
+
Example for an upcoming event using ReactIntl: In 3 Days
|
|
1644
|
+
|
|
1645
|
+
in 3 days
|
|
1646
|
+
|
|
1647
|
+
```jsx
|
|
1648
|
+
<FormattedRelativeTime value={0} numeric='auto' updateIntervalInSeconds={1} />
|
|
1649
|
+
```
|
|
1650
|
+
|
|
1651
|
+
<FormattedRelativeTime value={0} numeric='auto' updateIntervalInSeconds={1} />
|
|
1652
|
+
|
|
1653
|
+
- Locale and cultural context: Relative terms like "yesterday" or "next week" might vary across languages and cultures. Consider user locale when implementing these formats.
|
|
1654
|
+
- Level of detail: You might need to adjust the granularity of relative formats. For example, "3 weeks ago" might be more appropriate than "21 days ago" depending on the context.
|
|
1655
|
+
|
|
1656
|
+
## Time format including timezones
|
|
1657
|
+
|
|
1658
|
+
Time format including timezones
|
|
1659
|
+
|
|
1660
|
+
**Understanding time zones can be challenging**
|
|
1661
|
+
|
|
1662
|
+
While time zones are essential for global coordination, navigating them can be complex. Most users naturally think and schedule their activities in their local time zone. Concepts like Coordinated Universal Time (UTC) and daylight saving time (DST) can add layers of complexity.
|
|
1663
|
+
|
|
1664
|
+
This table lists the main timezones used across Europe, including their standard times and any daylight saving times. Note that some regions do not observe daylight saving time.
|
|
1665
|
+
|
|
1666
|
+
| Region | Standard Time (ST) | Daylight Saving Time (DST) |
|
|
1667
|
+
| --- | --- | --- |
|
|
1668
|
+
| Western European Time (WET) | GMT+0 | Western European Summer Time (WEST, GMT+1) |
|
|
1669
|
+
| Central European Time (CET) | GMT+1 | Central European Summer Time (CEST, GMT+2) |
|
|
1670
|
+
| Eastern European Time (EET) | GMT+2 | Eastern European Summer Time (EEST, GMT+3) |
|
|
1671
|
+
| Greenwich Mean Time (GMT) | GMT+0 | British Summer Time (BST, GMT+1) |
|
|
1672
|
+
| Further-Eastern European Time (FET) | GMT+3 | No DST |
|
|
1673
|
+
| Kaliningrad Time (KALT) | GMT+2 | No DST |
|
|
1674
|
+
| Moscow Time (MSK) | GMT+3 | No DST |
|
|
1675
|
+
| Turkey Time (TRT) | GMT+3 | No DST |
|
|
1676
|
+
| Armenia Time (AMT) | GMT+4 | No DST |
|
|
1677
|
+
| Azerbaijan Time (AZT) | GMT+4 | Azerbaijan Summer Time (AZST, GMT+5) |
|
|
1678
|
+
| Georgia Time (GET) | GMT+4 | No DST |
|
|
1679
|
+
|
|
1680
|
+
Studies show that users think in their local time - users often don’t think about UTC at all. Nor do they understand time zones, or the difference between UTC and GMT, or when and where daylight saving times are. But GMT is a more familiar time standard than UTC (even though UTC is the correct time standard). Since the UTC and GMT have the same offset and is widely more common in user interfaces, it is recommended to show GTM to the user instead of UTC.
|
|
1681
|
+
|
|
1682
|
+
For optimal clarity and consistency, it's best to display time zone offsets like GMT+1:00 without a blank space before the "+" symbol.
|
|
1683
|
+
|
|
1684
|
+
**Prioritize the user's local time**
|
|
1685
|
+
|
|
1686
|
+
To simplify the user's experience, we prioritize displaying times in your local time zone. This eliminates the need for manual conversions or deciphering time zone differences.
|
|
1687
|
+
|
|
1688
|
+
**Time zone transparency**
|
|
1689
|
+
|
|
1690
|
+
While we present times in the user's local time zone by default, we understand the importance of transparency. If needed, you can display information regarding the corresponding GMT time.
|
|
1691
|
+
|
|
1692
|
+
- Primary display: Show times in the user's local timezone for ease of use
|
|
1693
|
+
- Secondary display: Include the GMT offset in smaller text or tooltips to provide additional context
|
|
1694
|
+
|
|
1695
|
+
**Total duration matters**
|
|
1696
|
+
|
|
1697
|
+
For situations with multiple locations and time zones, providing a clear "total travel time" or "duration" alongside the individual departure and arrival times is incredibly helpful. This provides a comprehensive picture of the overall journey, just like the best travel itineraries do.
|
|
1698
|
+
|
|
1699
|
+
**Event-Based timezones**
|
|
1700
|
+
|
|
1701
|
+
For events, show both the local time and the event's original timezone. For example, "Meeting scheduled for 15:00 (CEST) / 16:00 (EEST)
|
|
1702
|
+
|
|
1703
|
+
Meeting scheduled for 15:00 (CEST) / 16:00 (EEST)
|
|
1704
|
+
|
|
1705
|
+
**Localizing time displays for various European countries**
|
|
1706
|
+
|
|
1707
|
+
When localizing time displays for German-speaking users, remember to append the term "Uhr" (with a blank separator) after the hour when displaying times in a 24-hour format to ensure accurate and culturally appropriate representation.
|
|
1708
|
+
|
|
1709
|
+
This table provides a comprehensive overview of how to handle time display formats across various European countries, ensuring localized and accurate time representations.
|
|
1710
|
+
|
|
1711
|
+
| Locale | Country | Time format | Standard Time (ST) | Daylight Saving Time (DST) |
|
|
1712
|
+
| --- | --- | --- | --- | --- |
|
|
1713
|
+
| bg-BG | Bulgaria | 24-hour | 16:00 (EET) | 17:00 (EEST) |
|
|
1714
|
+
| cs-CZ | Czech Republic | 24-hour | 15:00 (CET) | 16:00 (CEST) |
|
|
1715
|
+
| da-DK | Denmark | 24-hour | 15:00 (CET) | 16:00 (CEST) |
|
|
1716
|
+
| de-DE | Germany | 24-hour | 15:00 Uhr (CET) | 16:00 Uhr (CEST) |
|
|
1717
|
+
| el-GR | Greece | 24-hour | 16:00 (EET) | 17:00 (EEST) |
|
|
1718
|
+
| en-GB | United Kingdom | 24-hour | 15:00 (GMT) | 16:00 (BST) |
|
|
1719
|
+
| es-ES | Spain | 24-hour | 15:00 (CET) | 16:00 (CEST) |
|
|
1720
|
+
| et-EE | Estonia | 24-hour | 16:00 (EET) | 17:00 (EEST) |
|
|
1721
|
+
| fi-FI | Finland | 24-hour | 16:00 (EET) | 17:00 (EEST) |
|
|
1722
|
+
| fr-FR | France | 24-hour | 15:00 (CET) | 16:00 (CEST) |
|
|
1723
|
+
| hr-HR | Croatia | 24-hour | 15:00 (CET) | 16:00 (CEST) |
|
|
1724
|
+
| hu-HU | Hungary | 24-hour | 15:00 (CET) | 16:00 (CEST) |
|
|
1725
|
+
| it-IT | Italy | 24-hour | 15:00 (CET) | 16:00 (CEST) |
|
|
1726
|
+
| lt-LT | Lithuania | 24-hour | 16:00 (EET) | 17:00 (EEST) |
|
|
1727
|
+
| lv-LV | Latvia | 24-hour | 16:00 (EET) | 17:00 (EEST) |
|
|
1728
|
+
| nb-NO | Norway | 24-hour | 15:00 (CET) | 16:00 (CEST) |
|
|
1729
|
+
| nl-NL | Netherlands | 24-hour | 15:00 (CET) | 16:00 (CEST) |
|
|
1730
|
+
| pl-PL | Poland | 24-hour | 15:00 (CET) | 16:00 (CEST) |
|
|
1731
|
+
| pt-BR | Brazil | 24-hour | 15:00 (BRT) | 16:00 (BRST) |
|
|
1732
|
+
| pt-PT | Portugal | 24-hour | 15:00 (WET) | 16:00 (WEST) |
|
|
1733
|
+
| ro-RO | Romania | 24-hour | 16:00 (EET) | 17:00 (EEST) |
|
|
1734
|
+
| sk-SK | Slovakia | 24-hour | 15:00 (CET) | 16:00 (CEST) |
|
|
1735
|
+
| sl-SI | Slovenia | 24-hour | 15:00 (CET) | 16:00 (CEST) |
|
|
1736
|
+
| sv-SE | Sweden | 24-hour | 15:00 (CET) | 16:00 (CEST) |
|
|
1737
|
+
|
|
1738
|
+
Today, 1 Jun 2024Export
|
|
1739
|
+
|
|
1740
|
+
No tasks for todayThere are no tasks created for today. Enjoy your day.
|
|
1741
|
+
|
|
1742
|
+
Public holidays
|
|
1743
|
+
|
|
1744
|
+
- Constitution Day 23/05/2024, 3 days ago
|
|
1745
|
+
- Assumption Day 15/08/2024, in 64 days
|
|
1746
|
+
|
|
1747
|
+
Constitution Day23/05/2024, 3 days ago
|
|
1748
|
+
|
|
1749
|
+
Assumption Day15/08/2024, in 64 days
|
|
1750
|
+
|
|
1751
|
+
27 May - 30 May 2024
|
|
1752
|
+
|
|
1753
|
+
30/05/2024
|
|
1754
|
+
|
|
1755
|
+
| Username | Working hours | Total working time | Last Check-In time |
|
|
1756
|
+
| --- | --- | --- | --- |
|
|
1757
|
+
| Sarah Jones | 11:00 - 19:00 | 8h | 20 minutes ago |
|
|
1758
|
+
| David Miller | 08:00 - 14:30 | 6h 30min | 10 hours ago |
|
|
1759
|
+
| David Ripley | 10:45 - 18:15 | 7h 30min | 1 hour ago |
|
|
1760
|
+
|
|
1761
|
+
29/05/2024
|
|
1762
|
+
|
|
1763
|
+
## Number formats
|
|
1764
|
+
|
|
1765
|
+
## Number formats overview
|
|
1766
|
+
|
|
1767
|
+
Number formats overview
|
|
1768
|
+
|
|
1769
|
+
This is a list of all supported langues and their respective country, decimal separator, thousand separator, and an example of a formatted number.
|
|
1770
|
+
|
|
1771
|
+
| Locale | Country | Decimal Separator | Thousand Separator | Example |
|
|
1772
|
+
| --- | --- | --- | --- | --- |
|
|
1773
|
+
| bg-BG | Bulgaria | Comma (,) | Space ( ) | 1 234 567,89 |
|
|
1774
|
+
| cs-CZ | Czech Republic | Comma (,) | Space ( ) | 1 234 567,89 |
|
|
1775
|
+
| da-DK | Denmark | Comma (,) | Period (.) | 1.234.567,89 |
|
|
1776
|
+
| de-DE | Germany | Comma (,) | Period (.) | 1.234.567,89 |
|
|
1777
|
+
| el-GR | Greece | Comma (,) | Period (.) | 1.234.567,89 |
|
|
1778
|
+
| en-GB | United Kingdom | Period (.) | Comma (,) | 1,234,567.89 |
|
|
1779
|
+
| es-ES | Spain | Comma (,) | Period (.) | 1.234.567,89 |
|
|
1780
|
+
| et-EE | Estonia | Comma (,) | Space ( ) | 1 234 567,89 |
|
|
1781
|
+
| fi-FI | Finland | Comma (,) | Space ( ) | 1 234 567,89 |
|
|
1782
|
+
| fr-FR | France | Comma (,) | Space ( ) | 1 234 567,89 |
|
|
1783
|
+
| hr-HR | Croatia | Comma (,) | Period (.) | 1.234.567,89 |
|
|
1784
|
+
| hu-HU | Hungary | Comma (,) | Space ( ) | 1 234 567,89 |
|
|
1785
|
+
| it-IT | Italy | Comma (,) | Dot (.) | 1.234.567,89 |
|
|
1786
|
+
| lt-LT | Lithuania | Comma (,) | Space ( ) | 1 234 567,89 |
|
|
1787
|
+
| lv-LV | Latvia | Comma (,) | Space ( ) | 1 234 567,89 |
|
|
1788
|
+
| nb-NO | Norway | Comma (,) | Space ( ) | 1 234 567,89 |
|
|
1789
|
+
| nl-NL | Netherlands | Comma (,) | Period (.) | 1.234.567,89 |
|
|
1790
|
+
| pl-PL | Poland | Comma (,) | Space ( ) | 1 234 567,89 |
|
|
1791
|
+
| pt-BR | Brazil | Comma (,) | Period (.) | 1.234.567,89 |
|
|
1792
|
+
| pt-PT | Portugal | Comma (,) | Period (.) | 1.234.567,89 |
|
|
1793
|
+
| ro-RO | Romania | Comma (,) | Period (.) | 1.234.567,89 |
|
|
1794
|
+
| sk-SK | Slovakia | Comma (,) | Space ( ) | 1 234 567,89 |
|
|
1795
|
+
| sl-SI | Slovenia | Comma (,) | Period (.) | 1.234.567,89 |
|
|
1796
|
+
| sv-SE | Sweden | Comma (,) | Space ( ) | 1 234 567,89 |
|
|
1797
|
+
|
|
1798
|
+
**Best practices for number formatting**
|
|
1799
|
+
|
|
1800
|
+
- Locale awareness Always format numbers based on the user’s locale settings to ensure familiarity and reduce errors
|
|
1801
|
+
- Consistent use of delimiters Ensure the consistent use of decimal and thousand separators as per the locale’s conventions
|
|
1802
|
+
- Handling edge cases Be aware of edge cases like negative numbers, very large numbers, and numbers with many decimal places
|
|
1803
|
+
- Use libraries Utilize libraries like ReactIntl to handle number formatting, which provides built-in support for multiple locales and ensures correctness
|
|
1804
|
+
|
|
1805
|
+
```jsx
|
|
1806
|
+
const NumberFormattingExample = () => {
|
|
1807
|
+
const number = 1234567.89;
|
|
1808
|
+
|
|
1809
|
+
return (
|
|
1810
|
+
<IntlProvider locale="de-DE">
|
|
1811
|
+
<FormattedNumber value={number} />
|
|
1812
|
+
</IntlProvider>
|
|
1813
|
+
);
|
|
1814
|
+
};
|
|
1815
|
+
```
|
|
1816
|
+
|
|
1817
|
+
const
|
|
1818
|
+
|
|
1819
|
+
NumberFormattingExample
|
|
1820
|
+
|
|
1821
|
+
=
|
|
1822
|
+
|
|
1823
|
+
(
|
|
1824
|
+
|
|
1825
|
+
)
|
|
1826
|
+
|
|
1827
|
+
=>
|
|
1828
|
+
|
|
1829
|
+
{
|
|
1830
|
+
|
|
1831
|
+
const
|
|
1832
|
+
|
|
1833
|
+
=
|
|
1834
|
+
|
|
1835
|
+
1234567.89
|
|
1836
|
+
|
|
1837
|
+
;
|
|
1838
|
+
|
|
1839
|
+
return
|
|
1840
|
+
|
|
1841
|
+
(
|
|
1842
|
+
|
|
1843
|
+
<IntlProvider locale="de-DE">
|
|
1844
|
+
|
|
1845
|
+
<FormattedNumber value={number} />
|
|
1846
|
+
|
|
1847
|
+
</IntlProvider>
|
|
1848
|
+
|
|
1849
|
+
)
|
|
1850
|
+
|
|
1851
|
+
;
|
|
1852
|
+
|
|
1853
|
+
}
|
|
1854
|
+
|
|
1855
|
+
;
|
|
1856
|
+
|
|
1857
|
+
In this example, the number 1234567.89 will be formatted as 1.234.567,89 in the German locale.
|
|
1858
|
+
|
|
1859
|
+
## Omit unused or meaningless decimals
|
|
1860
|
+
|
|
1861
|
+
Omit unused or meaningless decimals
|
|
1862
|
+
|
|
1863
|
+
When displaying numbers with units, it's often more readable and professional to omit unnecessary trailing zeros in decimal places. For instance, displaying "123 km" instead of "123.0 km" when the value is a whole number.
|
|
1864
|
+
|
|
1865
|
+
Additionally, decimals should be omitted in cases where they do not add meaningful information, such as in a fuel level "74,87 %".
|
|
1866
|
+
|
|
1867
|
+
```jsx
|
|
1868
|
+
<FormattedNumber
|
|
1869
|
+
value={123.0}
|
|
1870
|
+
minimumFractionDigits={0}
|
|
1871
|
+
maximumFractionDigits={2}
|
|
1872
|
+
style='unit'
|
|
1873
|
+
unit='kilometer'
|
|
1874
|
+
/>
|
|
1875
|
+
```
|
|
1876
|
+
|
|
1877
|
+
<FormattedNumber value={123.0} minimumFractionDigits={0} maximumFractionDigits={2} style='unit' unit='kilometer' />
|
|
1878
|
+
|
|
1879
|
+
Example
|
|
1880
|
+
|
|
1881
|
+
> 123 km 1,234 km Fuel level: 75%
|
|
1882
|
+
|
|
1883
|
+
> 123.0 km 1234.0 km Fuel level: 74,87 %
|
|
1884
|
+
|
|
1885
|
+
## Formatting numbers with units
|
|
1886
|
+
|
|
1887
|
+
Formatting numbers with units
|
|
1888
|
+
|
|
1889
|
+
ReactIntl also supports formatting units like currency, percentages, and other measurements. Here are some examples on how to format numbers with units.
|
|
1890
|
+
|
|
1891
|
+
| en-GB | |
|
|
1892
|
+
| --- | --- |
|
|
1893
|
+
| Kilograms | 1,234.56 kg |
|
|
1894
|
+
| Kilometer | 1,234.56 km |
|
|
1895
|
+
| Kilometer (long) | 1,234.56 kilometres |
|
|
1896
|
+
| Meters | 1,234.56 m |
|
|
1897
|
+
| Kilowatt-hour* | 1,234.56 kWh |
|
|
1898
|
+
| Megawatt-hour* | 1,234.56 MWh |
|
|
1899
|
+
| Seconds (long) | 45 seconds |
|
|
1900
|
+
| Minutes (long) | 12 minutes |
|
|
1901
|
+
| Centimeters | 34 cm |
|
|
1902
|
+
| Percent | 12% |
|
|
1903
|
+
| Euro | €1,234.56 |
|
|
1904
|
+
| Kilobyte | 1,000kB |
|
|
1905
|
+
| Celsius | 27°C |
|
|
1906
|
+
| Duration | 2h 45min |
|
|
1907
|
+
|
|
1908
|
+
| de-DE | |
|
|
1909
|
+
| --- | --- |
|
|
1910
|
+
| Kilograms | 1.234,56 kg |
|
|
1911
|
+
| Kilometer | 1.234,56 km |
|
|
1912
|
+
| Kilometer (long) | 1.234,56 Kilometer |
|
|
1913
|
+
| Meters | 1.234,56 m |
|
|
1914
|
+
| Square meters | 1.234,56 m2 |
|
|
1915
|
+
| Cubic meters | 1.234,56 m3 |
|
|
1916
|
+
| Kilowatt-hour* | 1.234,56 kWh |
|
|
1917
|
+
| Megawatt-hour* | 1.234,56 MWh |
|
|
1918
|
+
| Seconds (long) | 45 Sekunden |
|
|
1919
|
+
| Minutes (long) | 12 Minuten |
|
|
1920
|
+
| Centimeters | 34 cm |
|
|
1921
|
+
| Percent | 12 % |
|
|
1922
|
+
| Euro | 1.234,56 € |
|
|
1923
|
+
| Kilobyte | 1.000 kB |
|
|
1924
|
+
| Celsius | 27 °C |
|
|
1925
|
+
| Duration | 2h 45min |
|
|
1926
|
+
|
|
1927
|
+
* Note: kilowatt-hour and megawatt-hour are not yet supported byIntl.NumberFormat(). Please append the unit manually. For more details, see here
|
|
1928
|
+
|
|
1929
|
+
```jsx
|
|
1930
|
+
const NumberExample = () => {
|
|
1931
|
+
const value = 1234.56;
|
|
1932
|
+
return (
|
|
1933
|
+
<table className='table table-condensed'>
|
|
443
1934
|
<tbody>
|
|
444
1935
|
<tr>
|
|
445
1936
|
<td>Kilograms</td>
|
|
@@ -478,47 +1969,285 @@ return (
|
|
|
478
1969
|
</td>
|
|
479
1970
|
</tr>
|
|
480
1971
|
<tr>
|
|
481
|
-
<td>Centimeters</td>
|
|
1972
|
+
<td>Centimeters</td>
|
|
1973
|
+
<td>
|
|
1974
|
+
<FormattedNumber value={34} style='unit' unit='centimeter' />
|
|
1975
|
+
</td>
|
|
1976
|
+
</tr>
|
|
1977
|
+
<tr>
|
|
1978
|
+
<td>Percent</td>
|
|
1979
|
+
<td>
|
|
1980
|
+
<FormattedNumber value={0.1234} style='percent' />
|
|
1981
|
+
</td>
|
|
1982
|
+
</tr>
|
|
1983
|
+
<tr>
|
|
1984
|
+
<td>Euro</td>
|
|
1985
|
+
<td>
|
|
1986
|
+
<FormattedNumber value={value} style='currency' currency='EUR' />
|
|
1987
|
+
</td>
|
|
1988
|
+
</tr>
|
|
1989
|
+
<tr>
|
|
1990
|
+
<td>Kilobyte</td>
|
|
1991
|
+
<td>
|
|
1992
|
+
<FormattedNumber value={1000} style='unit' unit='kilobyte' unitDisplay='narrow' />
|
|
1993
|
+
</td>
|
|
1994
|
+
</tr>
|
|
1995
|
+
<tr>
|
|
1996
|
+
<td>Celsius</td>
|
|
1997
|
+
<td>
|
|
1998
|
+
<FormattedNumber value={27} style='unit' unit='celsius' unitDisplay='narrow' />
|
|
1999
|
+
</td>
|
|
2000
|
+
</tr>
|
|
2001
|
+
<tr>
|
|
2002
|
+
<td>Duration</td>
|
|
2003
|
+
<td>
|
|
2004
|
+
<FormattedNumber value={2} />h <FormattedNumber value={45} />
|
|
2005
|
+
min
|
|
2006
|
+
</td>
|
|
2007
|
+
</tr>
|
|
2008
|
+
</tbody>
|
|
2009
|
+
</table>
|
|
2010
|
+
)
|
|
2011
|
+
};
|
|
2012
|
+
```
|
|
2013
|
+
|
|
2014
|
+
const
|
|
2015
|
+
|
|
2016
|
+
NumberExample
|
|
2017
|
+
|
|
2018
|
+
=
|
|
2019
|
+
|
|
2020
|
+
(
|
|
2021
|
+
|
|
2022
|
+
)
|
|
2023
|
+
|
|
2024
|
+
=>
|
|
2025
|
+
|
|
2026
|
+
{
|
|
2027
|
+
|
|
2028
|
+
const
|
|
2029
|
+
|
|
2030
|
+
=
|
|
2031
|
+
|
|
2032
|
+
1234.56
|
|
2033
|
+
|
|
2034
|
+
;
|
|
2035
|
+
|
|
2036
|
+
return
|
|
2037
|
+
|
|
2038
|
+
(
|
|
2039
|
+
|
|
2040
|
+
<table className='table table-condensed'>
|
|
2041
|
+
|
|
2042
|
+
<tbody>
|
|
2043
|
+
|
|
2044
|
+
<tr>
|
|
2045
|
+
|
|
2046
|
+
<td>
|
|
2047
|
+
|
|
2048
|
+
Kilograms
|
|
2049
|
+
|
|
2050
|
+
</td>
|
|
2051
|
+
|
|
2052
|
+
<td>
|
|
2053
|
+
|
|
2054
|
+
<FormattedNumber value={value} style='unit' unit='kilogram' />
|
|
2055
|
+
|
|
2056
|
+
</td>
|
|
2057
|
+
|
|
2058
|
+
</tr>
|
|
2059
|
+
|
|
2060
|
+
<tr>
|
|
2061
|
+
|
|
2062
|
+
<td>
|
|
2063
|
+
|
|
2064
|
+
Kilometer
|
|
2065
|
+
|
|
2066
|
+
</td>
|
|
2067
|
+
|
|
2068
|
+
<td>
|
|
2069
|
+
|
|
2070
|
+
<FormattedNumber value={value} style='unit' unit='kilometer' />
|
|
2071
|
+
|
|
2072
|
+
</td>
|
|
2073
|
+
|
|
2074
|
+
</tr>
|
|
2075
|
+
|
|
2076
|
+
<tr>
|
|
2077
|
+
|
|
2078
|
+
<td>
|
|
2079
|
+
|
|
2080
|
+
Kilometer (long)
|
|
2081
|
+
|
|
2082
|
+
</td>
|
|
2083
|
+
|
|
2084
|
+
<td>
|
|
2085
|
+
|
|
2086
|
+
<FormattedNumber value={value} style='unit' unit='kilometer' unitDisplay='long' />
|
|
2087
|
+
|
|
2088
|
+
</td>
|
|
2089
|
+
|
|
2090
|
+
</tr>
|
|
2091
|
+
|
|
2092
|
+
<tr>
|
|
2093
|
+
|
|
2094
|
+
<td>
|
|
2095
|
+
|
|
2096
|
+
Meters
|
|
2097
|
+
|
|
2098
|
+
</td>
|
|
2099
|
+
|
|
2100
|
+
<td>
|
|
2101
|
+
|
|
2102
|
+
<FormattedNumber value={value} style='unit' unit='meter' />
|
|
2103
|
+
|
|
2104
|
+
</td>
|
|
2105
|
+
|
|
2106
|
+
</tr>
|
|
2107
|
+
|
|
2108
|
+
<tr>
|
|
2109
|
+
|
|
2110
|
+
<td>
|
|
2111
|
+
|
|
2112
|
+
Seconds (long)
|
|
2113
|
+
|
|
2114
|
+
</td>
|
|
2115
|
+
|
|
2116
|
+
<td>
|
|
2117
|
+
|
|
2118
|
+
<FormattedNumber value={45} style='unit' unit='second' unitDisplay='long' />
|
|
2119
|
+
|
|
2120
|
+
</td>
|
|
2121
|
+
|
|
2122
|
+
</tr>
|
|
2123
|
+
|
|
2124
|
+
<tr>
|
|
2125
|
+
|
|
2126
|
+
<td>
|
|
2127
|
+
|
|
2128
|
+
Minutes (long)
|
|
2129
|
+
|
|
2130
|
+
</td>
|
|
2131
|
+
|
|
2132
|
+
<td>
|
|
2133
|
+
|
|
2134
|
+
<FormattedNumber value={12} style='unit' unit='minute' unitDisplay='long' />
|
|
2135
|
+
|
|
2136
|
+
</td>
|
|
2137
|
+
|
|
2138
|
+
</tr>
|
|
2139
|
+
|
|
2140
|
+
<tr>
|
|
2141
|
+
|
|
2142
|
+
<td>
|
|
2143
|
+
|
|
2144
|
+
Centimeters
|
|
2145
|
+
|
|
2146
|
+
</td>
|
|
2147
|
+
|
|
482
2148
|
<td>
|
|
2149
|
+
|
|
483
2150
|
<FormattedNumber value={34} style='unit' unit='centimeter' />
|
|
2151
|
+
|
|
484
2152
|
</td>
|
|
2153
|
+
|
|
485
2154
|
</tr>
|
|
2155
|
+
|
|
486
2156
|
<tr>
|
|
487
|
-
|
|
2157
|
+
|
|
2158
|
+
<td>
|
|
2159
|
+
|
|
2160
|
+
Percent
|
|
2161
|
+
|
|
2162
|
+
</td>
|
|
2163
|
+
|
|
488
2164
|
<td>
|
|
2165
|
+
|
|
489
2166
|
<FormattedNumber value={0.1234} style='percent' />
|
|
2167
|
+
|
|
490
2168
|
</td>
|
|
2169
|
+
|
|
491
2170
|
</tr>
|
|
2171
|
+
|
|
492
2172
|
<tr>
|
|
493
|
-
|
|
2173
|
+
|
|
2174
|
+
<td>
|
|
2175
|
+
|
|
2176
|
+
Euro
|
|
2177
|
+
|
|
2178
|
+
</td>
|
|
2179
|
+
|
|
494
2180
|
<td>
|
|
2181
|
+
|
|
495
2182
|
<FormattedNumber value={value} style='currency' currency='EUR' />
|
|
2183
|
+
|
|
496
2184
|
</td>
|
|
2185
|
+
|
|
497
2186
|
</tr>
|
|
2187
|
+
|
|
498
2188
|
<tr>
|
|
499
|
-
|
|
2189
|
+
|
|
500
2190
|
<td>
|
|
2191
|
+
|
|
2192
|
+
Kilobyte
|
|
2193
|
+
|
|
2194
|
+
</td>
|
|
2195
|
+
|
|
2196
|
+
<td>
|
|
2197
|
+
|
|
501
2198
|
<FormattedNumber value={1000} style='unit' unit='kilobyte' unitDisplay='narrow' />
|
|
2199
|
+
|
|
502
2200
|
</td>
|
|
2201
|
+
|
|
503
2202
|
</tr>
|
|
2203
|
+
|
|
504
2204
|
<tr>
|
|
505
|
-
|
|
2205
|
+
|
|
2206
|
+
<td>
|
|
2207
|
+
|
|
2208
|
+
Celsius
|
|
2209
|
+
|
|
2210
|
+
</td>
|
|
2211
|
+
|
|
506
2212
|
<td>
|
|
2213
|
+
|
|
507
2214
|
<FormattedNumber value={27} style='unit' unit='celsius' unitDisplay='narrow' />
|
|
2215
|
+
|
|
508
2216
|
</td>
|
|
2217
|
+
|
|
509
2218
|
</tr>
|
|
2219
|
+
|
|
510
2220
|
<tr>
|
|
511
|
-
|
|
2221
|
+
|
|
512
2222
|
<td>
|
|
513
|
-
|
|
2223
|
+
|
|
2224
|
+
Duration
|
|
2225
|
+
|
|
2226
|
+
</td>
|
|
2227
|
+
|
|
2228
|
+
<td>
|
|
2229
|
+
|
|
2230
|
+
<FormattedNumber value={2} />
|
|
2231
|
+
|
|
2232
|
+
h
|
|
2233
|
+
|
|
2234
|
+
<FormattedNumber value={45} />
|
|
2235
|
+
|
|
514
2236
|
min
|
|
2237
|
+
|
|
515
2238
|
</td>
|
|
2239
|
+
|
|
516
2240
|
</tr>
|
|
2241
|
+
|
|
517
2242
|
</tbody>
|
|
2243
|
+
|
|
518
2244
|
</table>
|
|
2245
|
+
|
|
519
2246
|
)
|
|
520
|
-
|
|
521
|
-
|
|
2247
|
+
|
|
2248
|
+
}
|
|
2249
|
+
|
|
2250
|
+
;
|
|
522
2251
|
|
|
523
2252
|
In Germany, the correct unit format for kilogram is "kg" with a lowercase "k" and "g". It follows the international standard for unit symbols defined by the International System of Units (SI).
|
|
524
2253
|
|
|
@@ -529,10 +2258,16 @@ Here's an example of the correct usage:
|
|
|
529
2258
|
|
|
530
2259
|
The unit symbol should always be in lowercase and a space should be used between the number and the unit symbol
|
|
531
2260
|
|
|
2261
|
+
> Note: When formatting durations in a short format, ReactIntl does not follow the more common style defined in the section "Format durations" especially for locales like de-DE. In this case we need to combine the FormattedNumber with a custom unit.
|
|
2262
|
+
|
|
532
2263
|
```jsx
|
|
533
2264
|
<FormattedNumber value={2} />h <FormattedNumber value={45} />min
|
|
534
2265
|
```
|
|
535
2266
|
|
|
2267
|
+
<FormattedNumber value={2} />
|
|
2268
|
+
|
|
2269
|
+
<FormattedNumber value={45} />
|
|
2270
|
+
|
|
536
2271
|
```tsx
|
|
537
2272
|
type FormattedDuration = {
|
|
538
2273
|
hours?: number,
|
|
@@ -582,4 +2317,276 @@ return (
|
|
|
582
2317
|
</div>
|
|
583
2318
|
);
|
|
584
2319
|
};
|
|
585
|
-
```
|
|
2320
|
+
```
|
|
2321
|
+
|
|
2322
|
+
type
|
|
2323
|
+
|
|
2324
|
+
FormattedDuration
|
|
2325
|
+
|
|
2326
|
+
=
|
|
2327
|
+
|
|
2328
|
+
{
|
|
2329
|
+
|
|
2330
|
+
?
|
|
2331
|
+
|
|
2332
|
+
:
|
|
2333
|
+
|
|
2334
|
+
number
|
|
2335
|
+
|
|
2336
|
+
,
|
|
2337
|
+
|
|
2338
|
+
?
|
|
2339
|
+
|
|
2340
|
+
:
|
|
2341
|
+
|
|
2342
|
+
number
|
|
2343
|
+
|
|
2344
|
+
,
|
|
2345
|
+
|
|
2346
|
+
?
|
|
2347
|
+
|
|
2348
|
+
:
|
|
2349
|
+
|
|
2350
|
+
number
|
|
2351
|
+
|
|
2352
|
+
,
|
|
2353
|
+
|
|
2354
|
+
}
|
|
2355
|
+
|
|
2356
|
+
;
|
|
2357
|
+
|
|
2358
|
+
const
|
|
2359
|
+
|
|
2360
|
+
FormattedDuration
|
|
2361
|
+
|
|
2362
|
+
=
|
|
2363
|
+
|
|
2364
|
+
(
|
|
2365
|
+
|
|
2366
|
+
{
|
|
2367
|
+
|
|
2368
|
+
,
|
|
2369
|
+
|
|
2370
|
+
,
|
|
2371
|
+
|
|
2372
|
+
}
|
|
2373
|
+
|
|
2374
|
+
)
|
|
2375
|
+
|
|
2376
|
+
=>
|
|
2377
|
+
|
|
2378
|
+
{
|
|
2379
|
+
|
|
2380
|
+
const
|
|
2381
|
+
|
|
2382
|
+
=
|
|
2383
|
+
|
|
2384
|
+
>
|
|
2385
|
+
|
|
2386
|
+
0
|
|
2387
|
+
|
|
2388
|
+
;
|
|
2389
|
+
|
|
2390
|
+
const
|
|
2391
|
+
|
|
2392
|
+
=
|
|
2393
|
+
|
|
2394
|
+
>
|
|
2395
|
+
|
|
2396
|
+
0
|
|
2397
|
+
|
|
2398
|
+
;
|
|
2399
|
+
|
|
2400
|
+
const
|
|
2401
|
+
|
|
2402
|
+
=
|
|
2403
|
+
|
|
2404
|
+
>
|
|
2405
|
+
|
|
2406
|
+
0
|
|
2407
|
+
|
|
2408
|
+
;
|
|
2409
|
+
|
|
2410
|
+
return
|
|
2411
|
+
|
|
2412
|
+
(
|
|
2413
|
+
|
|
2414
|
+
<div>
|
|
2415
|
+
|
|
2416
|
+
{
|
|
2417
|
+
|
|
2418
|
+
&&
|
|
2419
|
+
|
|
2420
|
+
(
|
|
2421
|
+
|
|
2422
|
+
<>
|
|
2423
|
+
|
|
2424
|
+
<FormattedNumber value={hours} />
|
|
2425
|
+
|
|
2426
|
+
h
|
|
2427
|
+
|
|
2428
|
+
{
|
|
2429
|
+
|
|
2430
|
+
&&
|
|
2431
|
+
|
|
2432
|
+
' '
|
|
2433
|
+
|
|
2434
|
+
}
|
|
2435
|
+
|
|
2436
|
+
</>
|
|
2437
|
+
|
|
2438
|
+
)
|
|
2439
|
+
|
|
2440
|
+
}
|
|
2441
|
+
|
|
2442
|
+
{
|
|
2443
|
+
|
|
2444
|
+
&&
|
|
2445
|
+
|
|
2446
|
+
(
|
|
2447
|
+
|
|
2448
|
+
<>
|
|
2449
|
+
|
|
2450
|
+
<FormattedNumber value={minutes} />
|
|
2451
|
+
|
|
2452
|
+
min
|
|
2453
|
+
|
|
2454
|
+
{
|
|
2455
|
+
|
|
2456
|
+
&&
|
|
2457
|
+
|
|
2458
|
+
' '
|
|
2459
|
+
|
|
2460
|
+
}
|
|
2461
|
+
|
|
2462
|
+
</>
|
|
2463
|
+
|
|
2464
|
+
)
|
|
2465
|
+
|
|
2466
|
+
}
|
|
2467
|
+
|
|
2468
|
+
{
|
|
2469
|
+
|
|
2470
|
+
&&
|
|
2471
|
+
|
|
2472
|
+
(
|
|
2473
|
+
|
|
2474
|
+
<>
|
|
2475
|
+
|
|
2476
|
+
<FormattedNumber value={seconds} />
|
|
2477
|
+
|
|
2478
|
+
s
|
|
2479
|
+
|
|
2480
|
+
</>
|
|
2481
|
+
|
|
2482
|
+
)
|
|
2483
|
+
|
|
2484
|
+
}
|
|
2485
|
+
|
|
2486
|
+
</div>
|
|
2487
|
+
|
|
2488
|
+
)
|
|
2489
|
+
|
|
2490
|
+
;
|
|
2491
|
+
|
|
2492
|
+
}
|
|
2493
|
+
|
|
2494
|
+
;
|
|
2495
|
+
|
|
2496
|
+
// Example Usage
|
|
2497
|
+
|
|
2498
|
+
const
|
|
2499
|
+
|
|
2500
|
+
App
|
|
2501
|
+
|
|
2502
|
+
=
|
|
2503
|
+
|
|
2504
|
+
(
|
|
2505
|
+
|
|
2506
|
+
)
|
|
2507
|
+
|
|
2508
|
+
=>
|
|
2509
|
+
|
|
2510
|
+
{
|
|
2511
|
+
|
|
2512
|
+
const
|
|
2513
|
+
|
|
2514
|
+
=
|
|
2515
|
+
|
|
2516
|
+
{
|
|
2517
|
+
|
|
2518
|
+
:
|
|
2519
|
+
|
|
2520
|
+
8
|
|
2521
|
+
|
|
2522
|
+
,
|
|
2523
|
+
|
|
2524
|
+
:
|
|
2525
|
+
|
|
2526
|
+
45
|
|
2527
|
+
|
|
2528
|
+
}
|
|
2529
|
+
|
|
2530
|
+
;
|
|
2531
|
+
|
|
2532
|
+
const
|
|
2533
|
+
|
|
2534
|
+
=
|
|
2535
|
+
|
|
2536
|
+
{
|
|
2537
|
+
|
|
2538
|
+
:
|
|
2539
|
+
|
|
2540
|
+
0
|
|
2541
|
+
|
|
2542
|
+
,
|
|
2543
|
+
|
|
2544
|
+
:
|
|
2545
|
+
|
|
2546
|
+
56
|
|
2547
|
+
|
|
2548
|
+
}
|
|
2549
|
+
|
|
2550
|
+
;
|
|
2551
|
+
|
|
2552
|
+
const
|
|
2553
|
+
|
|
2554
|
+
=
|
|
2555
|
+
|
|
2556
|
+
{
|
|
2557
|
+
|
|
2558
|
+
:
|
|
2559
|
+
|
|
2560
|
+
1
|
|
2561
|
+
|
|
2562
|
+
,
|
|
2563
|
+
|
|
2564
|
+
:
|
|
2565
|
+
|
|
2566
|
+
23
|
|
2567
|
+
|
|
2568
|
+
}
|
|
2569
|
+
|
|
2570
|
+
;
|
|
2571
|
+
|
|
2572
|
+
return
|
|
2573
|
+
|
|
2574
|
+
(
|
|
2575
|
+
|
|
2576
|
+
<div>
|
|
2577
|
+
|
|
2578
|
+
<FormattedDuration {...duration1} />
|
|
2579
|
+
|
|
2580
|
+
<FormattedDuration {...duration2} />
|
|
2581
|
+
|
|
2582
|
+
<FormattedDuration {...duration3} />
|
|
2583
|
+
|
|
2584
|
+
</div>
|
|
2585
|
+
|
|
2586
|
+
)
|
|
2587
|
+
|
|
2588
|
+
;
|
|
2589
|
+
|
|
2590
|
+
}
|
|
2591
|
+
|
|
2592
|
+
;
|