Skip to content

Express "0 precision-units away" appropriately for the precision. #280

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/relative-time-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ export class RelativeTimeElement extends HTMLElement implements Intl.DateTimeFor
if (tense === 'past' && duration.sign !== -1) duration = emptyDuration
const [int, unit] = getRelativeTimeUnit(duration)
if (unit === 'second' && int < 10) {
return relativeFormat.format(0, 'second')
return relativeFormat.format(0, this.precision === 'millisecond' ? 'second' : this.precision)
}
return relativeFormat.format(int, unit)
}
Expand Down
40 changes: 32 additions & 8 deletions test/relative-time.js
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@ suite('relative-time', function () {
datetime: '2022-10-24T14:46:00.000Z',
format: 'relative',
precision: 'hour',
expected: 'now',
expected: 'this hour',
},
{
datetime: '2022-10-24T14:46:00.000Z',
Expand Down Expand Up @@ -901,7 +901,7 @@ suite('relative-time', function () {
datetime: '2022-10-24T14:46:08.000Z',
format: 'relative',
precision: 'hour',
expected: 'now',
expected: 'this hour',
},
{
datetime: '2022-10-24T14:46:08.000Z',
Expand Down Expand Up @@ -973,8 +973,14 @@ suite('relative-time', function () {
{
datetime: '2022-10-24T14:46:50.000Z',
format: 'relative',
precision: 'hour',
expected: 'now',
precision: 'minute',
expected: 'this minute',
},
{
datetime: '2022-10-24T14:46:50.000Z',
format: 'relative',
precision: 'day',
expected: 'today',
},
{
datetime: '2022-10-24T14:46:50.000Z',
Expand Down Expand Up @@ -1047,7 +1053,7 @@ suite('relative-time', function () {
datetime: '2022-10-24T14:47:30.000Z',
format: 'relative',
precision: 'hour',
expected: 'now',
expected: 'this hour',
},
{
datetime: '2022-10-24T14:47:30.000Z',
Expand Down Expand Up @@ -1122,6 +1128,12 @@ suite('relative-time', function () {
precision: 'hour',
expected: 'in 3 weeks',
},
{
datetime: '2022-11-13T15:46:00.000Z',
format: 'relative',
precision: 'month',
expected: 'this month',
},
{
datetime: '2022-11-13T15:46:00.000Z',
format: 'relative',
Expand Down Expand Up @@ -1339,7 +1351,7 @@ suite('relative-time', function () {
datetime: '2022-10-24T14:45:52.000Z',
format: 'relative',
precision: 'hour',
expected: 'now',
expected: 'this hour',
},
{
datetime: '2022-10-24T14:45:52.000Z',
Expand Down Expand Up @@ -1412,7 +1424,13 @@ suite('relative-time', function () {
datetime: '2022-10-24T14:45:10.000Z',
format: 'relative',
precision: 'hour',
expected: 'now',
expected: 'this hour',
},
{
datetime: '2022-10-24T14:45:10.000Z',
format: 'relative',
precision: 'day',
expected: 'today',
},
{
datetime: '2022-10-24T14:45:10.000Z',
Expand Down Expand Up @@ -1485,7 +1503,7 @@ suite('relative-time', function () {
datetime: '2022-10-24T14:44:30.000Z',
format: 'relative',
precision: 'hour',
expected: 'now',
expected: 'this hour',
},
{
datetime: '2022-10-24T14:44:30.000Z',
Expand Down Expand Up @@ -1560,6 +1578,12 @@ suite('relative-time', function () {
precision: 'hour',
expected: '3 weeks ago',
},
{
datetime: '2022-10-04T14:46:00.000Z',
format: 'relative',
precision: 'month',
expected: 'this month',
},
{
datetime: '2022-10-04T14:46:00.000Z',
format: 'relative',
Expand Down
Loading