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

日時処理の新スタンダード: Synchro によるタイムゾーン安全、楽々開発

Kei Kamikawa
December 01, 2023

日時処理の新スタンダード: Synchro によるタイムゾーン安全、楽々開発

I talked about the https://github.com/Code-Hex/synchro library in Go Conference mini 2023 Winter IN KYOTO.

https://kyotogo.connpass.com/event/285351/

Kei Kamikawa

December 01, 2023
Tweet

More Decks by Kei Kamikawa

Other Decks in Programming

Transcript

  1. 🕐೔࣌ॲཧͷ৽ελϯμʔυ🕧

    4ZODISPʹΑΔλΠϜκʔϯ҆શɺָʑ։ൃ

    (P$POGFSFODFNJOJ8JOUFS*/,:050

    View full-size slide

  2. !DPEFIFY !$PEF)FY
    w /05")05&-Ͱಇ͍͍ͯ·͢
    w 1P$Λ࡞ͬͯɺӡ༻·Ͱ͍࣋ͬͯ͘
    w ࣗಈԽɺ"*ΠϯςάϨʔγϣϯ
    w *❤(P
    w IUUQTHJUIVCDPN$PEF)FYW[
    w IUUQTHJUIVCDPN$PEF)FYEE

    View full-size slide

  3. IUUQTWJNFPDPN

    View full-size slide

  4. 4ZODISP
    IUUQTHJUIVCDPN$PEF)FYTZODISP

    View full-size slide

  5. ։ൃ͖͔͚ͬͷϙετ

    View full-size slide

  6. ։ൃ͖͔͚ͬͷϙετ
    w ͜ͷπΠʔτ͸ਅ໘໨ʹड͚ࢭΊͯྑ͍

    ϑΟʔυόοΫͩͱࢥͬͨ
    w ೔෇ςΩετͷม׵ɺλΠϜκʔϯͷѻ͍͸೉͍͠
    w ՃࢉݮࢉͳͲجຊతͳॲཧ΋༉அ͢Δͱʜ
    w (FOFSJDTΛ࠷େʹ׆͔ͨ͠ྫ͕ͳ͔ͬͨ͜ͱ΋େ͖͍

    View full-size slide

  7. (PͰ΋Ͱ͖ΔΑʂ

    View full-size slide

  8. IUUQTHPEFWQMBZQ2M$./-GK

    View full-size slide

  9. 4ZODISP
    w $ISPOPʹӨڹΛड͚ͨ

    ܕΛར༻ͨ͠λΠϜκʔϯͷαϙʔτ
    w རศੑͱ࢖͍΍͢͞ʢ%FWFMPQFS&YQFSJFODF🚀ʣ
    w *40ͷ׬શαϙʔτʹΑΔ֦ுੑ

    View full-size slide

  10. ܕΛར༻ͨ͠λΠϜκʔϯͷαϙʔτ
    ڧྗͳܕ҆શͷ೔෇ॲཧ

    View full-size slide

  11. Ͳ͏࣮ݱͯ͠Δʁ

    View full-size slide

  12. Ͳ͏࣮ݱͯ͠Δʁ
    IUUQTHJUIVCDPN$PEF)FYTZODISPCMPCWTZODISPHP--

    View full-size slide

  13. ͜ΕͰղܾͰ͖Δࣄྫ

    View full-size slide

  14. ྫ%#ΞϓϦέʔγϣϯ

    View full-size slide

  15. w %#ͱΞϓϦέʔγϣϯίʔυؒͷม׵͸

    Ϩίʔυʹอଘ͞Ε͍ͯΔ೔෇࣌ࠁͷςΩετʹґଘ͢Δ
    w λΠϜκʔϯ৘ใؚ͕·Ε͍ͯΔ৔߹ɺ

    ΞϓϦέʔγϣϯ͕લఏͱ͢ΔλΠϜκʔϯͷม׵͕ඞਢ
    ྫ%#ΞϓϦέʔγϣϯ

    View full-size slide

  16. ྫ%#ΞϓϦέʔγϣϯ

    View full-size slide

  17. ྫ%#ΞϓϦέʔγϣϯ
    65$ͷ೔෇จࣈྻ
    +45ͷ೔෇จࣈྻ
    2023-12-02 00:00:00Z
    2023-12-02 00:00:00+09:00

    View full-size slide

  18. ྫ%#ΞϓϦέʔγϣϯ

    View full-size slide

  19. ྫ%#ΞϓϦέʔγϣϯ
    65$ͷ೔෇จࣈྻ
    +45ͷ೔෇จࣈྻ͸ͦͷ··
    2023-12-02 00:00:00Z
    2023-12-02 00:00:00+09:00
    ʹ࣌ؒ͞Εͨ
    IUUQTHPEFWQMBZQ+0I9.JCJ

    View full-size slide

  20. ྫ+40/ΞϓϦέʔγϣϯ

    View full-size slide

  21. w +40/͸ΞϓϦέʔγϣϯ֎ͷੈքͱ΍ΓऔΓͰ࢖͏
    w +40/͚ͩͰͳ͘9.-΍1SPUPDPM#V
    ff
    FS΋ͦ͏
    w ͜͜Ͱ΋λΠϜκʔϯ৘ใؚ͕·Ε͍ͯΔ৔߹ɺ

    ΞϓϦέʔγϣϯ͕લఏͱ͢ΔλΠϜκʔϯͷม׵͕ඞਢ
    w %#ͷྫͱಉ͡ײ͡ͳͷͰίʔυ͸ׂѪ
    ྫ+40/ΞϓϦέʔγϣϯ

    View full-size slide

  22. ΞϓϦͱ֎ͷੈքͷ

    λΠϜκʔϯΛ߹Θͤ΍͍͢ʂ

    View full-size slide

  23. *40ͷ׬શαϙʔτ
    ׬શαϙʔτͯ͠ಘΒΕͨύϫʔ💪

    View full-size slide

  24. *40ͷ׬શαϙʔτ
    IUUQT[FOOEFWOPUBIPUFMBSUJDMFTGBBGGG

    View full-size slide

  25. *40ͷ׬શαϙʔτ
    w ೔෇
    w ::::..%%PS::::..%% $BMFOEBS%BUF

    w ::::8XX%PS::::8XX% 8FFL%BUF

    w ::::%%%PS::::%%% 0SEJOBM%BUF

    w ࣌ؒ
    w IINNTT IINN IIPSIINNTT IINN II

    PS; λΠϜκʔϯ

    View full-size slide

  26. *40ͷ׬શαϙʔτ
    w ೔෇࣌ࠁ
    w 5; 5;

    w 5 5

    w ܧଓ࣌ؒظؒɺִ࣌ؒؒɺ܁Γฦִؒ͠
    w 1:.%5).4PS18
    w
    w 35;1:.%5).

    View full-size slide

  27. *40ͷ׬શαϙʔτ
    w *40ͷϑΥʔϚοτ͸ଟذʹ౉Δ
    w ೔෇ʹؔͯ͠͸૬ޓม׵͕Ͱ͖ΔΑ͏ʹͳ͍ͬͯΔ
    w 8FFL%BUF0SEJOBM%BUF$BMFOEBS%BUF
    w ϥΠϒϥϦͷ͍ͤͰόά͕ൃੜ͢Δͱҙຯ͕ͳ͍
    w

    View full-size slide

  28. *40ͷ׬શαϙʔτ
    w *40ͷϑΥʔϚοτ͸ଟذʹ౉Δ
    w ೔෇ʹؔͯ͠͸૬ޓม׵͕Ͱ͖ΔΑ͏ʹͳ͍ͬͯΔ
    w 8FFL%BUF0SEJOBM%BUF$BMFOEBS%BUF
    w ϥΠϒϥϦͷ͍ͤͰόά͕ൃੜ͢Δͱҙຯ͕ͳ͍
    w 4ZODISPͰ͸ςετΛ͔ͳΓଟ͘ॻ͍͍ͯΔ

    View full-size slide

  29. *40ͷ׬શαϙʔτ

    View full-size slide

  30. *40ͷ׬શαϙʔτ
    ʊਓਓਓਓਓਓਓਓਓਓʊ
    ʼɹ࠷େഒͷࠩʂʂɹʻ
    ʉ:?:?:?:?:?:?:?:?:ʉ

    View full-size slide

  31. iso8601.ParseDateTime()

    View full-size slide

  32. iso8601.ParseDateTime()
    IUUQTQLHHPEFWHJUIVCDPN$PEF)FYTZODISP!W
    JTP1BSTF%BUF5JNF

    View full-size slide

  33. iso8601.ParseDateTime()
    %#తʹΑ͘ݟΔϑΥʔϚοτ

    "2017-04-24 09:41:34.502+0100"
    ࣮ࡍͷ*40ͷ࢓༷Ͱ͸

    "2017-04-24T09:41:34.502+0100"
    ͜ΕΛڐ༰͢ΔΦϓγϣϯ

    iso8601.WithTimeDesignators(' ')

    View full-size slide

  34. iso8601.ParseDateTime()
    IUUQTHPEFWQMBZQU)98+0K&

    View full-size slide

  35. iso8601.ParseDateTime()
    w ͋ΔϩέʔγϣϯΛى఺ͱͯ͠ύʔε͍ͨ͠έʔε
    w time.ParseInLocation()ͷΑ͏ͳ΋ͷ
    • iso8601.WithInLocation(loc)

    View full-size slide

  36. iso8601.ParseDateTime()
    IUUQTHPEFWQMBZQ*(8C(BE.Y

    View full-size slide

  37. ֎ͷੈքͷೖྗ͔Β

    ࣌ؒͷߏ଄΁ͷม׵ʹ໾ཱ͍ͯͯΔ

    View full-size slide

  38. རศੑͱ࢖͍΍͢͞
    ϢʔβʔϑϨϯυϦʔͳػೳ

    View full-size slide

  39. ϦΫΤετ಺ͷ࣌ؒ౷Ұ
    IUUQTQLHHPEFWHJUIVCDPN$PEF)FYTZODISP/PX$POUFYU

    View full-size slide

  40. ϦΫΤετ಺ͷ࣌ؒ౷Ұ

    View full-size slide

  41. ϦΫΤετ಺ͷ࣌ؒ౷Ұ
    ݱࡏ࣌ࠁΛϛυϧ΢ΣΞͰηοτ
    ϋϯυϥͰऔΓग़ͯ͠࢖͏

    View full-size slide

  42. ϦΫΤετ಺ͷ࣌ؒ౷Ұ
    w %#ʹอଘ͢Δ࣌ࠁͱϩδοΫͷ࣌ࠁΛ؆୯ʹ౷ҰͰ͖Δ
    w ֎෦"1*΁ͷλΠϜελϯϓ͕%#ͱಉ࣌͡ࠁʹͳΔ
    w ੔߹ੑͷ୲อ

    View full-size slide

  43. ςετ΋؆୯
    $POUFYUͰ࣌ؒΛݻఆ͢Δ
    ݻఆ͞Ε͍ͯΔ͜ͱΛ֬ೝ

    View full-size slide

  44. ࿈ଓͨ࣌ؒ͠ͷੜ੒
    IUUQTQLHHPEFWHJUIVCDPN$PEF)FYTZODISP1FSJPE

    View full-size slide

  45. ࿈ଓͨ࣌ؒ͠ͷੜ੒
    TZODISP5JNFΛύϥϝʔλʹ͢Δ

    View full-size slide

  46. UJNF5JNFΛύϥϝʔλʹ͢Δ
    ࿈ଓͨ࣌ؒ͠ͷੜ੒

    View full-size slide

  47. TUSJOHͱ<>CZUFΛύϥϝʔλʹ͢Δ
    ࿈ଓͨ࣌ؒ͠ͷੜ੒

    View full-size slide

  48. TUSJOHΛύϥϝʔλͰ
    ࿈ଓͨ࣌ؒ͠ͷੜ੒

    View full-size slide

  49. ִؒΛࢦఆ͢Δ

    View full-size slide

  50. UJNF%VSBUJPOͰࢦఆ͢Δ
    ִؒͷࢦఆ
    IUUQTQLHHPEFWHJUIVCDPN$PEF)FYTZODISP1FSJPE1FSJPEJD%VSBUJPO

    View full-size slide

  51. "EE%BUFͷܗࣜͰࢦఆ͢Δ
    ִؒͷࢦఆ
    IUUQTQLHHPEFWHJUIVCDPN$PEF)FYTZODISP1FSJPE1FSJPEJD%BUF

    View full-size slide

  52. *40ͷظؒͰࢦఆ͢Δ
    ִؒͷࢦఆ
    IUUQTQLHHPEFWHJUIVCDPN$PEF)FY
    TZODISP1FSJPE1FSJPEJD*40%VSBUJPO

    View full-size slide

  53. εϥΠε΁ͷม׵΋Մೳ
    ִؒͷࢦఆ

    View full-size slide

  54. ࠓޙͷ։ൃ

    View full-size slide

  55. ࠓޙͷ։ൃ
    w ਓʹ༏͍͠ϑΥʔϚοτͰͷग़ྗ
    w EBZT EBZTBHP 5PEBZJTB4BUVSEBZͳͲ
    w *OରԠ
    w ศརϝιουͷ௥Ճ
    w ߴ଎Խ🚀

    View full-size slide