Trending

World technology news

→
Carrying all-day events and timed sessions in the same jCal calendar
Software Engineering · 2014
Software Engineering2014

Carrying all-day events and timed sessions in the same jCal calendar

Try the jCal format from the 2014 RFC 7265 with two sessions and see which fields preserve dates, times and end boundaries in a JSON exchange.

Archive retrospective · Topic year 2014

Developer's JournalPublished: Dec 5, 20266 min read
Reading progress0%
In this article
  1. Two calendar entries with different meanings
  2. The three parts of a component
  3. Run the example on a modern Node runtime
  4. Why the end boundary matters
  5. Named zones and floating local times
  6. Checking a round trip

Two calendar entries with different meanings

Imagine a workshop organizer opening the exhibition area on May 28. The same calendar carries a forty-five-minute presentation in the afternoon. The exhibition belongs to a calendar date. The presentation ties participants in different places to a shared instant. The starting values look similar because both contain May 28, and both entries have an end. The jCal format from RFC 7265, published in 2014, carries the iCalendar property value type explicitly in JSON. A reader can place the exhibition in a day cell and the presentation on a timeline. Preserving that choice during exchange lets the original organizer specify the meaning before any user interface displays the record. An import tool can then retain the semantics even as the organization switches calendar applications.

The three parts of a component

A jCal component uses a three-element array. It holds the component name, the property list and the nested component list. The vcalendar root holds a version and a product identifier. Each of its two vevent children carries a distinct calendar entry. The uid helps a receiver recognize the same event if the calendar travels again. The timestamp records information about the event entry, and dtstart carries the start. Within each property tuple, the name is followed by the parameter object, the type identifier and at least one value. The empty parameter object still occupies its position. The short example reads only properties that appear once in the events it creates. General readers need to preserve repeated properties as well as optional nested alarms, recurrence rules and custom extensions.

Application flowConceptual sketch · summary of the article's technical flow

Run the example on a modern Node runtime

The local exercise creates two entries, serializes the entire calendar as JSON and reads it back. It runs with the current Node runtime and requires no dependencies. The all-day entry carries the date type and the value 2014-05-28. Its upper boundary carries the following date. The scheduled entry carries the date-time type and ends both timestamp values with Z to mark UTC. Assertions confirm that both property types survive and that the scheduled session spans forty-five minutes. The two fictional entries illustrate a wire format standardized in 2014. The demonstration exercises the current runtime, so it provides no compatibility result for a calendar application of that period. Because the calculation compares two UTC instants, the machine's own time zone cannot change the measured interval.

import assert from 'node:assert/strict';

const calendar = ['vcalendar', [
  ['version', {}, 'text', '2.0'],
  ['prodid', {}, 'text', '-//Workshop Desk//jCal Demo//EN'],
], [
  ['vevent', [
    ['uid', {}, 'text', 'open-day@example.test'],
    ['dtstamp', {}, 'date-time', '2014-05-20T08:00:00Z'],
    ['dtstart', {}, 'date', '2014-05-28'],
    ['dtend', {}, 'date', '2014-05-29'],
  ], []],
  ['vevent', [
    ['uid', {}, 'text', 'demo-slot@example.test'],
    ['dtstamp', {}, 'date-time', '2014-05-20T08:00:00Z'],
    ['dtstart', {}, 'date-time', '2014-05-28T12:30:00Z'],
    ['dtend', {}, 'date-time', '2014-05-28T13:15:00Z'],
  ], []],
]];

const decoded = JSON.parse(JSON.stringify(calendar));
const rows = decoded[2].map(([, props]) => {
  const byName = new Map(props.map(([name, ...fields]) => [name, fields]));
  const [, type, start] = byName.get('dtstart');
  const [, endType, end] = byName.get('dtend');
  assert.equal(endType, type);
  return { uid: byName.get('uid')[2], type, start, end };
});

assert.deepEqual(rows.map(row => row.type), ['date', 'date-time']);
assert.equal(rows[0].start, '2014-05-28');
assert.equal(rows[0].end, '2014-05-29');
assert.equal(Date.parse(rows[1].end) - Date.parse(rows[1].start), 45 * 60_000);
console.log(JSON.stringify({ node: process.version, rows, timedMinutes: 45 }, null, 2));

Why the end boundary matters

The day after the exhibition appears because iCalendar specifies an inclusive start and an exclusive end for a VEVENT. An event running from May 28 to May 29 fills only the May 28 cell. Treating both endpoints as inclusive would incorrectly add a second day to the display. Changing the stored end in order to hide the extra cell would break the next export. Keep the original boundary and test the display calculation separately. The evening before the boundary still belongs to the relevant date, and its successor date falls outside the event. The scheduled presentation follows the same rule in time. Another session can begin at exactly 13:15 UTC. Sharing a boundary alone does not put both sessions in progress at once.

Named zones and floating local times

UTC makes the sample comparison simple. An organizer may instead schedule a recurring meeting in Berlin local time. A named zone can be carried in the tzid parameter alongside the local value. Apply the iCalendar zone rules and applicable zone definition when resolving those times, especially around clock changes. A local value without a named zone can also be a floating time. Resolve the intended semantics before applying a UTC assumption. Build a check with clients configured for two different regions. The scheduled entry should continue to refer to the intended instant or local schedule, and the date entry should show the same calendar date in both clients. For a repeating meeting, compare occurrences on both sides of a seasonal clock change. One correctly displayed week may conceal an error that will affect the next instance.

Checking a round trip

Start with sample records when moving a team calendar between clients. Read the identity, value type, boundaries and zone parameters after the first import. Export the calendar again without touching the entries and compare their meaning. JSON whitespace and property order do little to establish whether the event survived. Compare component nesting, parameter values and typed property values. Handle identity and update rules separately when subscribers might receive another version. Pay special attention to a storage layer that forces dates and instants into a single timestamp column. Turning a day into a midnight instant can move it to a previous date when read in another zone. Carrying the value type through each storage and display boundary makes that error easier to diagnose. The same distinction matters when one occurrence of a recurring class moves. The recurrence identifier refers to the originally scheduled instance while DTSTART can carry its new time. A round trip should display the moved occurrence once and preserve the dates of unaffected weeks.

864 reads ✎ Write a comment

Reader discussion

Discussion prompt

How would you measure this development's real-world impact?

No comments yet. Be the first to contribute.

Write a comment

Comments are real visitor contributions. Repeated, link-heavy or abusive submissions may be limited.