Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add "last updated at" times to the index and repo pages.
Fixes #31.
- Loading branch information
Showing
4 changed files
with
92 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { localFormatter } from '@lib/formatTime.js'; | ||
import { LitElement, html, type PropertyDeclaration } from 'lit'; | ||
import { customElement, property } from 'lit/decorators.js'; | ||
|
||
const dateProperty: PropertyDeclaration<Date | null> = { | ||
type: Object, | ||
converter(date: string | null) { | ||
const result = new Date(date ?? ""); | ||
if (isNaN(result.getTime())) return null; | ||
return result; | ||
}, | ||
} | ||
|
||
@customElement('local-time') | ||
export class LocalTime extends LitElement { | ||
// The single time represented by this element. | ||
@property(dateProperty) | ||
datetime: Date | null = null; | ||
|
||
// The range of time represented by this element. | ||
@property(dateProperty) | ||
from: Date | null = null | ||
@property(dateProperty) | ||
to: Date | null = null | ||
|
||
render() { | ||
if (this.datetime) { | ||
return html`${localFormatter.format(this.datetime)}`; | ||
} else if (this.from && this.to) { | ||
return html`${localFormatter.formatRange(this.from, this.to)}`; | ||
} else { | ||
console.error(this, "should have 'datetime' or 'from' and 'to' attributes."); | ||
return html`<slot></slot>`; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// For use in the static site generator. | ||
export const englishUtcFormatter = new Intl.DateTimeFormat("en-US", { | ||
dateStyle: "medium", | ||
timeStyle: "long", | ||
timeZone: "UTC", | ||
}); | ||
|
||
// For use in client-side code. | ||
export const localFormatter = new Intl.DateTimeFormat(undefined, { | ||
dateStyle: "medium", | ||
timeStyle: "long" | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters