Skip to content

Commit

Permalink
History Ordering, Relative Time
Browse files Browse the repository at this point in the history
  • Loading branch information
sidharthv96 committed Dec 4, 2020
1 parent 6a425cd commit d243507
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/routes/Edit.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@
setInterval(() => {
if (code != hisCode) {
//save history
historyList.push({
historyList.unshift({
time: new Date().toISOString(),
code: hisCode = code
});
if (historyList.length > 10) {
historyList.shift();
historyList.pop();
}
localStorage.setItem(historyListKey, JSON.stringify(historyList));
}
Expand Down Expand Up @@ -176,6 +176,10 @@
updateEditor: true,
});
}
function relativeTime(t){
return `${moment(t).fromNow()} (${new Date(t).toLocaleString()})`;
}
</script>

<style>
Expand Down Expand Up @@ -311,7 +315,7 @@
{#if historyList.length > 0}
{#each historyList as item, i}
<button class="button-style" on:click="{e => toUpdateCodeStore(item.code)}">
{moment(item.time).fromNow()}
{relativeTime(item.time)}
</button>
{/each}
{:else}
Expand Down

0 comments on commit d243507

Please sign in to comment.