diff --git a/package.json b/package.json index 13e8907..898da63 100644 --- a/package.json +++ b/package.json @@ -24,9 +24,9 @@ }, "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", @@ -34,6 +34,7 @@ "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", diff --git a/src/__tests__/backends/json/__snapshots__/JsonScheduleBackend.test.ts.snap b/src/__tests__/backends/json/__snapshots__/JsonScheduleBackend.test.ts.snap index ce26c3d..c0db6bd 100644 --- a/src/__tests__/backends/json/__snapshots__/JsonScheduleBackend.test.ts.snap +++ b/src/__tests__/backends/json/__snapshots__/JsonScheduleBackend.test.ts.snap @@ -50,7 +50,7 @@ Map { "role": "coordinator", }, ], - "startTime": 1706778000000, + "startTime": 1706776200000, "subtitle": "", "title": "Panacea3D: The Final Word in Open Source 3D Solid Modelling", }, @@ -98,7 +98,7 @@ Map { "role": "coordinator", }, ], - "startTime": 1706779800000, + "startTime": 1706777100000, "subtitle": "", "title": "A new architecture for Local-First Computing without boundaries", }, @@ -126,7 +126,7 @@ Map { "role": "coordinator", }, ], - "startTime": 1706783400000, + "startTime": 1706780700000, "subtitle": "", "title": "Devising a Blended Federation Topology that reaches Cosmique Perfection", }, @@ -188,7 +188,7 @@ Map { "role": "coordinator", }, ], - "startTime": 1706778000000, + "startTime": 1706776200000, "subtitle": "", "title": "Panacea3D: The Final Word in Open Source 3D Solid Modelling", }, @@ -216,7 +216,7 @@ Map { "role": "coordinator", }, ], - "startTime": 1706779800000, + "startTime": 1706777100000, "subtitle": "", "title": "A new architecture for Local-First Computing without boundaries", }, @@ -244,7 +244,7 @@ Map { "role": "coordinator", }, ], - "startTime": 1706783400000, + "startTime": 1706780700000, "subtitle": "", "title": "Devising a Blended Federation Topology that reaches Cosmique Perfection", }, diff --git a/src/backends/json/FosdemJsonScheduleLoader.ts b/src/backends/json/FosdemJsonScheduleLoader.ts index de047d4..ed6a669 100644 --- a/src/backends/json/FosdemJsonScheduleLoader.ts +++ b/src/backends/json/FosdemJsonScheduleLoader.ts @@ -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 @@ -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(), @@ -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), }; } diff --git a/src/commands/ScheduleCommand.ts b/src/commands/ScheduleCommand.ts index e88522f..ac2b5f4 100644 --- a/src/commands/ScheduleCommand.ts +++ b/src/commands/ScheduleCommand.ts @@ -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"]; @@ -47,8 +47,11 @@ export class ScheduleCommand implements ICommand { let html = "Upcoming tasks:"; await this.client.sendHtmlNotice(roomId, html); diff --git a/src/models/schedule.ts b/src/models/schedule.ts index 6a08e0e..764c6b7 100644 --- a/src/models/schedule.ts +++ b/src/models/schedule.ts @@ -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; /** diff --git a/yarn.lock b/yarn.lock index c7b7c45..2defab5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"