package com.censoredsoftware.library.util;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.TimeUnit;

public class Times
{
	/**
	 * Return the seconds since the provided time.
	 *
	 * @param time The provided time.
	 * @return Seconds.
	 */
	public static double getSeconds(long time)
	{
		return (double) TimeUnit.MILLISECONDS.toSeconds(time - System.currentTimeMillis());
	}

	/**
	 * Return the minutes since the provided time.
	 *
	 * @param time The provided time.
	 * @return Minutes.
	 */
	public static double getMinutes(long time)
	{
		return (double) TimeUnit.MILLISECONDS.toMinutes(time - System.currentTimeMillis());
	}

	/**
	 * Return the hours since the provided time.
	 *
	 * @param time The provided time.
	 * @return Hours.
	 */
	public static double getHours(long time)
	{
		return (double) TimeUnit.MILLISECONDS.toHours(time - System.currentTimeMillis());
	}

	/**
	 * Return a readable String of the amount of time since a provided time.
	 *
	 * @param time  The provided time.
	 * @param round Round to an int.
	 * @return The readable String.
	 */
	public static String getTimeTagged(long time, boolean round)
	{
		DecimalFormat format = round ? new DecimalFormat("#") : new DecimalFormat("#.##");
		if(getHours(time) >= 1) return format.format(getHours(time)) + "h";
		else if(Double.valueOf(format.format(getMinutes(time))) >= 1) return format.format(getMinutes(time)) + "m";
		else return format.format(getSeconds(time)) + "s";
	}

	public static String prettyDate(long time)
	{
		long diff = (System.currentTimeMillis() - time) / 1000;
		double day_diff = Math.floor(diff / 86400);

		if(day_diff == 0 && diff < 60) return "just now";
		if(diff < 120) return "1 minute ago";
		if(diff < 3600) return Math.floor(diff / 60) + " minutes ago";
		if(diff < 7200) return "1 hour ago";
		if(diff < 86400) return Math.floor(diff / 3600) + " hours ago";
		if(day_diff == 1) return "Yesterday";
		if(day_diff < 7) return day_diff + " days ago";
		if(day_diff < 31) return Math.ceil(day_diff / 7) + " weeks ago";

		return new SimpleDateFormat("yyyy-MM-dd").format(new Date(time));
	}
}

@@ -402,23 +402,16 @@
 Seconds(
-time - 
 System.c
@@ -420,32 +420,39 @@
 rentTimeMillis()
+ - time
 );%0A%09%7D%0A%0A%09/**%0A%09 * 
@@ -657,23 +657,16 @@
 Minutes(
-time - 
 System.c
@@ -675,32 +675,39 @@
 rentTimeMillis()
+ - time
 );%0A%09%7D%0A%0A%09/**%0A%09 * 
@@ -908,15 +908,8 @@
 urs(
-time - 
 Syst
@@ -930,16 +930,23 @@
 Millis()
+ - time
 );%0A%09%7D%0A%0A%09

Fix time diffs being negative.