Generalize study release-date gating across all studies
This commit is contained in:
@@ -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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user