Skip to content

Commit

Permalink
Merge pull request #280 from jyasskin/now-to-today
Browse files Browse the repository at this point in the history
Express "0 precision-units away" appropriately for the precision.
  • Loading branch information
keithamus committed Mar 27, 2024
2 parents a0483ce + e0d2780 commit 76df798
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/relative-time-element.ts
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
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

0 comments on commit 76df798

Please sign in to comment.