diff options
| author | Fuwn <[email protected]> | 2023-09-27 23:33:01 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2023-09-27 23:33:01 -0700 |
| commit | 8562ba4280c575b3f04df598b7954a2d28b19e50 (patch) | |
| tree | eaa43530441522b5104a1fd1e404ce6b663fc9b0 /src/lib/Tools/ActivityHistory.svelte | |
| parent | fix(anime): template increment render (diff) | |
| download | due.moe-8562ba4280c575b3f04df598b7954a2d28b19e50.tar.xz due.moe-8562ba4280c575b3f04df598b7954a2d28b19e50.zip | |
feat(wrapped): initial wrapped prototype
Diffstat (limited to 'src/lib/Tools/ActivityHistory.svelte')
| -rw-r--r-- | src/lib/Tools/ActivityHistory.svelte | 45 |
1 files changed, 8 insertions, 37 deletions
diff --git a/src/lib/Tools/ActivityHistory.svelte b/src/lib/Tools/ActivityHistory.svelte index 58ba4173..a8f3c45b 100644 --- a/src/lib/Tools/ActivityHistory.svelte +++ b/src/lib/Tools/ActivityHistory.svelte @@ -1,5 +1,9 @@ <script lang="ts"> - import { activityHistory, type ActivityHistoryEntry } from '$lib/AniList/activity.js'; + import { + activityHistory, + fillMissingDays, + type ActivityHistoryEntry + } from '$lib/AniList/activity.js'; import { onMount } from 'svelte'; import userIdentity from '../../stores/userIdentity.js'; import { @@ -11,7 +15,6 @@ let activityHistoryData: Promise<ActivityHistoryEntry[]>; let currentUserIdentity = { name: '', id: -1 }; - const timezoneOffset = new Date().getTimezoneOffset() * 60 * 1000; onMount(async () => { if (user !== undefined) { @@ -22,43 +25,9 @@ currentUserIdentity = JSON.parse($userIdentity); currentUserIdentity.name = currentUserIdentity.name; activityHistoryData = activityHistory(currentUserIdentity); - console.log(fillMissingDays(await activityHistory(currentUserIdentity))); } }); - const fillMissingDays = (inputActivities: ActivityHistoryEntry[]): ActivityHistoryEntry[] => { - let activities = inputActivities; - const firstDate = new Date(activities[0].date * 1000 + timezoneOffset); - const lastDate = new Date(activities[activities.length - 1].date * 1000 + timezoneOffset); - const currentDate = firstDate; - - while (currentDate <= lastDate) { - const current_unix_timestamp = currentDate.getTime(); - let found = false; - - for (let i = 0; i < activities.length; i++) { - if (activities[i].date * 1000 + timezoneOffset === current_unix_timestamp) { - found = true; - - break; - } - } - - if (!found) { - activities.push({ - date: current_unix_timestamp / 1000, - amount: 0 - }); - } - - currentDate.setDate(currentDate.getDate() + 1); - } - - // activities.sort((a: { date: number }, b: { date: number }) => a.date - b.date); - - return activities; - }; - // const incrementDate = (date: Date): Date => { // date.setDate(date.getDate() + 1); @@ -83,7 +52,9 @@ {#each fillMissingDays(activities) as activity} {#if activity.amount === 0} <li> - {new Date(activity.date * 1000 + timezoneOffset).toDateString()} + {new Date( + activity.date * 1000 + new Date().getTimezoneOffset() * 60 * 1000 + ).toDateString()} </li> {/if} {/each} |