package com.example.mynotepad.MenuFeatures.VoiceMassages.VoiceMassagesRecyclerView;


import java.util.Date;
import java.util.concurrent.TimeUnit;

public class TimeAgo {
    private Date now = new Date();

    public String getTimeAgo(long duration) {
        long seconds = TimeUnit.MILLISECONDS.toSeconds(now.getTime() - duration);
        long minutes = TimeUnit.MINUTES.toMinutes(now.getTime() - duration);
        long hours = TimeUnit.HOURS.toHours(now.getTime() - duration);
        long days = TimeUnit.DAYS.toDays(now.getTime() - duration);
        if (seconds < 60){
            return "just now";
        }
        else if (minutes == 1){
            return "a minute ago";
        }
        else if (minutes >1 && minutes < 60){
            return minutes+" minutes ago";
        }
        else if (hours ==1){
            return "an hour ago";
        }
        else if (hours>1 && hours<24){
            return "hours ago";
        }
        else if (days == 1){
            return  "a day ago";
        }
        else {
            return "days ago";
        }
    }
}
