Skip to content

Commit

Permalink
fix(from-now): issue for deltas which are lower than 1 sec
Browse files Browse the repository at this point in the history
  • Loading branch information
themojilla committed Apr 27, 2020
1 parent d1d4618 commit 97eb103
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions fromNow.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const units = [
export function diffUnitFor(from) {
const delta = Math.round((from - Date.now()) / 1000); // Rounded delta in seconds

for (let i = 0; i < units.length; i += 1) {
for (let i = 1; i < units.length; i += 1) {
if (Math.abs(delta) < units[i][1]) {
const [unit, value] = units[i - 1];

Expand Down Expand Up @@ -48,7 +48,7 @@ export default function fromNow(date, lang = 'en') {
}
}

const rtf = new Intl.RelativeTimeFormat(lang, { style: 'long' });
const rtf = new Intl.RelativeTimeFormat(lang, { style: 'long', numeric: 'auto' });
const { delta, unit } = diffUnitFor(from);

return rtf.format(delta, unit);
Expand Down

0 comments on commit 97eb103

Please sign in to comment.