Sort direction, for dates DESC means newest first    Page size 
Posted
Average Member
/mvc/ProtectedContent/Avatar/sadra132338283059455318.jpg
Posts: 350
starstarstar
Are you tired?
I'm sorry to bother you.
Originally posted by sadra

That's ok, you can bother me as much as you want in order to sort it out smile fortunately have plenty of time at the moment, but that may not be the case next month.نوشته شده توسط HuwR


Posted
Average Member
/mvc/ProtectedContent/Avatar/sadra132338283059455318.jpg
Posts: 350
starstarstar
using System;
using System.Globalization;
using System.Reflection;
using System.Threading;

public class Cultures
{
public static void InitializePersianCulture()
{
InitializeCulture("fa-ir", new[] { "ی", "د", "س", "چ", "پ", "ج", "ش" },
new[] { "یکشنبه", "دوشنبه", "سه شنبه", "چهارشنبه", "پنجشنبه", "جمعه", "شنبه" },
new[]
{
"فروردین", "اردیبهشت", "خرداد", "تیر", "مرداد", "شهریور", "مهر", "آبان", "آذر", "دی",
"بهمن", "اسفند", ""
},
new[]
{
"فروردین", "اردیبهشت", "خرداد", "تیر", "مرداد", "شهریور", "مهر", "آبان", "آذر", "دی",
"بهمن", "اسفند", ""
}, "ق.ظ. ", "ب.ظ. ", "yyyy/MM/dd", new PersianCalendar());
}

public static void InitializeCulture(string culture, string[] abbreviatedDayNames, string[] dayNames,
string[] abbreviatedMonthNames, string[] monthNames, string amDesignator,
string pmDesignator, string shortDatePattern, Calendar calendar)
{
var calture = new CultureInfo(culture);
var info = calture.DateTimeFormat;
info.AbbreviatedDayNames = abbreviatedDayNames;
info.DayNames = dayNames;
info.AbbreviatedMonthNames = abbreviatedMonthNames;
info.MonthNames = monthNames;
info.AMDesignator = amDesignator;
info.PMDesignator = pmDesignator;
info.ShortDatePattern = shortDatePattern;
info.FirstDayOfWeek = DayOfWeek.Saturday;
var cal = calendar;
var type = typeof(DateTimeFormatInfo);
var fieldInfo = type.GetField("calendar", BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic);
if (fieldInfo != null)
fieldInfo.SetValue(info, cal);
var field = typeof(CultureInfo).GetField("calendar", BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic);
if (field != null)
field.SetValue(calture, cal);
Thread.CurrentThread.CurrentCulture = calture;
Thread.CurrentThread.CurrentUICulture = calture;
CultureInfo.CurrentCulture.DateTimeFormat = info;
CultureInfo.CurrentUICulture.DateTimeFormat = info;
}
}
Posted
Forum Administrator
/mvc/ProtectedContent/Avatar/HuwR132430879466080654.jpg
Posts: 4393
starstarstarstarstar
Are you tired?
I'm sorry to bother you.
Originally posted by sadra

That's ok, you can bother me as much as you want in order to sort it out smile fortunately have plenty of time at the moment, but that may not be the case next month.
Posted
Forum Administrator
/mvc/ProtectedContent/Avatar/HuwR132430879466080654.jpg
Posts: 4393
starstarstarstarstar
Unfortunately the problem is that on the server it is not in the normal list of supported calendars so you can't just use the normal formatting of .net you have to construct the result manually (it's a real pain) however, I think it is good now, the month problem was me, I was getting the month number and then indexing the month name array using that, but I needed to do month-1 smile for the index as it is a 0 based array.
Posted
Average Member
/mvc/ProtectedContent/Avatar/sadra132338283059455318.jpg
Posts: 350
starstarstar
Are you tired?
I'm sorry to bother you.
Posted
Average Member
/mvc/ProtectedContent/Avatar/sadra132338283059455318.jpg
Posts: 350
starstarstar
what should for example 13 May 2020 be in Persian ? just so I can test some dates.

We may need to put the months in as resource, I'll let you know how I get on. It is just difficult to test locally as the calendars behave completely differently and all works fine on my local server, so I suspect it is the server version here that is the issue sadنوشته شده توسط HuwR


1. 13 May 2020 ==== 24 اردیبهشت 1399
2. I think that the Persian calendar is present in the .NET Framework by default and is probably independent of the server calendar. But I don't know how to use it.
Everything is ok but one, just one step away from the rest of the items. And that is the name of the Persian months.
Posted
Forum Administrator
/mvc/ProtectedContent/Avatar/HuwR132430879466080654.jpg
Posts: 4393
starstarstarstarstar
what should for example 13 May 2020 be in Persian ? just so I can test some dates.

We may need to put the months in as resource, I'll let you know how I get on. It is just difficult to test locally as the calendars behave completely differently and all works fine on my local server, so I suspect it is the server version here that is the issue sad
Posted
Average Member
/mvc/ProtectedContent/Avatar/sadra132338283059455318.jpg
Posts: 350
starstarstar
See the above...
Does the table above help?

If we can add the names of the months in the language resources .. maybe the problem will be solved
Posted
Forum Administrator
/mvc/ProtectedContent/Avatar/HuwR132430879466080654.jpg
Posts: 4393
starstarstarstarstar
could you tell me what the date is in English and what it should be in Persian. unfortunately I don't know what they should be so am just taking a stab in the dark smile

It may not even be possible to fix this on the server unfortunately, the persian calendar does not appear to give me month names just numbers smile
Posted
Average Member
/mvc/ProtectedContent/Avatar/sadra132338283059455318.jpg
Posts: 350
starstarstar
Month names:


Month No
Month Name - Gerigurian
Month Name - Persian
1
January
فروردیدن
2
February
اردیبهشت
3
March
خرداد
4
April
تیر
5
May
مرداد
6
June
شهریور
7
July
مهر
8
August
آبان
9
September
آذر
10
October
دی
11
November
بهمن
12
December
اسفند

You Must enter a message