Skip to content

Support Unicode Technical Standard #35 format in @gravity-ui/date-utils #29

@korvin89

Description

@korvin89

Why we may need it?

Currently in @gravity-ui/date-utils a moment-like format is used. Using this approach has several disadvantages:

  • To implement this approach, it's necessary to have separate files for each locale, for example, this is how it looks in dayjs, which we use in our library. This directory contains 142 files, each up to ~100 lines of code, which makes loading locales in date-utils happen asynchronously.
  • When using moment-like format, you cannot use standalone tokens. For example, the format 'D MMMM' in ru locale will always return '25 Февраля' because it uses complex logic that needs to be repeated for each locale.

Within this RFC, it is proposed to switch to using the Unicode Technical Standard #35 format. Below I suggest we consider its advantages and disadvantages and decide whether we want to switch to it.

Advantages:

  • Using Intl for translating date tokens
  • This is a big step towards abandoning dayjs
  • Using standalone tokens
    'd MMMM' // 25 февраля
    'd LLLL' // 25 февраль
  • No need to load required locales when using (if not using humanize duration or ordinal dates)
  • Using a generally accepted standard

Disadvantages:

  • Changing the familiar format. Let's imagine it's 25.02.2025 and we call the method dateTime().format(format) in our browser, where format is a pattern from the table below:

    Moment-like UTS Add support for generic in value prop to Select in gravity-ui #35 based Result
    D d 25
    YYYY yyyy 2025
    DD.MM.YYYY dd.MM.yyyy 25.02.2025
    L P 02/25/2025

    The full difference in formats can be seen at these links: Moment-like | UTS #35 based

  • We will have to describe humanize duration and ordinal dates ourselves for each locale, here's an example for the ru locale. This part of localization will have to be loaded asynchronously (just as it is done now for all locales)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestquestionFurther information is requested

    Projects

    Status

    Discussion

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions