Skip to content

Commit

Permalink
change defaults for hideSeconds and roundStrategy options
Browse files Browse the repository at this point in the history
  • Loading branch information
k-yle committed Feb 9, 2024
1 parent f88a75c commit 96b2cd0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ import TimeAgo from "react-timeago-i18n";
| `date` | `string` or `Date` | - |
| `locale` | the language to use | `navigator.language` |
| `formatOptions` | [options for `Intl.RelativeTimeFormat`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat#basic_format_usage) | `undefined` |
| `hideSeconds` | If `true`, values smaller than 1 minute will shown as "1 minute" instead of frequently updating seconds. | `false` |
| `roundStrategy` | By default, values are `floor`ed (e.g. 11.9 months becomes "1 year"). If this is not desired, the rounding strategy can be changed to `round`. | `"floor"` |
| `hideSeconds` | By default, values smaller than 1 minute will shown as "1 minute" instead of frequently updating seconds, unless you set this property to `false`. | `true` |
| `roundStrategy` | By default, values are `rounded`ed (e.g. 11.9 months becomes "2 years"). If this is not desired, the rounding strategy can be changed to `floor`. | `"round"` |
| `timeElement` | By default, the result is wrapped in `<time title="..."> ... </time>`, unless you set this property to `false` | `true` |
8 changes: 4 additions & 4 deletions src/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ describe("TimeAgo", () => {
${"2023-06-06T10:00:00Z"} | ${"es"} | ${"hace 1 hora"}
${"2023-06-06T10:00:00Z"} | ${"zh-Hant"} | ${"1 小時前"}
${"2023-06-06T10:00:00Z"} | ${"zh-Hans"} | ${"1小时前"}
${"1989-09-01"} | ${"sm"} | ${"33 years ago" /* lang not supported */}
${"1989-09-01"} | ${"rrm"} | ${"33 years ago" /* lang not supported */}
${"1989-09-01"} | ${"sm"} | ${"34 years ago" /* lang not supported */}
${"1989-09-01"} | ${"rrm"} | ${"34 years ago" /* lang not supported */}
`(
"renders $date as $output in $locale",
async ({ date, locale, output }) => {
const div = setup({ date, locale });
const div = setup({ date, locale, hideSeconds: false });

expect(div).toHaveTextContent(output);
}
Expand Down Expand Up @@ -91,7 +91,7 @@ describe("TimeAgo", () => {
${"2023"} | ${"hace 1 año"}
${"2023-06-01"} | ${"hace 1 año"}
${"2023-06-06"} | ${"hace 1 año"}
${"2024"} | ${"hace 0 segundos"}
${"2024"} | ${"hace 1 minuto"}
`(
"doesn't crash if someone tries to use ceil with $date",
({ date, output }) => {
Expand Down
6 changes: 3 additions & 3 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type RoundStrategy = "floor" | "round";

function timeSince(
date: Date,
roundStrategy: RoundStrategy = "floor"
roundStrategy: RoundStrategy
): [value: number, unit: Unit] {
const msAgo = Date.now() - +date;

Expand Down Expand Up @@ -61,8 +61,8 @@ const TimeAgo = memo<TimeAgoProps>(
date,
locale = navigator.language,
formatOptions,
hideSeconds,
roundStrategy,
hideSeconds = true,
roundStrategy = "round",
timeElement = true,
}) => {
const [text, setText] = useState("");
Expand Down

0 comments on commit 96b2cd0

Please sign in to comment.