It has been a while since the last time we did something like a programming challenge, so here's one for ya. The life story of the author before you get to the recipe I've been working on a little...
It has been a while since the last time we did something like a programming challenge, so here's one for ya.
The life story of the author before you get to the recipe
I've been working on a little "today" website, showing what day it is, if it's a significant date for holiday/independence/... reasons, and one of the things I wanted was a small calendar display that showed the full month and days in each week. Like how XFCE's Clock plugin does it.
So I got to figuring it out and after finishing it up I thought this could be a nice little programming challenge. It has one input (the date) that can be in any of the rows and columns, and it's up to you to figure out all the rest.
Here's how mine looks in about 250ish lines of TypeScript (TSX technically) and SCSS.
Make a mini calendar display that shows all the days of the current month and at least one day of each adjacent month. So for example for May 2023: the 31 days in May, the 30th of April and the 1st of June should at least be visible.
It can be in any language with any method of rendering; simple text, TUI/GUI toolkit, web-based, raytraced in some game engine, nixie tubes, whatever.
- Highlight the current day name in the first row, if you're including day names.
- Highlight the current day number, wherever it is.
- Highlight the current week row, wherever it is.
- Differentiate the days of current month and the days of the other adjacent months, wherever they are.
The week number
Make sure to test multiple different input dates, I thought I was finished with my display until I tried some other dates and noticed that there were still some bugs left to squash.
If you know what the first day in the calendar should be, counting up is as easy as "one two three"!
If you use 6 weeks in the display, you will always have enough space to fit all the current month's days and the minimum 1 day of the adjacent month's too.
If at all possible and with at least a few entries I will try to run all the submissions myself and create a little showcase website for it.