This commit is contained in:
MuslemRahimi 2024-12-02 20:32:23 +01:00
parent a886bbbbb9
commit 2a34847fa1
5 changed files with 22 additions and 72 deletions

View File

@ -23,11 +23,11 @@
let dividendYield;
async function stockSelector(ticker: string) {
if (ticker?.length !== 0 && !["BTC", "USD"]?.includes(ticker)) {
if (ticker?.length !== 0 && !["BTCUSD", "USD"]?.includes(ticker)) {
window?.scroll({ top: 0, left: 0, behavior: "smooth" });
stockTicker.update((value) => ticker);
goto("/stocks/" + ticker + "/");
} else if (ticker === "BTC") {
} else if (ticker === "BTCUSD") {
window?.scroll({ top: 0, left: 0, behavior: "smooth" });
cryptoTicker.update((value) => "BTCUSD");
goto("/crypto/BTCUSD");
@ -189,7 +189,10 @@
{#if typeof item?.name !== "undefined"}
{item?.name?.length > 20
? formatString(item?.name?.slice(0, 20)) + "..."
: formatString(item?.name)}
: formatString(item?.name)?.replace(
"Usd",
"USD",
)}
{:else}
n/a
{/if}

View File

@ -1,46 +1,12 @@
<script lang="ts">
import { stockTicker, etfTicker } from "$lib/store";
import { formatDate } from "$lib/utils";
export let data;
let rawData = [];
let newsList = [];
const formatDate = (dateString) => {
// Create a date object for the input dateString
const inputDate = new Date(dateString);
// Create a date object for the current time in New York City
const nycTime = new Date().toLocaleString("en-US", {
timeZone: "America/New_York",
});
const currentNYCDate = new Date(nycTime);
// Calculate the difference in milliseconds
const difference = inputDate.getTime() - currentNYCDate.getTime();
// Convert the difference to minutes
const minutes = Math.abs(Math.round(difference / (1000 * 60)));
if (minutes < 60) {
return `${minutes} minute${minutes !== 1 ? "s" : ""}`;
} else if (minutes < 1440) {
const hours = Math.round(minutes / 60);
return `${hours} hour${hours !== 1 ? "s" : ""}`;
} else if (minutes < 10080) {
const days = Math.round(minutes / 1440);
if (days > 6) {
return "1 week";
}
return `${days} day${days !== 1 ? "s" : ""}`;
} else if (minutes < 20160) {
return "2 weeks";
} else {
const weeks = Math.round(minutes / 10080);
return `${weeks} week${weeks !== 1 ? "s" : ""}`;
}
};
/*
let videoId = null;
@ -138,7 +104,7 @@
</a>
<div class="-mt-3 w-full">
<h3 class="text-sm text-white/80 truncate mb-2 mt-3">
{formatDate(item?.publishedDate)} ago · {item?.site}
{formatDate(item?.publishedDate)} &#183; {item?.site}
</h3>
<a
href={item?.url}

View File

@ -14,11 +14,11 @@
let totalAssetPercentage = 0;
async function stockSelector(ticker: string) {
if (ticker?.length !== 0 && !["BTC", "USD"]?.includes(ticker)) {
if (ticker?.length !== 0 && !["BTCUSD", "BTC" "USD"]?.includes(ticker)) {
window?.scroll({ top: 0, left: 0, behavior: "smooth" });
stockTicker.update((value) => ticker);
goto("/stocks/" + ticker + "/");
} else if (ticker === "BTC") {
} else if (ticker === "BTCUSD") {
window?.scroll({ top: 0, left: 0, behavior: "smooth" });
cryptoTicker.update((value) => "BTCUSD");
goto("/crypto/BTCUSD");

View File

@ -572,13 +572,20 @@ export function abbreviateNumber(number, addDollarSign = false) {
}
export const formatDate = (dateString) => {
const date = new Date(dateString);
const now = new Date();
const diffInDays = Math.floor((now - date) / (1000 * 60 * 60 * 24));
if (diffInDays >= 7) {
const weeks = Math.floor(diffInDays / 7);
return `${weeks} week${weeks > 1 ? "s" : ""} ago`;
}
return formatDistanceToNow(date, {
addSuffix: false,
addSuffix: true,
includeSeconds: false,
})?.replace(/about /i, "");
}).replace(/about /i, "");
};
export const formatRuleValue = (rule) => {

View File

@ -1,37 +1,11 @@
<script lang="ts">
import { etfTicker } from "$lib/store";
import ArrowLogo from "lucide-svelte/icons/move-up-right";
import { formatDate } from "$lib/utils";
export let data;
let newsList = data?.getNews ?? [];
const formatDate = (dateString) => {
// Create a date object for the input dateString
const inputDate = new Date(dateString);
// Create a date object for the current time in New York City
const nycTime = new Date().toLocaleString("en-US", {
timeZone: "America/New_York",
});
const currentNYCDate = new Date(nycTime);
// Calculate the difference in milliseconds
const difference = inputDate.getTime() - currentNYCDate.getTime();
// Convert the difference to minutes
const minutes = Math.abs(Math.round(difference / (1000 * 60)));
if (minutes < 60) {
return `${minutes} minutes`;
} else if (minutes < 1440) {
const hours = Math.round(minutes / 60);
return `${hours} hour${hours !== 1 ? "s" : ""}`;
} else {
const days = Math.round(minutes / 1440);
return `${days} day${days !== 1 ? "s" : ""}`;
}
};
</script>
<section class="w-auto overflow-hidden">
@ -77,7 +51,7 @@
<ul class="text-white">
{#each newsList?.slice(0, 10) as item}
<li class="mb-3 last:mb-1">
{formatDate(item?.publishedDate)} ago -
{formatDate(item?.publishedDate)} &#183;
<a
class="sm:hover:text-white text-blue-400"
href={item?.url}