Currently there is no centralized and recommended way for date formatting.
Apps use different methods like:
native window.Intl,
moment.js,
FormattedDate / FormattedTime from@kbn/i18n-react (re-exported from react-intl).
There're multiple things that have to be taken into account and have to be done ad-hoc now that leads to inconcistencies and larger developer effort:
Browser locale
Kibana's lang
Advanced settings like dateFormat and dateFormat:tz``dataFormat:dow
Design considerations: (in my opionin)
Set of the utils should support date and time formating, both absolute and relative. Timezone should default to dateFormat:tz from advanced settings
The utils should be easy to use without much boileraplate. Requiring explicitly passing uiSettings into the util is not ok.
Returning strings with native js is a priority . React wrapper is nice to have
Implementation ideas
Think if they should be part of @kbn/i18n since we already have react utils in @kbn/i18n-react. Then consider if @kbn/i18n-reactcan use preferences from advanced settings by default.
Needed for
This ask came up multiple times in the past, but the latest ask was from the observability team @dgieselaar @spong
Describe the feature:
Currently there is no centralized and recommended way for date formatting. Apps use different methods like:
FormattedDate
/FormattedTime
from@kbn/i18n-react
(re-exported from react-intl).There're multiple things that have to be taken into account and have to be done ad-hoc now that leads to inconcistencies and larger developer effort:
dateFormat
anddateFormat:tz``dataFormat:dow
Design considerations: (in my opionin)
dateFormat:tz
from advanced settingsuiSettings
into the util is not ok.Implementation ideas
@kbn/i18n
since we already have react utils in@kbn/i18n-react
. Then consider if@kbn/i18n-react
can use preferences from advanced settings by default.Needed for
This ask came up multiple times in the past, but the latest ask was from the observability team @dgieselaar @spong
Related
https://github.com/elastic/kibana/issues/178115