From da5f77c3c60f3da62bd32156ad85ad7108138e59 Mon Sep 17 00:00:00 2001 From: nmemmert Date: Thu, 21 May 2026 12:29:57 -0400 Subject: [PATCH] Generalize study release-date gating across all studies --- server.js | 22 +++++++++++++++++++--- src/colossiansStudy.tsx | 37 +++++++++++++++++++++++++++---------- 2 files changed, 46 insertions(+), 13 deletions(-) diff --git a/server.js b/server.js index 7f3b7cb..2bbc87b 100644 --- a/server.js +++ b/server.js @@ -114,10 +114,26 @@ function sanitizeUrl(value) { return '' } +function getSectionReleaseTime(section) { + if (!section || typeof section !== 'object') return Number.NaN + const candidateValues = [ + section.releasedAt, + section.releaseDate, + section.availableAt, + section.publishAt, + ] + + for (const candidate of candidateValues) { + if (typeof candidate !== 'string' || !candidate.trim()) continue + const releaseTime = Date.parse(candidate) + if (Number.isFinite(releaseTime)) return releaseTime + } + + return Number.NaN +} + function isSectionReleased(section) { - if (!section || typeof section !== 'object') return false - if (typeof section.releasedAt !== 'string' || !section.releasedAt.trim()) return false - const releaseTime = Date.parse(section.releasedAt) + const releaseTime = getSectionReleaseTime(section) if (!Number.isFinite(releaseTime)) return false return releaseTime <= Date.now() } diff --git a/src/colossiansStudy.tsx b/src/colossiansStudy.tsx index 9b49666..3585a85 100644 --- a/src/colossiansStudy.tsx +++ b/src/colossiansStudy.tsx @@ -97,31 +97,47 @@ function getChapterSummaries(study: StudyProgram) { }) } +function getSectionReleaseDate(section: StudySection): Date | null { + const candidateValues = [ + section?.releasedAt, + (section as StudySection & { releaseDate?: string }).releaseDate, + (section as StudySection & { availableAt?: string }).availableAt, + (section as StudySection & { publishAt?: string }).publishAt, + ] + + for (const candidate of candidateValues) { + if (typeof candidate !== 'string' || !candidate.trim()) continue + const parsed = new Date(candidate) + if (!Number.isNaN(parsed.getTime())) return parsed + } + + return null +} + function isNewLesson(section: StudySection): boolean { - if (!section.releasedAt) return false - const releaseDate = new Date(section.releasedAt) + const releaseDate = getSectionReleaseDate(section) + if (!releaseDate) return false const now = new Date() const daysSinceRelease = (now.getTime() - releaseDate.getTime()) / (1000 * 60 * 60 * 24) return daysSinceRelease >= 0 && daysSinceRelease <= 14 } function isComingSoon(section: StudySection): boolean { - if (!section.releasedAt) return false - const releaseDate = new Date(section.releasedAt) + const releaseDate = getSectionReleaseDate(section) + if (!releaseDate) return false const now = new Date() return releaseDate > now } function isSectionReleased(section: StudySection): boolean { - if (!section.releasedAt) return false - const releaseDate = new Date(section.releasedAt) - if (Number.isNaN(releaseDate.getTime())) return false + const releaseDate = getSectionReleaseDate(section) + if (!releaseDate) return false return releaseDate <= new Date() } function getReleaseDateDisplay(section: StudySection): string { - if (!section.releasedAt) return '' - const date = new Date(section.releasedAt) + const date = getSectionReleaseDate(section) + if (!date) return '' return date.toLocaleDateString('en-US', { month: 'short', day: 'numeric', year: 'numeric' }) } @@ -765,12 +781,13 @@ export function ColossiansStudySectionPage({ content }: Props) { } if (!sectionIsReleased) { + const releaseDateDisplay = getReleaseDateDisplay(section) return (

{study.title}

Lesson Coming Soon

-

This lesson will be available on {getReleaseDateDisplay(section)}.

+

{releaseDateDisplay ? `This lesson will be available on ${releaseDateDisplay}.` : 'This lesson will be available soon.'}

Back to Lessons