Advent is the Sunday that is 4 weeks before the Sunday before Christmas. In OpenBSD 7.2, I configured the .calendar/calendar to
#include #include <calendar.christian> And this month (December 2022) the calendar message wrongly shows Advent on December 4: Dec 04* First Sunday of Advent (4th Sunday before Christmas) Advent was actually on November 27, 2022... The bug is because of these lines in calendar.christian: 11/SunLast First Sunday of Advent (4th Sunday before Christmas) 12/SunFirst First Sunday of Advent (4th Sunday before Christmas) Sometimes Advent starts on the third Sunday of November, not always the last Sunday of November. The "First Sunday of Advent" never occurs in December and only occurs in November. So these lines need to be changed... My idea is to replace these two lines using a new "special event" called "Advent": Advent First Sunday of Advent (4th Sunday before Christmas) Advent+7 Second Sunday of Advent (3rd Sunday before Christmas) Advent+14 Third Sunday of Advent (2nd Sunday before Christmas) Advent+21 Fourth Sunday of Advent (Sunday before Christmas) Here are 5 patches to the 7.2 /usr/src/usr.bin/calendar files: --- calendar-7.2/calendars/calendar.christian.orig 1998-11-07 20:38:00.000000000 -0800 +++ calendar-7.2/calendars/calendar.christian 2022-12-02 17:05:29.111496350 -0800 @@ -21,8 +21,10 @@ 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 -11/SunLast First Sunday of Advent (4th Sunday before Christmas) -12/SunFirst First Sunday of Advent (4th Sunday before Christmas) +Advent First Sunday of Advent (4th Sunday before Christmas) +Advent+7 Second Sunday of Advent (3rd Sunday before Christmas) +Advent+14 Third Sunday of Advent (2nd Sunday before Christmas) +Advent+21 Fourth Sunday of Advent (Sunday before Christmas) 12/06 St. Nicholas' Day 12/25 Christmas --- calendar-7.2/Makefile.orig 2016-09-10 23:40:57.000000000 -0700 +++ calendar-7.2/Makefile 2022-12-02 17:28:49.720561727 -0800 @@ -1,7 +1,7 @@ # $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 +SRCS= calendar.c io.c day.c pesach.c ostern.c paskha.c advent.c INTER= de_DE.UTF-8 hr_HR.UTF-8 ru_RU.UTF-8 fr_FR.UTF-8 beforeinstall: --- calendar-7.2/calendar.h.orig 2022-12-02 12:24:15.858386699 -0800 +++ calendar-7.2/calendar.h 2022-12-02 13:21:12.184331976 -0800 @@ -80,6 +80,7 @@ int getmonth(char *); int pesach(int); int easter(int); int paskha(int); +int advent(int); void insert(struct event **, struct event *); struct match *isnow(char *, int); FILE *opencal(void); @@ -113,12 +114,14 @@ extern int f_Setday; /* calendar invoked #define EASTERNAMELEN (sizeof(EASTER) - 1) #define PASKHA "paskha" #define PASKHALEN (sizeof(PASKHA) - 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 4 /* Total number of such special events */ extern struct specialev spev[NUMEV]; /* For calendar -a, specify a maximum time (in seconds) to spend parsing --- calendar-7.2/day.c.orig 2019-08-12 13:03:28.000000000 -0700 +++ calendar-7.2/day.c 2022-12-02 13:25:46.483327583 -0800 @@ -143,6 +143,9 @@ setnnames(void) spev[2].name = strdup(PASKHA); spev[2].nlen = PASKHALEN; spev[2].getev = paskha; + spev[3].name = strdup(ADVENT); + spev[3].nlen = ADVENTLEN; + spev[3].getev = advent; for (i = 0; i < NUMEV; i++) { if (spev[i].name == NULL) err(1, NULL); --- calendar-7.2/advent.c.orig 2022-12-02 17:42:28.819599961 -0800 +++ calendar-7.2/advent.c 2022-12-02 17:59:16.287646987 -0800 @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2022 by Richard Narron <rich...@aaazen.com>, California + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <stdio.h> + +#include "calendar.h" + +/* return year day for Advent, the 4th Sunday before Christmas */ + +int +advent(int year) +{ + int dayofweek = 0; + int nextyear = 0; + int yearday = 0; + + /* Christmas and the next New years are on the same day of the week */ + nextyear = year + 1; + dayofweek = foy(nextyear); + + /* find Christmas day of year */ + if isleap(year) + yearday = 360; + else + yearday = 359; + + /* find the year day of Sunday before Christmas */ + yearday = yearday - dayofweek; + + /* find 4 weeks (28 days) before the Sunday before Christmas */ + yearday = yearday - 28; + + return (yearday); +} And last but not least is my /var/run/dmesg.boot: OpenBSD 7.2 (GENERIC.MP) #2: Thu Nov 24 23:54:39 MST 2022 r...@syspatch-72-amd64.openbsd.org:/usr/src/sys/arch/amd64/compile/GENERIC.MP real mem = 7991279616 (7621MB) avail mem = 7731691520 (7373MB) random: good seed from bootblocks mpath0 at root scsibus0 at mpath0: 256 targets mainbus0 at root bios0 at mainbus0: SMBIOS rev. 2.7 @ 0xeb390 (30 entries) bios0: vendor American Megatrends Inc. version "P01-A4" date 12/20/2011 bios0: Acer Aspire M3470G acpi0 at bios0: ACPI 4.0 acpi0: sleep states S0 S3 S4 S5 acpi0: tables DSDT FACP APIC MCFG SLIC HPET SSDT SSDT acpi0: wakeup devices SBAZ(S4) P0PC(S4) USB5(S4) UHC6(S4) UHC7(S4) XHC0(S4) XHC1(S4) BR12(S5) BR15(S5) PCE7(S5) UHC1(S4) UHC2(S4) USB3(S4) UHC4(S4) acpitimer0 at acpi0: 3579545 Hz, 32 bits acpimadt0 at acpi0 addr 0xfee00000: PC-AT compat cpu0 at mainbus0: apid 0 (boot processor) cpu0: AMD A6-3620 APU with Radeon(tm) HD Graphics, 2196.13 MHz, 12-01-00 cpu0: FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,MMX,FXSR,SSE,SSE2,HTT,SSE3,MWAIT,CX16,POPCNT,NXE,MMXX,FFXSR,PAGE1GB,RDTSCP,LONG,3DNOW2,3DNOW,LAHF,CMPLEG,SVM,EAPICSP,AMCR8,ABM,SSE4A,MASSE,3DNOWP,OSVW,IBS,SKINIT,ITSC cpu0: 64KB 64b/line 2-way D-cache, 64KB 64b/line 2-way I-cache cpu0: 1MB 64b/line 16-way L2 cache cpu0: smt 0, core 0, package 0 cpu0: AMD erratum 721 detected and fixed mtrr: Pentium Pro MTRR support, 8 var ranges, 88 fixed ranges cpu0: apic clock running at 199MHz cpu0: mwait min=64, max=64, IBE cpu1 at mainbus0: apid 1 (application processor) cpu1: AMD A6-3620 APU with Radeon(tm) HD Graphics, 2196.02 MHz, 12-01-00 cpu1: FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,MMX,FXSR,SSE,SSE2,HTT,SSE3,MWAIT,CX16,POPCNT,NXE,MMXX,FFXSR,PAGE1GB,RDTSCP,LONG,3DNOW2,3DNOW,LAHF,CMPLEG,SVM,EAPICSP,AMCR8,ABM,SSE4A,MASSE,3DNOWP,OSVW,IBS,SKINIT,ITSC cpu1: 64KB 64b/line 2-way D-cache, 64KB 64b/line 2-way I-cache cpu1: 1MB 64b/line 16-way L2 cache cpu1: smt 0, core 1, package 0 cpu2 at mainbus0: apid 2 (application processor) cpu2: AMD A6-3620 APU with Radeon(tm) HD Graphics, 2196.02 MHz, 12-01-00 cpu2: FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,MMX,FXSR,SSE,SSE2,HTT,SSE3,MWAIT,CX16,POPCNT,NXE,MMXX,FFXSR,PAGE1GB,RDTSCP,LONG,3DNOW2,3DNOW,LAHF,CMPLEG,SVM,EAPICSP,AMCR8,ABM,SSE4A,MASSE,3DNOWP,OSVW,IBS,SKINIT,ITSC cpu2: 64KB 64b/line 2-way D-cache, 64KB 64b/line 2-way I-cache cpu2: 1MB 64b/line 16-way L2 cache cpu2: smt 0, core 2, package 0 cpu3 at mainbus0: apid 3 (application processor) cpu3: AMD A6-3620 APU with Radeon(tm) HD Graphics, 2196.02 MHz, 12-01-00 cpu3: FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,MMX,FXSR,SSE,SSE2,HTT,SSE3,MWAIT,CX16,POPCNT,NXE,MMXX,FFXSR,PAGE1GB,RDTSCP,LONG,3DNOW2,3DNOW,LAHF,CMPLEG,SVM,EAPICSP,AMCR8,ABM,SSE4A,MASSE,3DNOWP,OSVW,IBS,SKINIT,ITSC cpu3: 64KB 64b/line 2-way D-cache, 64KB 64b/line 2-way I-cache cpu3: 1MB 64b/line 16-way L2 cache cpu3: smt 0, core 3, package 0 ioapic0 at mainbus0: apid 5 pa 0xfec00000, version 21, 24 pins acpimcfg0 at acpi0 acpimcfg0: addr 0xe0000000, bus 0-255 acpihpet0 at acpi0: 14318180 Hz acpiprt0 at acpi0: bus 0 (PCI0) acpiprt1 at acpi0: bus 1 (BR12) acpiprt2 at acpi0: bus 2 (BR15) acpiprt3 at acpi0: bus 3 (PCE7) acpipci0 at acpi0 PCI0: 0x00000000 0x00000011 0x00000001 acpicmos0 at acpi0 acpibtn0 at acpi0: PWRB "PNP0C14" at acpi0 not configured acpicpu0 at acpi0: C2(0@100 io@0x1771), C1(@1 halt!), PSS acpicpu1 at acpi0: C2(0@100 io@0x1771), C1(@1 halt!), PSS acpicpu2 at acpi0: C2(0@100 io@0x1771), C1(@1 halt!), PSS acpicpu3 at acpi0: C2(0@100 io@0x1771), C1(@1 halt!), PSS cpu0: 2196 MHz: speeds: 2200 2000 1800 1600 1400 1000 800 MHz pci0 at mainbus0 bus 0 pchb0 at pci0 dev 0 function 0 "AMD 12h Host" rev 0x00 radeondrm0 at pci0 dev 1 function 0 "ATI Radeon HD 6530D" rev 0x00 drm0 at radeondrm0 radeondrm0: msi azalia0 at pci0 dev 1 function 1 "ATI Radeon HD 6500D HD Audio" rev 0x00: msi azalia0: no supported codecs ppb0 at pci0 dev 2 function 0 "AMD 12h PCIE" rev 0x00: msi pci1 at ppb0 bus 1 puc0 at pci1 dev 0 function 0 "NetMos Nm9922" rev 0x00: ports: 16 com com4 at puc0 port 0 apic 5 int 18: st16650, 32 byte fifo ppb1 at pci0 dev 5 function 0 "AMD 12h PCIE" rev 0x00: msi pci2 at ppb1 bus 2 re0 at pci2 dev 0 function 0 "Realtek 8168" rev 0x02: RTL8168C/8111C (0x3c00), msi, address 00:e0:4c:81:39:20 rgephy0 at re0 phy 7: RTL8169S/8110S/8211 PHY, rev. 2 ppb2 at pci0 dev 7 function 0 "AMD 12h PCIE" rev 0x00: msi pci3 at ppb2 bus 3 re1 at pci3 dev 0 function 0 "Realtek 8168" rev 0x06: RTL8168E/8111E-VL (0x2c80), msi, address f8:0f:41:4d:5d:b5 rgephy1 at re1 phy 7: RTL8169S/8110S/8211 PHY, rev. 5 xhci0 at pci0 dev 16 function 0 "AMD Hudson-2 xHCI" rev 0x03: msi, xHCI 0.96 usb0 at xhci0: USB revision 3.0 uhub0 at usb0 configuration 1 interface 0 "AMD xHCI root hub" rev 3.00/1.00 addr 1 xhci1 at pci0 dev 16 function 1 "AMD Hudson-2 xHCI" rev 0x03: msi, xHCI 0.96 usb1 at xhci1: USB revision 3.0 uhub1 at usb1 configuration 1 interface 0 "AMD xHCI root hub" rev 3.00/1.00 addr 1 ahci0 at pci0 dev 17 function 0 "AMD Hudson-2 SATA" rev 0x40: msi, AHCI 1.3 ahci0: port 0: 6.0Gb/s ahci0: port 1: 1.5Gb/s ahci0: port 2: 6.0Gb/s scsibus1 at ahci0: 32 targets sd0 at scsibus1 targ 0 lun 0: <ATA, Samsung SSD 860, RVQ0> naa.5002538e704033b9 sd0: 953869MB, 512 bytes/sector, 1953525168 sectors, thin cd0 at scsibus1 targ 1 lun 0: <ATAPI, iHAS324 C, LL14> removable sd1 at scsibus1 targ 2 lun 0: <ATA, TOPMORE TP100 12, SBFM> t10.ATA_TOPMORE_TP100_120GB_SSD_TP1000I19210288_ sd1: 114473MB, 512 bytes/sector, 234441648 sectors, thin ohci0 at pci0 dev 18 function 0 "AMD Hudson-2 USB" rev 0x11: apic 5 int 18, version 1.0, legacy support ehci0 at pci0 dev 18 function 2 "AMD Hudson-2 USB2" rev 0x11: apic 5 int 17 usb2 at ehci0: USB revision 2.0 uhub2 at usb2 configuration 1 interface 0 "AMD EHCI root hub" rev 2.00/1.00 addr 1 ohci1 at pci0 dev 19 function 0 "AMD Hudson-2 USB" rev 0x11: apic 5 int 18, version 1.0, legacy support ehci1 at pci0 dev 19 function 2 "AMD Hudson-2 USB2" rev 0x11: apic 5 int 17 usb3 at ehci1: USB revision 2.0 uhub3 at usb3 configuration 1 interface 0 "AMD EHCI root hub" rev 2.00/1.00 addr 1 piixpm0 at pci0 dev 20 function 0 "AMD Hudson-2 SMBus" rev 0x13: SMI iic0 at piixpm0 spdmem0 at iic0 addr 0x52: 4GB DDR3 SDRAM PC3-10600 spdmem1 at iic0 addr 0x53: 4GB DDR3 SDRAM PC3-10600 azalia1 at pci0 dev 20 function 2 "AMD Hudson-2 HD Audio" rev 0x01: apic 5 int 16 azalia1: codecs: Realtek ALC662 audio0 at azalia1 pcib0 at pci0 dev 20 function 3 "AMD Hudson-2 LPC" rev 0x11 ppb3 at pci0 dev 20 function 4 "AMD Hudson-2 PCI" rev 0x40 pci4 at ppb3 bus 4 ohci2 at pci0 dev 20 function 5 "AMD Hudson-2 USB" rev 0x11: apic 5 int 18, version 1.0, legacy support pchb1 at pci0 dev 24 function 0 "AMD 14h Link Cfg" rev 0x43 pchb2 at pci0 dev 24 function 1 "AMD 14h Address Map" rev 0x00 pchb3 at pci0 dev 24 function 2 "AMD 14h DRAM Cfg" rev 0x00 km0 at pci0 dev 24 function 3 "AMD 14h Misc Cfg" rev 0x00 pchb4 at pci0 dev 24 function 4 "AMD 14h CPU Power" rev 0x00 pchb5 at pci0 dev 24 function 5 "AMD 14h Reserved" rev 0x00 pchb6 at pci0 dev 24 function 6 "AMD 14h NB Power" rev 0x00 pchb7 at pci0 dev 24 function 7 "AMD 14h Reserved" rev 0x00 usb4 at ohci0: USB revision 1.0 uhub4 at usb4 configuration 1 interface 0 "AMD OHCI root hub" rev 1.00/1.00 addr 1 usb5 at ohci1: USB revision 1.0 uhub5 at usb5 configuration 1 interface 0 "AMD OHCI root hub" rev 1.00/1.00 addr 1 isa0 at pcib0 isadma0 at isa0 pckbc0 at isa0 port 0x60/5 irq 1 irq 12 pckbd0 at pckbc0 (kbd slot) wskbd0 at pckbd0: console keyboard pcppi0 at isa0 port 0x61 spkr0 at pcppi0 it0 at isa0 port 0x2e/2: IT8772F rev 0, EC port 0xa30 usb6 at ohci2: USB revision 1.0 uhub6 at usb6 configuration 1 interface 0 "AMD OHCI root hub" rev 1.00/1.00 addr 1 vmm0 at mainbus0: SVM/RVI ulpt0 at uhub0 port 4 configuration 1 interface 0 "QinHeng Electronics USB2.0-Print" rev 1.10/2.54 addr 2 ulpt0: using bi-directional mode umass0 at uhub2 port 1 configuration 1 interface 0 "Generic USB2.0-CRW" rev 2.00/81.97 addr 2 umass0: using SCSI over Bulk-Only scsibus2 at umass0: 2 targets, initiator 0 sd2 at scsibus2 targ 1 lun 0: <Generic-, Compact Flash, 1.00> removable sd3 at scsibus2 targ 1 lun 1: <Generic-, SM/xD-Picture, 1.00> removable sd4 at scsibus2 targ 1 lun 2: <Generic-, SD/MMC, 1.00> removable sd5 at scsibus2 targ 1 lun 3: <Generic-, MS/MS-Pro/HG, 1.00> removable sd6 at scsibus2 targ 1 lun 4: <Generic-, SD/MMC/MS/MSPRO, 1.00> removable uhidev0 at uhub2 port 1 configuration 1 interface 1 "Generic USB2.0-CRW" rev 2.00/81.97 addr 2 uhidev0: iclass 3/0 uhid0 at uhidev0: input=1, output=0, feature=0 uhidev1 at uhub4 port 3 configuration 1 interface 0 "Microsoft Wired Keyboard 600" rev 1.10/1.10 addr 2 uhidev1: iclass 3/1 ukbd0 at uhidev1: 8 variable keys, 6 key codes wskbd1 at ukbd0 mux 1 uhidev2 at uhub4 port 3 configuration 1 interface 1 "Microsoft Wired Keyboard 600" rev 1.10/1.10 addr 2 uhidev2: iclass 3/0, 3 report ids ucc0 at uhidev2 reportid 1: 1024 usages, 18 keys, array wskbd2 at ucc0 mux 1 uhid1 at uhidev2 reportid 3: input=1, output=0, feature=0 uhidev3 at uhub4 port 4 configuration 1 interface 0 "PixArt USB Optical Mouse" rev 1.10/1.00 addr 3 uhidev3: iclass 3/1 ums0 at uhidev3: 3 buttons, Z dir wsmouse0 at ums0 mux 0 vscsi0 at root scsibus3 at vscsi0: 256 targets softraid0 at root scsibus4 at softraid0: 256 targets root on sd0a (de57f03e553efc65.a) swap on sd0b dump on sd0b radeondrm0: SUMO radeondrm0: 1280x1024, 32bpp wsdisplay0 at radeondrm0 mux 1: console (std, vt100 emulation), using wskbd0 wskbd1: connecting to wsdisplay0 wskbd2: connecting to wsdisplay0 wsdisplay0: screen 1-5 added (std, vt100 emulation)