Skip to content

Commit

Permalink
Add date-fns library and fix bug in FOSDEM schedule loader
Browse files Browse the repository at this point in the history
  • Loading branch information
reivilibre committed Jan 31, 2025
1 parent c88ef83 commit e111db0
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 20 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,17 @@
},
"dependencies": {
"@tsconfig/node18": "^18.2.2",
"matrix-bot-sdk": "git+https://github.com/reivilibre/fork-matrix-bot-sdk#rei/fd25_dms-catch",
"await-lock": "^2.1.0",
"config": "^3.3.3",
"date-fns": "^4.1.0",
"express": "^4.17.1",
"fast-xml-parser": "^4.3.2",
"hls.js": "^1.5.3",
"irc-upd": "^0.11.0",
"js-yaml": "^3.14.1",
"jsrsasign": "^10.1.4",
"liquidjs": "^9.19.0",
"matrix-bot-sdk": "git+https://github.com/reivilibre/fork-matrix-bot-sdk#rei/fd25_dms-catch",
"matrix-widget-api": "^1.6.0",
"moment": "^2.29.4",
"node-fetch": "^2.6.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Map {
"role": "coordinator",
},
],
"startTime": 1706778000000,
"startTime": 1706776200000,
"subtitle": "",
"title": "Panacea3D: The Final Word in Open Source 3D Solid Modelling",
},
Expand Down Expand Up @@ -98,7 +98,7 @@ Map {
"role": "coordinator",
},
],
"startTime": 1706779800000,
"startTime": 1706777100000,
"subtitle": "",
"title": "A new architecture for Local-First Computing without boundaries",
},
Expand Down Expand Up @@ -126,7 +126,7 @@ Map {
"role": "coordinator",
},
],
"startTime": 1706783400000,
"startTime": 1706780700000,
"subtitle": "",
"title": "Devising a Blended Federation Topology that reaches Cosmique Perfection",
},
Expand Down Expand Up @@ -188,7 +188,7 @@ Map {
"role": "coordinator",
},
],
"startTime": 1706778000000,
"startTime": 1706776200000,
"subtitle": "",
"title": "Panacea3D: The Final Word in Open Source 3D Solid Modelling",
},
Expand Down Expand Up @@ -216,7 +216,7 @@ Map {
"role": "coordinator",
},
],
"startTime": 1706779800000,
"startTime": 1706777100000,
"subtitle": "",
"title": "A new architecture for Local-First Computing without boundaries",
},
Expand Down Expand Up @@ -244,7 +244,7 @@ Map {
"role": "coordinator",
},
],
"startTime": 1706783400000,
"startTime": 1706780700000,
"subtitle": "",
"title": "Devising a Blended Federation Topology that reaches Cosmique Perfection",
},
Expand Down
16 changes: 8 additions & 8 deletions src/backends/json/FosdemJsonScheduleLoader.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { RoomKind } from "../../models/room_kinds";
import { IAuditorium, IConference, IInterestRoom, IPerson, ITalk, Role } from "../../models/schedule";
import { FOSDEMSpecificJSONSchedule, FOSDEMPerson, FOSDEMTrack, FOSDEMTalk } from "./jsontypes/FosdemJsonSchedule.schema";
import * as moment from "moment";
import { AuditoriumId, InterestId, TalkId } from "../IScheduleBackend";
import { IConfig } from "../../config";
import { addMinutes, getTime, getUnixTime, parseISO, startOfDay } from "date-fns";

/**
* Loader and holder for FOSDEM-specific JSON schedules, acquired from the
Expand Down Expand Up @@ -93,8 +93,9 @@ export class FosdemJsonScheduleLoader {

private convertTalk(talk: FOSDEMTalk): ITalk {
const auditoriumId = talk.track.id.toString();
const startMoment = moment.utc(talk.start_datetime, moment.ISO_8601, true);
const endMoment = startMoment.add(talk.duration, "minutes");
const startInstant = parseISO(talk.start_datetime);
const endInstant = addMinutes(startInstant, talk.duration);
const dateTs = getTime(startOfDay(startInstant));

return {
id: talk.event_id.toString(),
Expand All @@ -116,14 +117,13 @@ export class FosdemJsonScheduleLoader {
qa_startTime: talk.track.online_qa ? 0 : null,

// Since the talks are not pre-recorded, the livestream is considered ended when the event ends.
livestream_endTime: endMoment.valueOf(),
livestream_endTime: getTime(endInstant),

speakers: talk.persons.map(person => this.convertPerson(person)),

// Must .clone() here because .startOf() mutates the moment(!)
dateTs: startMoment.clone().startOf("day").valueOf(),
startTime: startMoment.valueOf(),
endTime: endMoment.valueOf(),
dateTs,
startTime: getTime(startInstant),
endTime: getTime(endInstant),
};
}

Expand Down
11 changes: 7 additions & 4 deletions src/commands/ScheduleCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ limitations under the License.

import { ICommand } from "./ICommand";
import { Scheduler, getStartTime, sortTasks } from "../Scheduler";
import moment = require("moment");
import { MatrixClient } from "matrix-bot-sdk";
import { Conference } from "../Conference";
import { formatISO, intlFormatDistance } from "date-fns";

export class ScheduleCommand implements ICommand {
public readonly prefixes = ["schedule"];
Expand Down Expand Up @@ -47,8 +47,11 @@ export class ScheduleCommand implements ICommand {
let html = "Upcoming tasks:<ul>";
for (const task of upcoming) {
const hasTalkRoom = this.conference.getTalk(task.talk.id) !== undefined;
const taskStart = moment(getStartTime(task));
const formattedTimestamp = taskStart.format("YYYY-MM-DD HH:mm:ss [UTC]ZZ");

const taskStart = getStartTime(task);

const formattedTimestamp = taskStart === null ? '<not runnable>' : formatISO(taskStart, {format: 'extended'});
const relativeTimestamp = taskStart === null ? '' : intlFormatDistance(taskStart, new Date());

if (html.length > 20000) {
// chunk up the message so we don't fail to send one very large event.
Expand All @@ -58,7 +61,7 @@ export class ScheduleCommand implements ICommand {
}

const hasRoomIndicator = hasTalkRoom ? 'has talk room' : 'no talk room';
html += `<li>${formattedTimestamp}: <b>${task.type} on ${task.talk.title}</b> (<code>${task.id}</code>, ${hasRoomIndicator}) ${taskStart.fromNow()}</li>`;
html += `<li>${formattedTimestamp}: <b>${task.type} on ${task.talk.title}</b> (<code>${task.id}</code>, ${hasRoomIndicator}) ${relativeTimestamp}</li>`;
}
html += "</ul>";
await this.client.sendHtmlNotice(roomId, html);
Expand Down
2 changes: 1 addition & 1 deletion src/models/schedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export interface ITalk {
* Start time of Q&A as a unix timestamp in ms, or null if Q&A is disabled for this talk.
*/
qa_startTime: number | null;
livestream_endTime: number;
livestream_endTime: number; // ms
title: string;
subtitle: string;
/**
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1836,6 +1836,11 @@ dashdash@^1.12.0:
dependencies:
assert-plus "^1.0.0"

date-fns@^4.1.0:
version "4.1.0"
resolved "https://registry.npmjs.org/date-fns/-/date-fns-4.1.0.tgz"
integrity sha512-Ukq0owbQXxa/U3EGtsdVBkR1w7KOQ5gIBqdH2hkvknzZPYvBxb/aa6E8L7tmjFtkwZBu3UXBbjIgPo/Ez4xaNg==

debug@^4.1.0:
version "4.3.1"
resolved "https://registry.npmjs.org/debug/-/debug-4.3.1.tgz"
Expand Down

0 comments on commit e111db0

Please sign in to comment.