Playing with Arabic date

Photo by Anna Jahn on Unsplash

Playing with Arabic date

First of all, you have to get a request as a native character (e.g.: ١٩.٠٥.٢٠٢٣)

URL : http://localhost/test.aspx?date=١٩.٠٥.٢٠٢٣

public static string GetQueryStringValueFromRawUrl(string queryStringKey)
{
    var currentUri = new Uri(HttpContext.Current.Request.Url.Scheme + "://" +
        HttpContext.Current.Request.Url.Authority +
        HttpContext.Current.Request.RawUrl);
    var queryStringCollection = HttpUtility.ParseQueryString((currentUri).Query);
    return queryStringCollection.Get(queryStringKey);
}

Second, get the int value of each item;

public static DateTime ArabicDate(string str)
{
    string[] teslim = str.Split('.');
    return new DateTime(getIntofArabicValue(teslim[2]), getIntofArabicValue(teslim[1]), getIntofArabicValue(teslim[0]));
}

static int getIntofArabicValue(string str)
{
    return Int32.Parse(string.Join("", str.Select(c => char.GetNumericValue(c))));
}

Then you can call the function;

PublicFunctions.ArabicDate(PublicFunctions.GetQueryStringValueFromRawUrl("date").Replace("'", ""));