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

Conversion problem between org.joda.time.LocalDate and java.sql.Date field for dates before Jan 2 1900 #1652

Closed
TRoorda opened this issue Mar 13, 2019 · 0 comments
Assignees
Labels
Milestone

Comments

@TRoorda
Copy link

TRoorda commented Mar 13, 2019

Expected behavior

Conversion between org.joda.time.LocalDate and java.sql.Date result in the same date.

Actual behavior

Conversion between org.joda.time.LocalDate and java.sql.Date of dates before Feb 2nd 1900 are one day off. For instance 1899-12-01 is converted to 1899-11-30. This is tested and confirmed wrong for Joda versions 2.9.7, 2.9.9 and 2.10.1. Note that dates after 1-1-1900 are not affected.

Steps to reproduce

Either take a look of the committed test or at the code example below:

Ebean entity:

  ...
import org.joda.time.LocalDate;
...

@Entity
@Table(name = "unit_assignment")
public class UnitAssignment {

    ...

    @Column(name = "datebegin")
    private LocalDate beginDate;

    ...

    public LocalDate getBeginDate() {
        return beginDate;
    }

    public void setBeginDate(LocalDate beginDate) {
        this.beginDate = beginDate;
    }

    ...
}

Database table:

CREATE TABLE `unit_assignment` (
  ...
  `datebegin` date DEFAULT NULL,
  ...
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci

Possible workaround is editting the Ebean entity:

...
import org.joda.time.LocalDate;
import java.util.Date;
...

@Entity
@Table(name = "unit_assignment")
public class UnitAssignment {

    ...

    @Column(name = "datebegin")
    private Date beginDate;

    ...

    public LocalDate getBeginDate() {
        return beginDate != null ? LocalDate.fromDateFields(beginDate) : null;
    }

    public void setBeginDate(LocalDate beginDate) {
        this.beginDate = beginDate.toDate();
    }

    ...
}
@rbygrave rbygrave self-assigned this Mar 14, 2019
@rbygrave rbygrave added the bug label Mar 14, 2019
@rbygrave rbygrave added this to the 11.36.2 milestone Mar 14, 2019
rbygrave added a commit that referenced this issue Mar 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants