-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUtils.cs
82 lines (73 loc) · 2.63 KB
/
Utils.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ValleyTube
{
class Utils
{
public static string ConvertUnixTimestampToRelativeTime(long unixTimestamp)
{
DateTimeOffset dateTimeOffset = new DateTimeOffset(1970, 1, 1, 0, 0, 0, TimeSpan.Zero);
DateTimeOffset dateTime = dateTimeOffset.AddSeconds(unixTimestamp);
DateTime dateTimeUtc = dateTime.UtcDateTime;
TimeSpan timeDifference = DateTime.UtcNow - dateTimeUtc;
if (timeDifference.TotalSeconds < 60)
{
return string.Format("{0} seconds ago", (int)timeDifference.TotalSeconds);
}
else if (timeDifference.TotalMinutes < 60)
{
return string.Format("{0} minutes ago", (int)timeDifference.TotalMinutes);
}
else if (timeDifference.TotalHours < 24)
{
return string.Format("{0} hours ago", (int)timeDifference.TotalHours);
}
else if (timeDifference.TotalDays < 30)
{
return string.Format("{0} days ago", (int)timeDifference.TotalDays);
}
else if (timeDifference.TotalDays < 365)
{
return string.Format("{0} months ago", (int)(timeDifference.TotalDays / 30));
}
else
{
return string.Format("{0} years ago", (int)(timeDifference.TotalDays / 365));
}
}
public static string ConvertViewsToShortFormat(long viewCount)
{
if (viewCount >= 1000000000)
{
return (viewCount / 1000000000D).ToString("0.#") + "B";
}
else if (viewCount >= 1000000)
{
return (viewCount / 1000000D).ToString("0.#") + "M";
}
else if (viewCount >= 1000)
{
return (viewCount / 1000D).ToString("0.#") + "k";
}
else
{
return viewCount.ToString();
}
}
public static string AddCommasToNumber(long number)
{
return number.ToString("N0");
}
public static string ConvertKeywordsToCommaSeparated(List<string> keywords)
{
return string.Join(",", keywords);
}
internal static string ConvertUnixTimestampToRelativeTime(string published)
{
throw new NotImplementedException();
}
}
}