feat: Generalize and extend notification channel type behaviour

This commit is contained in:
Joachim Van Herwegen
2023-01-27 11:53:30 +01:00
parent 7d029a9465
commit c36f15e2da
32 changed files with 1291 additions and 624 deletions

View File

@@ -28,3 +28,38 @@ export function sanitizeUrlPart(urlPart: string): string {
export function isValidFileName(name: string): boolean {
return /^[\w.-]+$/u.test(name);
}
/**
* Converts milliseconds to an ISO 8601 duration string.
* The only categories used are days, hours, minutes, and seconds,
* because months have no fixed size in milliseconds.
* @param ms - The duration in ms to convert.
*/
export function msToDuration(ms: number): string {
let totalSeconds = ms / 1000;
const days = Math.floor(totalSeconds / (60 * 60 * 24));
totalSeconds -= days * 60 * 60 * 24;
const hours = Math.floor(totalSeconds / (60 * 60));
totalSeconds -= hours * 60 * 60;
const minutes = Math.floor(totalSeconds / 60);
const seconds = totalSeconds - (minutes * 60);
const stringParts: string[] = [ 'P' ];
if (days > 0) {
stringParts.push(`${days}D`);
}
if (hours > 0 || minutes > 0 || seconds > 0) {
stringParts.push('T');
}
if (hours > 0) {
stringParts.push(`${hours}H`);
}
if (minutes > 0) {
stringParts.push(`${minutes}M`);
}
if (seconds > 0) {
stringParts.push(`${seconds}S`);
}
return stringParts.join('');
}

View File

@@ -200,10 +200,13 @@ export const NOTIFY = createVocabulary('http://www.w3.org/ns/solid/notifications
'startAt',
'state',
'subscription',
'target',
'topic',
'webhookAuth',
'webid',
'WebHookSubscription2021',
'WebSocketSubscription2021',
);
export const OIDC = createVocabulary('http://www.w3.org/ns/solid/oidc#',
@@ -276,7 +279,9 @@ export const VCARD = createVocabulary('http://www.w3.org/2006/vcard/ns#',
export const XSD = createVocabulary('http://www.w3.org/2001/XMLSchema#',
'dateTime',
'duration',
'integer',
'string',
);
// Alias for commonly used types