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