--- import type { Status } from '../plugins/mastodon/types'; type Props = Status['poll'] & { class?: string}; const { class: className, ...poll } = Astro.props; function calculatePercentage(votes: number, totalVotes: number) { return totalVotes > 0 ? (votes / totalVotes) * 100 : 0; } function timeLeft(untilDate: string): string { // Get the current date in UTC and set the time to start of the day const now = new Date(); const currentDate = new Date( Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate()), ); // Parse the target date and set the time to start of the day in UTC const targetDateTime = new Date(untilDate); const targetDate = new Date( Date.UTC( targetDateTime.getUTCFullYear(), targetDateTime.getUTCMonth(), targetDateTime.getUTCDate(), ), ); // Calculate the difference in milliseconds const diffInMilliseconds = targetDate.getTime() - currentDate.getTime(); if (diffInMilliseconds < 0) { return "Closed"; } // Convert milliseconds to days const diffInDays = Math.ceil(diffInMilliseconds / (1000 * 60 * 60 * 24)); return `${diffInDays} day${diffInDays !== 1 ? "s" : ""} left`; } ---