65.9K
CodeProject is changing. Read more.
Home

Get the Time in Israel, Including DST

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.37/5 (14 votes)

May 5, 2005

1 min read

viewsIcon

39793

The formula for DST in Israel is unique and based on the Jewish calendar. This function knows how to calculate this formula.

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.

// supply a default
public static DateTime GetIsraelTime() {
    return (GetIsraelTime(DateTime.UtcNow));
}

// input: UTC DateTime object
public static DateTime GetIsraelTime(DateTime d) {
    d = d.AddHours(2);           // Israel is at GMT+2

    // April 2nd, 2:00 AM
    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;
    // Yom HaKipurim, at the start of the next Jewish year, 2:00 AM
    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.