Introduction
The entailed function calculates the correct time in Israel, based on the derivation from GMT (Greenwich Mean Time) and DST (Daylight Summer Time).
Background
The basic calendar in Israel is the Jewish one, not the Gregorian one. The Jewish holidays start at sunset. So adding one hour to the clock postpones the holiday to start later, which is difficult for the kids. Another deviation of the Jewish calendar is that the Israeli weekend is Friday and Saturday instead of Saturday and Sunday.
Over the last 60 years, a ministerial clerk used to determine the beginning and end of DST each single year. It caused many problems - to airline companies, conference organizers and to us - the developers.
This year, a new law was approved, which makes end to this story. From 2005, the DST will start on last Friday before April 2nd, and finish on last Sunday before Yom HaKipurim - the holiest Jewish day (which is also a fast day). Both times are at 2:00 AM.
Using the Code
The function takes this formula and calculates the correct time in Israel.
public static DateTime GetIsraelTime() {
return (GetIsraelTime(DateTime.UtcNow));
}
public static DateTime GetIsraelTime(DateTime d) {
d = d.AddHours(2);
DateTime DSTStart = new DateTime(d.Year, 4, 2, 2, 0 ,0);
while (DSTStart.DayOfWeek != DayOfWeek.Friday)
DSTStart = DSTStart.AddDays(-1);
CultureInfo jewishCulture = CultureInfo.CreateSpecificCulture("he-IL");
System.Globalization.HebrewCalendar cal =
new System.Globalization.HebrewCalendar();
jewishCulture.DateTimeFormat.Calendar = cal;
DateTime DSTFinish =
new DateTime(cal.GetYear(DSTStart)+1, 1, 10, 2, 0 ,0, cal);
while (DSTFinish.DayOfWeek != DayOfWeek.Sunday)
DSTFinish= DSTFinish.AddDays(-1);
if (d>DSTStart && d<DSTFinish)
d = d.AddHours(1);
return (d);
}
License
This article has no explicit license attached to it, but may contain usage terms in the article text or the download files themselves. If in doubt, please contact the author via the discussion board below.
A list of licenses authors might use can be found here.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.