Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/relative-time-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ export class RelativeTimeElement extends HTMLElement implements Intl.DateTimeFor
month: this.month,
year: this.year,
timeZoneName: this.timeZoneName,
dateStyle: this.dateStyle,
timeStyle: this.timeStyle,
Comment on lines +201 to +202
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added these properties, but I'm not entirely sure on where to put the tests for them. Should they be in the 'table tests' suite or somewhere else?

})
return `${this.prefix} ${formatter.format(date)}`.trim()
}
Expand Down Expand Up @@ -326,6 +328,30 @@ export class RelativeTimeElement extends HTMLElement implements Intl.DateTimeFor
this.setAttribute('time-zone-name', value || '')
}

get dateStyle() {
const dateStyle = this.getAttribute('date-style')

if (dateStyle === 'short' || dateStyle === 'long' || dateStyle === 'full' || dateStyle === 'medium') {
return dateStyle
}
}

set dateStyle(value: 'short' | 'long' | 'full' | 'medium' | undefined) {
this.setAttribute('date-style', value ?? '')
}

get timeStyle() {
const timeStyle = this.getAttribute('time-style')

if (timeStyle === 'short' || timeStyle === 'long' || timeStyle === 'full' || timeStyle === 'medium') {
return timeStyle
}
}

set timeStyle(value: 'short' | 'long' | 'full' | 'medium' | undefined) {
this.setAttribute('time-style', value ?? '')
}

/** @deprecated */
get prefix(): string {
return this.getAttribute('prefix') ?? (this.format === 'datetime' ? '' : 'on')
Expand Down