private static FormatAbstract ( double value, string increment, double lowend, double halfway, double almost, bool future ) : String | ||
value | double | Number of items to evaluate (e.g. days, like 1.4). |
increment | string | Singular form of the text value to display for increments (e.g. "day"). |
lowend | double | Fractional value for determing low end (e.g. 0.4 makes a value of 3.4 "days" render as "3 days ago"). |
halfway | double | Fractional value for determing the maximum halfway point (e.g. 0.6 makes a value of 3.6 "days" render as "over 3 days ago"). |
almost | double | Fractional value for determing when a value should round up (e.g. 0.9 makes a value of 3.9 "days" render as "almost 4 days ago"). |
future | bool | True if the date is in the future. |
return | String |
private static String FormatAbstract(double value, string increment, double lowend, double halfway, double almost, bool future)
{
String abstraction = "";
if (value < (1 + lowend))
{
abstraction = "a " + increment + (future ? " from now" : " ago");
}
else if (value >= (1 + lowend) && value < (1 + halfway))
{
abstraction = "over a " + increment + (future ? " from now" : " ago");
}
else
{
double valuewhole = value - (value % 1);
double mod = (value % 1);
if (mod < lowend)
{
abstraction = valuewhole.ToString() + " " + increment + "s" + (future ? " from now" : " ago");
}
else if (mod >= lowend && mod < halfway)
{
abstraction = (future ? "more than " : "over ") + valuewhole.ToString() + " " + increment + "s" + (future ? " from now" : " ago");
}
else if (mod >= halfway && mod < almost)
{
abstraction = (future ? "about " : "almost ") + (valuewhole + 1).ToString() + " " + increment + "s" + (future ? " from now" : " ago");
}
else if (mod >= almost)
{
abstraction = (valuewhole + 1).ToString() + " " + increment + "s" + (future ? " from now" : " ago");
}
}
return abstraction;
}