Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(mobile): 手机上今天到期的待办不再让近况报错

zqchrisc768bba138ad
diff --git a/apps/mobile/src/__tests__/companionGlance.test.tsx b/apps/mobile/src/__tests__/companionGlance.test.tsx
index 253d0e8630..cd7e59ad65 100644
--- a/apps/mobile/src/__tests__/companionGlance.test.tsx
+++ b/apps/mobile/src/__tests__/companionGlance.test.tsx
@@ -4,7 +4,8 @@
* - 生产入口与可观察结果:手机伙伴近况的两份数据——「输出内容」列哪些文件(companionGlanceOutputs),
* 「待办」能否读到宿主第一页(25 条)之后的条目(useCompanionGlanceTodos)。
* - Bug/规则依据:docs/product-rules/cindy-bots-runtime.md「伙伴近况」;桌面同一入口在 #6681 review 中
- * 被指出只读一页时第 26 条之后看不到、引用不了、删不掉。
+ * 被指出只读一页时第 26 条之后看不到、引用不了、删不掉;模拟器目检发现 Hermes 没有 Intl.RelativeTimeFormat,
+ * 今天到期的待办让近况整块渲染报错。
* - 现有覆盖缺口:新入口;顶栏测试只验证打开近况,不覆盖数据。
* - 最小失败输入:30 条未完成待办;一份含成品、源码、已删文件的完成委派与一份失败委派。
* - tier:unit(jsdom 驱动真实 hook,device-link 用内存 fake)。
@@ -12,7 +13,7 @@
import { act, createElement } from 'react';
import { createRoot, type Root } from 'react-dom/client';
import { afterEach, beforeEach, expect, it, vi } from 'vitest';
-import type { TeammateTodo } from '@cindy/maker-shared/teammate-todo';
+import { todoDateLabel, todoLocalDate, type TeammateTodo } from '@cindy/maker-shared/teammate-todo';
const h = vi.hoisted(() => ({ items: [] as unknown[], reads: [] as Array<Record<string, unknown>> }));
vi.mock('react-native', () => ({ AppState: { addEventListener: () => ({ remove: () => undefined }) } }));
@@ -70,3 +71,16 @@ it("lists only this teammate's finished deliverables, newest first, each opening
} as never, 'bot');
expect(outputs.map(file => [file.name, file.childSessionId])).toEqual([['deck.pptx', 'c2'], ['report.docx', 'c1']]);
});
+
+it('labels a todo due today with its date where the engine has no relative-time formatting (Hermes)', () => {
+ const original = Intl.RelativeTimeFormat;
+ const today = todoLocalDate(new Date(), 'UTC');
+ const due = { ...todo('t'), sourceDeadline: { kind: 'date', date: today, timeZone: 'UTC' }, deadlineOverride: null } as unknown as TeammateTodo;
+ try {
+ (Intl as { RelativeTimeFormat?: unknown }).RelativeTimeFormat = undefined;
+ expect(todoDateLabel(due, 'zh-CN')).toBe(new Intl.DateTimeFormat('zh-CN', { timeZone: 'UTC', month: 'numeric', day: 'numeric' })
+ .format(new Date(`${today}T12:00:00Z`)));
+ } finally {
+ (Intl as { RelativeTimeFormat?: unknown }).RelativeTimeFormat = original;
+ }
+});
diff --git a/apps/mobile/src/session/CompanionGlanceSheet.tsx b/apps/mobile/src/session/CompanionGlanceSheet.tsx
index 04b54891a4..ead352588c 100644
--- a/apps/mobile/src/session/CompanionGlanceSheet.tsx
+++ b/apps/mobile/src/session/CompanionGlanceSheet.tsx
@@ -31,7 +31,8 @@ function dayLabel(at: number, language: string): string {
const date = new Date(at);
const startOf = (value: Date) => new Date(value.getFullYear(), value.getMonth(), value.getDate()).getTime();
const days = Math.round((startOf(now) - startOf(date)) / 86_400_000);
- if (days >= 0 && days <= 1) return new Intl.RelativeTimeFormat(language, { numeric: 'auto' }).format(-days, 'day');
+ // Hermes has no Intl.RelativeTimeFormat; there recent days show as dates too.
+ if (days >= 0 && days <= 1 && typeof Intl.RelativeTimeFormat === 'function') return new Intl.RelativeTimeFormat(language, { numeric: 'auto' }).format(-days, 'day');
return new Intl.DateTimeFormat(language, { month: 'numeric', day: 'numeric' }).format(date);
}
diff --git a/packages/maker-shared/src/teammateTodo.ts b/packages/maker-shared/src/teammateTodo.ts
index 8eafaf9796..daa7fe7b1c 100644
--- a/packages/maker-shared/src/teammateTodo.ts
+++ b/packages/maker-shared/src/teammateTodo.ts
@@ -232,8 +232,9 @@ export function todoDateLabel(t: TeammateTodo, locale: string, now = new Date())
month: 'numeric',
day: 'numeric',
}).format(new Date(dateString + 'T12:00:00Z'));
+ // Hermes (Mobile) has no Intl.RelativeTimeFormat; there "today" falls back to the date itself.
const day =
- d && d.date === todoLocalDate(now, d.timeZone)
+ d && d.date === todoLocalDate(now, d.timeZone) && typeof Intl.RelativeTimeFormat === 'function'
? new Intl.RelativeTimeFormat(locale, { numeric: 'auto' }).format(0, 'day')
: date;
return d?.kind === 'instant'