This problem is similar to Ethiopian calender. In
Ethiopian calender[
^], a year contains 13 months, the first 12 months have 30 days,the last month has 5 or 6 days depends on the leap year. New year starts September 11 or 12 based on the leap year so and so forth. So the only solution to work with conversion of datetime from Gregorian to Ethiopian is to implement the
System.Globalization.Calender
abstract class. That is
public sealed class EthiopianCalender : Calendar
{
public override DateTime AddMonths(DateTime time, int months)
{
throw new NotImplementedException();
}
public override int GetHour(DateTime time)
{
return base.GetHour(time);
}
public override int GetSecond(DateTime time)
{
return base.GetSecond(time);
}
public override int GetMinute(DateTime time)
{
return base.GetMinute(time);
}
public override int GetDaysInYear(int year)
{
return base.GetDaysInYear(year);
}
public override DateTime AddDays(DateTime time, int days)
{
return base.AddDays(time, days);
}
public override DateTime AddHours(DateTime time, int hours)
{
return base.AddHours(time, hours);
}
public override DateTime AddMilliseconds(DateTime time, double milliseconds)
{
return base.AddMilliseconds(time, milliseconds);
}
public override DateTime AddMinutes(DateTime time, int minutes)
{
return base.AddMinutes(time, minutes);
}
public override DateTime AddSeconds(DateTime time, int seconds)
{
return base.AddSeconds(time, seconds);
}
public override DateTime AddWeeks(DateTime time, int weeks)
{
return base.AddWeeks(time, weeks);
}
public override int GetLeapMonth(int year)
{
return base.GetLeapMonth(year);
}
public override bool IsLeapDay(int year, int month, int day)
{
return base.IsLeapDay(year, month, day);
}
public override int GetDaysInMonth(int year, int month)
{
return base.GetDaysInMonth(year, month);
}
public override bool IsLeapMonth(int year, int month)
{
return base.IsLeapMonth(year, month);
}
public override bool IsLeapYear(int year)
{
return base.IsLeapYear(year);
}
public override int GetLeapMonth(int year, int era)
{
return base.GetLeapMonth(year, era);
}
public override DateTime AddYears(DateTime time, int years)
{
throw new NotImplementedException();
}
public override double GetMilliseconds(DateTime time)
{
return base.GetMilliseconds(time);
}
public override int GetMonthsInYear(int year)
{
return base.GetMonthsInYear(year);
}
public override int GetWeekOfYear(DateTime time, CalendarWeekRule rule, DayOfWeek firstDayOfWeek)
{
return base.GetWeekOfYear(time, rule, firstDayOfWeek);
}
public override int[] Eras
{
get { throw new NotImplementedException(); }
}
public override DateTime ToDateTime(int year, int month, int day, int hour, int minute, int second, int millisecond)
{
return base.ToDateTime(year, month, day, hour, minute, second, millisecond);
}
public override int ToFourDigitYear(int year)
{
return base.ToFourDigitYear(year);
}
public override int GetDayOfMonth(DateTime time)
{
throw new NotImplementedException();
}
public override DayOfWeek GetDayOfWeek(DateTime time)
{
throw new NotImplementedException();
}
public override int GetDayOfYear(DateTime time)
{
throw new NotImplementedException();
}
public override int GetDaysInMonth(int year, int month, int era)
{
throw new NotImplementedException();
}
public override int GetDaysInYear(int year, int era)
{
throw new NotImplementedException();
}
public override int GetEra(DateTime time)
{
throw new NotImplementedException();
}
public override int GetMonth(DateTime time)
{
throw new NotImplementedException();
}
public override int GetMonthsInYear(int year, int era)
{
throw new NotImplementedException();
}
public override int GetYear(DateTime time)
{
throw new NotImplementedException();
}
public override bool IsLeapDay(int year, int month, int day, int era)
{
throw new NotImplementedException();
}
public override bool IsLeapMonth(int year, int month, int era)
{
throw new NotImplementedException();
}
public override bool IsLeapYear(int year, int era)
{
throw new NotImplementedException();
}
public override DateTime ToDateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, int era)
{
throw new NotImplementedException();
}
}
For example a leap year calculation will be
public override bool IsLeapYear(int year, int era)
{
try
{
if (year < 1)
{
throw new ArgumentOutOfRangeException("year", year, "Year is outside bounds");
}
}
catch (Exception exception)
{
throw exception;
}
return ((year % 4) == 3);
}
Once you finished implement the calender based on
Hebrew
calender, you can use as the same way you use
Gregorian
calender. i.e
EthiopianCalender calender = new EthiopianCalender();
DataTime dateTime = new DateTime(5771, 13, 26, calender.GetHour(Now), calender .GetMinute(Now), calender.GetSecond(Now), new EthiopianCalender())
I hope this will help you as a starting point.