Ver código fonte

add when the stock price was updated

Daniel Bohry 9 meses atrás
pai
commit
3caf038bbb
1 arquivos alterados com 18 adições e 4 exclusões
  1. 18 4
      src/components/StockPriceHistory.svelte

+ 18 - 4
src/components/StockPriceHistory.svelte

@@ -16,6 +16,7 @@
 	let currentPrice = null;
 	let currentCurrency = '';
 	let priceChange = null;
+	let lastUpdated = null;
 
 	const ranges = ['5d', '30d', '6m', '1y'];
 
@@ -106,11 +107,12 @@
 
 		if (history.length > 0) {
 			const first = history[0].price;
-			const last = history[history.length - 1].price;
+			const lastEntry = history[history.length - 1];
 
-			currentPrice = last;
-			currentCurrency = history[history.length - 1].currency || '';
-			priceChange = first !== 0 ? ((last - first) / first) * 100 : null;
+			currentPrice = lastEntry.price;
+			currentCurrency = lastEntry.currency || '';
+			priceChange = first !== 0 ? ((lastEntry.price - first) / first) * 100 : null;
+			lastUpdated = new Date(lastEntry.createdAt);
 
 			renderChart(history);
 		}
@@ -150,6 +152,18 @@
 		</span>
 			{/if}
 		</h3>
+		{#if lastUpdated}
+			<p class="text-xs text-gray-500 dark:text-gray-600 mb-4">
+				Last updated: {lastUpdated.toLocaleString('en-GB', {
+				day: '2-digit',
+				month: '2-digit',
+				year: 'numeric',
+				hour: '2-digit',
+				minute: '2-digit',
+				hour12: true
+			})}
+			</p>
+		{/if}
 		<canvas bind:this={chartCanvas}></canvas>
 
 		<div class="flex justify-center gap-4 mt-6">