Date format for posts

Snitz™ .NET Core
https://www.reddick.co.uk/mvc/Topic/Posts/6116?pagenum=1
Jul 06, 2025 11:51

Topic


sadra
Date format for posts
May 11, 2020 03:52


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 ...


HuwR
5/11/2020 6:41:23 AM..ToLocalTime().ToForumDisplay()


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.
sadra
5/11/2020 9:40:31 AM..ToLocalTime().ToForumDisplay()


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 11:57:34 AM..ToLocalTime().ToForumDisplay()


looks to me like it isn't loading one of the js files I will take a look
HuwR
5/11/2020 3:09:58 PM..ToLocalTime().ToForumDisplay()


it wasn't loading one of the language files, have fixed that so some of those may be fixed.
sadra
5/13/2020 7:54:17 AM..ToLocalTime().ToForumDisplay()


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/13/2020 8:54:23 AM..ToLocalTime().ToForumDisplay()


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/16/2020 6:57:50 AM..ToLocalTime().ToForumDisplay()


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/16/2020 11:15:49 AM..ToLocalTime().ToForumDisplay()


timeago should be turned off for Persian, is it still using it?
HuwR
5/16/2020 11:53:16 AM..ToLocalTime().ToForumDisplay()


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 12:52:12 PM..ToLocalTime().ToForumDisplay()


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
sadra
5/17/2020 6:41:03 AM..ToLocalTime().ToForumDisplay()


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/17/2020 2:59:50 PM..ToLocalTime().ToForumDisplay()


.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.
HuwR
5/18/2020 7:47:11 AM..ToLocalTime().ToForumDisplay()


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.
sadra
5/18/2020 9:05:46 AM..ToLocalTime().ToForumDisplay()


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/19/2020 10:37:23 AM..ToLocalTime().ToForumDisplay()


@Sadra are the post times now displaying correctly? (long format)
sadra
5/19/2020 11:00:41 AM..ToLocalTime().ToForumDisplay()


@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
sadra
5/19/2020 11:18:29 AM..ToLocalTime().ToForumDisplay()


Month names:
Month NoMonth Name - GerigurianMonth Name - Persian
1Januaryفروردیدن
2Februaryاردیبهشت
3Marchخرداد
4Aprilتیر
5Mayمرداد
6Juneشهریور
7Julyمهر
8Augustآبان
9Septemberآذر
10Octoberدی
11Novemberبهمن
12Decemberاسفند
HuwR
5/19/2020 11:19:52 AM..ToLocalTime().ToForumDisplay()


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 11:20:25 AM..ToLocalTime().ToForumDisplay()


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 11:29:40 AM..ToLocalTime().ToForumDisplay()


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 11:38:08 AM..ToLocalTime().ToForumDisplay()


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.
sadra
5/19/2020 11:44:18 AM..ToLocalTime().ToForumDisplay()


Are you tired? I'm sorry to bother you.
HuwR
5/19/2020 11:45:02 AM..ToLocalTime().ToForumDisplay()


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.
HuwR
5/19/2020 11:46:36 AM..ToLocalTime().ToForumDisplay()


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.
sadra
5/19/2020 11:52:40 AM..ToLocalTime().ToForumDisplay()


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;
}
}
sadra
5/19/2020 11:54:05 AM..ToLocalTime().ToForumDisplay()


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 11:55:03 AM..ToLocalTime().ToForumDisplay()


Does the above code help?
HuwR
5/19/2020 12:49:36 PM..ToLocalTime().ToForumDisplay()


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 2:50:21 PM..ToLocalTime().ToForumDisplay()


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.
sadra
5/19/2020 3:11:13 PM..ToLocalTime().ToForumDisplay()


this date is true... this is .NET or javascript fetching?
HuwR
5/19/2020 5:29:00 PM..ToLocalTime().ToForumDisplay()


that is JavaScript, it is from the calendar plugin smile.
What do the post dates look like now ?
sadra
5/19/2020 5:53:31 PM..ToLocalTime().ToForumDisplay()


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/20/2020 12:23:33 PM..ToLocalTime().ToForumDisplay()


time fixed
sadra
5/21/2020 6:03:42 AM..ToLocalTime().ToForumDisplay()


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

Tanx HuwR... It's Ok...
HuwR
5/21/2020 7:27:35 AM..ToLocalTime().ToForumDisplay()


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 11:10:03 AM..ToLocalTime().ToForumDisplay()


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
© 2016-2025 Snitz™ Forums MVC