-
Notifications
You must be signed in to change notification settings - Fork 20
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
Conversation
@marcvk can you run the autoformatter to get |
…matAll __.sources + "scalasql[2.13.12].test" + generateTutorial + generateReference to fix formatting (a.o.)
@lihaoyi I found that statement in the developer reference doc, is that what you meant? |
Should be! Lets run CI again and see if it worked |
@marcvk tagged 0.1.7 if youd like to begin using it |
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"), |
There was a problem hiding this comment.
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)
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.