Implement Drupal-Specific Date Formatting

Created on 13 December 2024, 9 days ago

Overview

We found an issue while working on Create a New React Component and Add Storybook Story โœจ Create a New React Component and Add Storybook Story Active , here we are using hardcoded date format. for example format(inputDate, 'd MMM'); where format is a function from date-fns plugin.

Here the hardcoded date format ('d MMM') is working fine but it's better that the date formatting should align with Drupalโ€™s standards to maintain consistency across the platform.

Proposed resolution

Replace the hardcoded format with the Drupal-specific formatting.

๐Ÿ“Œ Task
Status

Active

Version

0.0

Component

Miscellaneous

Created by

๐Ÿ‡ฎ๐Ÿ‡ณIndia soaratul

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @soaratul
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    Here the hardcoded date format ('d MMM') is working fine but it's better that the date formatting should align with Drupalโ€™s standards to maintain consistency across the platform.

    There is no one standard.

    I bet you're referring to core/modules/system/config/install/core.date_format.short.yml and other core.date_format.*.yml files in that directory.

    The challenges in switching to one of those would be:

    1. Ensuring the patterns that PHP support are also supported on the client-side.
    2. What if the chosen DateFormat config entity is deleted? โ† mitigated by using a locked DateFormat, which \Drupal\system\DateFormatAccessControlHandler disallows being deleted. Not a perfect guarantee, but probably good enough. โœ…
    3. Bikeshedding which DateFormat config entity the XB UI would use ๐Ÿ˜œ

    For point 2: safer/better still would be to make XB depend on that DateFormat config entity, but that'd require a XbUiConfig config entity or something like that, which would declare various config dependencies on behalf of XB. But โ€ฆ perhaps that'd actually be a good thing? There are likely more needs like this! That'd even allow a single central "XB configuration" UI (in an optional submodule? or contrib module?) for these kinds of settings.

    Asking @lauriii for feedback for that last paragraph :)

  • ๐Ÿ‡ซ๐Ÿ‡ฎFinland lauriii Finland

    Ensuring the patterns that PHP support are also supported on the client-side.

    Would it be a bad idea to process the date formatting in PHP and send the client both the formatted date and timestamp?

    What if the chosen DateFormat config entity is deleted? โ† mitigated by using a locked DateFormat, which \Drupal\system\DateFormatAccessControlHandler disallows being deleted. Not a perfect guarantee, but probably good enough. โœ…

    I don't think locked date formats provide the right capabilities. Besides preventing deletion, locking prevents changing the date format and translating the date format. Especially latter is something that is pretty unfortunate, because there isn't a standard international time format. Because of this, maybe the config dependency approach would work better for us?

    Bikeshedding which DateFormat config entity the XB UI would use ๐Ÿ˜œ

    The designs are currently using "M j" as the date format. We should at least start with that.

Production build 0.71.5 2024