Skip to content
This repository has been archived by the owner on Dec 3, 2019. It is now read-only.

Fix for #240, also added some tests #255

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ object PostgreSQLTimestampEncoderDecoder extends ColumnEncoderDecoder {
index =>
new DateTimeFormatterBuilder()
.appendPattern("yyyy-MM-dd HH:mm:ss")
.appendPattern("." + ("S" * index ))
.appendOptional(new DateTimeFormatterBuilder().appendPattern("." + ("S" * index )).toParser)
.appendOptional(optionalTimeZone)
.toFormatter
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.github.mauricio.async.db.postgresql.column

import com.github.mauricio.async.db.postgresql.messages.backend.PostgreSQLColumnData
import io.netty.buffer.Unpooled
import io.netty.util.CharsetUtil
import org.joda.time
import org.joda.time.DateTimeZone
import org.specs2.mutable.Specification

class PostgreSQLTimestampEncoderDecoderSpec extends Specification {

def execute( columnType:Int, data : String ) : Any = {
val date = data.getBytes( CharsetUtil.UTF_8 )
PostgreSQLTimestampEncoderDecoder.decode(
PostgreSQLColumnData("name",1,1,columnType,1,1,1),
Unpooled.wrappedBuffer(date), CharsetUtil.UTF_8)
}

"encoder/decoder" should {

"parse a date" in {
val localDateTime = execute(ColumnTypes.Timestamp, "2018-08-15 18:26:36").asInstanceOf[time.LocalDateTime]
localDateTime.getYear === 2018
localDateTime.getMonthOfYear === 8
localDateTime.getDayOfMonth === 15
localDateTime.getHourOfDay === 18
localDateTime.getMinuteOfHour === 26
localDateTime.getSecondOfMinute === 36

}

"parse a date with timezone" in {
DateTimeZone.setDefault(DateTimeZone.UTC)
val dateTime = execute(ColumnTypes.TimestampWithTimezone, "2018-08-15 18:26:36+08").asInstanceOf[time.DateTime]
dateTime.getYear === 2018
dateTime.getMonthOfYear === 8
dateTime.getDayOfMonth === 15
dateTime.getHourOfDay === 10
dateTime.getMinuteOfHour === 26
dateTime.getSecondOfMinute === 36
}

}

}