Skip to content

Commit

Permalink
feat: format title attribute when using relative time (#16)
Browse files Browse the repository at this point in the history
Closes #12
  • Loading branch information
imbolc committed May 15, 2022
1 parent 24ae98d commit 2d9bc08
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/Time.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
/**
* Timestamp format for display
* It's also used as a title in the `relative` mode
* @type {import("dayjs").OptionType}
* @example "YYYY-MM-DD"
*/
Expand Down Expand Up @@ -55,7 +56,7 @@
});
$: formatted = relative ? dayjs(timestamp).from() : dayjs(timestamp).format(format);
$: title = relative ? timestamp : undefined;
$: title = relative ? dayjs(timestamp).format(format) : undefined;
</script>

<time {...$$restProps} title="{title}" datetime="{timestamp}">
Expand Down
2 changes: 1 addition & 1 deletion src/svelte-time.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function svelteTime(node, options = {}) {
const formatted = relative ? dayjs(timestamp).from() : dayjs(timestamp).format(format);

if (relative) {
node.setAttribute("title", timestamp);
node.setAttribute("title", dayjs(timestamp).format(format));

if (live !== false) {
interval = setInterval(() => {
Expand Down

0 comments on commit 2d9bc08

Please sign in to comment.