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

Would be useful to remove "ago" from relative time #49

Open
dboundz opened this issue Oct 3, 2024 · 1 comment
Open

Would be useful to remove "ago" from relative time #49

dboundz opened this issue Oct 3, 2024 · 1 comment

Comments

@dboundz
Copy link

dboundz commented Oct 3, 2024

There are many cases where you want relative time, but not the word "ago".

For instance: In stage for 18 hours

Would be nice to be able to toggle off "ago" in the realtive output.

@dboundz
Copy link
Author

dboundz commented Jan 19, 2025

Just using my own function for this now

    timeSince: (date) => {
      if (!date) return
      date = new Date(date)
      let seconds = Math.floor((new Date() - date) / 1000)
      let interval = seconds / 31536000
      if (interval > 1) {
        let value = Math.floor(interval)
        if (value == 1) return '1 year'
        else return value + ' years'
      }
      interval = seconds / 2592000
      if (interval > 1) {
        let value = Math.floor(interval)
        if (value == 1) return '1 month'
        else return value + ' months'
      }
      interval = seconds / 86400
      if (interval > 1) {
        let value = Math.floor(interval)
        if (value == 1) return '1 day'
        else return value + ' days'
      }
      interval = seconds / 3600
      if (interval > 1) {
        let value = Math.floor(interval)
        if (value == 1) return '1 hour'
        else return value + ' hours'
      }
      interval = seconds / 60
      if (interval > 1) {
        let value = Math.floor(interval)
        if (value == 1) return '1 minute'
        else return value + ' minutes'
      }
      let value = Math.floor(seconds)
      if (value == 1) return '1 second'
      else return value + ' seconds'
    },

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