Skip to content

Instantly share code, notes, and snippets.

@dnnsmnstrr
Created March 11, 2023 13:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dnnsmnstrr/53946633c1b830b1143ccf6e85800502 to your computer and use it in GitHub Desktop.
Save dnnsmnstrr/53946633c1b830b1143ccf6e85800502 to your computer and use it in GitHub Desktop.
Prototype code for advent calendar
const schema = {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://example.com/advent.json",
"title": "Advent Calendar",
"description": "A calendar for the Advent season",
"type": "object",
"properties": {
"title": {
"description": "The title of the calendar",
"type": "string"
},
"ignoreMonth": {
"description": "Wether to check if the month is December",
"type": "boolean"
},
"days": {
"description": "The days of the calendar",
"type": "array",
"items": {
"type": "object",
"properties": {
"number": {
"description": "The number of the day",
"type": "integer"
},
"title": {
"description": "The title for the day",
"type": "string"
},
"description": {
"description": "The description for the day",
"type": "string"
}
},
"required": ["number", "title"]
}
}
},
"required": ["days"]
}
const adventConfig = {
"title": "Advent Calendar",
"description": "A calendar for the Advent season",
"ignoreMonth": true,
"days": [ // days up to 24
{
"number": 1,
"title": "First Day of Advent",
"description": "The first day of Advent",
},
{
"number": 2,
"title": "Second Day of Advent"
},
{
"number": 3,
"title": "Third Day of Advent"
},
{
"number": 4,
"title": "Fourth Day of Advent"
},
{
"number": 5,
"title": "Fifth Day of Advent"
},
{
"number": 6,
"title": "Sixth Day of Advent"
},
{
"number": 7,
"title": "Seventh Day of Advent"
},
{
"number": 8,
"title": "Eighth Day of Advent"
},
{
"number": 9,
"title": "Ninth Day of Advent"
},
{
"number": 10,
"title": "Tenth Day of Advent"
},
{
"number": 11,
"title": "Eleventh Day of Advent"
},
{
"number": 12,
"title": "Twelfth Day of Advent"
},
{
"number": 13,
"title": "Thirteenth Day of Advent"
},
{
"number": 14,
"title": "Fourteenth Day of Advent"
},
{
"number": 15,
"title": "Fifteenth Day of Advent"
},
{
"number": 16,
"title": "Sixteenth Day of Advent"
},
{
"number": 17,
"title": "Seventeenth Day of Advent"
},
{
"number": 18,
"title": "Eighteenth Day of Advent"
},
{
"number": 19,
"title": "Nineteenth Day of Advent"
},
{
"number": 20,
"title": "Twentieth Day of Advent"
},
{
"number": 21,
"title": "Twenty-first Day of Advent"
},
{
"number": 22,
"title": "Twenty-second Day of Advent"
},
{
"number": 23,
"title": "Twenty-third Day of Advent"
},
{
"number": 24,
"title": "Twenty-fourth Day of Advent"
}
]
}
const getCurrentDay = ({ days, ignoreMonth = false }) => {
if (!days || !days.length) {
throw new Error('No days provided')
}
const today = new Date()
const isDecember = today.getMonth() === 11
if (!isDecember && !ignoreMonth) {
throw new Error('Not December')
}
const day = today.getDate()
const current = days[day]
if (!current) {
throw
}
return current
}
const current = getCurrentDay(adventConfig, true) //?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment