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

Comparison LocalDate (Month,..) #1162

Closed
456634 opened this issue Feb 7, 2021 · 2 comments · Fixed by #1741
Closed

Comparison LocalDate (Month,..) #1162

456634 opened this issue Feb 7, 2021 · 2 comments · Fixed by #1741
Assignees

Comments

@456634
Copy link

456634 commented Feb 7, 2021

I think there is an issue with LocalDate.

Table
     .slice(Table.value.sum())
     .select { Table.date.year() eq dateParam(LocalDate.of(2020,1,1)).year() }
     .groupBy(Table.date.month())

With LocalDate the result is empty.

Table
     .slice(Table.value.sum())
     .select { Table.dateTime.year() eq dateTimeParam(LocalDateTime.of(2020,1,1,0,0)).year() }
     .groupBy(Table.dateTime.month())

With LocalDateTime it works as expected.

While troubleshooting, I noticed that LocalDate is stored as a Datatype DATE in Sqllite.
LocalDateTime, however, as TEXT. Maybe this is the problem.

Exposed Version: 0.29.1
Sqlite-jdbc: 3.34.0

@AJRego
Copy link

AJRego commented Nov 23, 2022

Hello. I have the same problem.

exposed: 0.40.1
sqlite-jdbc: 3.36.0.3

The problem with the date column is that it's stored in a format that sqlite doesn't recognize as a valid date, so all queries return null. This is very strange, because when entering data, the date is in "YYYY-MM-dd" format, but later in the database it appears as a string of integers.

Did you find any solution? I find it cumbersome to save the time in my database when I only use the date.

@456634
Copy link
Author

456634 commented Nov 24, 2022

Hey AJ,

No, not yet. I simply convert LocalDate to LocalDateTime with LocalTime.Min and remove it when I get it from the db.

fun LocalDate.asLocalDateTime(): LocalDateTime = LocalDateTime.of(this, LocalTime.MIN)
localDateTime.toLocalDate()

Then if there is a solution, you just have to adjust the db. Otherwise I haven't bothered with it.

@bog-walk bog-walk self-assigned this May 4, 2023
@bog-walk bog-walk linked a pull request May 11, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants