I am trying to find out from today's UTC date the date of the next Hannukah.
I already found that C# has HebrewCalendar
class and I was able to get the current Jewish date with GetYear()
, GetMonth()
andGetDayOfMonth()
. But don't really know how to work with this information to get the Jewish date that is gonna happen next for the current date.
Hannukah is dated on 25th of Kislev (3rd month in Jewish calendar).
@DmitryBychenko's answer is fine, although if you don't want to loop, you can also calculate it:
var calendar = new HebrewCalendar();
var result = DateTime.UtcNow;
if(
calendar.GetMonth(result) < 3
|| (calendar.GetMonth(result)==3 && calendar.GetDayOfMonth(result)<25)
)
result = new DateTime(calendar.GetYear(result), 3, 25, calendar);
else
result = new DateTime(calendar.GetYear(result)+1, 3, 25, calendar);
If you are under 25/3 on the HebrewCalendar
, use this year, else use next
Result is also 7 Dec 2015 in the gregorian calendar
If (as per the comments) you don't want those pesky if
statements for some reason, you could do something like:
var calendar = new HebrewCalendar();
var result = DateTime.UtcNow;
var addYear = (calendar.GetMonth(result) < 3 || (calendar.GetMonth(result)==3 && calendar.GetDayOfMonth(result)<25)) ? 0 : 1;
result = new DateTime(calendar.GetYear(result) + addYear, 3, 25, calendar);
I don't think this helps readability but there you go
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With