Add date formats without time

Created on 11 January 2025, 7 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
    7 months ago
    Total: 2225s
    #393151
  • Pipeline finished with Success
    7 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
    6 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
    6 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 4 months 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
    3 months 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
    3 months ago
    Total: 167s
    #492621
  • Pipeline finished with Failed
    3 months ago
    Total: 1752s
    #492641
  • Pipeline finished with Failed
    3 months ago
    Total: 375s
    #492684
  • Merge request !12081Recreate MR with updated branch → (Open) created by ressa
  • Pipeline finished with Failed
    3 months ago
    Total: 123s
    #492697
  • Pipeline finished with Failed
    3 months ago
    Total: 532s
    #492701
  • 🇩🇰Denmark ressa Copenhagen

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

  • Pipeline finished with Success
    3 months 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
    3 months ago
    Total: 249s
    #493403
  • Pipeline finished with Success
    3 months ago
    Total: 617s
    #493421
  • Pipeline finished with Success
    3 months 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
    3 months 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 🇪🇺
  • Pipeline finished with Canceled
    3 months ago
    Total: 94s
    #493852
  • 🇪🇸Spain penyaskito Seville 💃, Spain 🇪🇸, UTC+2 🇪🇺

    Thanks for the quick response 😊

  • Pipeline finished with Success
    3 months ago
    Total: 918s
    #493854
  • 🇩🇰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.

  • Status changed to Needs work about 2 months ago
  • 🇦🇺Australia mstrelan

    Do we need a CR for the new formats and the removal of Olivero Medium? We had one last time formats changed - https://www.drupal.org/node/3467774 →

    In general I agree with removing Olivero Medium, but isn't it possible there are existing configs depending on this? I found at least 38 references in code after filtering out the cruft - https://git.drupalcode.org/search?group_id=2&scope=blobs&search=olivero_...

    These tend to be in recipes, formatter config, views fields and tokens.

    I think maybe we need a follow up to deprecate and remove it.

  • Pipeline finished with Success
    about 2 months ago
    Total: 1050s
    #518420
  • 🇩🇰Denmark ressa Copenhagen

    Great catch @mstrelan, and @penyaskito also noticed this ("olivero_medium shouldn't be deleted. We know how it's being used in core, but not how could be used in contrib/custom sites.")

    So In the end, "Olivero Medium" was not removed. The only Olivero theme-related change was Olivero theme using a new format:

    But since the "Olivero Medium" date format stays, and you documented many more places where olivero_medium is in use, I removed the Olivero theme update as well. (And great way to use GitLab to search the code base of all contrib projects, BTW!)

    So now this MR only adds three new date only date formats, and updates the Announcements feed to use short_date_only.

    But this may need a change record? I have created a draft Default date formats have been expanded with date only formats → .

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

    I'm not sure how we deprecate a config entity. But definitely we should have a specific change record for the olivero date format.

  • 🇩🇰Denmark ressa Copenhagen

    But the Olivero format is not touched, please check my last comment or the MR.

  • 🇩🇰Denmark ressa Copenhagen

    Adding "Review Change record Default date formats have been expanded with date only formats → " in Issue summary under Remaining tasks".

  • 🇩🇰Denmark ressa Copenhagen
  • 🇪🇸Spain penyaskito Seville 💃, Spain 🇪🇸, UTC+2 🇪🇺

    In #44 I expected that we would do the deprecation (but not the removal) here. That's why I suggested a new change record.

  • 🇩🇰Denmark ressa Copenhagen

    All right, perhaps it's most efficient, if you update the Issue Summary to more precisely reflect the remaining tasks? The other issue probably then also needs to be updated.

  • 🇩🇰Denmark ressa Copenhagen

    @mstrelan and @penyaskito: I have added deprecating Olivero Medium in the Issue Summary here, and updated the Change Record with this:

    Olivero Medium has been deprecated and removed

    ToDo: Add description about what this means.

    Perhaps only the three new "date only" formats and deprecation Olivero Medium should be part of that Change Record, and the actual removal in a separate Change Record?

  • 🇦🇺Australia mstrelan

    FWIW I think deprecation should be a separate issue and not even discussed here, make this easier to get in.

  • 🇩🇰Denmark ressa Copenhagen

    Thanks for a fast answer @mstrelan, and I agree -- getting this small change completed by itself would be optimal, and then dealing with the complicated stuff in a follow up issue. I have updated issues and Change Record.

    Perhaps -- if you have time -- you could check the Change Record, which is the last remaining task? And I guess maybe also the MR, since it was updated 10 June 2025 to only add three new date formats, and update the date in the Announcements Feed.

  • 🇺🇸United States smustgrave

    Tweaked the CR slightly for 11.3 rest seems fine to me!

  • 🇩🇰Denmark ressa Copenhagen

    Thanks @smustgrave!

  • 🇳🇿New Zealand quietone

    I removed 'proposed' from the CR and added a screenshot to the issue summary.

    Everything appears to be in order here.

  • 🇺🇸United States xjm

    I can see adding one of these new formats, but adding three of them is essentially almost doubling the number of date formats. Perhaps we should just pick one to include? I find the new list kind of overwhelming. I think this would need usability review in addition to product signoff. (Meaning, we would want to add before-and-after screenshots and then tag it for usability review.)

    Also, given that these are only being added to new installs, but we are also changing the production Twig template for the announcements feed, that could be a problem, no? So that might be a reason we actually would need an upgrade path, at least for the one that Announcements is now expecting to exist. No?

  • 🇩🇰Denmark ressa Copenhagen

    Thanks for reviewing this @xjm. Looking at the list again, you have a point and I tend to agree ... Maybe we should only add a new short date without time format?

    About an upgrade path for the announcements feed Twig template, you may be right ...

  • Production build 0.71.5 2024