metering

Time and the calendar

Why a German day is 23, 24 or 25 hours, why the Gastag starts at 06:00, and the one API — DayBoundary to Period — that answers both.

German metering periods are local calendar periods. Instants are jiff::Timestamp, dates jiff::civil::Date, elapsed time jiff::SignedDuration; Europe/Berlin is compiled in from the IANA database jiff-tzdb bundles, so every machine gives the same answer.

DayLengthQuarter-hours
ordinary24 h96
last Sunday in March (spring forward)23 h92
last Sunday in October (fall back)25 h100

A fixed 96 raises a false alarm every spring and hides a four-slot gap every autumn.

One API: DayBoundary → Period

A DayBoundary — Strom at 00:00 local, Gas at 06:00 — names a day, month or year as a half-open UTC Period. Years 1900 to 9998; outside them every constructor answers None.

use jiff::civil::date;
use metering::{DayBoundary, Resolution};
use metering::time::calendar::DayKind;

let spring = DayBoundary::Strom.day(date(2026, 3, 29)).unwrap();
assert_eq!(spring.count(Resolution::QUARTER_HOUR), Some(92));
assert_eq!(spring.kind(), DayKind::ShortDay);

// March 2026 holds 2 972 quarter-hours, not 31 × 96 = 2 976.
let march = DayBoundary::Strom.month(2026, 3).unwrap();
assert_eq!(march.count(Resolution::QUARTER_HOUR), Some(2_972));

// A German day starts at 23:00 UTC in winter and 22:00 UTC in summer.
assert_eq!(DayBoundary::Strom.day(date(2026, 1, 15)).unwrap().start().to_string(), "2026-01-14T23:00:00Z");
assert_eq!(DayBoundary::Strom.day(date(2026, 7, 15)).unwrap().start().to_string(), "2026-07-14T22:00:00Z");

// The repeated autumn hour starts at the transition instant.
let autumn = DayBoundary::Strom.day(date(2026, 10, 25)).unwrap();
assert_eq!(autumn.transition().unwrap().to_string(), "2026-10-25T01:00:00Z");

Resolution::fixed_seconds() is None for Day, Month and Year; count with Period::count.

The slots of a period

Period::intervals tiles a period into the buckets of a resolution, in order — the slots a series has over it. Build intervals from it instead of adding 15 minutes × i to a start, which is right on 363 days a year:

use metering::prelude::*;

let autumn = DayBoundary::Strom.day(date(2026, 10, 25)).unwrap();
let slots = autumn
    .intervals(Resolution::QUARTER_HOUR)
    .map(|slot| MeterInterval::quarter_hour(slot.start(), dec!(0.25), QualityFlag::Measured))
    .collect::<Result<Vec<_>, _>>()?;
assert_eq!(slots.len(), 100);

let series = Series::new(Resolution::QUARTER_HOUR, DayBoundary::Strom, slots)?;
assert_eq!(aggregate(&series, autumn)?.arbeitsmenge, dec!(25));
# Ok::<(), Box<dyn std::error::Error>>(())

A Period's ends are plain jiff::Timestamps, so it passes to any other crate on jiff 1 as it is.

The Gastag

The Gastag runs 06:00 local to 06:00 (GaBi Gas, Art. 3 Nr. 6 VO (EU) 312/2014), and the gas month with it — Allgemeine Festlegungen 6.1d, Kap. 3.1: "in der Sparte Gas ist damit der Zeitraum vom 01.06.2021 06:00 Uhr bis 01.07.2021 06:00 Uhr gesetzlicher deutscher Zeit abgedeckt". The 23- or 25-hour Gastag is the one named after the Saturday (SLP-Gas Leitfaden: "Daher ist die Zeitumstellung in den Werten für den Samstag vor der Umstellung zu berücksichtigen.").

use jiff::civil::date;
use metering::DayBoundary;

assert_eq!(DayBoundary::Gas.day(date(2026, 1, 15)).unwrap().start().to_string(), "2026-01-15T05:00:00Z");
assert_eq!(DayBoundary::Gas.day(date(2026, 10, 24)).unwrap().duration().as_hours(), 25);

// 05:30 local on 15 July still belongs to the Gastag of the 14th.
assert_eq!(DayBoundary::Gas.day_of("2026-07-15T03:30Z".parse()?), Some(date(2026, 7, 14)));
# Ok::<(), Box<dyn std::error::Error>>(())

A Series carries its boundary; resampling, validation and substitution use it.

Which day an instant belongs to

Not instant.date() — that is the UTC day. Ask the boundary:

use jiff::{Timestamp, civil::date};
use metering::{DayBoundary, Resolution};
use metering::time::calendar;

// 23:30 UTC on 14 July is already 01:30 on 15 July in Berlin.
assert_eq!(DayBoundary::Strom.day_of("2026-07-14T23:30Z".parse()?), Some(date(2026, 7, 15)));

// The quarter-hour containing an instant, laid out from the local day start.
let slot = DayBoundary::Strom.bucket("2026-06-01T12:07Z".parse()?, Resolution::QUARTER_HOUR).unwrap();
assert_eq!(slot.start().to_string(), "2026-06-01T12:00:00Z");

// "One week earlier, same local time" is 169 hours across the autumn change.
let t: Timestamp = "2026-10-28T11:00Z".parse()?;
let back = calendar::shift_back_days(t, 7).unwrap();
assert_eq!((t - back).as_hours(), 169);
# Ok::<(), Box<dyn std::error::Error>>(())

Berlin wall-clock time and instants convert both ways. A local time that occurs twice resolves to the earlier instant; one the spring change skips is pushed forward by the gap:

use jiff::civil::date;
use metering::time::calendar::{from_berlin, to_berlin};

let twice = from_berlin(date(2026, 10, 25).at(2, 30, 0, 0)).unwrap();
assert_eq!(twice.to_string(), "2026-10-25T00:30:00Z"); // the CEST pass
let skipped = from_berlin(date(2026, 3, 29).at(2, 30, 0, 0)).unwrap();
assert_eq!(to_berlin(skipped).time(), jiff::civil::time(3, 30, 0, 0));

Holidays are Land law

A delivery point's holiday calendar is its Land's; every holiday rule carries the years it is valid in.

use metering::slp::strom::SlpDayType;
use metering::time::holiday::{Bundesland, Holiday, SlpCalendar};
use jiff::civil::date;

// Fronleichnam 2026: a holiday in Bavaria, an ordinary Thursday in Berlin.
let fronleichnam = date(2026, 6, 4);
assert_eq!(Bundesland::By.holiday(fronleichnam), Some(Holiday::Fronleichnam));
assert_eq!(SlpCalendar::new(Bundesland::By).day_type(fronleichnam), SlpDayType::SonnFeiertag);
assert_eq!(SlpCalendar::new(Bundesland::Be).day_type(fronleichnam), SlpDayType::Werktag);

// Frauentag is a Berlin holiday from 2019, not before.
assert!(Bundesland::Be.is_holiday(date(2019, 3, 8)));
assert!(!Bundesland::Be.is_holiday(date(2018, 3, 8)));

Holidays below Land level (Fronleichnam in parts of Sachsen and Thüringen, Mariä Himmelfahrt in Catholic municipalities of Bayern) are not modelled; supply your own day type. This is not a Fristenkalender.

Leap seconds

Allgemeine Festlegungen 6.1d Kap. 3.9 permits 23:59:60. A jiff::Timestamp has no such second, and jiff's parser clamps it to 23:59:59 — one second early and indistinguishable from the real one. The crate's serde wire refuses a leap second instead; if you parse EDIFACT yourself, decide what a leap second means before you build a Timestamp.