diff --git a/src/main/scala/com/github/tminglei/slickpg/addon/PgDateSupportJoda.scala b/src/main/scala/com/github/tminglei/slickpg/addon/PgDateSupportJoda.scala index bb2443e9..e21f8157 100644 --- a/src/main/scala/com/github/tminglei/slickpg/addon/PgDateSupportJoda.scala +++ b/src/main/scala/com/github/tminglei/slickpg/addon/PgDateSupportJoda.scala @@ -75,11 +75,14 @@ trait PgDateSupportJoda extends date.PgDateExtensions with utils.PgCommonJdbcTyp def nextLocalDate() = nextLocalDateOption().orNull def nextLocalDateOption() = r.nextStringOption().map(LocalDate.parse(_, jodaDateFormatter)) def nextLocalTime() = nextLocalTimeOption().orNull - def nextLocalTimeOption() = r.nextStringOption().map(LocalTime.parse(_, jodaTimeFormatter)) + def nextLocalTimeOption() = r.nextStringOption().map(s => LocalTime.parse(s, + if(s.indexOf(".") > 0 ) jodaTimeFormatter else jodaTimeFormatter_NoFraction)) def nextLocalDateTime() = nextLocalDateTimeOption().orNull - def nextLocalDateTimeOption() = r.nextStringOption().map(LocalDateTime.parse(_, jodaDateTimeFormatter)) + def nextLocalDateTimeOption() = r.nextStringOption().map(s => LocalDateTime.parse(s, + if(s.indexOf(".") > 0 ) jodaDateTimeFormatter else jodaDateTimeFormatter_NoFraction)) def nextZonedDateTime() = nextZonedDateTimeOption().orNull - def nextZonedDateTimeOption() = r.nextStringOption().map(DateTime.parse(_, jodaTzDateTimeFormatter)) + def nextZonedDateTimeOption() = r.nextStringOption().map(s => DateTime.parse(s, + if(s.indexOf(".") > 0 ) jodaTzDateTimeFormatter else jodaTzDateTimeFormatter_NoFraction)) def nextPeriod() = nextPeriodOption().orNull def nextPeriodOption() = r.nextStringOption().map(pgIntervalStr2jodaPeriod) } diff --git a/src/test/scala/com/github/tminglei/slickpg/addon/PgDateSupportJodaTest.scala b/src/test/scala/com/github/tminglei/slickpg/addon/PgDateSupportJodaTest.scala index 6436d248..91b8d966 100644 --- a/src/test/scala/com/github/tminglei/slickpg/addon/PgDateSupportJodaTest.scala +++ b/src/test/scala/com/github/tminglei/slickpg/addon/PgDateSupportJodaTest.scala @@ -240,16 +240,23 @@ class PgDateSupportJodaTest { } (Q.u + "SET TIMEZONE TO '+8';").execute - val dateBean = new DatetimeBean(107L, LocalDate.parse("2010-11-03"), LocalTime.parse("12:33:01.101357"), + val b1 = new DatetimeBean(107L, LocalDate.parse("2010-11-03"), LocalTime.parse("12:33:01.101357"), LocalDateTime.parse("2001-01-03T13:21:00.223571"), DateTime.parse("2001-01-03 13:21:00.102203+08", jodaTzDateTimeFormatter), Period.parse("P1DT1H1M0.335701S")) + val b2 = new DatetimeBean(108L, LocalDate.parse("2010-11-03"), LocalTime.parse("12:33:01"), + LocalDateTime.parse("2001-01-03T13:21:00"), DateTime.parse("2001-01-03 13:21:00+08", jodaTzDateTimeFormatter_NoFraction), + Period.parse("P1DT1H1M0.335701S")) - (Q.u + "insert into DatetimeJodaTest values(" +?dateBean.id + ", " +? dateBean.date + ", " +? dateBean.time - + ", " +? dateBean.dateTime + ", " +? dateBean.dateTimetz + ", " +? dateBean.interval + ")").execute + (Q.u + "insert into DatetimeJodaTest values(" +?b1.id + ", " +? b1.date + ", " +? b1.time + + ", " +? b1.dateTime + ", " +? b1.dateTimetz + ", " +? b1.interval + ")").execute + (Q.u + "insert into DatetimeJodaTest values(" +?b2.id + ", " +? b2.date + ", " +? b2.time + + ", " +? b2.dateTime + ", " +? b2.dateTimetz + ", " +? b2.interval + ")").execute - val found = (Q[DatetimeBean] + "select * from DatetimeJodaTest where id = " +? dateBean.id).first + val f1 = (Q[DatetimeBean] + "select * from DatetimeJodaTest where id = " +? b1.id).first + val f2 = (Q[DatetimeBean] + "select * from DatetimeJodaTest where id = " +? b2.id).first - assertEquals(dateBean, found) + assertEquals(b1, f1) + assertEquals(b2, f2) } } }