question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ability to customize the default format for DatePipe

See original GitHub issue

Which @angular/* package(s) are relevant/releated to the feature request?

common

Description

Currently the DatePipe defaults the format to mediumDate. It would be great if we could provide an InjectionToken to customize it, like we already do for timezone and locale.

Proposed solution

Like the DATE_PIPE_DEFAULT_TIMEZONE, we could have something like DATE_PIPE_DEFAULT_FORMAT, so we can avoid to pass the most common format used in app (in my case shortDate) for every | date or even create our own pipe to override the default one.

Alternatives considered

Create our own pipe, but I’d prefer to avoid this… imagine if every app has its own DatePipe? Also that sounds a bit weird to have InjectionToken for timezone and locale, but not for the format.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:31
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
dev054commented, Dec 13, 2021

Hey @flash-me, thanks for your input. As you may have noticed in the OP (Alternatives considered), we’re aware of the option of creating our own pipe, but the feature request is to include the InjectionToken in the Framework to be paired with the other parameters: timezone and locale.

It sounds a bit strange to ask for every app to create their own @Pipe, instead of providing a token, like we’re already have for the other parameters.

1reaction
Nosfistiscommented, Apr 29, 2022

Given that we can use an injection token to customize the global timezone, this implementation should not be hard!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Override Angular default date pipe - Stack Overflow
To override an angular pipe throughout the app, it's enough to add your custom pipe to the declarations array of your root AppModule:...
Read more >
DatePipe - Angular
Field type Format Description Era G, GG & GGG Abbreviated GGGG Wide GGGGG Narrow
Read more >
Angular Tips: Formatting Dates with a Custom Date Pipe (dd ...
Using Angular default Date Pipe​​ The date pipe accepts a format (optional parameter) that can be customized as showed in the code above...
Read more >
Managing date formats in Angular apps | by Wojciech Trawiński
As a result, dates are rendered with the default format, unless you override it. Conclusions. Wrapping the built-in DatePipe into a custom one ......
Read more >
Displaying Custom Date Formats in Angular 12 - HTML Goodies
The Angular DatePipe boasts 12 predefined formats, including “short“, “medium“, and “long“. These formats include both the date and time.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found