Files
Nico 4c6aa754e0 Time ago timestamps: use days instead of months when under 90 days (#48964)
<!-- Add the related story/sub-task/bug number, like Resolves #123, or
remove if NA -->
**Related issue:** Resolves #46965

Relative "time ago" timestamps switched to months at ~30 days, so a
timestamp 45 days ago read "about 2 months ago" (even 89 days showed "3
months ago"). This centralizes the day/month cutoff in a new `timeAgo`
helper and routes existing call sites through it, so anything under 90
days is shown in days.

# Checklist for submitter

- [x] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
See [Changes
files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-changes.md#changes-files)
for more information.

## Testing

- [x] Added/updated automated tests

- [x] QA'd all new/changed functionality manually


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Bug Fixes**
* Relative “time ago” timestamps now keep values in **days** for items
under **90 days**, switching to **months** later for more accurate
wording.
* Improved consistency of relative time labels across status modals,
activity feeds, host details, and management screens (including “last
updated,” “uploaded,” and “added” text).
* **Tests**
* Added/updated coverage for the shared relative-time cutoff and
formatting behavior to prevent regressions.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-07-08 15:07:48 -03:00

58 lines
1.4 KiB
TypeScript

import React from "react";
import { timeAgo } from "utilities/date_format";
import { abbreviateTimeUnits } from "utilities/helpers";
import TooltipWrapper from "components/TooltipWrapper";
const baseClass = "component__last-updated-text";
interface ILastUpdatedTextBase {
lastUpdatedAt?: string | null;
}
interface ILastUpdatedTextWithCustomTooltip extends ILastUpdatedTextBase {
customTooltipText: React.ReactNode;
whatToRetrieve?: never;
}
interface ILastUpdatedTextWithWhatToRetrieve extends ILastUpdatedTextBase {
customTooltipText?: never;
whatToRetrieve: string;
}
const LastUpdatedText = ({
lastUpdatedAt,
whatToRetrieve,
customTooltipText,
}:
| ILastUpdatedTextWithCustomTooltip
| ILastUpdatedTextWithWhatToRetrieve): JSX.Element => {
if (!lastUpdatedAt || lastUpdatedAt === "0001-01-01T00:00:00Z") {
lastUpdatedAt = "never";
} else {
lastUpdatedAt = abbreviateTimeUnits(
timeAgo(new Date(lastUpdatedAt), {
addSuffix: true,
strict: true,
})
);
}
const tooltipContent = customTooltipText || (
<>
Fleet periodically queries all hosts <br />
to retrieve {whatToRetrieve}.
</>
);
return (
<span className={baseClass}>
<TooltipWrapper tipContent={tooltipContent}>
{`Updated ${lastUpdatedAt}`}
</TooltipWrapper>
</span>
);
};
export default LastUpdatedText;