# Demurrage Across a Weekend

Industry: Intermodal

### Demurrage Across a Weekend

Discharged Friday 15:00 with three free calendar days, the container gates out on Monday morning. How many days of demurrage are due, and for which dates?

The usual approach:
```js
// The naive approach: elapsed hours beyond the free time, rounded up
const discharged = new Date("2024-12-20T13:00:00Z");
const gatedOut = new Date("2024-12-22T22:00:01Z");
const hours = (gatedOut.getTime() - discharged.getTime()) / 36e5; // 57.0003
const chargeable = Math.max(0, Math.ceil((hours - 72) / 24));
// 0 — but free time ended at Monday 00:00, and the box left one second into Monday
```

Free time ended at 00:00 on Monday, the start of the local day after the last free day. The dwell is half-open, so a gate-out at exactly that instant is not a chargeable day, and a gate-out one second later is one: Monday 23 December, which \`chargedDates\` lists, so the count can be checked date by date (the dates an itemised invoice can list). The weekend was consumed on the calendar basis whether or not the terminal was open. \`freeDaysUsed\` plus \`chargeableDays\` is exactly \`dwellTime\`'s \`calendarDays\` for the same dwell.

With GMT:
```js
import { chargeableDays } from "@northguild/gmt/intermodal";

const tariff = { basis: "calendar", chargeBasis: "calendar", timeZone: "Africa/Johannesburg", firstDay: "eventDay" };

chargeableDays("2024-12-20T13:00:00Z", "2024-12-22T22:00:00Z", 3, tariff);
// { freeDaysUsed: 3, chargeableDays: 0, expiresAt: "2024-12-22T22:00:00Z",
//   chargedDates: [], byTier: [{ from: 1, to: null, days: 0 }] }

chargeableDays("2024-12-20T13:00:00Z", "2024-12-22T22:00:01Z", 3, tariff);
// { freeDaysUsed: 3, chargeableDays: 1, expiresAt: "2024-12-22T22:00:00Z",
//   chargedDates: ["2024-12-23"], byTier: [{ from: 1, to: null, days: 1 }] }

// Twelve chargeable days in bands of five, five and the rest.
chargeableDays("2024-12-20T13:00:00Z", "2025-01-03T13:00:00Z", 3, { ...tariff, tiers: [5, 10] });
// { freeDaysUsed: 3, chargeableDays: 12, expiresAt: "2024-12-22T22:00:00Z",
//   chargedDates: ["2024-12-23", "2024-12-24", "2024-12-25", "2024-12-26", "2024-12-27",
//                  "2024-12-28", "2024-12-29", "2024-12-30", "2024-12-31", "2025-01-01",
//                  "2025-01-02", "2025-01-03"],
//   byTier: [{ from: 1, to: 5, days: 5 }, { from: 6, to: 10, days: 5 }, { from: 11, to: null, days: 2 }] }
```

Change `firstDay` to `"nextDay"` above and the Monday-morning gate-out is still free, because
free time then ends on Tuesday. Change `basis` to `"working"`, add
`calendar: { weekend: [6, 7], holidays: ["2024-12-25"], timeZone: "Africa/Johannesburg" }` and gate
out at `2024-12-30T13:00:00Z`: the free days are Friday, Monday and Tuesday, and free time ends
as Christmas Day begins. With `chargeBasis: "calendar"`, the most common shape where free time is in
working days, all six days from the 25th to the 30th are charged, holiday and weekend included.
Change `chargeBasis` to `"working"`, as some tariffs do, and only the 26th, 27th and 30th are. To
drag the gate-out across the expiry yourself, open it in the [Free Time
Ledger](/gmt/tools/free-time-ledger/?w=freetime&wa=%7B%22clockStart%22%3A%222024-12-20T13%3A00%3A00Z%22%2C%22clockEnd%22%3A%222024-12-22T22%3A00%3A00Z%22%2C%22freeDays%22%3A%223%22%2C%22firstDay%22%3A%22eventDay%22%2C%22basis%22%3A%22calendar%22%2C%22chargeBasis%22%3A%22calendar%22%2C%22zone%22%3A%22Africa%2FJohannesburg%22%7D).
The full rules are in [Intermodal: Free Time and
Demurrage](/gmt/guides/industries/intermodal-free-time-and-demurrage/).
