mirror of https://github.com/sveltejs/svelte
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
18 lines
356 B
18 lines
356 B
6 years ago
|
import { readable, derive } from 'svelte/store';
|
||
|
|
||
|
export const time = readable(function start(set) {
|
||
|
const interval = setInterval(() => {
|
||
|
set(new Date());
|
||
|
}, 1000);
|
||
|
|
||
|
return function stop() {
|
||
|
clearInterval(interval);
|
||
|
};
|
||
|
}, new Date());
|
||
|
|
||
|
const start = new Date();
|
||
|
|
||
|
export const elapsed = derive(
|
||
|
time,
|
||
|
$time => Math.round(($time - start) / 1000)
|
||
|
);
|