Groups | Blog | Home
all groups > dotnet internationalization > april 2006 >

dotnet internationalization : Bug in PersianCalendar.ToDateTime


kourosh
4/13/2006 12:09:02 PM
As you see in code below The answer of code in last line must be:
Persian calendar: 5/30/1383 8:30:15 PM
But It is:
Persian calendar: 11/11/2625 8:30:15 PM
How can I avoid this BUG?

// Start Of Code
System.Globalization.PersianCalendar jc = new
System.Globalization.PersianCalendar();
DateTime thisDate = new DateTime(2004, 8, 20);
Console.WriteLine("GetMonth: month = {0}", jc.GetMonth(thisDate));
Console.WriteLine("GetDayOfMonth: month = {0}", jc.GetDayOfMonth(thisDate));
Console.WriteLine("GetYear: year = {0}", jc.GetYear(thisDate));
DateTime dt1 = new DateTime(thisDate.Year, thisDate.Month, thisDate.Day, 20,
30, 15, 500);
DateTime dt2 = jc.ToDateTime(thisDate.Year, thisDate.Month, thisDate.Day,
20, 30, 15, 500, System.Globalization.PersianCalendar.PersianEra);
Console.WriteLine("Gregorian calendar: {0}\n" + "Persian calendar: {1}",
dt1, dt2);
// End Of Code
DLasheen
4/25/2006 5:36:02 AM
There is inconsistency in the code:
1 - When you fill the datetime in the following line, you are actually
passing Gregorian date instead of Persian dates:
[quoted text, click to view]

You should pass the Persian dates and not Gregorian date, for example your
code should look like this:
DateTime dt2 = jc.ToDateTime(jc.GetYear(thisDate), jc.GetMonth(thisDate),
jc.GetDayOfMonth(thisDate), 20, 30, 15, 500,
System.Globalization.PersianCalendar.PersianEra);

All dates, irrespective of the calendar, are stored in the same manner. So
if you want to display non-Gregorian date, then you need to specify it.
You are simply printing the DateTime and this default to Gregorian.

The PersianCalendar is not a full calendar in .NET framework 2.0. So you
can't parse dates using it.


[quoted text, click to view]
kourosh
6/1/2006 4:14:02 AM
Dear Dlasheen,
I try with syntax that you write, but the result is false, jc.ToDateTime
convert persian calendar to Gregorian Calendar for example it convert:
1385/03/11 -> 2006/06/01.
How can I show persian calendar using: dt2?

[quoted text, click to view]
DLasheen
6/10/2006 5:31:02 AM
You have to explicitly use dt2 in the persian calendar.
For example use the code below to display the date using the format
"dd/mm/yy".
textBox1.Text = jc.GetDayOfMonth(dt2) + "/" + jc.GetMonth(dt2) + "/" +
jc.GetYear(dt2);
This should give you the expected output

[quoted text, click to view]
AddThis Social Bookmark Button