Skip to content

Support IANA time zone for date formatting #48279

@dzonatan

Description

@dzonatan

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

No response

Description

This was once requested #40865 but is now locked due to inactivity. I want to raise this again because IMO supporting IANA timezone names natively is a huge improvement, especially now when you can set the default timezone (which is actually an UTC offset, not a timezone) through DATE_PIPE_DEFAULT_OPTIONS token.

Why supporting IANA is such a big deal? Because of Daylight Saving Time (DST).
Countries that are using DST does not have a fixed UTC offset, it depends on the season.
So setting a default timezone (which is an UTC offset) through DATE_PIPE_DEFAULT_OPTIONS does not bring that much value today, it's even hard to think of a use case for this. For applications that let the user to set their preferred timezone in settings this token can't be utilized, you're still forced to come up with workaroundish solutions like creating a custom date pipe.

This is a default behaviour when timezone is not provided:

<!-- 
Browser timezone: Europe/Vilnius
DATE_PIPE_DEFAULT_OPTIONS: not provided
-->

{{ '2022-10-29T05:00:00.000Z' | date: 'full' }} // Thursday, 29 October 2022 at 08:00:00 GMT+03:00 ✅ 
{{ '2022-10-31T06:00:00.000Z' | date: 'full' }} // Thursday, 31 October 2022 at 08:00:00 GMT+02:00 ✅ 
<!-- As you can see DST is handled flawlessly. -->

Now imagine we want to format all dates the same for all the users not matter on what timezone they are (maybe it's a company timezone, whatever). What DATE_PIPE_DEFAULT_OPTIONS value has to be provided for this to work? UTC+2 or UTC+3 (in case of Europe/Vilnius tz)? You see, you can't choose one, both are needed depending on the date you're trying to format.

<!-- 
Browser timezone: Europe/Stockholm (does not matter, can be any tz)
DATE_PIPE_DEFAULT_OPTIONS: { timezone: 'UTC+2' }
-->

{{ '2022-10-29T05:00:00.000Z' | date: 'full' }} // Thursday, 29 October 2022 at 07:00:00 GMT+02:00 ❌ 
{{ '2022-10-31T06:00:00.000Z' | date: 'full' }} // Thursday, 31 October 2022 at 08:00:00 GMT+02:00 ✅ 
<!-- 
Browser timezone: Europe/Stockholm (does not matter, can be any tz)
DATE_PIPE_DEFAULT_OPTIONS: { timezone: 'UTC+3' }
-->

{{ '2022-10-29T05:00:00.000Z' | date: 'full' }} // Thursday, 29 October 2022 at 08:00:00 GMT+03:00 ✅ 
{{ '2022-10-31T06:00:00.000Z' | date: 'full' }} // Thursday, 31 October 2022 at 09:00:00 GMT+03:00 ❌ 

Proposed solution

Add support for IANA time zone name in all these APIs:

https://angular.io/api/common/DATE_PIPE_DEFAULT_OPTIONS

{ provide: DATE_PIPE_DEFAULT_OPTIONS, useValue: { timezone: 'Europe/Vilnius' } }

https://angular.io/api/common/formatDate

{{ myDate | date: 'full':'Europe/Vilnius' }}

https://angular.io/api/common/DatePipe

formatDate(myDate, 'full', 'Europe/Vilnius');

Alternatives considered

If for some reason IANA time zone support is not considered to be implemented now or in the future then I would suggest renaming the timezone property to utcOffset which would be more accurate and less confusing for developers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P4A relatively minor issue that is not relevant to core functionsarea: commonIssues related to APIs in the @angular/common packagehelp wantedAn issue that is suitable for a community contributor (based on its complexity/scope).

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions