forked from mauricio/postgresql-async
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix for mauricio#240, also added some tests
- Loading branch information
1 parent
5d0a7e0
commit 65b4368
Showing
2 changed files
with
46 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
...om/github/mauricio/async/db/postgresql/column/PostgreSQLTimestampEncoderDecoderSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
|
||
} | ||
|
||
} |