updates, cleanup and skip nextTopic to june
This commit is contained in:
parent
4012433860
commit
25056cfcf9
|
@ -8,10 +8,10 @@ var today = new Date()
|
|||
export default function NextTopic() {
|
||||
// don't put the nextTopic date in the staticly generated html
|
||||
// because it would be outdated rather quickly
|
||||
const isSSR = typeof window === "undefined"
|
||||
const isSSR = typeof window === 'undefined'
|
||||
if (isSSR) {
|
||||
test()
|
||||
return "unbekannt"
|
||||
return '<Benötigt JavaScript>'
|
||||
}
|
||||
|
||||
return formatDateInfo(getNextTopicDate())
|
||||
|
@ -23,13 +23,16 @@ function getNextTopicDate() {
|
|||
// first thursday and third tuesday in month
|
||||
const nextTopic = zeroizeTime(today)
|
||||
|
||||
nextTopic.setMonth(5)
|
||||
nextTopic.setDate(1)
|
||||
|
||||
// first thursday
|
||||
if (calculatePriorWeekdays(THURSDAY) === 0) {
|
||||
if (calculatePriorWeekdays(nextTopic, THURSDAY) === 0) {
|
||||
addDays(nextTopic, getDaysUntilNext(THURSDAY, nextTopic))
|
||||
return nextTopic
|
||||
}
|
||||
// third tuesday
|
||||
const priorTuesdays = calculatePriorWeekdays(TUESDAY)
|
||||
const priorTuesdays = calculatePriorWeekdays(nextTopic, TUESDAY)
|
||||
if (priorTuesdays <= 2) {
|
||||
addDays(nextTopic, getDaysUntilNext(TUESDAY, nextTopic))
|
||||
addDays(nextTopic, WEEK * (2 - priorTuesdays))
|
||||
|
@ -48,12 +51,12 @@ function getNextTopicDate() {
|
|||
* calculate how many of the given weekday this month already had.
|
||||
* for example: how many tuesdays were in this month already
|
||||
*/
|
||||
function calculatePriorWeekdays(weekday) {
|
||||
const testDate = new Date(today)
|
||||
function calculatePriorWeekdays(date, weekday) {
|
||||
const testDate = new Date(date)
|
||||
testDate.setDate(1)
|
||||
|
||||
var priorWeekdays = 0
|
||||
while (testDate < today) {
|
||||
while (testDate < date) {
|
||||
if (testDate.getDay() === weekday) {
|
||||
priorWeekdays++
|
||||
}
|
||||
|
@ -95,8 +98,8 @@ function addDays(date, days) {
|
|||
*/
|
||||
function formatDateInfo(date) {
|
||||
const dayNames = {
|
||||
"2": "Dienstag",
|
||||
"4": "Donnerstag",
|
||||
2: 'Dienstag',
|
||||
4: 'Donnerstag',
|
||||
}
|
||||
|
||||
const dayName = dayNames[date.getDay()]
|
||||
|
@ -133,8 +136,8 @@ function getISODateString(date) {
|
|||
const year = date.getFullYear()
|
||||
const month = date.getMonth() + 1
|
||||
const day = date.getDate()
|
||||
const monthPadded = (month < 10 ? "0" : "") + month
|
||||
const dayPadded = (day < 10 ? "0" : "") + day
|
||||
const monthPadded = (month < 10 ? '0' : '') + month
|
||||
const dayPadded = (day < 10 ? '0' : '') + day
|
||||
return `${year}-${monthPadded}-${dayPadded}`
|
||||
}
|
||||
|
||||
|
@ -158,10 +161,10 @@ function test() {
|
|||
}
|
||||
|
||||
function testLateSunday() {
|
||||
today = new Date("2020-01-19T23:59:59+01:00")
|
||||
today = new Date('2020-01-19T23:59:59+01:00')
|
||||
const result = formatDateInfo(getNextTopicDate())
|
||||
console.assert(
|
||||
result === "Nächste Woche Dienstag, 2020-01-21",
|
||||
result === 'Nächste Woche Dienstag, 2020-01-21',
|
||||
`starting at ${getISODateString(
|
||||
today
|
||||
)}: was ${result}, expected "Nächste Woche Dienstag, 2020-01-21"`
|
||||
|
@ -170,35 +173,35 @@ function testLateSunday() {
|
|||
|
||||
function testYear2020() {
|
||||
const topicsIn2020 = [
|
||||
"2020-01-02",
|
||||
"2020-01-21",
|
||||
"2020-02-06",
|
||||
"2020-02-18",
|
||||
"2020-03-05",
|
||||
"2020-03-17",
|
||||
"2020-04-02",
|
||||
"2020-04-21",
|
||||
"2020-05-07",
|
||||
"2020-05-19",
|
||||
"2020-06-04",
|
||||
"2020-06-16",
|
||||
"2020-07-02",
|
||||
"2020-07-21",
|
||||
"2020-08-06",
|
||||
"2020-08-18",
|
||||
"2020-09-03",
|
||||
"2020-09-15",
|
||||
"2020-10-01",
|
||||
"2020-10-20",
|
||||
"2020-11-05",
|
||||
"2020-11-17",
|
||||
"2020-12-03",
|
||||
"2020-12-15",
|
||||
'2020-01-02',
|
||||
'2020-01-21',
|
||||
'2020-02-06',
|
||||
'2020-02-18',
|
||||
'2020-03-05',
|
||||
'2020-03-17',
|
||||
'2020-04-02',
|
||||
'2020-04-21',
|
||||
'2020-05-07',
|
||||
'2020-05-19',
|
||||
'2020-06-04',
|
||||
'2020-06-16',
|
||||
'2020-07-02',
|
||||
'2020-07-21',
|
||||
'2020-08-06',
|
||||
'2020-08-18',
|
||||
'2020-09-03',
|
||||
'2020-09-15',
|
||||
'2020-10-01',
|
||||
'2020-10-20',
|
||||
'2020-11-05',
|
||||
'2020-11-17',
|
||||
'2020-12-03',
|
||||
'2020-12-15',
|
||||
]
|
||||
today = zeroizeTime(new Date("2020-01-01"))
|
||||
today = zeroizeTime(new Date('2020-01-01'))
|
||||
let currentIndex = 0
|
||||
|
||||
while (today <= new Date("2020-12-15")) {
|
||||
while (today <= new Date('2020-12-15')) {
|
||||
const result = getISODateString(getNextTopicDate())
|
||||
const expect = topicsIn2020[currentIndex]
|
||||
console.assert(
|
||||
|
|
|
@ -12,24 +12,25 @@ export default function RoomState() {
|
|||
|
||||
useEffect(() => {
|
||||
fetch('https://status.ctdo.de/api/simple/v2')
|
||||
.then(response => {
|
||||
.then((response) => {
|
||||
if (response.status >= 200 && response.status <= 299) {
|
||||
return response
|
||||
} else {
|
||||
throw new Error()
|
||||
}
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(json => setOpenState(json.state ? 'open' : 'closed'))
|
||||
.then((response) => response.json())
|
||||
.then((json) => setOpenState(json.state ? 'open' : 'closed'))
|
||||
.catch(() => setOpenState('error'))
|
||||
}, [])
|
||||
|
||||
const isSSR = typeof window === 'undefined'
|
||||
return (
|
||||
<a
|
||||
href="https://status.ctdo.de/"
|
||||
style={{ color: roomStateData[openState].color }}
|
||||
>
|
||||
{roomStateData[openState].text}
|
||||
{isSSR ? '<Benötigt JavaScript>' : roomStateData[openState].text}
|
||||
</a>
|
||||
)
|
||||
}
|
||||
|
|
|
@ -1,87 +1,71 @@
|
|||
@font-face {
|
||||
font-family: "Space Mono";
|
||||
font-family: 'Space Mono';
|
||||
font-style: bold;
|
||||
font-weight: 700;
|
||||
font-display: swap;
|
||||
src: url("../../static/fonts/space-mono-v5-latin-700.eot"); /* IE9 Compat Modes */
|
||||
src: local("Space Mono"), local("SpaceMono-Regular"),
|
||||
url("../../static/fonts/space-mono-v5-latin-700.eot?#iefix")
|
||||
format("embedded-opentype"),
|
||||
/* IE6-IE8 */ url("../../static/fonts/space-mono-v5-latin-700.woff2")
|
||||
format("woff2"),
|
||||
/* Super Modern Browsers */
|
||||
url("../../static/fonts/space-mono-v5-latin-700.woff") format("woff"),
|
||||
/* Modern Browsers */ url("../../static/fonts/space-mono-v5-latin-700.ttf")
|
||||
format("truetype"),
|
||||
/* Safari, Android, iOS */
|
||||
url("../../static/fonts/space-mono-v5-latin-700.svg#SpaceMono")
|
||||
format("svg"); /* Legacy iOS */
|
||||
src: url('../../static/fonts/space-mono-v5-latin-700.eot');
|
||||
src: local('Space Mono'), local('SpaceMono-Regular'),
|
||||
url('../../static/fonts/space-mono-v5-latin-700.eot?#iefix')
|
||||
format('embedded-opentype'),
|
||||
url('../../static/fonts/space-mono-v5-latin-700.woff2') format('woff2'),
|
||||
url('../../static/fonts/space-mono-v5-latin-700.woff') format('woff'),
|
||||
url('../../static/fonts/space-mono-v5-latin-700.ttf') format('truetype'),
|
||||
url('../../static/fonts/space-mono-v5-latin-700.svg#SpaceMono')
|
||||
format('svg');
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: "Source Sans Pro";
|
||||
font-family: 'Source Sans Pro';
|
||||
font-style: normal;
|
||||
font-weight: 400;
|
||||
font-display: swap;
|
||||
src: url("../../static/fonts/source-sans-pro-v13-latin-regular.eot"); /* IE9 Compat Modes */
|
||||
src: local("Source Sans Pro Regular"), local("SourceSansPro-Regular"),
|
||||
url("../../static/fonts/source-sans-pro-v13-latin-regular.eot?#iefix")
|
||||
format("embedded-opentype"),
|
||||
/* IE6-IE8 */
|
||||
url("../../static/fonts/source-sans-pro-v13-latin-regular.woff2")
|
||||
format("woff2"),
|
||||
/* Super Modern Browsers */
|
||||
url("../../static/fonts/source-sans-pro-v13-latin-regular.woff")
|
||||
format("woff"),
|
||||
/* Modern Browsers */
|
||||
url("../../static/fonts/source-sans-pro-v13-latin-regular.ttf")
|
||||
format("truetype"),
|
||||
/* Safari, Android, iOS */
|
||||
url("../../static/fonts/source-sans-pro-v13-latin-regular.svg#SourceSansPro")
|
||||
format("svg"); /* Legacy iOS */
|
||||
src: url('../../static/fonts/source-sans-pro-v13-latin-regular.eot');
|
||||
src: local('Source Sans Pro Regular'), local('SourceSansPro-Regular'),
|
||||
url('../../static/fonts/source-sans-pro-v13-latin-regular.eot?#iefix')
|
||||
format('embedded-opentype'),
|
||||
url('../../static/fonts/source-sans-pro-v13-latin-regular.woff2')
|
||||
format('woff2'),
|
||||
url('../../static/fonts/source-sans-pro-v13-latin-regular.woff')
|
||||
format('woff'),
|
||||
url('../../static/fonts/source-sans-pro-v13-latin-regular.ttf')
|
||||
format('truetype'),
|
||||
url('../../static/fonts/source-sans-pro-v13-latin-regular.svg#SourceSansPro')
|
||||
format('svg');
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: "Source Sans Pro";
|
||||
font-family: 'Source Sans Pro';
|
||||
font-style: italic;
|
||||
font-weight: 400;
|
||||
font-display: swap;
|
||||
src: url("../../static/fonts/source-sans-pro-v13-latin-italic.eot"); /* IE9 Compat Modes */
|
||||
src: local("Source Sans Pro Italic"), local("SourceSansPro-Italic"),
|
||||
url("../../static/fonts/source-sans-pro-v13-latin-italic.eot?#iefix")
|
||||
format("embedded-opentype"),
|
||||
/* IE6-IE8 */
|
||||
url("../../static/fonts/source-sans-pro-v13-latin-italic.woff2")
|
||||
format("woff2"),
|
||||
/* Super Modern Browsers */
|
||||
url("../../static/fonts/source-sans-pro-v13-latin-italic.woff")
|
||||
format("woff"),
|
||||
/* Modern Browsers */
|
||||
url("../../static/fonts/source-sans-pro-v13-latin-italic.ttf")
|
||||
format("truetype"),
|
||||
/* Safari, Android, iOS */
|
||||
url("../../static/fonts/source-sans-pro-v13-latin-italic.svg#SourceSansPro")
|
||||
format("svg"); /* Legacy iOS */
|
||||
src: url('../../static/fonts/source-sans-pro-v13-latin-italic.eot');
|
||||
src: local('Source Sans Pro Italic'), local('SourceSansPro-Italic'),
|
||||
url('../../static/fonts/source-sans-pro-v13-latin-italic.eot?#iefix')
|
||||
format('embedded-opentype'),
|
||||
url('../../static/fonts/source-sans-pro-v13-latin-italic.woff2')
|
||||
format('woff2'),
|
||||
url('../../static/fonts/source-sans-pro-v13-latin-italic.woff')
|
||||
format('woff'),
|
||||
url('../../static/fonts/source-sans-pro-v13-latin-italic.ttf')
|
||||
format('truetype'),
|
||||
url('../../static/fonts/source-sans-pro-v13-latin-italic.svg#SourceSansPro')
|
||||
format('svg');
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: "Source Sans Pro";
|
||||
font-family: 'Source Sans Pro';
|
||||
font-style: normal;
|
||||
font-weight: 700;
|
||||
font-display: swap;
|
||||
src: url("../../static/fonts/source-sans-pro-v13-latin-700.eot"); /* IE9 Compat Modes */
|
||||
src: local("Source Sans Pro Bold"), local("SourceSansPro-Bold"),
|
||||
url("../../static/fonts/source-sans-pro-v13-latin-700.eot?#iefix")
|
||||
format("embedded-opentype"),
|
||||
/* IE6-IE8 */ url("../../static/fonts/source-sans-pro-v13-latin-700.woff2")
|
||||
format("woff2"),
|
||||
/* Super Modern Browsers */
|
||||
url("../../static/fonts/source-sans-pro-v13-latin-700.woff")
|
||||
format("woff"),
|
||||
/* Modern Browsers */
|
||||
url("../../static/fonts/source-sans-pro-v13-latin-700.ttf")
|
||||
format("truetype"),
|
||||
/* Safari, Android, iOS */
|
||||
url("../../static/fonts/source-sans-pro-v13-latin-700.svg#SourceSansPro")
|
||||
format("svg"); /* Legacy iOS */
|
||||
src: url('../../static/fonts/source-sans-pro-v13-latin-700.eot');
|
||||
src: local('Source Sans Pro Bold'), local('SourceSansPro-Bold'),
|
||||
url('../../static/fonts/source-sans-pro-v13-latin-700.eot?#iefix')
|
||||
format('embedded-opentype'),
|
||||
url('../../static/fonts/source-sans-pro-v13-latin-700.woff2')
|
||||
format('woff2'),
|
||||
url('../../static/fonts/source-sans-pro-v13-latin-700.woff') format('woff'),
|
||||
url('../../static/fonts/source-sans-pro-v13-latin-700.ttf')
|
||||
format('truetype'),
|
||||
url('../../static/fonts/source-sans-pro-v13-latin-700.svg#SourceSansPro')
|
||||
format('svg');
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue