@@ -12,7 +12,7 @@ const DateTimeFormat = supportsIntlDatetime ? Intl.DateTimeFormat : DateTimeForm
1212const supportsIntlRelativeTime = typeof Intl !== 'undefined' && 'RelativeTimeFormat' in Intl
1313const RelativeTimeFormat = supportsIntlRelativeTime ? Intl . RelativeTimeFormat : RelativeTimeFormatPonyfill
1414
15- export type Format = 'auto' | 'micro' | 'elapsed' | string
15+ export type Format = 'auto' | 'micro' | 'elapsed'
1616export type Tense = 'auto' | 'past' | 'future'
1717
1818export class RelativeTimeUpdatedEvent extends Event {
@@ -113,7 +113,7 @@ export default class RelativeTimeElement extends HTMLElement implements Intl.Dat
113113 // value takes precedence over this custom format.
114114 //
115115 // Returns a formatted time String.
116- getFormattedTitle ( ) : string | undefined {
116+ # getFormattedTitle( ) : string | undefined {
117117 const date = this . date
118118 if ( ! date ) return
119119
@@ -127,7 +127,13 @@ export default class RelativeTimeElement extends HTMLElement implements Intl.Dat
127127 } ) . format ( date )
128128 }
129129
130- getFormattedDate ( now = new Date ( ) ) : string | undefined {
130+ private getFormattedTitle ( ) : string | undefined {
131+ // eslint-disable-next-line no-console
132+ console . warn ( `Calling getFormattedTitle is deprecated and will be removed in v5.0.0` )
133+ return this . #getFormattedTitle( )
134+ }
135+
136+ #getFormattedDate( now = new Date ( ) ) : string | undefined {
131137 const date = this . date
132138 if ( ! date ) return
133139 const format = this . format
@@ -168,6 +174,12 @@ export default class RelativeTimeElement extends HTMLElement implements Intl.Dat
168174 return `${ this . prefix } ${ formatter . format ( date ) } ` . trim ( )
169175 }
170176
177+ private getFormattedDate ( now = new Date ( ) ) : string | undefined {
178+ // eslint-disable-next-line no-console
179+ console . warn ( `Calling getFormattedTitle is deprecated and will be removed in v5.0.0` )
180+ return this . #getFormattedDate( now )
181+ }
182+
171183 get second ( ) {
172184 const second = this . getAttribute ( 'second' )
173185 if ( second === 'numeric' || second === '2-digit' ) return second
@@ -301,11 +313,23 @@ export default class RelativeTimeElement extends HTMLElement implements Intl.Dat
301313 const format = this . getAttribute ( 'format' )
302314 if ( format === 'micro' ) return 'micro'
303315 if ( format === 'elapsed' ) return 'elapsed'
304- if ( format && format . includes ( '%' ) ) return format
316+ if ( format && format . includes ( '%' ) ) {
317+ // eslint-disable-next-line no-console
318+ console . warn (
319+ `srftime formatting is deprecated and will be removed in v5.0.0. stftime formats will default to 'auto'`
320+ )
321+ return format as unknown as Format
322+ }
305323 return 'auto'
306324 }
307325
308326 set format ( value : Format ) {
327+ if ( value && value . includes ( '%' ) ) {
328+ // eslint-disable-next-line no-console
329+ console . warn (
330+ `srftime formatting is deprecated and will be removed in v5.0.0. stftime formats will default to 'auto'`
331+ )
332+ }
309333 this . setAttribute ( 'format' , value )
310334 }
311335
@@ -338,7 +362,7 @@ export default class RelativeTimeElement extends HTMLElement implements Intl.Dat
338362 attributeChangedCallback ( attrName : string , oldValue : unknown , newValue : unknown ) : void {
339363 if ( oldValue === newValue ) return
340364 if ( attrName === 'title' ) {
341- this . #customTitle = newValue !== null && this . getFormattedTitle ( ) !== newValue
365+ this . #customTitle = newValue !== null && this . # getFormattedTitle( ) !== newValue
342366 }
343367 if ( ! this . #updating && ! ( attrName === 'title' && this . #customTitle) ) {
344368 this . #updating = ( async ( ) => {
@@ -355,11 +379,11 @@ export default class RelativeTimeElement extends HTMLElement implements Intl.Dat
355379 let newText : string = oldText
356380 const now = new Date ( )
357381 if ( ! this . #customTitle) {
358- newTitle = this . getFormattedTitle ( ) || ''
382+ newTitle = this . # getFormattedTitle( ) || ''
359383 if ( newTitle ) this . setAttribute ( 'title' , newTitle )
360384 }
361385
362- newText = this . getFormattedDate ( now ) || ''
386+ newText = this . # getFormattedDate( now ) || ''
363387 if ( newText ) {
364388 this . #renderRoot. textContent = newText
365389 } else if ( this . shadowRoot === this . #renderRoot && this . textContent ) {
0 commit comments