Make a algorithm / formula to calculate the Chinese date from a gregorian date for the year 2020.
Answers
Formula to calculate the Chinese date from a gregorian date for the year 2020.
- This is a C language code u can execute it in CODE-BLOCK or Turbo C/C++.
private void ChineasedateOccurances(DateTime startDate, DateTime endDate, List<ObservedHoliday> observedHolidays, StandardHoliday holiday)
{
for (DateTime date = startDate; date <= endDate; date = date.AddYears(1))
{
#region Finding the Day of Easter Algorithm
int day, month;
int firstTwo = date.Year / 100;
int remainderMod = date.Year % 19;
int pfmDate = (firstTwo - 15) / 2 + 202 - 11 * remainderMod;
#region switches
switch (firstTwo)
{
case 21:
case 24:
case 25:
case 27:
case 28:
case 29:
case 30:
case 31:
case 32:
case 34:
case 35:
case 38:
pfmDate = pfmDate - 1;
break;
case 33:
case 36:
case 37:
case 39:
case 40:
pfmDate = pfmDate - 2;
break;
}
#endregion
pfmDate = pfmDate % 30;
int tA = pfmDate + 21;
if (pfmDate == 29)
tA = tA - 1;
if (pfmDate == 29 && remainderMod > 10)
tA = tA - 1;
//Find next sunday
int tB = (tA - 19) % 7;
int tC = (40 - firstTwo) % 4;
if (tC == 3 || tC > 1)
tC = tC + 1;
pfmDate = date.Year % 100;
int tD = (pfmDate + pfmDate / 4) % 7;
int tE = ((20 - tB - tC - tD) % 7) + 1;
day = tA + tE;
if (day > 31)
{
day = day - 31;
month = 4;
}
else
{
month = 3;
}
#endregion
DateTime observed = new DateTime(date.Year, month, day).AddDays(-2);
ObservedHoliday obsdate = new ObservedHoliday(holiday);
if (startDate == endDate && startDate.Day == observed.Day)
{
obsdate.DateObserved = observed;
observedHolidays.Add(obsdate);
}
else if (startDate != endDate && observed >= startDate)
{
obsdate.DateObserved = observed;
observedHolidays.Add(obsdate);
}
}
Finally u can take what-ever u want.