Formerly ryannhg/date-format. Search finds this package by either name.
A reliable way to get a pretty message for the relative time difference between two dates.
Maybe relativeTime is too lame. (Or maybe you speak a different language than English!)
With relativeTimeWithOptions, you can provide your own custom messages for each time range.
(That's what relativeTime uses under the hood!)
You can provide a set of your own custom options, and use relativeTimeWithOptions instead.
Options for configuring your own relative message formats!
For example, here is how someSecondsAgo is implemented by default:
defaultSomeSecondsAgo : Int -> String
defaultSomeSecondsAgo seconds =
if seconds < 30 then
"just now"
else
toString seconds ++ " seconds ago"And here is how inSomeHours might look:
defaultInSomeHours : Int -> String
defaultInSomeHours hours =
if hours < 2 then
"in an hour"
else
"in " ++ toString hours ++ " hours"If there is something you'd like to tweak based off of the defaults, this record might be a good starting point!
This function takes in two times and returns the relative difference!
Here are a few examples to help: