Index | Thread | Search

From:
jle <jle@xkc.se>
Subject:
calendar(1): added special events
To:
tech@openbsd.org
Date:
Sun, 25 May 2025 17:38:26 +0200

Download raw body.

Thread
  • jle:

    calendar(1): added special events

Hi tech-list.

I have made an addition of two special events in the calendar program.

The first is midsommar, the saturday that occurs in the period 20-26 june.
This is a public holiday (Midsommardagen) in Sweden and Finland. 
It can also be used to find another public holiday that occurs
133 days later (Alla helgons dag). This makes it possible to address all
public holidays in Sweden without having to modify the calendar file
yearly. 

The second one is advent (Advent Sunday). I added it because it is
found the same way as midsommar, and because it was discussed on this
list a couple of years ago (2018). 

Best Regards
jle


Index: Makefile
===================================================================
RCS file: /cvs/src/usr.bin/calendar/Makefile,v
diff -u -p -r1.11 Makefile
--- Makefile	11 Sep 2016 06:40:57 -0000	1.11
+++ Makefile	25 May 2025 14:18:29 -0000
@@ -1,8 +1,8 @@
 #	$OpenBSD: Makefile,v 1.11 2016/09/11 06:40:57 natano Exp $
 
 PROG=	calendar
-SRCS=   calendar.c io.c day.c pesach.c ostern.c paskha.c
-INTER=	de_DE.UTF-8 hr_HR.UTF-8 ru_RU.UTF-8 fr_FR.UTF-8
+SRCS=   calendar.c io.c day.c pesach.c ostern.c paskha.c mids_advent.c
+INTER=	de_DE.UTF-8 hr_HR.UTF-8 ru_RU.UTF-8 fr_FR.UTF-8 sv_SE.UTF-8
 
 beforeinstall:
 	${INSTALL} ${INSTALL_COPY} -o ${BINOWN} -g ${BINGRP} -m 444 \
Index: calendar.1
===================================================================
RCS file: /cvs/src/usr.bin/calendar/calendar.1,v
diff -u -p -r1.45 calendar.1
--- calendar.1	21 Feb 2025 19:04:34 -0000	1.45
+++ calendar.1	25 May 2025 14:18:29 -0000
@@ -136,6 +136,12 @@ multiple line specifications for a singl
 .Dq Paskha
 (may be followed by a positive or negative integer) is
 Orthodox Easter for this year.
+.Dq Midsommar
+(may be followed by a positive or negative integer) is
+Midsommardagen in Sweden and Finland for this year.
+.Dq Advent 
+(may be followed by a positive or negative integer) is
+Advent Sunday for this year.
 Weekdays may be followed by
 .Dq -4
 .Li ...
@@ -188,6 +194,9 @@ May Sun+2\fB\et\fRsecond Sunday in May (
 Easter\fB\et\fREaster
 Ostern-2\fB\et\fRGood Friday (2 days before Easter)
 Paskha\fB\et\fROrthodox Easter
+Midsommar-1\fB\et\fRMidsommarafton (day before Midsommardagen)
+Midsommar+133\fB\et\fRAlla helgons dag (All Saints Day in Sweden)
+Advent+14\fB\et\fRGaudete Sunday (third Sunday of Advent)
 .Ed
 .Sh FILES
 .Bl -tag -width ~/.calendar/calendar -compact
@@ -245,6 +254,8 @@ Pagan holidays, celebrations and festiva
 Russian calendar.
 .It Pa calendar.space
 Cosmic history.
+.It Pa calendar.swedish
+Swedish calendar (mostly public holidays).
 .It Pa calendar.uk
 UK calendar.
 .It Pa calendar.ushistory
Index: calendar.h
===================================================================
RCS file: /cvs/src/usr.bin/calendar/calendar.h,v
diff -u -p -r1.17 calendar.h
--- calendar.h	1 Feb 2019 16:22:53 -0000	1.17
+++ calendar.h	25 May 2025 14:18:29 -0000
@@ -80,6 +80,8 @@ int	 getmonth(char *);
 int	 pesach(int);
 int	 easter(int);
 int	 paskha(int);
+int	 midsommar(int);
+int	 advent(int);
 void	 insert(struct event **, struct event *);
 struct match	*isnow(char *, int);
 FILE	*opencal(void);
@@ -113,12 +115,16 @@ extern int f_Setday;	/* calendar invoked
 #define EASTERNAMELEN (sizeof(EASTER) - 1)
 #define PASKHA "paskha"
 #define PASKHALEN (sizeof(PASKHA) - 1)
+#define MIDSOMMAR "midsommar"
+#define MIDSOMMARLEN (sizeof(MIDSOMMAR) - 1)
+#define ADVENT "advent"
+#define ADVENTLEN (sizeof(ADVENT) - 1)
 
 /* calendars */
 extern enum calendars { GREGORIAN = 0, JULIAN, LUNAR } calendar;
 extern u_long julian;
 
-#define NUMEV 3	/* Total number of such special events */
+#define NUMEV 5	/* Total number of such special events */
 extern struct specialev spev[NUMEV];
 
 /* For calendar -a, specify a maximum time (in seconds) to spend parsing
Index: day.c
===================================================================
RCS file: /cvs/src/usr.bin/calendar/day.c,v
diff -u -p -r1.37 day.c
--- day.c	12 Aug 2019 20:03:28 -0000	1.37
+++ day.c	25 May 2025 14:18:29 -0000
@@ -143,6 +143,12 @@ setnnames(void)
 	spev[2].name = strdup(PASKHA);
 	spev[2].nlen = PASKHALEN;
 	spev[2].getev = paskha;
+	spev[3].name = strdup(MIDSOMMAR);
+	spev[3].nlen = MIDSOMMARLEN;
+	spev[3].getev = midsommar;
+	spev[4].name = strdup(ADVENT);
+	spev[4].nlen = ADVENTLEN;
+	spev[4].getev = advent;
 	for (i = 0; i < NUMEV; i++) {
 		if (spev[i].name == NULL)
 			err(1, NULL);
Index: mids_advent.c
===================================================================
RCS file: mids_advent.c
diff -N mids_advent.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ mids_advent.c	25 May 2025 14:18:29 -0000
@@ -0,0 +1,46 @@
+#include <stdio.h>
+#include "calendar.h"
+
+/* Use modified version of foy() from day.c. For dates after february, the
+ * leap day for the current year should be included. Hence year is not decreased
+ * before calculation of weekday number. 
+ * The day of year of the next saturday (weekday #6) after day 171 is found by:
+ * day = 171 + (6 - (weekday of day 171)).
+ */
+
+/* Returns year day for Midsommardagen in Sweden
+ * (the first saturday that occurs on or after june 20).
+ */
+
+int
+midsommar(int year)	/* 0 ... abcd, NOT since 1900 */
+{
+	int mday;
+
+	/* June 20 is day 171 of the year and 170 days after jan 1. */
+	/* Saturday is day 6 of the week. */
+	mday = 171 + (7 + 6 - (170 - year/100 + year/400 + (int)(1.25 * year)) % 7) % 7;
+	if isleap(year)
+		mday++;
+
+	return (mday);
+}
+
+
+/* Returns year day for first sunday in Advent.
+ * (the first sunday that occurs on or after november 27).
+ */
+
+int
+advent(int year)	/* 0 ... abcd, NOT since 1900 */
+{
+	int aday;
+
+	/* November 27 is day 331 of the year and 330 days after jan 1. */
+	/* Sunday is day 0 of the week. */
+	aday = 331 + (7 + 0 - (330 - year/100 + year/400 + (int)(1.25 * year)) % 7) % 7;
+	if isleap(year)
+		aday++;
+
+	return (aday);
+}
Index: calendars/calendar.all
===================================================================
RCS file: /cvs/src/usr.bin/calendar/calendars/calendar.all,v
diff -u -p -r1.7 calendar.all
--- calendars/calendar.all	20 Jan 2016 19:12:28 -0000	1.7
+++ calendars/calendar.all	25 May 2025 14:18:29 -0000
@@ -19,5 +19,6 @@
 #include <calendar.canada>
 #include <calendar.uk>
 #include <calendar.nz>
+#include <calendar.swedish>
 
 #endif /* !_calendar_all_ */
Index: calendars/calendar.christian
===================================================================
RCS file: /cvs/src/usr.bin/calendar/calendars/calendar.christian,v
diff -u -p -r1.5 calendar.christian
--- calendars/calendar.christian	13 Dec 2022 07:08:17 -0000	1.5
+++ calendars/calendar.christian	25 May 2025 14:18:29 -0000
@@ -21,7 +21,7 @@ Easter+50	Whitmonday
 Easter+56	Trinity Sunday (7 days after Pentecost)
 Easter+60	Corpus Christi (11 days after Pentecost)
 10/18	Feast Day of St. Luke
-12/SunFirst	First Sunday of Advent (4th Sunday before Christmas)
+Advent	First Sunday of Advent (4th Sunday before Christmas)
 12/06	St. Nicholas' Day
 12/25	Christmas
 
Index: calendars/calendar.swedish
===================================================================
RCS file: calendars/calendar.swedish
diff -N calendars/calendar.swedish
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ calendars/calendar.swedish	25 May 2025 14:18:29 -0000
@@ -0,0 +1,10 @@
+/*
+ * Swedish calendar file(s)
+ */
+
+#ifndef _calendar_swedish_
+#define _calendar_swedish_
+
+#include <sv_SE.UTF-8/calendar.all>
+
+#endif /* !_calendar_swedish_ */
Index: calendars/sv_SE.UTF-8/calendar.all
===================================================================
RCS file: calendars/sv_SE.UTF-8/calendar.all
diff -N calendars/sv_SE.UTF-8/calendar.all
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ calendars/sv_SE.UTF-8/calendar.all	25 May 2025 14:18:29 -0000
@@ -0,0 +1,12 @@
+
+/*
+ * Svensk kalender
+ */
+
+#ifndef _sv_SE_UTF_8_all_
+#define _sv_SE_UTF_8_all_
+
+#include <sv_SE.UTF-8/calendar.helgdagar>
+#include <sv_SE.UTF-8/calendar.sv>
+
+#endif /*! _sv_SE_UTF_8_all_ */
Index: calendars/sv_SE.UTF-8/calendar.helgdagar
===================================================================
RCS file: calendars/sv_SE.UTF-8/calendar.helgdagar
diff -N calendars/sv_SE.UTF-8/calendar.helgdagar
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ calendars/sv_SE.UTF-8/calendar.helgdagar	25 May 2025 14:18:29 -0000
@@ -0,0 +1,38 @@
+
+/*
+ * Helgdagar och helgdagsaftnar
+ *
+ * Källor:
+ * Lag (1989:253) om allmänna helgdagar
+ * Semesterlag (1977:480) 3 a § 2:a stycket
+ */
+
+#ifndef _sv_SE_UTF_8_helgdagar_
+#define _sv_SE_UTF_8_helgdagar_
+
+LANG=sv_SE.UTF-8
+
+1 jan	Nyårsdagen (röd dag)
+5 jan	Trettondagsafton
+6 jan	Trettondedag jul (röd dag)
+Easter-3	Skärtorsdagen 
+Easter-2	Långfredagen (röd dag)
+Easter-1	Påskafton
+Easter	Påskdagen (röd dag)
+Easter+1	Annandag påsk (röd dag)
+30 apr	Valborgsmässoafton
+1 may	Första maj (röd dag)
+Easter+39	Kristi himmelsfärdsdag (röd dag)
+6 jun	Sveriges nationaldag (röd dag)
+Easter+48	Pingstafton
+Easter+49	Pingstdagen (röd dag)
+Midsommar-1	Midsommarafton (arbetsfri helgdagsafton)
+Midsommar	Midsommardagen (röd dag)
+Midsommar+132	Allhelgonaafton
+Midsommar+133	Alla helgons dag (röd dag)
+24 dec	Julafton (arbetsfri helgdagsafton)
+25 dec	Juldagen (röd dag)
+26 dec	Annandag jul (röd dag)
+31 dec	Nyårsafton (arbetsfri helgdagsafton)
+
+#endif /*! _sv_SE_UTF_8_helgdagar_ */
Index: calendars/sv_SE.UTF-8/calendar.sv
===================================================================
RCS file: calendars/sv_SE.UTF-8/calendar.sv
diff -N calendars/sv_SE.UTF-8/calendar.sv
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ calendars/sv_SE.UTF-8/calendar.sv	25 May 2025 14:18:29 -0000
@@ -0,0 +1,18 @@
+
+/*
+ * Lagreglerade helgdagar finns i filen calendar.helgdagar.
+ *
+ */
+
+#ifndef _sv_SE_UTF_8_sv_
+#define _sv_SE_UTF_8_sv_
+
+LANG=sv_SE.UTF-8
+
+Mar SunLast	Sommartid börjar
+May SunLast	Mors dag
+Oct SunLast	Sommartid slutar
+Nov Sun+2	Fars dag
+Advent	Första Advent
+
+#endif /* _sv_SE_UTF_8_sv_ */