HighTechTalks DotNet Forums  

Bug in PersianCalendar.ToDateTime

Dotnet Internationalization microsoft.public.dotnet.internationalization


Discuss Bug in PersianCalendar.ToDateTime in the Dotnet Internationalization forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
kourosh
 
Posts: n/a

Default Bug in PersianCalendar.ToDateTime - 04-13-2006 , 03:09 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


Reply With Quote
  #2  
Old   
DLasheen
 
Posts: n/a

Default RE: Bug in PersianCalendar.ToDateTime - 04-25-2006 , 08:36 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:
Quote:
DateTime dt2 = jc.ToDateTime(thisDate.Year, thisDate.Month,
thisDate.Day, 20, 30, 15, 500,
System.Globalization.PersianCalendar.PersianEra);
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.


"kourosh" wrote:

Quote:
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


Reply With Quote
  #3  
Old   
kourosh
 
Posts: n/a

Default RE: Bug in PersianCalendar.ToDateTime - 06-01-2006 , 07:14 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?

"DLasheen" wrote:

Quote:
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:
DateTime dt2 = jc.ToDateTime(thisDate.Year, thisDate.Month,
thisDate.Day, 20, 30, 15, 500,
System.Globalization.PersianCalendar.PersianEra);

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.


"kourosh" wrote:

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


Reply With Quote
  #4  
Old   
DLasheen
 
Posts: n/a

Default RE: Bug in PersianCalendar.ToDateTime - 06-10-2006 , 08:31 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

"kourosh" wrote:

Quote:
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?

"DLasheen" wrote:

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:
DateTime dt2 = jc.ToDateTime(thisDate.Year, thisDate.Month,
thisDate.Day, 20, 30, 15, 500,
System.Globalization.PersianCalendar.PersianEra);

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.


"kourosh" wrote:

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


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.