Skip to content

Commit

Permalink
fixed files form Time #12
Browse files Browse the repository at this point in the history
  • Loading branch information
tdurieux committed Mar 7, 2017
1 parent 5296138 commit 0df3209
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 7 additions & 1 deletion projects/Time/12/org/joda/time/LocalDate.java
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,10 @@ public static LocalDate fromCalendarFields(Calendar calendar) {
if (calendar == null) {
throw new IllegalArgumentException("The calendar must not be null");
}
int era = calendar.get(Calendar.ERA);
int yearOfEra = calendar.get(Calendar.YEAR);
return new LocalDate(
yearOfEra,
(era == GregorianCalendar.AD ? yearOfEra : 1 - yearOfEra),
calendar.get(Calendar.MONTH) + 1,
calendar.get(Calendar.DAY_OF_MONTH)
);
Expand Down Expand Up @@ -240,7 +241,12 @@ public static LocalDate fromDateFields(Date date) {
if (date == null) {
throw new IllegalArgumentException("The date must not be null");
}
if (date.getTime() < 0) {
// handle years in era BC
GregorianCalendar cal = new GregorianCalendar();
cal.setTime(date);
return fromCalendarFields(cal);
}
return new LocalDate(
date.getYear() + 1900,
date.getMonth() + 1,
Expand Down
8 changes: 7 additions & 1 deletion projects/Time/12/org/joda/time/LocalDateTime.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,10 @@ public static LocalDateTime fromCalendarFields(Calendar calendar) {
if (calendar == null) {
throw new IllegalArgumentException("The calendar must not be null");
}
int era = calendar.get(Calendar.ERA);
int yearOfEra = calendar.get(Calendar.YEAR);
return new LocalDateTime(
yearOfEra,
(era == GregorianCalendar.AD ? yearOfEra : 1 - yearOfEra),
calendar.get(Calendar.MONTH) + 1,
calendar.get(Calendar.DAY_OF_MONTH),
calendar.get(Calendar.HOUR_OF_DAY),
Expand Down Expand Up @@ -233,7 +234,12 @@ public static LocalDateTime fromDateFields(Date date) {
if (date == null) {
throw new IllegalArgumentException("The date must not be null");
}
if (date.getTime() < 0) {
// handle years in era BC
GregorianCalendar cal = new GregorianCalendar();
cal.setTime(date);
return fromCalendarFields(cal);
}
return new LocalDateTime(
date.getYear() + 1900,
date.getMonth() + 1,
Expand Down

0 comments on commit 0df3209

Please sign in to comment.