Fix task display

Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
This commit is contained in:
Sacha Al Himdani
2026-01-05 12:58:42 +01:00
parent e077b5866f
commit 6ab5ace353
18 changed files with 216 additions and 655 deletions

View File

@@ -26,3 +26,36 @@ function parseDate(dateString: string): Date {
parts[2] ? parseInt(parts[2], 10) : 1
);
}
export function formatDuration(duration?: string | null, __?: (s: string) => string): string | null {
if (!duration || !__) return null;
const timeMatch = duration.match(/PT(\d+)([MH])/);
if (timeMatch) {
const amount = parseInt(timeMatch[1], 10) || 0;
const unit = timeMatch[2];
if (unit === "M") {
return `${amount} ${amount === 1 ? __("Minute") : __("Minutes")}`;
} else if (unit === "H") {
return `${amount} ${amount === 1 ? __("Hour") : __("Hours")}`;
}
}
const dateMatch = duration.match(/P(\d+)([DW])/);
if (dateMatch) {
const amount = parseInt(dateMatch[1], 10) || 0;
const unit = dateMatch[2];
if (unit === "W") {
return `${amount} ${amount === 1 ? __("Week") : __("Weeks")}`;
} else if (unit === "D") {
const days = amount;
if (days % 7 === 0 && days > 0) {
const weeks = days / 7;
return `${weeks} ${weeks === 1 ? __("Week") : __("Weeks")}`;
}
return `${days} ${days === 1 ? __("Day") : __("Days")}`;
}
}
return null;
}

View File

@@ -61,7 +61,7 @@ export {
} from "./trustCenterVisibility";
export { promisifyMutation } from "./relay";
export { fileType, fileSize } from "./file";
export { formatDatetime, formatDate, toDateInput } from "./date";
export { formatDatetime, formatDate, toDateInput, formatDuration } from "./date";
export { getTrustCenterUrl } from "./trustCenter";
export { formatError, type GraphQLError } from "./error";
export { Role, getAssignableRoles } from "./roles";