qwen-code/packages/web-shell/client/utils/timeAgo.ts
Shaojin Wen a4f5e50d19
feat(web-shell): add read-only GitHub pull requests panel (#7683)
* feat(web-shell): add read-only GitHub pull requests panel

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>

* fix(web-shell): address review findings for GitHub PRs panel

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>

* fix(web-shell): clamp GitDialog view when PR capability is withdrawn mid-session

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>

* fix(web-shell): address review feedback for GitHub PRs panel (#7683)

- Add workspace_github_prs to integration test baseline capabilities
- Sanitize git root path in error responses to prevent path leakage
  when workspace is a repo subdirectory
- Add NEUTRAL check-run conclusion test case
- Add not.toContain path-leak assertion for sanitization test
- Add pending checks indicator UI test
- Add timeAgo utility unit test

* fix(web-shell): address review feedback for GitHub PRs panel (#7683)

- Sanitize workspace paths before truncating the error message so a path
  straddling the 512-char display boundary is redacted, not cut mid-token
- Render a badge for the review_required decision instead of leaving it dead
- Align PR row icon sizes (12px) with sibling git dialogs

---------

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
Co-authored-by: qwen-code-dev-bot <qwen-code-dev@service.alibaba.com>
Co-authored-by: qwen-code-ci-bot <qwen-code-ci-bot@users.noreply.github.com>
2026-07-25 02:44:50 +00:00

30 lines
1.1 KiB
TypeScript

/**
* @license
* Copyright 2026 Qwen Team
* SPDX-License-Identifier: Apache-2.0
*/
/**
* Format an epoch-seconds timestamp as a localized relative time
* ("3 hours ago"). `now` is also epoch seconds.
*/
export function timeAgo(
timestamp: number,
now: number,
language: string,
): string {
const seconds = Math.max(0, Math.floor(now - timestamp));
const formatter = new Intl.RelativeTimeFormat(language, { numeric: 'auto' });
if (seconds < 60) return formatter.format(0, 'second');
const minutes = Math.floor(seconds / 60);
if (minutes < 60) return formatter.format(-minutes, 'minute');
const hours = Math.floor(minutes / 60);
if (hours < 24) return formatter.format(-hours, 'hour');
const days = Math.floor(hours / 24);
if (days < 7) return formatter.format(-days, 'day');
const weeks = Math.floor(days / 7);
if (weeks < 5) return formatter.format(-weeks, 'week');
const months = Math.floor(days / 30);
if (months < 12) return formatter.format(-months, 'month');
return formatter.format(-Math.max(1, Math.floor(days / 365)), 'year');
}