Skip to content

Feature request: micro relative format #46

@dboundz

Description

@dboundz

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"
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions