Skip to content

Instantly share code, notes, and snippets.

@y-yu
Last active September 14, 2022 08:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save y-yu/91c7d6565834fe98001dc429b3b33df8 to your computer and use it in GitHub Desktop.
Save y-yu/91c7d6565834fe98001dc429b3b33df8 to your computer and use it in GitHub Desktop.
slick-joda-mapperの件

slick-joda-mapperの動作がおかしそう

概要

どういうときに変なことになるのか?

  • まず、現在は次のようにグローバルな設定をやっている
    Locale.setDefault(Locale.JAPAN)
    val tz = TimeZone.getTimeZone("Asia/Tokyo")
    TimeZone.setDefault(tz)
    DateTimeZone.setDefault(DateTimeZone.forID(tz.getID))
  • そしてテストの結果がこのようになる
    [info] - should be the same in/out joda-time zoned Asia/Tokyo
    [info] - should be the same in/out joda-time zoned UTC *** FAILED ***
    [info]   1354806000000 was not equal to 1354838400000 (JodaSupportSpec.scala:252)
    [info] - should be the same in/out joda-time zoned Europe/London *** FAILED ***
    [info]   1354806000000 was not equal to 1354838400000 (JodaSupportSpec.scala:252)
    [info] - should be the same in/out joda-time zoned America/New_York *** FAILED ***
    [info]   1354806000000 was not equal to 1354856400000 (JodaSupportSpec.scala:252)
    
  • 保存されるDateTimeのゾーンがjava.util.TimeZoneのグローバル設定と異なるときに発生していると考えられる
    • たとえば下記のようにjava.util.TimeZoneUTCに設定すると、UTCEurope/Londonは通って他が落ちるというようになる
    val tz = TimeZone.getTimeZone("UTC")
    TimeZone.setDefault(tz)

互換性について

  • 吉田さんのPRは互換性に最大限配慮されていて、tototoshi/slick-joda-mapper#77 をマージしても基本現在の利用者に影響はない
    • PRのコメントにもあるように、最初も自分はそれで「なおってないじゃないか🤔」と勘違いしてました……😇
  • 吉田さんのPRがマージされたあとの修正バージョンを使いたい人は、下記のように明示的に使う必要がある
    - val jodaSupport = com.github.tototoshi.slick.MySQLJodaSupport
    + val jodaSupport = new com.github.tototoshi.slick.GenericJodaSupport(MySQLProfile, _ => None)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment