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

Adding support for java.util.Date #24

Merged
merged 5 commits into from
Aug 25, 2024
Merged

Adding support for java.util.Date #24

merged 5 commits into from
Aug 25, 2024

Conversation

marcvk
Copy link
Contributor

@marcvk marcvk commented Aug 24, 2024

I've added support java.util.Date. I've added the same tests as for LocalDateTime and all tests pass successfully. Let me know if anything else is needed.

@lihaoyi
Copy link
Member

lihaoyi commented Aug 24, 2024

@marcvk can you run the autoformatter to get ci / check-formatting to pass. Should be instructions in the readme

…matAll __.sources + "scalasql[2.13.12].test" + generateTutorial + generateReference

to fix formatting (a.o.)
@marcvk
Copy link
Contributor Author

marcvk commented Aug 25, 2024

@lihaoyi I found that statement in the developer reference doc, is that what you meant?

@lihaoyi
Copy link
Member

lihaoyi commented Aug 25, 2024

Should be! Lets run CI again and see if it worked

@lihaoyi lihaoyi merged commit 3aa29ff into com-lihaoyi:main Aug 25, 2024
6 checks passed
@lihaoyi
Copy link
Member

lihaoyi commented Aug 25, 2024

@marcvk tagged 0.1.7 if youd like to begin using it

@marcvk
Copy link
Contributor Author

marcvk commented Aug 25, 2024

thnx!

@@ -9219,6 +9243,7 @@ val value = DataTypes[Sc](
myLocalDate = LocalDate.parse("2023-12-20"),
myLocalTime = LocalTime.parse("10:15:30"),
myLocalDateTime = LocalDateTime.parse("2011-12-03T10:15:30"),
myUtilDate = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS").parse("2011-12-03T10:15:30.000"),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use SimpleDateFormat here ?

There are instances where java.text.SimpleDateFormat is used to parse dates. A better approach is to use java.time.format.DateTimeFormatter from the modern Java Time API (java.time) introduced in Java 8, which is thread-safe, more flexible, and offers better support for various date/time formats.

We could also convert from LocalDateTime

import java.time.format.DateTimeFormatter
import java.time.{LocalDateTime, ZoneId, ZoneOffset, ZonedDateTime}
import java.util.Date

val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
val date = Date.from(
  LocalDateTime.parse("2023-11-12 03:22:41", formatter)
    .toInstant(
      ZonedDateTime.now(ZoneId.systemDefault()).getOffset
    )
)

println(date)

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 this pull request may close these issues.

3 participants