0

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
Arvind Kumar Avinash
  • 71,965
  • 6
  • 74
  • 110
  • 1
    I think your schedule is not broken. Instead, it considers there is no 2 am at that very day (when daylight saving makes one hour disappear, the clock goes from 1:59 am directly to 3 am). – deHaar Mar 25 '21 at 15:40
  • Well, if you really want to ignore the offset, use a `java.time.LocalDateTime` (don't know if there's an equivalent in JodaTime). – deHaar Mar 25 '21 at 16:12
  • But half an hour after 01:30 it *was* 03:00. Are you saying that you want to schedule non-existing times? Why? – Ole V.V. Mar 28 '21 at 15:43
  • 1
    @deHaar As the answer says, there is a like-named equivalent to `java.time.LocalDateTime` in `org.joda.time.LocalDateTime`. – Ole V.V. Mar 28 '21 at 15:46
  • Or to ask differently: What *precisely* is your desired output? Please give both time and UTC offset for each desired output time (if I understand correctly that you want both). – Ole V.V. Mar 28 '21 at 18:06

1 Answers1

1

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.

Arvind Kumar Avinash
  • 71,965
  • 6
  • 74
  • 110