Skip to content
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

Humanize require both duration and relativeTime plugins #890

Closed
doliG opened this issue Apr 29, 2020 · 2 comments
Closed

Humanize require both duration and relativeTime plugins #890

doliG opened this issue Apr 29, 2020 · 2 comments

Comments

@doliG
Copy link

doliG commented Apr 29, 2020

Describe the bug

Hello guys, and thank you for this awesome lib.

I am trying to migrate from moment to dayjs, and I found something which IMHO is weird: it looks like humanize does not work without duration and relativeTime plugin.

This script, which is a copy/paste from the humanize doc, result to an error:

const dayjs = require("dayjs")
const duration = require("dayjs/plugin/duration")

dayjs.extend(duration)

const result = dayjs.duration(1, "minutes").humanize() // a minute
console.log({ result })
TypeError: t(...).add(...).locale(...).fromNow is not a function
    at s.u.humanize (/private/tmp/dayjstest/node_modules/dayjs/plugin/duration.js:1:2489)

Error logs: https://pastebin.com/rGhgezBU

But, adding relativeTime plugin make it works:

const dayjs = require("dayjs")
const duration = require("dayjs/plugin/duration")
const relativeTime = require('dayjs/plugin/relativeTime')

dayjs.extend(duration)
dayjs.extend(relativeTime)

const result = dayjs.duration(1, "minutes").humanize() // a minute
console.log({ result })
// { result: 'a minute' }

Expected behavior

Well, I feel like plugin should work in isolation. If it is not possible, maybe it can be a good thing to update the documentation and wrote that humanize require both relativeTime and duration plugins.

But, I'm still a beginner with dayjs, so maybe I just missed something big. What do you think ?

Information

  • Day.js Version :v1.8.25
  • OS: MacOS Mojave
  • Node: 13.11.0
@iamkun
Copy link
Owner

iamkun commented Apr 30, 2020

My bad, Humanize dependent on RelativeTime plugin to work

Doc updated https://day.js.org/docs/en/durations/humanize

@doliG
Copy link
Author

doliG commented Apr 30, 2020

Thanks you for your quick response :)

@doliG doliG closed this as completed Apr 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants