Skip to content

Commit

Permalink
Selectable formatter for joda Plain SQL support (fix #137)
Browse files Browse the repository at this point in the history
  • Loading branch information
tminglei committed Mar 14, 2015
1 parent b6f85d4 commit 6dea8b0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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"
Expand Down

0 comments on commit 6dea8b0

Please sign in to comment.