aboutsummaryrefslogtreecommitdiff
path: root/internal/caldata/caldata.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/caldata/caldata.go')
-rw-r--r--internal/caldata/caldata.go37
1 files changed, 29 insertions, 8 deletions
diff --git a/internal/caldata/caldata.go b/internal/caldata/caldata.go
index 9272fbb..14b3985 100644
--- a/internal/caldata/caldata.go
+++ b/internal/caldata/caldata.go
@@ -16,8 +16,11 @@ import (
//go:embed roman-calendar.ini
var romanCalendar []byte
-// Universal parses the embedded universal calendar. It panics on a malformed
-// embedded file (a build-time bug caught by tests), never at the request layer.
+//go:embed tridentine-calendar.ini
+var tridentineCalendar []byte
+
+// Universal parses the embedded Ordinary Form universal calendar. It panics on a
+// malformed embedded file (a build-time bug caught by tests).
func Universal() calendar.Layer {
l, err := ParseLayer(romanCalendar)
if err != nil {
@@ -26,6 +29,24 @@ func Universal() calendar.Layer {
return l
}
+// Tridentine parses the embedded Extraordinary Form (1962) universal calendar.
+func Tridentine() calendar.Layer {
+ l, err := ParseLayer(tridentineCalendar)
+ if err != nil {
+ panic(fmt.Sprintf("caldata: embedded tridentine-calendar.ini invalid: %v", err))
+ }
+ return l
+}
+
+// Base returns the universal base layer for a form: the 1962 calendar for
+// "old" (EF), the General Roman Calendar otherwise (OF).
+func Base(form string) calendar.Layer {
+ if form == "old" {
+ return Tridentine()
+ }
+ return Universal()
+}
+
// LoadLayer reads and parses a user calendar layer file. id (the filename stem)
// is used as the layer's ID when the file's [layer] header omits one.
func LoadLayer(path, id string) (calendar.Layer, error) {
@@ -43,12 +64,12 @@ func LoadLayer(path, id string) (calendar.Layer, error) {
return l, nil
}
-// Stack returns the ordered layer stack for the engine: the universal base
-// first, then each user layer named in use (matched to "<dir>/<id>.ini"), in
-// order. A layer that fails to load is skipped and reported in the error slice
-// so a single bad file never breaks calendar computation.
-func Stack(dir string, use []string) ([]calendar.Layer, []error) {
- layers := []calendar.Layer{Universal()}
+// Stack returns the ordered layer stack for the engine: the form's universal
+// base first, then each user layer named in use (matched to "<dir>/<id>.ini"),
+// in order. A layer that fails to load is skipped and reported in the error
+// slice so a single bad file never breaks calendar computation.
+func Stack(form, dir string, use []string) ([]calendar.Layer, []error) {
+ layers := []calendar.Layer{Base(form)}
var errs []error
for _, id := range use {
l, err := LoadLayer(filepath.Join(dir, id+".ini"), id)