dayjs icon indicating copy to clipboard operation
dayjs copied to clipboard

The fromNow() method of the "relativeTime"plugin considers 11 months ago as a year

Open saguilarolmo opened this issue 3 years ago • 1 comments

Describe the bug When I print the difference between dates from 1 month to 12 with this code: console.log("dayjs("2021-01-01T00:00:00+00:00").from(dayjs("2022-01-01"))) console.log("dayjs("2021-02-01T00:00:00+00:00").from(dayjs("2022-01-01"))) console.log("dayjs("2021-03-01T00:00:00+00:00").from(dayjs("2022-01-01"))) console.log("dayjs("2021-04-01T00:00:00+00:00").from(dayjs("2022-01-01"))) console.log("dayjs("2021-05-01T00:00:00+00:00").from(dayjs("2022-01-01"))) console.log("dayjs("2021-06-01T00:00:00+00:00").from(dayjs("2022-01-01"))) console.log("dayjs("2021-07-01T00:00:00+00:00").from(dayjs("2022-01-01"))) console.log("dayjs("2021-08-01T00:00:00+00:00").from(dayjs("2022-01-01"))) console.log("dayjs("2021-09-01T00:00:00+00:00").from(dayjs("2022-01-01"))) console.log(" dayjs("2021-10-01T00:00:00+00:00").from(dayjs("2022-01-01"))) console.log("dayjs("2021-11-01T00:00:00+00:00").from(dayjs("2022-01-01"))) console.log("dayjs("2021-12-01T00:00:00+00:00").from(dayjs("2022-01-01")))

the result is: a year ago a year ago 10 months ago 9 months ago 8 months ago 7 months ago 6 months ago 5 months ago 4 months ago 3 months ago 2 months ago a month ago

See: https://runkit.com/62da9163adca2e0009a4206c/62da91756e916c00084e970b

Expected behavior The expected result is that it will also show 11 months ago as: a year ago **11 months ago** 10 months ago 9 months ago 8 months ago 7 months ago 6 months ago 5 months ago 4 months ago 3 months ago 2 months ago a month ago

Information

  • Day.js Version [e.g. v1.11.4]
  • OS: [e.g. iOS]
  • Browser [e.g. chrome 62]
  • Time zone: [e.g. GMT-014:16 DST (CEST)]

saguilarolmo avatar Jul 22 '22 12:07 saguilarolmo

Hi, it's not a bug, according to the docs

46 days to 10 months MM 2 months ago ... 10 months ago
11 months to 17months y a year ago

You can create your own thresholds or patch existing according to the docs.

Bykiev avatar Jul 22 '22 12:07 Bykiev