The loss of the day when the translation of the Gregorian date to Um al-Kura

I had a problem getting the components of the day, month and year of a C # DateTime object using the Um al Qura calendar.

Code snippet:

DateTime date = new DateTime(2013, 6, 24); UmAlQuraCalendar umAlQuraCalendar = new UmAlQuraCalendar(); int year = umAlQuraCalendar.GetYear(date); int month = umAlQuraCalendar.GetMonth(date); int day = umAlQuraCalendar.GetDayOfMonth(date); 

After the launch of this year there will be 1434, and the month will be 8, which is correct. However, day 14, which is incorrect (according to here: http://www.al-habib.info/islamic-calendar/islamic-calendar-ummulqura-2013.htm )

If I changed the code to:

 DateTime date = new DateTime(2013, 6, 24, 0, 0, 0, 1); // ie One millisecond after midnight UmAlQuraCalendar umAlQuraCalendar = new UmAlQuraCalendar(); int year = umAlQuraCalendar.GetYear(date); int month = umAlQuraCalendar.GetMonth(date); int day = umAlQuraCalendar.GetDayOfMonth(date); 

Then the day is 15, which is true.

To make the situation more complicated, this code is at the back of a large application: C # code is called from exe VB6.

If I extract the first fragment above into a standalone C # project (.NET 2.0), then the day will be 15, which is true.

I checked everything I could think that might differ between the two projects: the .NET version, the target platform platform (x86), but cannot see anything obvious.

Any thoughts were greatly appreciated.

+4
source share
2 answers

I checked your code:

 DateTime date = new DateTime(2013, 6, 24); UmAlQuraCalendar umAlQuraCalendar = new UmAlQuraCalendar(); int year = umAlQuraCalendar.GetYear(date); int month = umAlQuraCalendar.GetMonth(date); int day = umAlQuraCalendar.GetDayOfMonth(date); Log.Info(string.Format("{0} / {1} / {2}", year, month, day)); 

In .NET 4.5 and I get 1434 / 8 / 15 as a response. This seems to be a bug in .NET 2.0.

Also check if there is umAlQuraCalendar.AlgorithmType LunarCalendar (This should be so). Because if it is a LunisolarCalendar , there may be some slight differences.

0
source

The solution for this is to use a configuration value of +1 or -1 day, and then add this value to the estimated date to fix it.

0
source

Source: https://habr.com/ru/post/1488029/


All Articles