Upgrade to Pro — share decks privately, control downloads, hide ads and more …

タイムゾーンの†闇†

 タイムゾーンの†闇†

社内のプレゼン大会でしゃべった(10分相当)

404139d782ec666acea93dffc86e089f?s=128

sylph01

May 25, 2017
Tweet

Transcript

  1. λΠϜκʔϯͷ†ҋ† Ryo Kajiwara, 5/25/2017

  2. None
  3. ࠓճ͸௝͘͠ ηΩϡϦςΟͷ࿩Ͱ͸ ͋Γ·ͤΜ

  4. None
  5. ݁࿦

  6. ೔ຊ͸ ୯ҰTZͰ Α͔ͬͨͶ

  7. ೔ຊ͸ DSTඇద༻Ͱ Α͔ͬͨͶ

  8. ·͋ ໧ͬͯ UTC࢖͑

  9. None
  10. QiitaʹRailsͷλΠϜκʔϯ ͷ࿩Λॻ͖·ͨ͠ ཁ໿ͱͯ͠͸ɺRubyͷTimeͱDateͱDateTime͸ΦϒδΣΫτੜ੒ ࣌ͷڍಈͱλΠϜκʔϯΛอ࣋͢Δ͔Ͳ͏͔͕ͦΕͧΕඍົʹҧ ͍·͢ɻ

  11. QiitaʹRailsͷλΠϜκʔϯ ͷ࿩Λॻ͖·ͨ͠ …͕ɺγεςϜ࣌ࠁ͕JSTʁͦΜͳαʔόʔͰproductionಈ͔͢Θ͚ ͋Γ·ͤΜɻ ʢ΄Μͱʹ೔ຊࠃ֎ʹҰ੾ग़͢ؾ͕ͳͯ͘೔ຊࠃ֎ʹҰ੾σʔλ Λserve͢Δؾ͕ͳ͚Ε͹ߏ͍·ͤΜ͕ʣ

  12. αʔό͸໧ͬͯUTC • σʔλϕʔεʹอଘ͢Δ஋΋ɺ • ΫΤϦ͢ΔͨΊʹ࢖͏஋΋ɺ • ͢΂ͯUTCͰ͢ɻ • JSTͷn࣌Ҏલ͕ཉ͚͠Ε͹ΫΤϦʹ࢖͏஋͸ม׵Λ௨͢ɻ

  13. ؓ࿩ٳ୊: UTCͬͯԿͷུ • ӳޠͰ͸Coordinated Universal Time • Α͋͘Δӳޠ͡Όͳུ͍শ͸͍͍ͩͨϑϥϯεޠʢFIFAͱ͔ FIBAͱ͔FINAͱ͔͋ΕͶʣͰ͕͢ϑϥϯεޠͰ͸Temps universel

    coordonné • ͦͷؒΛऔͬͯUTC
  14. ͡Ό͋ ԿͰʁ

  15. Daylight Saving Time

  16. Daylight Saving Timeͱ͸ • ՆʹͳΔͱ࣌ܭΛ1࣌ؒޙΖʹͣΒ͠ • ౙʹͳΔͱ࣌ܭΛ1࣌ؒલʹ໭͢ ʮՈʹؼͬͨ͋ͱ΋໌Δ͍͕࣌ؒ௕͘ͳΔʯΛૂ͍ͬͯΔɻ

  17. None
  18. αϚʔλΠϜࡴਓࣄ݅ ΧϦϑΥϧχΞʢඪ४࣌͸UTC-8ɺՆ࣌ؒ͸UTC-7ʣɺ11݄ͷୈ1 ೔༵೔ʹͯ Aʮඃ֐ऀͷࢮ๢ਪఆ࣌ࠁ͸01:30ʯ BʮԶ͸΍ͬͯͳ͍ʂԶ͸01:30ʹ͸60ϚΠϧ཭Εͨͱ͜Ζʹ͍ͨ ΜͩʂϨγʔτ͕ΞϦόΠΛূ໌ͯ͘͠ΕΔʂʯ

  19. Կ͕໰୊͔ʁ DSTద༻ԼͰlocal timeΛ࢖͏ͱʮಉ࣌͡ࠁ͕2ճ΍ͬͯ͘Δʯ΋͠ ͘͸ʮ΍ͬͯ͜ͳ͍࣌ࠁ͕͋Δʯ ͳͷͰ࣌ࠁ͕࿈ଓͯ͠ଘࡏ͢ΔUTCΛج४ʹม׵ͯ͠΍Ε͹͍͍ɻ Aʮඃ֐ऀͷࢮ๢ਪఆ࣌ࠁ͸UTC08:30Ͱ͓લͷϨγʔτ͸ UTC09:30ͳΜ͕ͩͳ͋ɻͦ͏͍͑͹ߴ଎ಓ࿏ͷ੍ݶ଎౓͸65mph ͚ͩͬʁʯ

  20. ͋Δ೔෇͕DSTద༻͔Ͳ͏͔ Λ஌Δʹ͸ʁ ࠃʹΑΓDSTద༻ͷϙϦγʔ͕ҟͳΔͷͰࣗ໌ͳ໰୊Ͱ͸ͳ͍ɻ

  21. ͋Δ೔෇͕DSTద༻͔Ͳ͏͔ Λ஌Δʹ͸ʁ • ೔ຊͰ͢Β઎ྖԼͷ1948೥ʙ1951೥͸DSTద༻ͩͬͨ • DSTద༻Ͱ஌ΒΕΔΞϝϦΧ΋໽հɻΞϦκφभ͸ඇద༻ɺͨ ͩ͠ΞϦκφभʹؚ·ΕΔφόϗɾωΠγϣϯͷ஍Ҭ͸DSTద ༻ʢΞϝϦΧࠃ಺ͩͱଞʹϋϫΠ΋DSTඇద༻ʣ • DSTద༻ࠃؒͰ΋ʮԿ݄ͷୈԿͷԿ༵೔ʹ։࢝ɾऴྃʯ͕ҟͳ

    ΔʢΠϥϯ͸ݻఆͷ೔෇Ͱߦ͏ʣ
  22. †ҋ†Λղܾ͢Δ tz database

  23. tz databaseͱ͸ ผ໊IANA Timezone Database, Olson/Eggert database ͋Δ஍ҬͰλΠϜκʔϯ͕ͲͷΑ͏ͳมԽΛḷ͔ͬͨΛه࿥͢Δ σʔλϕʔεɻ ΤϦΞ໊/஍Ҭ໊(ྫ:Asia/Tokyo,

    America/Los_Angeles)ͱ͍ͬͨදه Ͱಛఆͷ஍Ҭͷ࣌ࠁͷมԽΛτϨʔε͢Δɻ
  24. ྫ s1 = {{2017, 5, 25}, {0, 0, 0}} |>

    :calendar.datetime_to_gregorian_seconds Tzdata.periods_for_time("Asia/Tokyo", s1, :utc) # [%{from: %{standard: 61589206800, utc: 61589174400, wall: 61589206800}, # std_off: 0, until: %{standard: :max, utc: :max, wall: :max}, utc_off: 32400, # zone_abbr: "JST"}] ࠓ೔ͷ೔෇͸Asia/TokyoͰ͸౰વJSTɺUTC offset͸32400ඵ(+9h)
  25. ྫ s2 = {{1948, 5, 3}, {0, 0, 0}} |>

    :calendar.datetime_to_gregorian_seconds Tzdata.periods_for_time("Asia/Tokyo", s2, :utc) # [%{from: %{standard: 61483456800, utc: 61483424400, wall: 61483460400}, # std_off: 3600, # until: %{standard: 61494858000, utc: 61494825600, wall: 61494861600}, # utc_off: 32400, zone_abbr: "JDT"}] JSTͷ1948೥5݄2೔0:00ΑΓՆ࣌ؒద༻ͳͷͰɺUTCͰͷ1948/5/3 0:00͸Ն࣌ؒద༻ൣғɻJDTͱ͍͏λΠϜκʔϯʂ
  26. ྫ s3 = :calendar.datetime_to_gregorian_seconds({{2017 ,11, 5}, {1, 30, 0}}) Tzdata.periods_for_time("America/Los_Angeles",

    s3, :wall) # [%{from: %{standard: 63656503200, utc: 63656532000, wall: 63656506800}, # std_off: 3600, # until: %{standard: 63677062800, utc: 63677091600, wall: 63677066400}, # utc_off: -28800, zone_abbr: "PDT"}, # %{from: %{standard: 63677062800, utc: 63677091600, wall: 63677062800}, # std_off: 0, # until: %{standard: 63687952800, utc: 63687981600, wall: 63687952800}, # utc_off: -28800, zone_abbr: "PST"}] wall clock͕2017೥11݄5೔ 01:30Λࢦ࣌͢ࠁ͸PST 01:30ͱPDT 01:30ͷ2͕ͭ͋Γ͏Δɻ
  27. ྫ s4 = :calendar.datetime_to_gregorian_seconds({{2017, 3, 12}, {2, 30, 0}}) Tzdata.periods_for_time("America/Los_Angeles",

    s4, :wall) # [] wall clock͕2017೥3݄12೔ 02:30Λࢦ͢͜ͱ͸ͳ͍
  28. Ξοϓσʔτ͕සൟʹ͋Δ 2016೥ͷ࠷ऴ͸2016jɺͭ·Γ2016೥ͷؒͰ10ճ΋ߋ৽͕͋ͬ ͨɻ ϙϦγʔͷมԽ͕10ճ͋ͬͨͷͰ͸ͳ͘bugfixͱ͔΋͋Δɻ ੲͷLinuxͰJapan/South Ryukyu IslandsΛࢦ͢ͱUTC+8ʹͳͬͨͱ ͍͏όά͕͋ͬͨɻ͜Ε͸tzdataʹʮླྀٿॾౡͰ͸UTC+8͕࢖ΘΕ ͍ͯͨʯͱ͍͏ޡ৘ใ͕هࡌ͞Ε͍ͯͨͨΊɻ

  29. Erlang/Elixirͷ࣌ࠁϥΠϒϥ Ϧ͕͠ΜͲ͍ • Erlang΋Elixir΋ͦ͜·Ͱ࣌ࠁม׵͕ڧ͍Θ͚Ͱ͸ͳ͍ • λΠϜκʔϯΛؚΉ࣌ࠁܕ͸Elixirʹ͸͋Δ • Tzdata͸tz database΁ͷAPIΛఏڙ͢ΔͷΈɺ͔͠͠ಉػೳͷ RubyͷϥΠϒϥϦʹൺ΂ͯAPI͕গʑ͠ΜͲ͍

    • Erlangͷerlang_localtime͸API͸Α͍͕tz databaseߋ৽ͷpull request͕์ஔ͞Ε͍ͯΔ
  30. Erlang/Elixirͷ࣌ࠁϥΠϒϥ Ϧ͕͠ΜͲ͍ • ݱঢ়ͰʮAPI͕͠ΜͲ͘ͳ͍ʯʮself-updating or maintainedʯΛ ຬͨ͢ͷ͸͓ͦΒ͘Calendar @ ElixirɻElixir 1.3Ͱಋೖ͞Εͨܕ

    ʹλΠϜκʔϯม׵౳Λఏڙ͢Δɻ΋ͬͱ΋λΠϜκʔϯಋೖʹ Αͬͯएׯͷ͠ΜͲ͞͸ಋೖ͞Ε͍ͯΔ
  31. Erlang/Elixirͷ࣌ࠁϥΠϒϥ Ϧ͕͠ΜͲ͍ iex(3)> Calendar.DateTime.from_erl {{2017, 11, 5}, {8, 30, 0}},

    "America/Los_Angeles" {:ok, %DateTime{calendar: Calendar.ISO, day: 5, hour: 8, microsecond: {0, 0}, minute: 30, month: 11, second: 0, std_offset: 0, time_zone: "America/Los_Angeles", utc_offset: -28800, year: 2017, zone_abbr: "PST"}}
  32. Erlang/Elixirͷ࣌ࠁϥΠϒϥ Ϧ͕͠ΜͲ͍ iex(4)> Calendar.DateTime.from_erl {{2017, 11, 5}, {1, 30, 0}},

    "America/Los_Angeles" {:ambiguous, %Calendar.AmbiguousDateTime{possible_date_times: [%DateTime{calendar: Calendar.ISO, day: 5, hour: 1, microsecond: {0, 0}, minute: 30, month: 11, second: 0, std_offset: 3600, time_zone: "America/Los_Angeles", utc_offset: -28800, year: 2017, zone_abbr: "PDT"}, %DateTime{calendar: Calendar.ISO, day: 5, hour: 1, microsecond: {0, 0}, minute: 30, month: 11, second: 0, std_offset: 0, time_zone: "America/Los_Angeles", utc_offset: -28800, year: 2017, zone_abbr: "PST"}]}}
  33. Erlang/Elixirͷ࣌ࠁϥΠϒϥ Ϧ͕͠ΜͲ͍ iex(5)> Calendar.DateTime.from_erl {{2017, 3, 12}, {2, 30, 0}},

    "America/Los_Angeles" {:error, :invalid_datetime_for_timezone}
  34. Erlang/Elixirͷ࣌ࠁϥΠϒϥ Ϧ͕͠ΜͲ͍ • from_erl/1 ͷҾ਺͕UTCͰ͸ͳͦ͘ͷλΠϜκʔϯʹ͓͚Δ wall clockͰ͋Δ͜ͱ໊͕લ͔Β஌Γ͍ͨɻͦΓΌͦ͏ͩͱ͍͑ ͹ͦ͏͚ͩͲ… • %Calendar.AmbiguousDateTime

    ʹแ·ΕͯΔͷ͸ύλʔϯϚ ονͷͨΊͩΖ͏͚Ͳ… ͱ͸͍͑ݱঢ়ͰҰ൪Ϛγʹݟ͑Δɻ
  35. None
  36. ݁࿦

  37. ೔ຊ͸ ୯ҰTZͰ Α͔ͬͨͶ

  38. ೔ຊ͸ DSTඇద༻Ͱ Α͔ͬͨͶ

  39. ·͋ ໧ͬͯ UTC࢖͑

  40. Questions?