workcal

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 4, 2026 License: MIT Imports: 4 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

workcal

A Go library for the Serbian calendar: dates in Europe/Belgrade, calendar-day and month arithmetic, Orthodox Easter, the public non-working holidays, and "N working days after receipt" deadlines.

It has no dependencies outside the Go standard library and holds no policy: it does not know which law gives which period, only how to count one.

How it works

  • Dates are Belgrade dates. DateOf(t) takes the calendar date of t in Europe/Belgrade, so 23:30 UTC on Dec 31 is Jan 1. The zone database is embedded (time/tzdata), so it works on images with no zoneinfo.
  • Deadlines are the end of a day: 23:59:59.999 Belgrade time.
  • The day of receipt is never counted (Regulation (EEC, Euratom) No 1182/71 Art. 3(1)). 30 days from the 1st ends at the end of the 31st; 3 working days from a Thursday ends at the end of the following Tuesday.
  • Arithmetic is DST-safe. A Date has no time and no zone; adding days goes through UTC midnight, where every day is 24 hours, so the 23- and 25-hour days in March and October cannot shift a date. EndOfDay then puts the result back in Belgrade, at +1 or +2 as the date requires.
  • Months clamp (Regulation 1182/71 Art. 3(2)(c)): Jan 31 + 1 month is Feb 28, or Feb 29 in a leap year. Go's time.AddDate would give Mar 3.
  • Working days are Monday to Friday, optionally excluding Serbian public non-working holidays. AddWorkingDays(received, n, skipHolidays) steps forward one date at a time from the day after receipt and returns the end of the n-th working day.
The holiday rules and their sources

From the Zakon o državnim i drugim praznicima u Republici Srbiji ("Sl. glasnik RS", br. 43/2001, 101/2007 i 92/2011):

Rule Days off
čl. 1 and 1a, state holidays Nova godina Jan 1-2; Sretenje (Dan državnosti) Feb 15-16; Praznik rada May 1-2; Dan primirja Nov 11
čl. 2, religious holidays for all prvi dan Božića Jan 7; Vaskrs from Good Friday to Easter Monday (Orthodox)
čl. 3a, Sunday carry-over a state holiday on a Sunday makes the first following working day off. Christmas and Easter do not carry. "First following working day" skips days already off: Jan 1 2023 (Sunday) moved to Tue Jan 3, past the Jan 2 holiday; May 2 2021 (Sunday) moved to Tue May 4, past Easter Monday.
čl. 3, working holidays Dan pobede (May 9) and the other working holidays are not days off and never carry

Sources: the law's text at paragraf.rs/propisi/zakon_o_drzavnim_i_drugim_praznicima_u_republici_srbiji.html and propisi.net/zakon-o-drzavnim-i-drugim-praznicima-u-republici-srbiji/ (read 2026-09-27); the carry-over outcomes checked against published non-working-day calendars, e.g. ipc.rs/statisticki_podaci/2023/praznici-neradni-dani-u-2023-godini (2023) and unija.com/sr/koji-su-to-neradni-dani-za-prvomajske-i-vaskrsnje-praznike/ (2021).

Orthodox Easter is Meeus's Julian Easter algorithm plus 13 days.

Verified versus computed
Range Status
2018, 2021-2027 (8 years) Full holiday set pinned in tests, written out from the law and checked against published calendars
1900, 2018, 2021-2027 Orthodox Easter date pinned in tests
1900-2099 (200 years) Computed. Tests check every Easter falls on a Sunday; the holiday set follows from the same rules but no year outside the pinned ones has been compared to a published calendar
before 1900, after 2099 OrthodoxEaster panics, and so does everything that needs the holiday set: IsSerbianHoliday, SerbianHolidays, IsWorkingDay(d, true), AddWorkingDays(t, n, true). Weekend-only counting (skipHolidays=false) works for any year

Install

go get github.com/kinreply/workcal

Requires Go 1.27 or later (the go directive in go.mod).

Usage

import "github.com/kinreply/workcal"

received := time.Date(2026, 4, 9, 10, 0, 0, 0, workcal.Location()) // Thursday before Easter

// 3 working days, skipping Good Friday to Easter Monday: end of Thu Apr 16.
due := workcal.AddWorkingDays(received, 3, true)

// Weekends only: end of Tue Apr 14.
due = workcal.AddWorkingDays(received, 3, false)

// 30 days or one calendar month from receipt, whichever ends first.
r := workcal.DateOf(received)
due = workcal.Earlier(r.AddDays(30), r.AddMonthsClamped(1)).EndOfDay()

// Whole calendar days left.
left := workcal.DaysBetween(workcal.DateOf(time.Now()), workcal.DateOf(due))

workcal.IsSerbianHoliday(time.Date(2026, 2, 17, 12, 0, 0, 0, workcal.Location())) // true: Feb 15 was a Sunday
workcal.SerbianHolidays(2026) // 13 dates, in order
API
Name What
Location() *time.Location Europe/Belgrade
type Date struct{ Year int; Month time.Month; Day int } a calendar date, no time, no zone
DateOf(t time.Time) Date t's Belgrade date
(Date) AddDays(n int) Date n calendar days later
(Date) AddMonthsClamped(n int) Date same date n months later, clamped to the month's last day
(Date) Before(o Date) bool, (Date) Weekday() time.Weekday
(Date) EndOfDay() time.Time 23:59:59.999 Belgrade
Earlier(a, b Date) Date the first of two dates
DaysBetween(from, to Date) int calendar days from from to to
IsWorkingDay(d Date, skipHolidays bool) bool Monday-Friday, optionally not a holiday
AddWorkingDays(received time.Time, n int, skipHolidays bool) time.Time end of the n-th working day after receipt
IsSerbianHoliday(t time.Time) bool t's Belgrade date is a non-working holiday
SerbianHolidays(year int) []Date the year's non-working holidays, in order
OrthodoxEaster(year int) time.Time Easter Sunday, midnight Belgrade
EasterMinYear, EasterMaxYear 1900, 2099
Cost

The holiday set is rebuilt on every call rather than cached. On a Ryzen 5 5600: IsSerbianHoliday 1.1 µs and 5 allocations; AddWorkingDays(t, 3, true) across Easter 6.0 µs and 25 allocations. Fine for deadlines on requests; measure before putting it in a loop over millions of dates.

Development

make check   # gofmt -l, go vet, go test -race

Limitations

  • Year bounds. Orthodox Easter is computed as the Julian date plus 13 days, which holds only from 1900 to 2099: in 2100 the Julian-Gregorian gap becomes 14 days. Outside those years OrthodoxEaster and everything that needs the holiday set panic, on purpose: a zero time.Time is year 1, and a calendar silently off by a day is worse than a crash. Weekend-only counting is not bounded.
  • Holidays of other faiths are not counted. Under čl. 2 of the law, holidays of other faiths (Catholic Christmas, Bajram, Yom Kippur and others) are days off only for employees of that faith. They are not general non-working days, so they are not in the set.
  • No end-of-period roll-forward. Regulation 1182/71 Art. 3(4), and similar Serbian procedural rules, move a period that ends on a weekend or holiday to the next working day. AddDays and AddMonthsClamped do not apply it, so a date they give is never later than the law's and at worst a day or two early. A caller that needs it can step forward with IsWorkingDay. (AddWorkingDays always ends on a working day by construction.)
  • The law as of "Sl. glasnik RS" br. 92/2011. The rules are code, not data. A future amendment, or a one-off government decision adding a non-working day, needs a code change and a new release. The same rules are applied to every year 1900-2099, including years before the law or its amendments took effect, so results for those years are not historical fact.
  • One country, one zone. Other countries' holidays and other time zones are out of scope.
  • Only the years in the table above are checked against published calendars.

License

MIT. See LICENSE.

Documentation

Overview

Package workcal is the Serbian civil and working-day calendar: dates in Europe/Belgrade, calendar-day and month arithmetic, Orthodox Easter, the public non-working holidays, and working-day counting.

It holds calendar mechanism only. Which period a deadline uses, and which law sets it, is the caller's business.

A deadline here is the END OF A DAY in Europe/Belgrade (23:59:59.999 local). The day of the triggering event is never counted: a period of 30 days from receipt on the 1st ends at the end of the 31st. That is Regulation (EEC, Euratom) No 1182/71 Art. 3(1), and the ordinary reading of Serbian law.

What this deliberately does NOT do

Regulation 1182/71 Art. 3(4) moves a period that ends on a Saturday, Sunday or public holiday to the end of the next working day, and Serbian procedural law has a similar rule. Both only ever make a deadline LATER. Nothing here applies them: AddDays and AddMonthsClamped are purely calendar, so a date computed from them is never later than the law's; at worst it is a day or two early. That is the cheap direction to be wrong in. A caller that wants the roll-forward can apply it with IsWorkingDay.

Index

Examples

Constants

View Source
const (
	EasterMinYear = 1900
	EasterMaxYear = 2099
)

EasterMinYear and EasterMaxYear bound OrthodoxEaster: in these years the Julian calendar runs exactly 13 days behind the Gregorian for every date Easter can fall on. 1900 is inside because its Julian Feb 29 precedes the earliest Easter; 2100 is outside because the gap becomes 14 on its (Julian) Mar 1.

Variables

This section is empty.

Functions

func AddWorkingDays

func AddWorkingDays(received time.Time, n int, skipHolidays bool) time.Time

AddWorkingDays is the end (in Belgrade) of the n-th working day after the date of received, the day of receipt not counted, whatever day it is. A working day is as IsWorkingDay defines it: skipHolidays=true skips Serbian non-working holidays as well as weekends, false skips weekends only.

"Within 3 working days" of a report received on a Thursday ends at the end of the following Tuesday; received on a Saturday, at the end of Wednesday.

It panics if n < 1, and, with skipHolidays, if the count reaches a year outside EasterMinYear..EasterMaxYear.

Example
package main

import (
	"fmt"
	"time"

	"github.com/kinreply/workcal"
)

func main() {
	received := time.Date(2026, 4, 9, 10, 0, 0, 0, workcal.Location()) // Thursday before Easter
	fmt.Println(workcal.AddWorkingDays(received, 3, true).Format(time.DateTime))
	fmt.Println(workcal.AddWorkingDays(received, 3, false).Format(time.DateTime))
}
Output:
2026-04-16 23:59:59
2026-04-14 23:59:59

func DaysBetween

func DaysBetween(from, to Date) int

DaysBetween is the number of calendar days from `from` to `to`: positive when to is later, negative when it is earlier, 0 on the same date. It counts dates, not 24-hour spans, so a 23- or 25-hour DST day is still one day.

func IsSerbianHoliday

func IsSerbianHoliday(t time.Time) bool

IsSerbianHoliday reports whether t's Belgrade date is a public non-working day in Serbia, under the Zakon o državnim i drugim praznicima u Republici Srbiji ("Sl. glasnik RS", br. 43/2001, 101/2007 i 92/2011):

  • čl. 1 and 1a, state holidays: Nova godina Jan 1-2, Sretenje (Dan državnosti) Feb 15-16, Praznik rada May 1-2, Dan primirja Nov 11. (Dan pobede, May 9, is also listed but čl. 3 makes it a working holiday.)
  • čl. 2, religious: prvi dan Božića Jan 7, and Vaskrs "počev od Velikog petka zaključno sa drugim danom Vaskrsa", Good Friday to Easter Monday.
  • čl. 3a: "Ako jedan od datuma kada se praznuju državni praznici Republike Srbije padne u nedelju, ne radi se prvog narednog radnog dana." Only the state holidays carry, so not Christmas and not Easter. "Prvi naredni radni dan" skips days that are already off: in 2023 Jan 1 was a Sunday, Jan 2 a holiday anyway, so Jan 3 (Tuesday) was off; in 2021 May 2 was a Sunday and May 3 Easter Monday, so May 4 was off. Both match the non-working calendars published for those years.

Sources:

  • the law's text: paragraf.rs/propisi/zakon_o_drzavnim_i_drugim_praznicima_u_republici_srbiji.html and propisi.net/zakon-o-drzavnim-i-drugim-praznicima-u-republici-srbiji/, read 2026-09-27;
  • the carry-over outcomes: the published non-working-day calendars, e.g. ipc.rs/statisticki_podaci/2023/praznici-neradni-dani-u-2023-godini (2023) and unija.com/sr/koji-su-to-neradni-dani-za-prvomajske-i-vaskrsnje-praznike/ (2021); the tests pin the holiday set for 2018 and 2021-2027 against them.

Dan pobede (May 9) is a WORKING holiday: it never makes a day off and never carries. Holidays of other faiths (Catholic Christmas, Bajram, Yom Kippur...) are days off only for employees of that faith (čl. 2) and are not in this set.

It panics outside EasterMinYear..EasterMaxYear (see OrthodoxEaster).

func IsWorkingDay

func IsWorkingDay(d Date, skipHolidays bool) bool

IsWorkingDay reports whether d is Monday to Friday and, when skipHolidays is true, not a Serbian public non-working holiday (SerbianHolidays).

With skipHolidays it panics outside EasterMinYear..EasterMaxYear (see OrthodoxEaster).

func Location

func Location() *time.Location

Location is Europe/Belgrade, the zone every date here is taken in.

func OrthodoxEaster

func OrthodoxEaster(year int) time.Time

OrthodoxEaster is the Orthodox Easter Sunday of year as a Gregorian date (midnight, Belgrade): Meeus's Julian Easter algorithm, plus 13 days.

It panics outside EasterMinYear..EasterMaxYear. A date in those years is a bug in the caller (a zero time.Time is year 1), and silently computing a holiday calendar off by a day is worse than failing loudly.

Types

type Date

type Date struct {
	Year  int
	Month time.Month
	Day   int
}

Date is a calendar date with no time and no zone. Arithmetic on it goes through UTC midnight, where every day is 24 hours, so a DST change in Belgrade cannot shift a date by one.

func DateOf

func DateOf(t time.Time) Date

DateOf is t's calendar date in Belgrade.

func Earlier

func Earlier(a, b Date) Date

Earlier is whichever of a and b comes first.

func SerbianHolidays

func SerbianHolidays(year int) []Date

SerbianHolidays is every public non-working day of year, as IsSerbianHoliday defines them, in date order. Days that coincide (May 2 that is also Easter) appear once. It panics outside EasterMinYear..EasterMaxYear.

Example
package main

import (
	"fmt"

	"github.com/kinreply/workcal"
)

func main() {
	for _, d := range workcal.SerbianHolidays(2026) {
		fmt.Printf("%s %d ", d.Month.String()[:3], d.Day)
	}
	fmt.Println()
}
Output:
Jan 1 Jan 2 Jan 7 Feb 15 Feb 16 Feb 17 Apr 10 Apr 11 Apr 12 Apr 13 May 1 May 2 Nov 11

func (Date) AddDays

func (d Date) AddDays(n int) Date

AddDays is the date n calendar days later (earlier for negative n).

func (Date) AddMonthsClamped

func (d Date) AddMonthsClamped(n int) Date

AddMonthsClamped is "the same date n months later", and when the target month has no such date, its last day. That is Regulation 1182/71 Art. 3(2)(c): a period in months ends on the day "which is the same date as the day during which the event ... occurred", and "if, in a period expressed in months ..., the day on which it should expire does not occur in the last month, the period shall end with the expiry of the last hour of the last day of that month". So Jan 31 + 1 month is Feb 28 (Feb 29 in a leap year).

time.AddDate(0, n, 0) is NOT this: it normalises Feb 31 to Mar 3, which would show a deadline three days after the law's.

Example
package main

import (
	"fmt"
	"time"

	"github.com/kinreply/workcal"
)

func main() {
	r := workcal.Date{Year: 2026, Month: time.January, Day: 31}
	fmt.Println(r.AddMonthsClamped(1))
	fmt.Println(workcal.Earlier(r.AddDays(30), r.AddMonthsClamped(1)).EndOfDay().Format(time.DateTime))
}
Output:
{2026 February 28}
2026-02-28 23:59:59

func (Date) Before

func (d Date) Before(o Date) bool

Before reports whether d is an earlier date than o.

func (Date) EndOfDay

func (d Date) EndOfDay() time.Time

EndOfDay is the last millisecond of the date in Belgrade.

func (Date) Weekday

func (d Date) Weekday() time.Weekday

Weekday is d's day of the week.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL