All files / app-leaderboard/client local-time.ts

30% Statements 3/10
16.66% Branches 1/6
0% Functions 0/2
30% Lines 3/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42          1x                                                                 1x 1x    
import { LitElement, html } from 'lit';
import { localTimePresentation, type LocalTimePrecision } from '../src/pages/local-time.ts';
 
/** Shadow DOM keeps localized text separate from htmx's server fallback and morph ownership. */
class BeMusicLocalTimeElement extends LitElement {
  static override properties = {
    dateTime: { attribute: 'datetime' },
    utc: {},
    precision: {},
  };
 
  declare dateTime: string;
  declare utc: string;
  declare precision: LocalTimePrecision;
 
  constructor() {
    super();
    this.dateTime = '';
    this.utc = '';
    this.precision = 'minute';
  }
 
  protected override render() {
    const language = this.closest<HTMLElement>('[lang]')?.lang ?? this.ownerDocument.documentElement.lang;
    const presentation = localTimePresentation({
      dateTime: this.dateTime,
      utc: this.utc,
      precision: this.precision,
      locale: language,
      timeZone: Intl.DateTimeFormat().resolvedOptions().timeZone,
      now: Date.now(),
    });
    return presentation === undefined
      ? html`<slot></slot>`
      : html`<time datetime=${this.dateTime} title=${presentation.title}>${presentation.text}</time>`;
  }
}
 
Eif (customElements.get('be-music-local-time') === undefined) {
  customElements.define('be-music-local-time', BeMusicLocalTimeElement);
}