Date format for posts

Snitz™ Forums .NET Core
https://www.reddick.co.uk/mvc/Topic/Posts/6116?pagenum=1
5/20/2024

Topic


sadra
Date format for posts
5/11/2020


Does anyone have any functionality they would like changing or adding for the next version?نوشته شده توسط HuwR


Hi HuwR
I would be very grateful if you could complete the Persian calendar for display on all pages and in profile birthday

 

Replies ...


sadra
5/21/2020


Ok great, I'll leave it as is for now, and we can test the timeago later, although it will probably be ok now we have the format correct.نوشته شده توسط HuwR


Ok
HuwR
5/21/2020


Ok great, I'll leave it as is for now, and we can test the timeago later, although it will probably be ok now we have the format correct.
sadra
5/21/2020


time fixedنوشته شده توسط HuwR


Tanx HuwR...
It's Ok...
HuwR
5/20/2020


time fixed
sadra
5/19/2020


What do the post dates look like now ?نوشته شده توسط HuwR





A bit...
in RTL page and in long date format: TIME must be show after date same as: 30 اردیبهشت 1399 11:37
HuwR
5/19/2020


that is JavaScript, it is from the calendar plugin smile.

What do the post dates look like now ?
sadra
5/19/2020


this date is true...
this is .NET or javascript fetching?
sadra
5/19/2020


Does the above code help?Originally posted by sadra

Unfortunately not sad, I will try just creating a static array of month names and see if that helps, but I think the server is getting the month wrong somehow.

works fine on both my local servers bigsmile
نوشته شده توسط HuwR


Thanks Mr. Huw
That's enough
The rest can be left to later
You made a good effort
Please switch to a short format and save the changes you made.
HuwR
5/19/2020


Does the above code help?Originally posted by sadra

Unfortunately not sad, I will try just creating a static array of month names and see if that helps, but I think the server is getting the month wrong somehow.

works fine on both my local servers bigsmile
sadra
5/19/2020


Does the above code help?
sadra
5/19/2020


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


sadra
5/19/2020


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;
}
}
HuwR
5/19/2020


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
5/19/2020


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.
sadra
5/19/2020


Are you tired?
I'm sorry to bother you.
sadra
5/19/2020


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.
HuwR
5/19/2020


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
sadra
5/19/2020


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
HuwR
5/19/2020


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
sadra
5/19/2020


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
اسفند

sadra
5/19/2020


@Sadra are the post times now displaying correctly? (long format)نوشته شده توسط HuwR


30 مارس 1399..... this is Persian name of March month
30 اردیبهشت 1399

Hi...
the red mark is incorrect...
this is March
HuwR
5/19/2020


@Sadra are the post times now displaying correctly? (long format)
sadra
5/18/2020


I'm going to move the date format strings to the language resource so they can be formatted better, should have an update later today.نوشته شده توسط HuwR


Ok..
HuwR
5/18/2020


I'm going to move the date format strings to the language resource so they can be formatted better, should have an update later today.
HuwR
5/17/2020


.NET Short date is Ok...
But Long date?!!

Seems to be still a server/calendar problem, it defaults to that format because the Persian calendar is unsupported, not sure why, I will do some more digging.
sadra
5/17/2020


for TimeAgo remember

The problem isn't timeago unfortunately, on my local server the date is correct without timeago: 24 اردیبهشت 1399 11:29
but here it is showing as: 13 مي 2020 09:20نوشته شده توسط HuwR


tanx ...
For now, let's skip the TimeAgo ..

.NET Short date is Ok...
But Long date?!!
I can't see example for Long Date
HuwR
5/16/2020


bingo! I have it displaying the correct date now I think, looks like the server was not loading the calendar for some reason, so have added code to force it to load. can you confirm it is now correct and I will retry enabling timeago as I believe that will work now
HuwR
5/16/2020


for TimeAgo remember

The problem isn't timeago unfortunately, on my local server the date is correct without timeago: 24 اردیبهشت 1399 11:29
but here it is showing as: 13 مي 2020 09:20
HuwR
5/16/2020


timeago should be turned off for Persian, is it still using it?
sadra
5/16/2020


the calendar is a javascript plugin it is nothing to do with .net

Currently, displaying All Dates on pages is only a Persian translation of gregorian date... Not Persian date, only persian translation of date.

Yes, all Displayed dates except JavaScript calendar


You will have to explain with examples since I know nothing about Persian dates. AFIK, this date 13/05/2020 should be shown as ۲۴ اردیبهشت ۱۳۹۹ is that not happening?نوشته شده توسط HuwR


That's true...is not happening...
examples:
Short format: Gregorian: 13/05/2020 should be shown as Persian: 1399/02/24
Persian short format only is yyyy/mm/dd

Long format: Gregorian: 13 May 2020 11:29 should be shown as Persian: 24 اردیبهشت 1399 11:29

End of .NET configuration

-----------------------------------------------------------------------

next point:
for TimeAgo remember:
https://www.reddick.co.uk/mvc/Topic/4846?pagenum=2&archived=0


HuwR
5/13/2020


the calendar is a javascript plugin it is nothing to do with .net

Currently, displaying All Dates on pages is only a Persian translation of gregorian date... Not Persian date, only persian translation of date.

You will have to explain with examples since I know nothing about Persian dates. AFIK, this date 13/05/2020 should be shown as ۲۴ اردیبهشت ۱۳۹۹ is that not happening?
sadra
5/13/2020


looks to me like it isn't loading one of the js files I will take a lookنوشته شده توسط HuwR


The lack of a solar calendar display is not related to the JavaScript file.
but related to the correct .NET support for this calendar.

Currently, displaying All Dates on pages is only a Persian translation of gregorian date... Not Persian date, only persian translation of date.
HuwR
5/11/2020


it wasn't loading one of the language files, have fixed that so some of those may be fixed.
HuwR
5/11/2020


looks to me like it isn't loading one of the js files I will take a look
sadra
5/11/2020


Could you try to explain what is wrong/needs changing and I will try my best, but the calendar display is not my code so can't promise success.نوشته شده توسط HuwR


tanx...
1. The calendar section is no problem
2. Global view Dates on all pages of the site are gregorian date, not solar (Hijri Shamsi or Jalali or Persian) date.
for example: and more


I remember when you first tried this, you ran into a problem with the TimeAgo , and it was decided that we could choose optional the TimeAgo.
HuwR
5/11/2020


Could you try to explain what is wrong/needs changing and I will try my best, but the calendar display is not my code so can't promise success.
© 2016-2024 Snitz™ Forums MVC