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 1eb9976a..6fb6c866 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 0576b515..e6f9e8dd 100644 --- a/src/test/scala/com/github/tminglei/slickpg/addon/PgDateSupportJodaTest.scala +++ b/src/test/scala/com/github/tminglei/slickpg/addon/PgDateSupportJodaTest.scala @@ -200,9 +200,12 @@ class PgDateSupportJodaTest { implicit val getDateBean = GetResult(r => DatetimeBean( r.nextLong(), r.nextLocalDate(), r.nextLocalTime(), r.nextLocalDateTime(), r.nextZonedDateTime(), r.nextPeriod())) - val b = 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")) db.run(DBIO.seq( sqlu"""create table DatetimeJodaTest( @@ -215,9 +218,13 @@ class PgDateSupportJodaTest { """, sqlu"SET TIMEZONE TO '+8';", /// - sqlu"insert into DatetimeJodaTest values(${b.id}, ${b.date}, ${b.time}, ${b.dateTime}, ${b.dateTimetz}, ${b.interval})", - sql"select * from DatetimeJodaTest where id = ${b.id}".as[DatetimeBean].head.map( - assertEquals(b, _) + sqlu"insert into DatetimeJodaTest values(${b1.id}, ${b1.date}, ${b1.time}, ${b1.dateTime}, ${b1.dateTimetz}, ${b1.interval})", + sql"select * from DatetimeJodaTest where id = ${b1.id}".as[DatetimeBean].head.map( + assertEquals(b1, _) + ), + sqlu"insert into DatetimeJodaTest values(${b2.id}, ${b2.date}, ${b2.time}, ${b2.dateTime}, ${b2.dateTimetz}, ${b2.interval})", + sql"select * from DatetimeJodaTest where id = ${b2.id}".as[DatetimeBean].head.map( + assertEquals(b2, _) ), /// sqlu"drop table if exists DatetimeJodaTest cascade"