romcal 4.0.0-beta.6

Core Rust library for calculating Catholic liturgical dates and calendars
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
# Romcal

A Rust library for calculating Catholic liturgical dates and generating liturgical calendars.

For command-line usage, see the [CLI documentation](../cli/README.md).

## Installation

Add to your `Cargo.toml`:

```toml
[dependencies]
romcal = "4.0"
```

## Quick Start

```rust
use romcal::Romcal;

fn main() -> romcal::RomcalResult<()> {
    // Create a default configuration
    let romcal = Romcal::default();

    // Get a specific liturgical date
    let easter = romcal.get_date("easter_sunday", 2026)?;
    println!("Easter 2026: {}", easter);  // 2026-04-05

    // Generate the liturgical calendar for year 2026
    let calendar = romcal.generate_liturgical_calendar(2026)?;

    // Access a specific date
    if let Some(days) = calendar.get("2025-12-25") {
        for day in days {
            println!("{}: {}", day.date, day.fullname);
        }
    }

    Ok(())
}
```

## Configuration

### Using Preset

`Preset` is a configuration builder with optional fields. Use `Romcal::new(preset)` to create an instance:

```rust
use romcal::{Preset, Romcal, CalendarContext, EasterCalculationType};

let preset = Preset {
    calendar: Some("france".to_string()),
    locale: Some("fr".to_string()),
    context: Some(CalendarContext::Liturgical),
    epiphany_on_sunday: Some(true),
    ascension_on_sunday: Some(true),
    corpus_christi_on_sunday: Some(true),
    ..Preset::default()
};

let romcal = Romcal::new(preset);
```

### Configuration Options

| Option                     | Type                    | Default           | Description                                              |
| -------------------------- | ----------------------- | ----------------- | -------------------------------------------------------- |
| `calendar`                 | `String`                | `"general_roman"` | Calendar ID (e.g., `"france"`, `"united_states"`)        |
| `locale`                   | `String`                | `"en"`            | Locale code (e.g., `"fr"`, `"es"`)                       |
| `context`                  | `CalendarContext`       | `Gregorian`       | `Gregorian` (Jan-Dec) or `Liturgical` (Advent to Advent) |
| `epiphany_on_sunday`       | `bool`                  | `false`           | Celebrate Epiphany on Sunday (Jan 2-8) instead of Jan 6  |
| `ascension_on_sunday`      | `bool`                  | `false`           | Celebrate Ascension on Sunday instead of Thursday        |
| `corpus_christi_on_sunday` | `bool`                  | `true`            | Celebrate Corpus Christi on Sunday instead of Thursday   |
| `easter_calculation_type`  | `EasterCalculationType` | `Gregorian`       | `Gregorian` or `Julian` Easter calculation               |
| `ordinal_format`           | `OrdinalFormat`         | `Numeric`         | `Numeric` ("1st") or `Letters` ("first")                 |

### Available Calendars and Locales

```rust
use romcal::{CALENDAR_IDS, LOCALE_CODES};

// List all available calendar IDs
for id in CALENDAR_IDS {
    println!("{}", id);
}

// List all available locale codes
for code in LOCALE_CODES {
    println!("{}", code);
}
```

### Loading Calendar Data

For calendar generation, you need to load calendar definitions and resources:

```rust
use romcal::{Preset, Romcal};

// Load from JSON files or embedded data
let calendar_definitions = load_calendar_definitions(); // Your loading logic
let resources = load_resources();                       // Your loading logic

let preset = Preset {
    calendar: Some("france".to_string()),
    locale: Some("fr".to_string()),
    calendar_definitions: Some(calendar_definitions),
    resources: Some(resources),
    ..Preset::default()
};

let romcal = Romcal::new(preset);
```

## Getting a Liturgical Date by ID

The `get_date` method calculates a liturgical date by its ID:

```rust
use romcal::Romcal;

let romcal = Romcal::default();

// Easter-related dates
let easter = romcal.get_date("easter_sunday", 2026)?;       // 2026-04-05
let ash_wed = romcal.get_date("ash_wednesday", 2026)?;      // 2026-02-18
let pentecost = romcal.get_date("pentecost_sunday", 2026)?; // 2026-05-24

// Fixed feasts
let christmas = romcal.get_date("christmas", 2026)?;        // 2026-12-25
let all_saints = romcal.get_date("all_saints", 2026)?;      // 2026-11-01

// Any date from the calendar
let monday = romcal.get_date("ordinary_time_5_monday", 2026)?;
```

Any date ID from the liturgical calendar can be used (e.g., `easter_sunday`, `christmas`, `ordinary_time_5_monday`).

## Generating a Liturgical Calendar

Generate a complete liturgical calendar with all celebrations:

```rust
use romcal::Romcal;

let romcal = Romcal::default();

// Year parameter is the liturgical year end (2026 = liturgical year 2025-2026)
let calendar = romcal.generate_liturgical_calendar(2026)?;

// calendar is BTreeMap<String, Vec<LiturgicalDay>>
// Keys are dates in "YYYY-MM-DD" format
for (date, days) in &calendar {
    for day in days {
        println!("{}: {} ({:?})", date, day.fullname, day.rank);
    }
}
```

### LiturgicalDay Structure

Each `LiturgicalDay` contains:

| Field                       | Type               | Description                             |
| --------------------------- | ------------------ | --------------------------------------- |
| `id`                        | `String`           | Unique identifier                       |
| `fullname`                  | `String`           | Localized display name                  |
| `date`                      | `String`           | Date in YYYY-MM-DD format               |
| `precedence`                | `Precedence`       | Liturgical precedence level             |
| `rank`                      | `Rank`             | Rank (Solemnity, Feast, Memorial, etc.) |
| `rank_name`                 | `String`           | Localized rank name                     |
| `season`                    | `Option<Season>`   | Liturgical season                       |
| `season_name`               | `Option<String>`   | Localized season name                   |
| `colors`                    | `Vec<ColorInfo>`   | Liturgical colors                       |
| `entities`                  | `Vec<Entity>`      | Saints, Blessed, or Places              |
| `sunday_cycle`              | `SundayCycle`      | Year A, B, or C                         |
| `weekday_cycle`             | `WeekdayCycle`     | Year 1 or 2                             |
| `psalter_week`              | `PsalterWeekCycle` | Week 1-4                                |
| `is_holy_day_of_obligation` | `bool`             | Holy day of obligation                  |
| `is_optional`               | `bool`             | Optional celebration                    |

## Generating a Mass-Centric Calendar

The mass-centric calendar organizes by civil date and mass time, useful for scheduling:

```rust
use romcal::Romcal;

let romcal = Romcal::default();
let mass_calendar = romcal.generate_mass_calendar(2026)?;

// mass_calendar is BTreeMap<String, Vec<MassContext>>
// Keys are civil dates (not liturgical dates)
for (civil_date, masses) in &mass_calendar {
    for mass in masses {
        println!("{} - {:?}: {} (liturgical: {})",
            mass.civil_date,
            mass.mass_time,
            mass.fullname,
            mass.liturgical_date
        );
    }
}
```

### Key Difference from Liturgical Calendar

Evening masses appear on the **previous civil day**:

- Easter Vigil (April 19) has `civil_date: "2025-04-19"` but `liturgical_date: "2025-04-20"`
- Christmas Vigil Mass has `civil_date: "2025-12-24"` but `liturgical_date: "2025-12-25"`

### MassContext Structure

Each `MassContext` is a flat structure containing:

| Field                   | Type                      | Description                                   |
| ----------------------- | ------------------------- | --------------------------------------------- |
| `mass_time`             | `MassTime`                | Type of mass (DayMass, EasterVigil, etc.)     |
| `mass_time_name`        | `String`                  | Localized mass time name                      |
| `civil_date`            | `String`                  | Calendar date (YYYY-MM-DD)                    |
| `liturgical_date`       | `String`                  | Theological celebration date                  |
| `id`                    | `String`                  | Unique identifier                             |
| `fullname`              | `String`                  | Localized display name                        |
| `precedence`            | `Precedence`              | Liturgical precedence level                   |
| `rank`                  | `Rank`                    | Liturgical rank                               |
| `rank_name`             | `String`                  | Localized rank name                           |
| `season`                | `Option<Season>`          | Liturgical season                             |
| `season_name`           | `Option<String>`          | Localized season name                         |
| `colors`                | `Vec<ColorInfo>`          | Liturgical colors                             |
| `entities`              | `Vec<Entity>`             | Saints, Blessed, or Places                    |
| `sunday_cycle`          | `SundayCycle`             | Year A, B, or C                               |
| `weekday_cycle`         | `WeekdayCycle`            | Year 1 or 2                                   |
| `psalter_week`          | `PsalterWeekCycle`        | Week 1-4                                      |
| `periods`               | `Vec<PeriodInfo>`         | Liturgical periods                            |
| `week_of_season`        | `Option<u32>`             | Week number within the season                 |
| `day_of_season`         | `Option<u32>`             | Day number within the season                  |
| `optional_celebrations` | `Vec<CelebrationSummary>` | Alternative celebrations (optional memorials) |

## Creating an Optimized Bundle

Generate a minimal JSON bundle for deployment (useful for web/mobile apps):

```rust
use romcal::{Preset, Romcal};

let preset = Preset {
    calendar: Some("france".to_string()),
    locale: Some("fr".to_string()),
    calendar_definitions: Some(all_definitions),
    resources: Some(all_resources),
    ..Preset::default()
};

let romcal = Romcal::new(preset);
let json_bundle = romcal.optimize()?;

// json_bundle contains only:
// - Target calendar and its parent calendars
// - Target locale and parent locales
// - Entities actually used in the calendar
```

## Key Types

### Seasons

The liturgical year is divided into five seasons:

| Season          | Period                                          |
| --------------- | ----------------------------------------------- |
| `Advent`        | Four weeks before Christmas                     |
| `ChristmasTime` | Christmas to Baptism of the Lord                |
| `Lent`          | Ash Wednesday to Holy Thursday                  |
| `EasterTime`    | Easter Sunday to Pentecost (50 days)            |
| `OrdinaryTime`  | Two periods: after Epiphany and after Pentecost |

### Ranks

Celebrations are classified by rank, from highest to lowest (GNLY #11-16):

| Rank               | Description                                                                          |
| ------------------ | ------------------------------------------------------------------------------------ |
| `Solemnity`        | Most important days; begins at First Vespers on the preceding day                    |
| `Sunday`           | The Lord's Day; the primordial feast day celebrating the Paschal Mystery             |
| `Feast`            | Celebrated within the natural day; no First Vespers (except Lord's feasts on Sunday) |
| `Memorial`         | Obligatory commemoration; becomes optional during Lent and Advent privileged days    |
| `OptionalMemorial` | Non-obligatory commemoration; only one may be chosen if multiple fall on same day    |
| `Weekday`          | Ordinary weekdays; some (Ash Wednesday, Holy Week, Dec 17-24) take precedence        |

### Precedence

Precedence levels are essential for determining which celebration takes priority when multiple celebrations fall on the same day. Romcal implements the 13 levels defined in the _General Norms for the Liturgical Year and the Calendar_ (GNLY #49):

| Level | Description                                                                                                      |
| ----- | ---------------------------------------------------------------------------------------------------------------- |
| 1     | Paschal Triduum                                                                                                  |
| 2     | Nativity, Epiphany, Ascension, Pentecost; Sundays of Advent/Lent/Easter; Ash Wednesday; Holy Week; Easter Octave |
| 3     | Solemnities in the General Calendar; All Souls                                                                   |
| 4     | Proper Solemnities (patron, dedication, title, founder)                                                          |
| 5     | Feasts of the Lord in the General Calendar                                                                       |
| 6     | Sundays of Christmas Time and Ordinary Time                                                                      |
| 7     | Feasts of Mary and Saints in the General Calendar                                                                |
| 8     | Proper Feasts (diocese, region, religious order)                                                                 |
| 9     | Privileged weekdays (Advent Dec 17-24, Lent)                                                                     |
| 10    | Obligatory Memorials in the General Calendar                                                                     |
| 11    | Proper Obligatory Memorials                                                                                      |
| 12    | Optional Memorials                                                                                               |
| 13    | Weekdays                                                                                                         |

### Liturgical Colors

Colors are automatically computed based on the season and celebration. For memorials of martyrs, red is automatically applied.

| Color    | Usage                                                             |
| -------- | ----------------------------------------------------------------- |
| `White`  | Christmas, Easter, feasts of the Lord, Mary, Saints (non-martyrs) |
| `Red`    | Martyrs, Pentecost, Palm Sunday, Good Friday                      |
| `Purple` | Advent, Lent                                                      |
| `Green`  | Ordinary Time                                                     |
| `Rose`   | Gaudete Sunday (3rd Advent), Laetare Sunday (4th Lent)            |
| `Gold`   | Solemn celebrations (alternative to white)                        |
| `Black`  | Funerals, All Souls (optional)                                    |

### Liturgical Periods

Periods are sub-divisions within liturgical seasons, traditionally used in monastic and religious communities. They help determine specific elements such as the antiphon to the Blessed Virgin Mary (Alma Redemptoris Mater, Ave Regina Caelorum, Regina Caeli, Salve Regina).

| Period                                | Description                                    |
| ------------------------------------- | ---------------------------------------------- |
| `ChristmasOctave`                     | December 25 to January 1                       |
| `DaysBeforeEpiphany`                  | January 2 to the day before Epiphany           |
| `DaysFromEpiphany`                    | Epiphany to the day before the Presentation    |
| `ChristmasToPresentationOfTheLord`    | Christmas to Presentation (Feb 2)              |
| `PresentationOfTheLordToHolyThursday` | Presentation to Holy Thursday                  |
| `HolyWeek`                            | Palm Sunday to Holy Saturday                   |
| `PaschalTriduum`                      | Holy Thursday evening to Easter Sunday Vespers |
| `EasterOctave`                        | Easter Sunday to the following Sunday          |
| `EarlyOrdinaryTime`                   | After Presentation to Ash Wednesday            |
| `LateOrdinaryTime`                    | After Pentecost to first Sunday of Advent      |

### Cycles

Cycles determine which readings and psalms are used in the liturgy.

**Sunday Cycle** (`SundayCycle`): A three-year cycle for Sunday and solemnity readings.

| Cycle   | Years (examples)    | Gospel focus |
| ------- | ------------------- | ------------ |
| `YearA` | 2023, 2026, 2029... | Matthew      |
| `YearB` | 2024, 2027, 2030... | Mark         |
| `YearC` | 2025, 2028, 2031... | Luke         |

**Weekday Cycle** (`WeekdayCycle`): A two-year cycle for weekday readings (first reading only; Gospel follows its own sequence).

| Cycle    | Years (examples)                 |
| -------- | -------------------------------- |
| `Year_1` | Odd years (2025, 2027, 2029...)  |
| `Year_2` | Even years (2024, 2026, 2028...) |

**Psalter Week** (`PsalterWeekCycle`): A four-week cycle for the Liturgy of the Hours (Divine Office).

| Cycle    | Usage                              |
| -------- | ---------------------------------- |
| `Week_1` | Week 1 of the psalter              |
| `Week_2` | Week 2 of the psalter              |
| `Week_3` | Week 3 of the psalter              |
| `Week_4` | Week 4 of the psalter, then repeat |

### Mass Times

`MassTime` variants:

| Variant                       | Description                                               |
| ----------------------------- | --------------------------------------------------------- |
| `EasterVigil`                 | Easter Vigil on Holy Saturday night                       |
| `PreviousEveningMass`         | Mass the evening before a major feast                     |
| `NightMass`                   | Night Mass of the Nativity of the Lord (Christmas)        |
| `MassAtDawn`                  | Mass at Dawn of the Nativity of the Lord (Christmas)      |
| `MorningMass`                 | Morning Mass on December 24                               |
| `MassOfThePassion`            | Palm Sunday Mass with procession                          |
| `CelebrationOfThePassion`     | Good Friday celebration                                   |
| `DayMass`                     | Regular daytime Mass                                      |
| `ChrismMass`                  | Chrism Mass (typically Tuesday or Wednesday of Holy Week) |
| `EveningMassOfTheLordsSupper` | Holy Thursday evening                                     |

## Error Handling

All fallible operations return `RomcalResult<T>`, which is an alias for `Result<T, RomcalError>`.

```rust
use romcal::{Romcal, RomcalResult, RomcalError};

fn generate_calendar() -> RomcalResult<()> {
    let romcal = Romcal::default();

    // This will fail: year must be >= 1583 (Gregorian calendar adoption)
    match romcal.generate_liturgical_calendar(1500) {
        Ok(calendar) => { /* use calendar */ }
        Err(RomcalError::InvalidYear(year, min_year)) => {
            eprintln!("Invalid year: {} (min: {})", year, min_year);
        }
        Err(e) => {
            eprintln!("Error: {}", e);
        }
    }

    Ok(())
}
```

### Error Types

| Error                     | Description                           |
| ------------------------- | ------------------------------------- |
| `InvalidYear(i32, i32)`   | Year is before min_year or after 9999 |
| `InvalidDate`             | Invalid date encountered              |
| `CalculationError`        | Error during liturgical calculations  |
| `InvalidConfig`           | Invalid configuration provided        |
| `DateConversionError`     | Error converting between date formats |
| `ValidationError(String)` | Validation failed with message        |
| `InvalidDateName(String)` | Unknown date ID passed to `get_date`  |

## Development

```bash
# Run tests
cargo test -p romcal

# Run quality checks
./scripts/check-core.sh

# Build release
cargo build -p romcal --release
```

## Related

- [romcal]https://github.com/romcal/romcal - Main Romcal project
- [romcal-cli]../cli/ - Command-line interface
- [romcal (TypeScript)]../bindings/typescript/ - TypeScript/JavaScript binding
- [romcal (Python)]../bindings/python/ - Python binding

## License

Apache License 2.0. See [LICENSE](../LICENSE) for details.