From 8562ba4280c575b3f04df598b7954a2d28b19e50 Mon Sep 17 00:00:00 2001
From: Fuwn <contact@fuwn.me>
Date: Wed, 27 Sep 2023 23:33:01 -0700
Subject: feat(wrapped): initial wrapped prototype

---
 src/lib/Tools/ActivityHistory.svelte | 45 +++++++-----------------------------
 1 file changed, 8 insertions(+), 37 deletions(-)

(limited to 'src/lib/Tools/ActivityHistory.svelte')

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}
-- 
cgit v1.2.3

