Add date formats without time

Created on 11 January 2025, 4 months ago

Problem/Motivation

📌 Update announcements date format Active showed a need for a shorter date format, without time. Several users agreed that it would be nice to offer this:

I agree a date format in core for date only (without time) would be good.

Steps to reproduce

Open Administration > Configuration > Region and language > Date and time formats (/admin/config/regional/date-time) and see that all human readable date formats include time.

Proposed resolution

It would be nice to offer human readable date formats, without time:

Remaining tasks

Add the three date formats above.

User interface changes

New installs now offer shorter human readable date formats, without time.

API changes

Data model changes

Translations

📌 Task
Status

Active

Version

11.0 🔥

Component

user system

Created by

🇩🇰Denmark ressa Copenhagen

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

Merge Requests

Comments & Activities

  • Issue created by @ressa
  • 🇩🇰Denmark ressa Copenhagen
  • 🇩🇰Denmark ressa Copenhagen
  • 🇩🇰Denmark ressa Copenhagen

    Update formats in Issue Summary.

  • Merge request !10875Add three timeless date formats → (Closed) created by ressa
  • Pipeline finished with Failed
    4 months ago
    Total: 2225s
    #393151
  • Pipeline finished with Success
    4 months ago
    Total: 1085s
    #393175
  • 🇩🇰Denmark ressa Copenhagen
  • 🇩🇰Denmark ressa Copenhagen
  • 🇺🇸United States smustgrave

    Going to have and look at this later. Not sure why migration test had to be updated

  • 🇩🇰Denmark ressa Copenhagen

    Thanks for looking at this so fast.

    It's the function below. And since there are three more date formats, the date_format count increases from 12 to 15:

      /**
       * {@inheritdoc}
       */
      protected function getEntityCounts(): array {
        return [
          'block' => 37,
          'block_content' => 2,
          'block_content_type' => 1,
    [...]
          'date_format' => 15,
          'entity_form_display' => 23,
          'entity_form_mode' => 1,
          'entity_view_display' => 33,
          'entity_view_mode' => 11,
          'base_field_override' => 2,
        ];
      }
    

    In:

    • /core/modules/migrate_drupal_ui/tests/src/Functional/d6/Upgrade6Test.php
    • /core/modules/migrate_drupal_ui/tests/src/Functional/d7/Upgrade7Test.php
  • 🇺🇸United States smustgrave

    Seems like a fine addition and no objection. I didn't see any recipe that was installing datetime formats

    Also doesn't feel like something that would need test coverage as just offering more options.

  • 🇩🇰Denmark ressa Copenhagen

    At the risk of repeating myself, the Needs Review Queue Initiative is among the best things to happen to Drupal the last few years, and the community can't be grateful enough, so thank you @smustgrave!

  • 🇬🇧United Kingdom catch

    Very minor but I'm wondering if these could be e.g. 'Medium date (without time)', rather than starting with 'no time'.

    Since this is user-facing tagging for product manager review.

  • Pipeline finished with Canceled
    3 months ago
    Total: 163s
    #426502
  • 🇩🇰Denmark ressa Copenhagen

    Thanks @catch, great suggestion and I updated the id's and labels. Perhaps you can review and check if "Needs Review" by product manager is still the case?

  • Pipeline finished with Success
    3 months ago
    Total: 381s
    #426506
  • 🇩🇰Denmark ressa Copenhagen

    Update format names in Issue Summary.

  • 🇬🇧United Kingdom catch

    @ressa yes it changes out of the box behaviour so I think it could use it.

  • 🇩🇰Denmark ressa Copenhagen

    Sorry if it wasn't clear, I just meant that if it still looks good to you after my update, then you should feel free to change status to Needs Review :)

  • Status changed to Needs review about 1 month ago
  • 🇫🇮Finland lauriii Finland

    Seems fine from product perspective. I've wondered several times myself why we don't have these out of the box 🥲

  • 🇺🇸United States smustgrave

    Thank you @lauriii!

  • 🇳🇿New Zealand quietone

    Just a few questions

    Why is this change limited to new installs?

    I did a fresh install with this MR and there are now two identical formats, 'Olivero Medium' and 'Short date (without time)'. I think that is confusing and should be addressed somehow.

    And, can we use a more positive description, "Short date (date only)" instead of "Short date (without time)".

    Setting to NW for responses to the above.

  • 🇩🇰Denmark ressa Copenhagen

    Thanks for the feedback @quietone, I have updated to use "(date only)" from "(without time)".

    About "Olivero Medium" I am not sure, so I have updated the Issue Summary, with these Remaining tasks:

    • Figure out what to do with "Olivero Medium", since it has the same format as "Short date (date only)".
    • Should existing installations also get these date only formats, via an update hook?
  • 🇩🇰Denmark ressa Copenhagen
  • Pipeline finished with Success
    9 days ago
    Total: 640s
    #492152
  • 🇪🇸Spain penyaskito Seville 💃, Spain 🇪🇸, UTC+2 🇪🇺
    • I'd replace "Olivero Medium" with the new one, here or maybe even on a follow-up.
    • Should existing installations also get these date only formats, via an update hook? Yes, if there aren't pre-existing date formats with the same machine names.
  • 🇩🇰Denmark ressa Copenhagen

    Thanks for clearing that up so quickly @penyaskito, if you have time, feel free to update the MR with your suggestions. Maybe the update hook is safe to add, as a first step?

  • 🇬🇧United Kingdom catch

    Good idea to remove the Olivero date format. My main concern with this issue is that it's a lot of default date formats, but if we're able to start getting rid of one-off ones, that's a good trade-off.

  • Pipeline finished with Failed
    9 days ago
    Total: 167s
    #492621
  • Pipeline finished with Failed
    9 days ago
    Total: 1752s
    #492641
  • Pipeline finished with Failed
    8 days ago
    Total: 375s
    #492684
  • Merge request !12081Recreate MR with updated branch → (Open) created by ressa
  • Pipeline finished with Failed
    8 days ago
    Total: 123s
    #492697
  • Pipeline finished with Failed
    8 days ago
    Total: 532s
    #492701
  • 🇩🇰Denmark ressa Copenhagen

    ressa → changed the visibility of the branch 3498980-add-date-formats to hidden.

  • Pipeline finished with Success
    8 days ago
    Total: 1653s
    #492712
  • 🇩🇰Denmark ressa Copenhagen

    I somehow managed to make an update hook for existing installations, so they now also get these date only formats. But only if there aren't pre-existing date formats with the same machine names.

    I also removed Olivero Medium data format. It is replaced with the new Short date format, in the Olivero theme. Luckily, if for some reason a date format cannot be found, the fallback date format is used.

    PS. I had to close the original branch, and start fresh, since rebasing was not possible. Oh, and Nightwatch had to be re-run three times, before it finally went green :)

  • 🇪🇸Spain penyaskito Seville 💃, Spain 🇪🇸, UTC+2 🇪🇺

    See MR comments.
    Also tagging for required upgrade path tests.

  • Pipeline finished with Failed
    8 days ago
    Total: 249s
    #493403
  • Pipeline finished with Success
    8 days ago
    Total: 617s
    #493421
  • Pipeline finished with Success
    8 days ago
    Total: 843s
    #493438
  • 🇩🇰Denmark ressa Copenhagen

    Thank you very much @penyaskito for fast and thorough review, I greatly appreciate it.

    I have made the changes you suggested, and your new method for setting the date formats were spot on, so that made it a lot easier. I also restored olivero_medium format.

    As you suggested in the original Announcement issue, I have updated the date format to short_date_only in this MR as well.

    I have updated Remaining tasks, and added the upgrade path test task as well. I wonder if there is a documentation page on how to write upgrade path tests, going from Drupal 10 to 11 (I guess)?

  • 🇩🇰Denmark ressa Copenhagen

    Just updating the title, since the Announcement date update will also get done here.

  • 🇩🇰Denmark ressa Copenhagen
  • 🇬🇧United Kingdom catch

    I don't think we need an update here, they can just be available on new sites. Even if existing sites don't have formats with the same names, they may have all kinds of custom formats already created which are similar, and then suddenly these new ones would appear alongside them. Similarly we often don't even fix arguable bugs in shipped views like admin/content in update paths, because there is a higher chance of breaking a site than fixing it.

  • 🇳🇿New Zealand quietone

    Just came back to this. My question,"Why is this change limited to new installs?" was truly a question. It was not an implication that any work was needed to change that decision. Apologies for the confusion.

  • 🇪🇸Spain penyaskito Seville 💃, Spain 🇪🇸, UTC+2 🇪🇺

    Oh, really? Then 🚀 ship it. @pameeela said this already, but I was pretty sure this was one of the core gates.

    That means we need to actually remove that upgrade from this MR and we're done.

    We don't need upgrade tests if there's no upgrade. Removing tag.
    @ressa For the sake of learning, see https://www.drupal.org/docs/drupal-apis/update-api/writing-automated-upd... →

    Updated issue summary.
    Only left: Revert

  • Pipeline finished with Success
    7 days ago
    Total: 1136s
    #493660
  • 🇩🇰Denmark ressa Copenhagen

    Thanks for clearing that up @catch, and that's totally all right @quietone. As a side effect I realized what a useful feature the ddev snapshot command is, to quickly roll back changes. I also learned a bit or two about making a hook_update and running phpcs, so it turned out to be a gain after all. I am pasting the end result below, just in case someone else needs to do something similar in the future. Thanks for the Doc page link @penyaskito!

    Unused hook_update code:

    use Drupal\Core\Datetime\Entity\DateFormat;
    
    /**
     * Add date-only date formats.
     *
     * @see https://www.drupal.org/project/drupal/issues/3498980
     */
    function system_update_11202(): string {
      $message = NULL;
      $date_formats = [
        'long_date_only' => [
          'label' => t('Long date (date only)'),
          'pattern' => t('l, j F Y', [], ['context' => 'PHP date format']),
        ],
        'medium_date_only' => [
          'label' => t('medium date (date only)'),
          'pattern' => t('D, j M Y', [], ['context' => 'PHP date format']),
        ],
        'short_date_only' => [
          'label' => t('short date (date only)'),
          'pattern' => t('j M Y', [], ['context' => 'PHP date format']),
        ],
      ];
      foreach ($date_formats as $id => $date_format_info) {
        if (!DateFormat::load($id)) {
          $date_format = DateFormat::create([
            'id' => $id,
            'locked' => FALSE,
            'status' => TRUE,
            'pattern' => $date_format_info['pattern'],
            'label' => $date_format_info['label'],
          ]);
          $message .= "Date format " . $date_format_info['label'] . " was created.\n";
          $date_format->save();
        }
      }
      return $message;
    }
  • 🇪🇸Spain penyaskito Seville 💃, Spain 🇪🇸, UTC+2 🇪🇺

    Tested this locally and found the sorting in the listing a bit weird. I think it would be better to prefix the labels.
    I won't do it myself so I can still RTBC.

    PS: don't try to test on the MR tugboat because it doesn't trigger a new install.

  • 🇪🇸Spain penyaskito Seville 💃, Spain 🇪🇸, UTC+2 🇪🇺
  • 🇪🇸Spain penyaskito Seville 💃, Spain 🇪🇸, UTC+2 🇪🇺

    Thanks for the quick response 😊

  • 🇩🇰Denmark ressa Copenhagen

    You're welcome! And great catch, the order is much better now.

  • 🇦🇺Australia mstrelan

    This is probably a duplicate of ✨ Add default date formats without time Closed: duplicate but this has obviously had much more recent discussion. Perhaps someone could credit @dead_arm for the original issue I've just closed.

  • Production build 0.71.5 2024