65 lines
1.6 KiB
C#
65 lines
1.6 KiB
C#
using System.Text.RegularExpressions;
|
|
|
|
namespace ReportingServices.Shared.Blazor.HelperClasses;
|
|
|
|
public static class APIHelperFunctions
|
|
{
|
|
public static string GetBeginningOfWeekAsAPIString()
|
|
{
|
|
DateTime date = DateTime.Now;
|
|
|
|
int dayOfWeek = (int)date.DayOfWeek;
|
|
|
|
date = dayOfWeek switch
|
|
{
|
|
0 => date.AddDays(-6),
|
|
1 => date,
|
|
_ => date.AddDays(1 - dayOfWeek)
|
|
};
|
|
|
|
return GetDateTimeAsAPIString(date.ToString(), false);
|
|
}
|
|
|
|
public static string GetDateWithOffsetAsAPIString(string dateString, float offset)
|
|
{
|
|
DateTime date = DateTime.Parse(dateString);
|
|
|
|
date = date.AddHours(offset);
|
|
|
|
return GetDateTimeAsAPIString(date.ToString(), true);
|
|
}
|
|
|
|
public static string GetDateTimeAsAPIString(string dateString, bool fullDateTime)
|
|
{
|
|
DateTime date = DateTime.Parse(dateString);
|
|
|
|
if (fullDateTime)
|
|
dateString = date.ToString("yyyy-M-d HH:mm:ss");
|
|
else
|
|
dateString = date.Year + "-" + date.Month + "-" + date.Day + " 0:0:0";
|
|
|
|
return dateString;
|
|
}
|
|
|
|
public static List<T> ReverseList<T>(List<T> inputList)
|
|
{
|
|
List<T> temp = new();
|
|
|
|
for (int i = inputList.Count - 1; i >= 0; i--)
|
|
{
|
|
temp.Add(inputList[i]);
|
|
}
|
|
|
|
return temp;
|
|
}
|
|
|
|
public static string SplitOnCamelCase(string input)
|
|
{
|
|
Regex r = new(@"
|
|
(?<=[A-Z])(?=[A-Z][a-z]) |
|
|
(?<=[^A-Z])(?=[A-Z]) |
|
|
(?<=[A-Za-z])(?=[^A-Za-z])", RegexOptions.IgnorePatternWhitespace);
|
|
|
|
return r.Replace(input, " ");
|
|
}
|
|
} |