Click here to Skip to main content
Licence 
First Posted 4 May 2005
Views 29,748
Bookmarked 11 times

Get the time in Israel, including DST

By | 4 May 2005 | Article
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

About the Author

YoniP

Software Developer (Senior)

Israel Israel

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionWhat perfect timing PinmemberAshaman3:14 10 May '05  
GeneralThank You Pinmemberdl4gbe9:17 5 May '05  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120517.1 | Last Updated 5 May 2005
Article Copyright 2005 by YoniP
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid