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

Feature request: micro relative format #46

Open
dboundz opened this issue Aug 4, 2024 · 0 comments
Open

Feature request: micro relative format #46

dboundz opened this issue Aug 4, 2024 · 0 comments

Comments

@dboundz
Copy link

dboundz commented Aug 4, 2024

It doesn't seem to be possible to support micro relative timestamps. e.g. 4d 2h 5y 1m 6s

These are quite common in a variety of cases and with other libraries (e.g. timeago).

e.g.


  const microTimeSince(date) {
    let seconds = Math.floor((new Date() - date) / 1000)
    let interval = seconds / 31536000
  
    if (interval > 1) {
      return Math.floor(interval) + "y"
    }
    interval = seconds / 2592000
    if (interval > 1) {
      return Math.floor(interval) + "m"
    }
    interval = seconds / 86400
    if (interval > 1) {
      return Math.floor(interval) + "d"
    }
    interval = seconds / 3600
    if (interval > 1) {
      return Math.floor(interval) + "h"
    }
    interval = seconds / 60
    if (interval > 1) {
      return Math.floor(interval) + "m"
    }
    return Math.floor(seconds) + "s"
  }
@dboundz dboundz changed the title Feature request: micro format Feature request: micro relative format Aug 4, 2024
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

1 participant