JodaTime and Daylight saving time

I develop a custom schedule calendar, with 30 minutes gap, so when i generetae this by adding 30 minutes:

date = date.plusMinutes(minuteStep)

so in moment when our time zone switch to Daylight saving time, jodatime add 1 hour to current time and in this case my schedule got broken, it's posibile to exclude this offset?. Thank's

example:

2021-03-28T00:00:00.000+02:00
2021-03-28T00:30:00.000+02:00
2021-03-28T01:00:00.000+02:00
2021-03-28T01:30:00.000+02:00

and just after this i got:

2021-03-28T03:00:00.000+03:00

Upvotes: 0

Views: 724

Answers (1)

Arvind Kumar Avinash
Arvind Kumar Avinash

Reputation: 79095

It looks like you are using org.joda.time.DateTime which is the wrong class for this requirement. The right class for this requirement would be org.joda.time.LocalDate.

org.joda.time.LocalTime is useful for representing human-based date-time, such as movie times, or the opening and closing times of the local library, or to create a digital clock etc. LocalDateTime, a combination of LocalDate with LocalTime, can be used to represent a specific event, such as the first race for the Louis Vuitton Cup Finals in America's Cup Challenger Series, which began at 1:10 p.m. on August 17, 2013. Note that this means 1:10 p.m. in local time. (Source)

Switching to org.joda.time.LocalDate should fix the issue. However, check the following notice at the Home Page of Joda-Time

Joda-Time is the de facto standard date and time library for Java prior to Java SE 8. Users are now asked to migrate to java.time (JSR-310).

Therefore, I suggest you switch to the modern date-time API* . You can learn about the modern date-time API from Trail: Date Time.


* For any reason, if you have to stick to Java 6 or Java 7, you can use ThreeTen-Backport which backports most of the java.time functionality to Java 6 & 7. If you are working for an Android project and your Android API level is still not compliant with Java-8, check Java 8+ APIs available through desugaring and How to use ThreeTenABP in Android Project.

Upvotes: 1

Related Questions