0

Egypt has reintroduced Day light saving time from April 28, 2023 and We are using Java 11 version in the Spring boot application. DST is not getting applied to the time since it is not enabled in the used tz library. Anyone can help to fix this issue in the java 11 version?

//Code sample:
String tz = TimeZone.getTimeZone(timeZone);
if(tz.useDaylightTime()){ // returning false here 
   // need to add dst here 
   e.g date.plus(tz.dstSavings.toLong(), MILLIS);
}

I had tried to create custom timezone for Egypt only but the application is supporting multiple countries so it wasn't a permanent solution.

Yzee
  • 3
  • 2
  • Can you show some example code? – deHaar May 08 '23 at 08:28
  • Please provide enough code so others can better understand or reproduce the problem. – Community May 08 '23 at 08:57
  • Added the example code – Yzee May 08 '23 at 10:54
  • I strongly recommend that you don’t use `TimeZone`. That class is poorly designed and long outdated. Use `ZoneId` and `ZoneRules` from [java.time, the modern Java date and time API](https://docs.oracle.com/javase/tutorial/datetime/index.html). Not that it answers your question. – Ole V.V. May 08 '23 at 18:20

1 Answers1

1

Use the Timezone Updater tool to update your tzdb database. You can download it here.

Run the jar that you downloaded like this (for the 2023c version, which includes the Egypt DST change):

java -jar tzupdater.jar -l https://data.iana.org/time-zones/releases/tzdata2023c.tar.gz

For other versions, you can find the URLs to use on this page.

After that, you will see that Egypt is indeed in DST:

// today is 2023-05-08
System.out.println(ZoneId.of("Africa/Cairo").getRules().getDaylightSavings(Instant.now()));
// Outputs PT1H, i.e. 1 hour
Sweeper
  • 213,210
  • 22
  • 193
  • 313
  • Take a look at the time functions in this. https://drive.google.com/file/d/1gjHmdC-BW0Q2vXiQYmp1rzPU497sybNy/view?usp=drivesdk – Samuel Marchant May 08 '23 at 09:00
  • Thanks @Sweeper. it worked on my local machine. how can we apply this on higher env? we are using Azure and Kubernetes for here. – Yzee May 08 '23 at 09:16
  • @Yzee I am not familiar with those, but I don't think it would be much different. As far as I know, you can do everything here if you have access to a terminal shell. – Sweeper May 08 '23 at 09:24
  • Note that 2023c breaks a bunch of timezones, notably Europe/Amsterdam (anything before 1980 is suspect. For Europe/Amsterdam, pre-1945. This _will_ cause e.g. the birthdate of folks stored in a h2 database to move by one day). Other than handcrafting a frankenstein tz file I don't know of a fix for this. It's one of those situations where 4 people lightly messed up and everybody is pointing at everybody else. – rzwitserloot May 08 '23 at 10:15