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).
As it was suggested on Twitter, here's a Noda Time solution:
// As of 2.0, it will be CalendarSystem.HebrewCivil
var calendar = CalendarSystem.GetHebrewCalendar(HebrewMonthNumbering.Civil);
var today = SystemClock.Instance.InZone(DateTimeZone.Utc, calendar).Date;
var thisHannukah = new LocalDate(today.Year, 3, 25, calendar);
return thisHannukah >= today ? thisHannukah : thisHannukah.PlusYears(1);
Alternative for the last two statements:
var year = today.Month < 3 || today.Month == 3 && today.Day <= 25
? today.Year : today.Year + 1;
return new LocalDate(year, 3, 25, calendar);
If we go ahead with feature request 317, this could be much simpler. For example:
// Putative API only! Doesn't work yet!
MonthDay hannukah = new MonthDay(3, 25, calendar);
var nextHannukah = hannukah.NextOrSame(today);
See more on this question at Stackoverflow