-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHelperExtenions.cs
More file actions
53 lines (42 loc) · 1.55 KB
/
HelperExtenions.cs
File metadata and controls
53 lines (42 loc) · 1.55 KB
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
using AzureDevopsTracker.Data;
using System;
using System.Linq;
namespace AzureDevopsTracker.Extensions
{
public static class HelperExtenions
{
public static bool IsNullOrEmpty(this string text)
{
return string.IsNullOrEmpty(text?.Trim());
}
public static string Truncate(this string value, int maxLength = 8000)
{
if (value.IsNullOrEmpty()) return value;
return value.Length <= maxLength ? value : value[..maxLength];
}
public static string ExtractEmail(this string user)
{
if (user is null)
return user;
if (!user.Contains(" <") && !user.TrimEnd().Contains('>'))
return user;
return user.Split('<').LastOrDefault()?.Split('>')?.FirstOrDefault();
}
public static string ToTextTime(this TimeSpan timeSpan)
{
if (timeSpan.Days > 0)
return $@"{timeSpan:%d} Day(s) {timeSpan:%h} h e {timeSpan:%m} min e {timeSpan:%s} s";
if (timeSpan.Hours > 0)
return $@"{timeSpan:%h} h e {timeSpan:%m} min e {timeSpan:%s} s";
if (timeSpan.Minutes > 0)
return $@"{timeSpan:%m} min e {timeSpan:%s} s";
if (timeSpan.Seconds > 0)
return $@"{timeSpan:%s} s";
return "-";
}
public static DateTime ToDateTimeFromTimeZoneInfo(this DateTime date)
{
return TimeZoneInfo.ConvertTimeFromUtc(date, DataBaseConfig.TimeZoneInfo);
}
}
}