hroptatyr / dateutils

nifty command line date and time utilities; fast date calculations and conversion in the shell
http://www.fresse.org/dateutils/
Other
601 stars 40 forks source link

Human readable datediff: "2 days ago" #154

Open minfrin opened 10 months ago

minfrin commented 10 months ago

Is there a way to show human readable date differences?

Most specifically, given the expiry date of a certificate, I can get raw output of number of days until expiry or after expiry, positive or negative.

Is there a way to provide separate formats for positive results (eg "Expires in $d days"), exact results (eg "Expires today), and negative results (eg "Expired 2 days ago")?

hroptatyr commented 10 months ago

Hi, no there is not. Can you maybe use awk to do what you desire?

$ echo 4 | awk '$0 = $1 > 0 ? "Expires in "$1" days" : $1 < 0 ? "Expired " ""-$1" days ago" : "Expires today"'
Expires in 4 days

$ echo -4  | awk '$0 = $1 > 0 ? "Expires in "$1" days" : $1 < 0 ? "Expired " ""-$1" days ago" : "Expires today"'
Expired 4 days ago