@@ -120,14 +120,27 @@ export class RelativeTimeElement extends HTMLElement implements Intl.DateTimeFor
120
120
//
121
121
// Returns a formatted time String.
122
122
#getFormattedTitle( date : Date ) : string | undefined {
123
- return new Intl . DateTimeFormat ( this . #lang, {
124
- day : 'numeric' ,
125
- month : 'short' ,
126
- year : 'numeric' ,
127
- hour : 'numeric' ,
128
- minute : '2-digit' ,
129
- timeZoneName : 'short' ,
130
- } ) . format ( date )
123
+ let dateTimeFormat
124
+ try {
125
+ dateTimeFormat = new Intl . DateTimeFormat ( this . #lang, {
126
+ day : 'numeric' ,
127
+ month : 'short' ,
128
+ year : 'numeric' ,
129
+ hour : 'numeric' ,
130
+ minute : '2-digit' ,
131
+ timeZoneName : 'short' ,
132
+ } )
133
+ } catch ( _e ) {
134
+ dateTimeFormat = new Intl . DateTimeFormat ( 'default' , {
135
+ day : 'numeric' ,
136
+ month : 'short' ,
137
+ year : 'numeric' ,
138
+ hour : 'numeric' ,
139
+ minute : '2-digit' ,
140
+ timeZoneName : 'short' ,
141
+ } )
142
+ }
143
+ return dateTimeFormat . format ( date )
131
144
}
132
145
133
146
#resolveFormat( duration : Duration ) : ResolvedFormat {
@@ -172,10 +185,20 @@ export class RelativeTimeElement extends HTMLElement implements Intl.DateTimeFor
172
185
}
173
186
174
187
#getRelativeFormat( duration : Duration ) : string {
175
- const relativeFormat = new Intl . RelativeTimeFormat ( this . #lang, {
176
- numeric : 'auto' ,
177
- style : this . formatStyle ,
178
- } )
188
+ let relativeFormat
189
+
190
+ try {
191
+ relativeFormat = new Intl . RelativeTimeFormat ( this . #lang, {
192
+ numeric : 'auto' ,
193
+ style : this . formatStyle ,
194
+ } )
195
+ } catch ( _e ) {
196
+ relativeFormat = new Intl . RelativeTimeFormat ( 'default' , {
197
+ numeric : 'auto' ,
198
+ style : this . formatStyle ,
199
+ } )
200
+ }
201
+
179
202
const tense = this . tense
180
203
if ( tense === 'future' && duration . sign !== 1 ) duration = emptyDuration
181
204
if ( tense === 'past' && duration . sign !== - 1 ) duration = emptyDuration
@@ -187,16 +210,30 @@ export class RelativeTimeElement extends HTMLElement implements Intl.DateTimeFor
187
210
}
188
211
189
212
#getDateTimeFormat( date : Date ) : string {
190
- const formatter = new Intl . DateTimeFormat ( this . #lang, {
191
- second : this . second ,
192
- minute : this . minute ,
193
- hour : this . hour ,
194
- weekday : this . weekday ,
195
- day : this . day ,
196
- month : this . month ,
197
- year : this . year ,
198
- timeZoneName : this . timeZoneName ,
199
- } )
213
+ let formatter
214
+ try {
215
+ formatter = new Intl . DateTimeFormat ( this . #lang, {
216
+ second : this . second ,
217
+ minute : this . minute ,
218
+ hour : this . hour ,
219
+ weekday : this . weekday ,
220
+ day : this . day ,
221
+ month : this . month ,
222
+ year : this . year ,
223
+ timeZoneName : this . timeZoneName ,
224
+ } )
225
+ } catch ( _e ) {
226
+ formatter = new Intl . DateTimeFormat ( 'default' , {
227
+ second : this . second ,
228
+ minute : this . minute ,
229
+ hour : this . hour ,
230
+ weekday : this . weekday ,
231
+ day : this . day ,
232
+ month : this . month ,
233
+ year : this . year ,
234
+ timeZoneName : this . timeZoneName ,
235
+ } )
236
+ }
200
237
return `${ this . prefix } ${ formatter . format ( date ) } ` . trim ( )
201
238
}
202
239
0 commit comments