Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Periods with extremely long durations behave differently for UTC #436

Open
mccartney opened this issue Jul 21, 2017 · 1 comment
Open

Periods with extremely long durations behave differently for UTC #436

mccartney opened this issue Jul 21, 2017 · 1 comment

Comments

@mccartney
Copy link

mccartney commented Jul 21, 2017

Key information

  • Joda-Time version: 2.9.3

Program

import org.joda.time.*;

public class PeriodMain {

  public static void main(String[] argv) {
     System.out.println(java.util.TimeZone.getDefault().getDisplayName());
     System.out.println(org.joda.time.DateTimeZone.getDefault());
  
     long period = 10000000000000000L;
     new Period(period, PeriodType.yearDayTime()).normalizedStandard(PeriodType.dayTime());
   }
}

Problem description

The program above behaves differently depending on the time zone. It works for UTC, while it fails with (what seems) any other time zone.

Test case

  1. Success
# TZ=Etc/UTC java -cp ./joda-time-2.9.3.jar:. PeriodMain
Picked up _JAVA_OPTIONS: -Djava.awt.headless=true
Coordinated Universal Time
Etc/UTC
  1. Failure
# TZ=Europe/Warsaw java -cp ./joda-time-2.9.3.jar:. PeriodMain 
Picked up _JAVA_OPTIONS: -Djava.awt.headless=true
Central European Time
Europe/Warsaw
Exception in thread "main" java.lang.ArithmeticException: Value cannot fit in an int: 2777777777
		at org.joda.time.field.FieldUtils.safeToInt(FieldUtils.java:206)
		at org.joda.time.field.BaseDurationField.getDifference(BaseDurationField.java:141)
		at org.joda.time.chrono.ZonedChronology$ZonedDurationField.getDifference(ZonedChronology.java:343)
		at org.joda.time.chrono.BaseChronology.get(BaseChronology.java:285)
		at org.joda.time.base.BasePeriod.<init>(BasePeriod.java:258)
		at org.joda.time.Period.<init>(Period.java:402)
		at PeriodMain.main(PeriodMain.java:11)

Other time zones fail similarly: America/Chicago, etc.

@deivitaka
Copy link

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants