Date precision (#6359)

* Remove month/year only formats from ParseDateStringAsTime
* Add precision field to Date and handle parsing year/month-only dates
* Add date precision columns for date columns
* Adjust UI to account for fuzzy dates
This commit is contained in:
WithoutPants
2025-12-08 09:11:40 +11:00
committed by GitHub
parent eb9d0705bc
commit 7db394bbea
23 changed files with 285 additions and 154 deletions

View File

@@ -0,0 +1,36 @@
import React from "react";
import { FormattedDate as IntlDate } from "react-intl";
import { PatchComponent } from "src/patch";
// wraps FormattedDate to handle year or year/month dates
export const FormattedDate: React.FC<{
value: string | number | Date | undefined;
}> = PatchComponent("Date", ({ value }) => {
if (typeof value === "string") {
// try parsing as year or year/month
const yearMatch = value.match(/^(\d{4})$/);
if (yearMatch) {
const year = parseInt(yearMatch[1], 10);
return (
<IntlDate value={Date.UTC(year, 0)} year="numeric" timeZone="utc" />
);
}
const yearMonthMatch = value.match(/^(\d{4})-(\d{2})$/);
if (yearMonthMatch) {
const year = parseInt(yearMonthMatch[1], 10);
const month = parseInt(yearMonthMatch[2], 10) - 1;
return (
<IntlDate
value={Date.UTC(year, month)}
year="numeric"
month="long"
timeZone="utc"
/>
);
}
}
return <IntlDate value={value} format="long" timeZone="utc" />;
});