1
0
mirror of synced 2025-12-21 02:46:50 -05:00
Files
docs/javascripts/deprecation-banner.js
Vanessa Yuen 3df90fc9b8 Hello git history spelunker!
Are you looking for something? Here is all of the GitHub Docs history in one single commit. Enjoy! 🎉
2020-09-27 14:10:11 +02:00

31 lines
1.0 KiB
JavaScript

// Make deprecation banner language adaptive to past and future tense based on deprecation date
export default function () {
const spanWillBeDeprecated = document.querySelector('span[data-display-until]')
const spanWasDeprecated = document.querySelector('span[data-display-starting]')
if (!spanWillBeDeprecated) return
if (!spanWasDeprecated) return
const today = getDate()
const deprecationDate = getDate(spanWillBeDeprecated.getAttribute('data-display-until'))
// if deprecation date is >= today's date, the date is in the future, so display "will be deprecated"
// if deprecation date is < today's date, the date is in the past, so display "was deprecated"
if (deprecationDate > today || getTime(deprecationDate) === getTime(today)) {
spanWasDeprecated.style.display = 'none'
} else {
spanWillBeDeprecated.style.display = 'none'
}
}
function getDate (date) {
const dateObj = date ? new Date(date) : new Date()
return dateObj.toISOString().slice(0, 10)
}
function getTime (date) {
return new Date(date).getTime()
}