question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Hey guys,

I’ve been using Exposed to create a database for some timeseries data. I’ve noticed the following code in ColumnType.kt:

class DateColumnType(val time: Boolean): ColumnType() {
    override fun sqlType(): String  = if (time) currentDialect.dataTypeProvider.dateTimeType() else "DATE"

    override fun nonNullValueToString(value: Any): String {
        if (value is String) return value

        val dateTime = when (value) {
            is DateTime -> value
            is java.sql.Date -> DateTime(value.time)
            is java.sql.Timestamp -> DateTime(value.time)
            else -> error("Unexpected value: $value of ${value::class.qualifiedName}")
        }

        return if (time)
            "'${DEFAULT_DATE_TIME_STRING_FORMATTER.print(dateTime.toDateTime(DateTimeZone.getDefault()))}'"
        else
            "'${DEFAULT_DATE_STRING_FORMATTER.print(dateTime)}'"
    }

This uses DateTimeZone.getDefault() to get the string for the DateTime value. However, I do not want to use the System Locale Timezone to save values on the DB. Could we make a change to specify the timezone to use? Another (maybe easier) solution would be to include functionality for Joda’s LocalDateTime instead.

Let me know what you guys think.

Fred

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

14reactions
Rubyjcommented, Jul 28, 2020

@Tapac That is not a solution to this issue. I argue this should be re-opened. Java LocalDateTime does not use a time zone. IF we use a LocalDateTime with exposed, it will assume system default time zone on insert.

3reactions
Smitty010commented, Jul 26, 2021

I was going to tryout exposed. However, the lack of ZonedDateTime means I will use Hibernate/JPA. I don’t really have a choice. My company decided a few years ago was that everything would be GMT going forward, but we can’t change all of the servers to GMT because of older existing software. Exposed looks promising, but it needs it needs full support for the java 8 date/time api.

Read more comments on GitHub >

github_iconTop Results From Across the Web

LocalDateTime (Java Platform SE 8 ) - Oracle Help Center
LocalDateTime is an immutable date-time object that represents a date-time, often viewed as year-month-day-hour-minute-second. Other date and time fields, ...
Read more >
Java 8 Date - LocalDate, LocalDateTime, Instant - DigitalOcean
LocalDate is an immutable class that represents Date with default format of yyyy-MM-dd. We can use now() method to get the current date....
Read more >
Java LocalDateTime - Javatpoint
Java LocalDateTime class is an immutable date-time object that represents a date-time, with the default format as yyyy-MM-dd-HH-mm-ss.zzz.
Read more >
java.time.LocalDateTime Class in Java - GeeksforGeeks
time.LocalDateTime class, introduced in Java 8, represents a local date-time object without timezone information. The LocalDateTime class in ...
Read more >
Guide to Java LocalDateTime - HowToDoInJava
Java LocalDateTime class, introduced in Java 8, represents a local date time object without timezone information. It is immutable and thread ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found