#!/bin/sh

rt() {
    time=$(date -d "${1}" +%s)
    curr=$(date +%s)
    shift=$(($curr - $time));

    if [ $shift -lt 45 ]; then
        diff="$shift"
        term="second" # 45 秒前
    elif [ $shift -lt 2700 ]; then
        diff="$(($shift / 60))"
        term="minute" # 45 分钟前
    elif [ $shift -lt 64800 ]; then
        diff="$(($shift / 60 / 60))"
        term="hour" # 18 小时前
    elif [ $shift -lt 518400 ]; then
        diff="$(($shift / 60 / 60 / 24))"
        term="day" # 6 天前
    elif [ $shift -lt 1814400 ]; then
        diff="$(($shift / 60 / 60 / 24))"
        term="week" # 3 周前 (21 天前)
    fi

    if [ $diff -gt 1 ]; then
        term=$term"s";
    else
        diff="1";
    fi
    echo "$diff $term ago";
}