namespace ITArts.SyncFox.Utils
{
using System;
using System.Web;
using System.Text;
using ITArts.SyncFox.Utils;
using System.Web.Query.Dynamic;
public static class DataTimeExtension
{
public static string NumericTxt(int Number,
string nominative, //Именительный падеж
string genitive_singular,//Родительный падеж, единственное число
string genitive_plural) //Родительный падеж, множественное число
{
int[] FormsTable = { 2, 0, 1, 1, 1, 2, 2, 2, 2, 2 };
Number = Math.Abs(Number);
int res = FormsTable[((((Number % 100) / 10) != 1) ? 1 : 0) * (Number % 10)];
switch (res)
{
case 0:
return nominative;
case 1:
return genitive_singular;
default:
return genitive_plural;
}
}
public static string Ago(this DateTime targetUTC)
{
StringBuilder result = new StringBuilder();
TimeSpan diff = (DateTime.Now - targetUTC);
if (diff.Days > 0)
{
result.AppendFormat(NumericTxt(diff.Days,CommonRes.msg_AgoDaysI, CommonRes.msg_AgoDaysR1,CommonRes.msg_AgoDaysRm), diff.Days);
}
if (diff.Hours > 0)
{
if (result.Length > 0)
{
result.Append(", ");
}
result.AppendFormat(NumericTxt(diff.Hours, CommonRes.msg_AgoHoursI, CommonRes.msg_AgoHoursR1, CommonRes.msg_AgoHoursRm), diff.Hours);
}
if (diff.Minutes > 0)
{
if (result.Length > 0)
{
result.Append(", ");
}
result.AppendFormat(NumericTxt(diff.Minutes, CommonRes.msg_AgoMinutesI, CommonRes.msg_AgoMinutesR1, CommonRes.msg_AgoMinutesRm), diff.Minutes);
}
if (result.Length == 0)
{
result.Append(CommonRes.msg_AgoFewMoments);
}
else
{
result.Insert(0, CommonRes.msg_About);
result.AppendFormat(" " + CommonRes.msg_Ago);
}
return result.ToString();
}
}