Skip to contents

Human readable format of a time interval

Usage

vague_dt(dt, format = c("default", "short", "terse"))

Arguments

dt

A difftime object, the time interval(s).

format

Format, currently available formats are: ‘default’, ‘short’, ‘terse’. See examples below.

Value

Character vector of the formatted time intervals.

Examples

vague_dt(as.difftime(30, units = "secs"))
#> [1] "less than a minute ago"
vague_dt(as.difftime(14, units = "mins"))
#> [1] "14 minutes ago"
vague_dt(as.difftime(5, units = "hours"))
#> [1] "5 hours ago"
vague_dt(as.difftime(25, units = "hours"))
#> [1] "a day ago"
vague_dt(as.difftime(5, units = "days"))
#> [1] "5 days ago"
vague_dt(as.difftime(30, units = "days"))
#> [1] "about a month ago"
vague_dt(as.difftime(365, units = "days"))
#> [1] "about a year ago"
vague_dt(as.difftime(365 * 10, units = "days"))
#> [1] "10 years ago"

## Short format
vague_dt(format = "short", as.difftime(30, units = "secs"))
#> [1] "<1 min"
vague_dt(format = "short", as.difftime(14, units = "mins"))
#> [1] "14 min"
vague_dt(format = "short", as.difftime(5, units = "hours"))
#> [1] "5 hours"
vague_dt(format = "short", as.difftime(25, units = "hours"))
#> [1] "1 day"
vague_dt(format = "short", as.difftime(5, units = "days"))
#> [1] "5 day"
vague_dt(format = "short", as.difftime(30, units = "days"))
#> [1] "1 mon"
vague_dt(format = "short", as.difftime(365, units = "days"))
#> [1] "1 year"
vague_dt(format = "short", as.difftime(365 * 10, units = "days"))
#> [1] "10 years"

## Even shorter, terse format, (almost always) exactly 3 characters wide
vague_dt(format = "terse", as.difftime(30, units = "secs"))
#> [1] "30s"
vague_dt(format = "terse", as.difftime(14, units = "mins"))
#> [1] "14m"
vague_dt(format = "terse", as.difftime(5, units = "hours"))
#> [1] " 5h"
vague_dt(format = "terse", as.difftime(25, units = "hours"))
#> [1] " 1d"
vague_dt(format = "terse", as.difftime(5, units = "days"))
#> [1] " 5d"
vague_dt(format = "terse", as.difftime(30, units = "days"))
#> [1] " 1M"
vague_dt(format = "terse", as.difftime(365, units = "days"))
#> [1] " 1y"
vague_dt(format = "terse", as.difftime(365 * 10, units = "days"))
#> [1] "10y"