QR code dates

This commit is contained in:
2025-10-02 09:14:30 -04:00
parent ef4d47c4f0
commit 3b206e3f79

View File

@@ -16,7 +16,7 @@
<div class="flex flex-col items-center">
<div class="text-center mb-4">
<h4 class="text-lg font-semibold text-gray-900 mb-1">{{ sermon.title }}</h4>
<p class="text-sm text-gray-600">{{ formatDate(sermon.date) }}</p>
<p class="text-sm text-gray-600">{{ formatDateRange(sermon) }}</p>
</div>
<div class="bg-white p-4 rounded-lg border-2 border-gray-200">
<canvas ref="qrCanvas"></canvas>
@@ -51,7 +51,8 @@ const qrCanvas = ref<HTMLCanvasElement | null>(null)
const config = useRuntimeConfig()
function formatDate(dateString: string) {
const date = new Date(dateString)
// Add T00:00:00 to ensure the date is interpreted as local time, not UTC
const date = new Date(dateString + 'T00:00:00')
return date.toLocaleDateString('en-US', {
year: 'numeric',
month: '2-digit',
@@ -59,6 +60,24 @@ function formatDate(dateString: string) {
})
}
function formatDateRange(sermon: any) {
// Start with primary date
const dates = [sermon.date]
// Add additional dates if they exist
if (sermon.dates) {
try {
const additionalDates = JSON.parse(sermon.dates)
dates.push(...additionalDates)
} catch {
// If parsing fails, just use primary date
}
}
// Format all dates and join with " - "
return dates.map(formatDate).join(' - ')
}
onMounted(async () => {
if (qrCanvas.value) {
const url = `${config.public.siteUrl}/${props.sermon.slug}`