diff options
Diffstat (limited to 'apps/web-shared')
| -rw-r--r-- | apps/web-shared/package.json | 2 | ||||
| -rw-r--r-- | apps/web-shared/src/components/stopwatch.svelte | 30 | ||||
| -rw-r--r-- | apps/web-shared/src/lib/helpers.ts | 16 |
3 files changed, 27 insertions, 21 deletions
diff --git a/apps/web-shared/package.json b/apps/web-shared/package.json index b7b83d5..e30d0ba 100644 --- a/apps/web-shared/package.json +++ b/apps/web-shared/package.json @@ -1,5 +1,5 @@ { - "name": "time-tracker-shared", + "name": "greatoffice-web-shared", "version": "0.0.1", "private": "true", "devDependencies": { diff --git a/apps/web-shared/src/components/stopwatch.svelte b/apps/web-shared/src/components/stopwatch.svelte index 8287e31..3ed0d0e 100644 --- a/apps/web-shared/src/components/stopwatch.svelte +++ b/apps/web-shared/src/components/stopwatch.svelte @@ -1,8 +1,8 @@ <script lang="ts"> - import {writable_persistent} from "$shared/lib/persistent-store"; import Button from "$shared/components/button.svelte"; import {Textarea} from "$shared/components/form"; import {StorageKeys} from "$shared/lib/configuration"; + import {StoreType, writable_persistent} from "$shared/lib/persistent-store"; import {Temporal} from "@js-temporal/polyfill"; import {createEventDispatcher, onMount} from "svelte"; @@ -11,11 +11,15 @@ hours: 0, minutes: 0, seconds: 0, - startTime: null as Temporal.PlainTime, + startTime: null as Temporal.PlainDateTime, + lastStep: null as Temporal.PlainDateTime, isRunning: false, intervalId: 0, note: "", }, + options: { + store: StoreType.LOCAL + }, name: StorageKeys.stopwatch, }); @@ -30,10 +34,27 @@ } onMount(() => { + start_if_running(); + }); + + function start_if_running() { if ($state.isRunning) { + if (Temporal.PlainDateTime.compare($state.lastStep, Temporal.Now.plainDateTimeISO()) == -1) { + const duration = Temporal.Now.plainDateTimeISO().since($state.lastStep, {smallestUnit: "second"}); + console.log("lastStep",$state.lastStep.toString()); + console.log("duration", duration.toString()); + console.log(duration.seconds); + // for (let i = 0; i < steps; i++) { + // step(); + // } + } clearInterval($state.intervalId); $state.intervalId = setInterval(step, 1000); } + } + + window.addEventListener("focus", () => { + start_if_running(); }); const dispatch = createEventDispatcher(); @@ -52,7 +73,8 @@ $state.seconds = 0; } - if (!$state.startTime) $state.startTime = Temporal.Now.plainTimeISO(); + if (!$state.startTime) $state.startTime = Temporal.Now.plainDateTimeISO(); + $state.lastStep = Temporal.Now.plainDateTimeISO(); } function reset() { @@ -108,7 +130,7 @@ function on_create_entry() { if (!$state.startTime) return; - const plainStartTime = Temporal.PlainTime.from($state.startTime); + const plainStartTime = Temporal.PlainDateTime.from($state.startTime); dispatch("create", { from: plainStartTime, to: plainStartTime.add({hours: $state.hours, minutes: $state.minutes, seconds: $state.seconds}), diff --git a/apps/web-shared/src/lib/helpers.ts b/apps/web-shared/src/lib/helpers.ts index 650bccf..ed526af 100644 --- a/apps/web-shared/src/lib/helpers.ts +++ b/apps/web-shared/src/lib/helpers.ts @@ -207,11 +207,6 @@ export function get_selected_options(domElement: HTMLSelectElement): Array<strin return ret; } -export function uuid_v4(): string { - // @ts-ignore - return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c => (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)); -} - export function random_string(length: number): string { if (!length) { throw new Error("length is undefined"); @@ -343,12 +338,6 @@ export function get_style_string(rules: CSSRuleList) { return styleString; } -export function get_local_time_zone_date(date: Date): Date { - const timeOffsetInMS = new Date().getTimezoneOffset() * 60000; - date.setTime(date.getTime() - timeOffsetInMS); - return date; -} - export function parse_iso_local(s: string) { const b = s.split(/\D/); //@ts-ignore @@ -410,11 +399,6 @@ export function resolve_references(json: any) { return json; } -export function to_readable_date_string(date: Date, locale = "nb-NO"): string { - date.setMinutes(date.getMinutes() - date.getTimezoneOffset()); - return date.toLocaleString(locale); -} - export function get_random_int(min: number, max: number): number { min = Math.ceil(min); max = Math.floor(max); |
