Perpetual Calendar
Problem
Please make a calendar for a specified year in the future (2020 for example). The output shall be strings in a format of a normal calendar, separated by month and year with the date and week day information included.
Tip
General steps: Firstly, loop through the 12 months to get and add the titles of the month and the week onto the yearly calendar. Then loop through all days of a specific month, concatenate the dates in a week, separated with the \t. Once the concatenation for one week is done, append the result to the calendar and proceed to the next week.
-
Define the year and the resulting sequence of the calendar, and calculate the day on which Jan. 1 falls.
-
Loop through the 12 months, setting the header for each month.
-
Loop through the days of the current month in a loop and concatenate the strings in a week
-
After concatenating strings for one week, fill the result onto the calendar and proceed to the next week.
-
After the loop of one month is finished,append the stings of the remaining days less than one week onto the calendar
Code
A | B | C | D | ||
---|---|---|---|---|---|
1 | 1984 | =["Year"+string(A1)] | Store the resulting perpetual calendar | ||
2 | =day@w(date(A1,1,1)) | Store the week day of the current day in the loop, the initial value is Jan 1 | |||
3 | for 12 | >B1=B1|["\n","\t\t\t"+string(date(A1,A3,1),"MMMM"),"Sun\tMon\tTue\tWed\tThu\tFri\tSat"] | Cycle the months and set the header field for each month | ||
4 | =fill("\t",A2-1) | Store the current week string during the process of loop. Regarding the first week of each month, the indentation of the first day must be considered. | |||
5 | for days(date(A1, A3,1)) | Cycle all day in the current month and concatenate the week to the current week string B4 by day | |||
6 | >A2=A2+1 | ||||
7 | >B4=B4+string(B5) | ||||
8 | if A2==8 | >A2=1 | Return to Monday after cycling through the whole week | ||
9 | >B1=B1|B4 | Add the week string cycled through to the perpetual calendar | |||
10 | >B4="" | ||||
11 | else | >B4=B4+"\t" | Otherwise, add \t as the separator between days | ||
12 | if B4!="" | >B1=B1|B4 | The last week of each month maybe less than 7 days. These days shall also be filled onto the perpetual calendar. |
Result
SPL Official Website 👉 https://www.scudata.com
SPL Feedback and Help 👉 https://www.reddit.com/r/esProc_SPL
SPL Learning Material 👉 https://c.scudata.com
SPL Source Code and Package 👉 https://github.com/SPLWare/esProc
Discord 👉 https://discord.gg/cFTcUNs7
Youtube 👉 https://www.youtube.com/@esProc_SPL
Chinese version