Merge pull request #68 from mwlaboratories/calendar-event-end

Calendar: include the end of each event, and list ongoing multi-day events under today
This commit is contained in:
James Babcock authored and GitHub committed 2026-11-18 20:53:00 -08:00
commit 25cb255be2
8 files changed
+211 -30

No files matched your search

+47
View File
@@ -0,0 +1,47 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const fs = require('node:fs');
const path = require('node:path');
const vm = require('node:vm');
const ts = require('typescript');
// Local-time day arithmetic: pin the zone so the expectations hold on any machine.
process.env.TZ = 'Europe/Brussels';
function load(file) {
const sandbox = { exports: {}, require: id => { throw new Error(`Unstubbed import: ${id}`); } };
vm.runInNewContext(ts.transpileModule(fs.readFileSync(path.join(__dirname, '..', file), 'utf8'), {
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 },
}).outputText, sandbox);
return sandbox.exports;
}
const { listingDayMs, spansDays, spanLabel } = load('app/apps/calendar/event-days.ts');
const local = (y, m, d, h = 0, min = 0) => new Date(y, m - 1, d, h, min).getTime();
// Mon Nov 16 – Wed Nov 18, all day, as the provider stores it (end = midnight after the last day).
const threeDays = { startMs: local(2026, 11, 16), endMs: local(2026, 11, 19), allDay: true };
test('an all-day event still going is listed under today, not its first day', () => {
assert.equal(listingDayMs(threeDays, local(2026, 11, 18, 0, 24)), local(2026, 11, 18));
assert.equal(listingDayMs(threeDays, local(2026, 11, 17, 9)), local(2026, 11, 17));
});
test('events that have not started are listed under their start day', () => {
assert.equal(listingDayMs(threeDays, local(2026, 11, 14, 12)), local(2026, 11, 16));
const meeting = { startMs: local(2026, 11, 19, 9), endMs: local(2026, 11, 19, 12), allDay: false };
assert.equal(listingDayMs(meeting, local(2026, 11, 18, 0, 24)), local(2026, 11, 19));
});
test('a timed event running past midnight is listed under today the next morning', () => {
const lateShift = { startMs: local(2026, 11, 17, 22), endMs: local(2026, 11, 18, 2), allDay: false };
assert.equal(listingDayMs(lateShift, local(2026, 11, 18, 0, 30)), local(2026, 11, 18));
assert.equal(spansDays(lateShift), true);
});
test('only events covering more than one day get a span, and it reads naturally', () => {
assert.equal(spansDays(threeDays), true);
assert.equal(spanLabel(threeDays), 'Mon 16 – Wed 18 Nov');
assert.equal(spansDays({ startMs: local(2026, 11, 16), endMs: local(2026, 11, 17), allDay: true }), false);
assert.equal(spansDays({ startMs: local(2026, 11, 19, 9), endMs: local(2026, 11, 19, 12), allDay: false }), false);
assert.equal(spanLabel({ startMs: local(2026, 11, 30), endMs: local(2026, 12, 2), allDay: true }), 'Mon 30 Nov – Tue 1 Dec');
});
+45
View File
@@ -0,0 +1,45 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const fs = require('node:fs');
const path = require('node:path');
const vm = require('node:vm');
const ts = require('typescript');
// Local-time formatting: pin the zone so the expectations hold on any machine.
process.env.TZ = 'Europe/Brussels';
function load(file) {
const sandbox = { exports: {}, require: id => { throw new Error(`Unstubbed import: ${id}`); } };
vm.runInNewContext(ts.transpileModule(fs.readFileSync(path.join(__dirname, '..', file), 'utf8'), {
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 },
}).outputText, sandbox);
return sandbox.exports;
}
const { formatEvent, formatEventSpan } = load('app/assistant/date-format.ts');
const local = (y, m, d, h = 0, min = 0) => new Date(y, m - 1, d, h, min).getTime();
test('a multi-day all-day event names its last day (all-day ends are exclusive)', () => {
// Mon Nov 16 – Wed Nov 18, as the calendar provider stores it: end = midnight after the last day.
const span = formatEventSpan({ startMs: local(2026, 11, 16), endMs: local(2026, 11, 19), allDay: true });
assert.equal(span, 'Mon Nov 16 – Wed Nov 18 (all day)');
});
test('a one-day all-day event stays a single date', () => {
assert.equal(formatEventSpan({ startMs: local(2026, 11, 16), endMs: local(2026, 11, 17), allDay: true }), 'Mon Nov 16 (all day)');
});
test('a timed event shows its end time, and the end date when it crosses midnight', () => {
assert.equal(formatEventSpan({ startMs: local(2026, 11, 19, 9), endMs: local(2026, 11, 19, 12), allDay: false }), 'Thu Nov 19, 9:00 AM – 12:00 PM');
assert.equal(formatEventSpan({ startMs: local(2026, 11, 19, 22), endMs: local(2026, 11, 20, 2), allDay: false }), 'Thu Nov 19, 10:00 PM – Fri Nov 20, 2:00 AM');
});
test('a timed event without a usable end keeps the old start-only form', () => {
assert.equal(formatEventSpan({ startMs: local(2026, 11, 19, 9), endMs: local(2026, 11, 19, 9), allDay: false }), 'Thu Nov 19, 9:00 AM');
});
test('formatEvent keeps the title and location around the span', () => {
const line = formatEvent({ title: 'Office', startMs: local(2026, 11, 16), endMs: local(2026, 11, 19), allDay: true, location: 'HQ' });
assert.equal(line, '- Office — Mon Nov 16 – Wed Nov 18 (all day) @ HQ');
assert.equal(formatEvent({ title: '', startMs: local(2026, 11, 16), endMs: local(2026, 11, 17), allDay: true, location: '' }), '- (untitled) — Mon Nov 16 (all day)');
});
+2 -1
View File
@@ -163,7 +163,7 @@ function screenFixture() {
'util/numeric-util': { clamp: (n, min, max) => Math.max(min, Math.min(max, n)) },
};
const modules = depth => Object.fromEntries(Object.entries(common).map(([key, value]) => [depth + key, value]));
const calendar = load('app/apps/calendar/calendar.ts', modules('../../'));
const calendar = load('app/apps/calendar/calendar.ts', { ...modules('../../'), './event-days': load('app/apps/calendar/event-days.ts') });
const widget = load('app/apps/glanceboard/widgets/calendar-widget.ts', {
...modules('../../../'), '../../calendar/calendar': calendar,
'../glance-font': { glanceFont: { small: () => font, medium: () => font } },
@@ -243,6 +243,7 @@ test('iOS assistant calendar tool awaits events, reports denied access and failu
'../native/media-controller': { mediaControllerBridge: { start: async () => {} } },
'../native/spotify': { spotifyService: () => null },
'../native/notification-icons': {}, '../ui/shell/shell': {}, './tool-registry': {},
'./date-format': load('app/assistant/date-format.ts'),
}, { global: { isIOS: true } });
registerSystemTools({ registerSystemTool: (definition, handler) => registered.set(definition.name, handler) });
assert.deepEqual([...registered.keys()], ['glasses.get_state', 'glasses.show_alert', 'calendar.list_events',
+1
View File
@@ -511,6 +511,7 @@ test('the assistant offers Spotify search-and-play once signed in and refreshes
snapshot: () => ({ accessEnabled: true, playbackState: 'playing', title: 'Song', artist: 'Band', appName: 'Spotify' }) } },
'../native/spotify': { spotifyService: () => spotify },
'../native/notification-icons': {}, '../ui/shell/shell': {}, './tool-registry': {},
'./date-format': load('app/assistant/date-format.ts'),
}, { global: { isIOS: true } });
registerSystemTools({
registerSystemTool: (definition, handler) => systemTools.set(definition.name, handler),