Desk: age parses strict RFC3339 only; a served count outside the contract shows no count line
All checks were successful
Build pull request / Build pull request (pull_request) Successful in 4m0s
All checks were successful
Build pull request / Build pull request (pull_request) Successful in 4m0s
Soul found Date.parse accepting '2026-11-06', 'Nov 6 2026', '0' and 2026-02-30, and decider_count 0/65 or a missing/negative answerer_count rendering as served. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
9e02536e02
commit
79fae54a0a
4 changed files with 52 additions and 10 deletions
|
|
@ -145,7 +145,7 @@ describe("a question's age", () => {
|
|||
expect(html('2026-11-11T11:40:00Z')).toContain('raised just now');
|
||||
});
|
||||
it('shows no age when the card carries none, or an instant that does not parse or is ahead of the clock', () => {
|
||||
['null', 'yesterday', '2027-01-01T00:00:00Z'].forEach((v) => {
|
||||
['null', 'yesterday', '2027-01-01T00:00:00Z', '2026-11-06', 'Nov 6 2026', '0', '2026-02-30T00:00:00Z'].forEach((v) => {
|
||||
expect(html(v === 'null' ? null : v)).not.toContain('raised ');
|
||||
});
|
||||
});
|
||||
|
|
@ -173,6 +173,31 @@ describe('counts when the ids are withheld', () => {
|
|||
);
|
||||
expect(html).toContain('3 deciders · 2 answerers');
|
||||
});
|
||||
it('shows no count line for a served count outside the contract', () => {
|
||||
const bad = (card: object, record: object): string => {
|
||||
const entry = STATES.noAnswers.forks[0];
|
||||
const list = {
|
||||
...STATES.noAnswers,
|
||||
forks: [{ card: { ...entry.card, ...card }, record: { ...entry.record, ...record } }],
|
||||
} as ForkList;
|
||||
return renderToStaticMarkup(
|
||||
<ScreenSizeProvider value={ScreenSize.Desktop}>
|
||||
<DeskView mind="void" label="Void" list={list} />
|
||||
</ScreenSizeProvider>
|
||||
);
|
||||
};
|
||||
[
|
||||
[{ decider_count: 0 }, {}],
|
||||
[{ decider_count: 65 }, {}],
|
||||
[{ decider_count: undefined }, {}],
|
||||
[{}, { answerer_count: -1 }],
|
||||
[{}, { answerer_count: 1.5 }],
|
||||
].forEach(([c, r]) => {
|
||||
const out = bad(c, r);
|
||||
expect(out).not.toContain('undefined');
|
||||
expect(out).not.toMatch(/deciders? ·/);
|
||||
});
|
||||
});
|
||||
it('says the singular for one', () => {
|
||||
const html = view('noAnswers', ScreenSize.Desktop);
|
||||
expect(html).toContain('1 decider · 0 answerers');
|
||||
|
|
|
|||
|
|
@ -83,9 +83,11 @@ function Row({ row, now }: { row: DeskRow; now: number }) {
|
|||
{raisedAge(row.raisedAt, now) && (
|
||||
<p className={css.Quiet}>{raisedAge(row.raisedAt, now)}</p>
|
||||
)}
|
||||
<p className={css.Quiet}>
|
||||
{`${plural(row.deciderCount, 'decider')} · ${plural(row.answererCount, 'answerer')}`}
|
||||
</p>
|
||||
{row.deciderCount !== undefined && row.answererCount !== undefined && (
|
||||
<p className={css.Quiet}>
|
||||
{`${plural(row.deciderCount, 'decider')} · ${plural(row.answererCount, 'answerer')}`}
|
||||
</p>
|
||||
)}
|
||||
<p className={css.Body}>{row.context}</p>
|
||||
<ul className={css.Options}>
|
||||
{row.options.map((o) => (
|
||||
|
|
|
|||
|
|
@ -7,8 +7,20 @@ const DAY = 24 * HOUR;
|
|||
* holds. Nothing when there is no instant, it does not parse, or it is ahead of the clock: the desk shows no age
|
||||
* rather than a wrong one.
|
||||
*/
|
||||
const RFC3339 = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$/;
|
||||
|
||||
/** Date.parse is lenient ("2026-11-06", "Nov 6 2026", "0"); the card's instant is RFC3339 and a real calendar day. */
|
||||
const parseRfc3339 = (s: string): number => {
|
||||
const m = RFC3339.exec(s);
|
||||
if (!m) return NaN;
|
||||
const [y, mo, d] = [Number(m[1]), Number(m[2]), Number(m[3])];
|
||||
const day = new Date(Date.UTC(y, mo - 1, d));
|
||||
if (day.getUTCMonth() !== mo - 1 || day.getUTCDate() !== d) return NaN;
|
||||
return Date.parse(s);
|
||||
};
|
||||
|
||||
export const raisedAge = (raisedAt: string | undefined, now: number): string | undefined => {
|
||||
const then = raisedAt === undefined ? NaN : Date.parse(raisedAt);
|
||||
const then = raisedAt === undefined ? NaN : parseRfc3339(raisedAt);
|
||||
const ms = now - then;
|
||||
if (Number.isNaN(ms) || ms < 0) return undefined;
|
||||
if (ms < HOUR) return 'raised just now';
|
||||
|
|
|
|||
|
|
@ -30,9 +30,9 @@ export type DeskRow =
|
|||
depends: string[];
|
||||
/** When the question was first admitted, as served; absent when the card carries none. */
|
||||
raisedAt?: string;
|
||||
/** Counts as served: the same in the decider and the withheld view, so they show either way. */
|
||||
deciderCount: number;
|
||||
answererCount: number;
|
||||
/** Counts as served: the same in the decider and the withheld view, so they show either way. Absent when the served number is outside the contract's range or not an integer. */
|
||||
deciderCount?: number;
|
||||
answererCount?: number;
|
||||
/** In admission order, as served. */
|
||||
answers: AnswerRow[];
|
||||
};
|
||||
|
|
@ -62,6 +62,9 @@ const answerRow = (a: DeskAnswer, entry: ForkEntry): AnswerRow => ({
|
|||
counted: entry.record.counted_answer_id === a.answer_id,
|
||||
});
|
||||
|
||||
const validCount = (n: number, min: number, max: number): number | undefined =>
|
||||
Number.isInteger(n) && n >= min && n <= max ? n : undefined;
|
||||
|
||||
export const buildDesk = (
|
||||
list: ForkList | undefined,
|
||||
unverified: ReadonlySet<string> = new Set()
|
||||
|
|
@ -89,8 +92,8 @@ export const buildDesk = (
|
|||
recommended: card.options.find((o) => o.id === card.recommendation)?.text,
|
||||
depends: card.depends,
|
||||
raisedAt: card.raised_at ?? undefined,
|
||||
deciderCount: card.decider_count,
|
||||
answererCount: record.answerer_count,
|
||||
deciderCount: validCount(card.decider_count, 1, 64),
|
||||
answererCount: validCount(record.answerer_count, 0, Infinity),
|
||||
answers: record.answers.map((a) => answerRow(a, entry)),
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue