Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
🕗Perlの時間はモジュールで #perlwakate
Search
koluku
July 01, 2020
Programming
0
1.1k
🕗Perlの時間はモジュールで #perlwakate
2020/07/01 にオンラインで開催された 「Perl若手の会(
https://connpass.com/event/179235/)」でのLT資料です
koluku
July 01, 2020
Tweet
Share
More Decks by koluku
See All by koluku
日常業務のカイゼンで図る開発チームへの貢献 - YAPC::Kyoto 2023
koluku
4
1.8k
Other Decks in Programming
See All in Programming
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
100
A Journey of Contribution and Collaboration in Open Source
ivargrimstad
0
1.1k
as(型アサーション)を書く前にできること
marokanatani
10
2.8k
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
1
100
CSC509 Lecture 13
javiergs
PRO
0
110
Outline View in SwiftUI
1024jp
1
340
見せてあげますよ、「本物のLaravel批判」ってやつを。
77web
7
7.8k
flutterkaigi_2024.pdf
kyoheig3
0
160
DevTools extensions で 独自の DevTool を開発する | FlutterKaigi 2024
kokiyoshida
0
120
What’s New in Compose Multiplatform - A Live Tour (droidcon London 2024)
zsmb
1
480
TypeScriptでライブラリとの依存を限定的にする方法
tutinoko
3
710
Creating a Free Video Ad Network on the Edge
mizoguchicoji
0
120
Featured
See All Featured
Scaling GitHub
holman
458
140k
Optimising Largest Contentful Paint
csswizardry
33
2.9k
Six Lessons from altMBA
skipperchong
27
3.5k
Art, The Web, and Tiny UX
lynnandtonic
297
20k
How to train your dragon (web standard)
notwaldorf
88
5.7k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.3k
Gamification - CAS2011
davidbonilla
80
5k
Side Projects
sachag
452
42k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
27
840
Producing Creativity
orderedlist
PRO
341
39k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
250
21k
Transcript
Perlͷ࣌ؒϞδϡʔϧͰ Perlएखͷձ 2020-07-01 @koluku
ࣗݾհ • koluku ʢίϧΫʣ • एख, Perlܦݧ2ϲ݄, ొஃܦݧແ͠ • Python/Go͕ϝΠϯ
͢͜ͱɾ͞ͳ͍͜ͱ • ͢͜ͱ • ࣌ؒͷ੍ޚͷ͋Ε͜Ε • Time::Pieceָ͕ͩΑ • ͞ͳ͍͜ͱ •
࣮ͷ
$^T • ʮϓϩάϥϜΛ࣮ߦ։࢝ͨ࣌͠ࠁΛɺلݩ (1970ͷ࢝Ί) ͔Βͷඵ Ͱ ࣔͨ͠ͷͰ͢ʯ • لݩ (1970ͷ࢝Ί)
ͬͯԿΑʁ
time • ʮ΄ͱΜͲͷγεςϜͰلݩUTC19701݄100:00:00Ͱ͢; ಛతͳྫ֎ͱͯ͠ɺݹ͍MacOSͰϩʔΧϧλΠϜκʔϯͷ 19041݄100:00:00Λلݩͱ͍ͯ͠·͢ɻʯ • UTC19701݄100:00:00͍ΘΏΔUNIX࣌ؒ • UTC19041݄100:00:00͏Δ͏ͷྫ֎ճආͷͨΊͷ •
1904͔Β2096·Ͱ͏Δ͏ଘࡏ͢Δ
$^Tͱtime • ͲͪΒγεςϜ࣌ؒΛฦ͢ͷͰ࣮࣭ಉ͡ • ݱࡏ࣌ؒΛΖ͏ʹUNIX࣌ؒʢඵʣͰฦ͞ΕΔͷͰී௨ʹѻ ͑ͳ͍ • ͦ͜ͰlocaltimeͱgmtimeΛ͏
localtime • ʮtime͕ؔฦ࣌͢ࠁΛɺϩʔΧϧͳλΠϜκʔϯͰଌͬͨ࣌ࠁͱ͠ ͯɺ9ཁૉͷྻʹม͠·͢ɻී௨ɺҎԼͷΑ͏ʹ͍ͯ͠·͢:ʯ • $wday༵Λ0ͱ༵ͨ͠ɺ $yday ͦͷͷԿ͕ؼͬͯ͘ Δ •
εΧϥʔͷͱ͖ʹѻ͏ͱจࣈྻͰؼͬͯ͘Δ • ศརʂ
gmtime • localtimeͩͱϚγϯͷ࣌ؒʹґଘ͢ΔͨΊຊͩͱGMT+9:00 • άϦχοδඪ४࣌ʹ͢ʹ-9࣌ؒ͢Δඞཁ͕… • localtimeͱಉ͡ΈͰάϦχοδඪ४࣌Λѻ͏gmtime͕͋ΔͷͰ ҆৺ʂ
localtimeͱgmtimeͷ᠘ • ʮ$year 1900 ͔ΒͷΛ࣋ͪ·͢ɻʯ • ਓ͕ؒಡΈ͍͢Α͏ʹԼೋܻͰஅͰ͖Δ։࢝ͷͨΊ • ͍ΘΏΔPOSIX४ڌ
• ͚ͩͰݟΔͱ3ύλʔϯ͋Δ
localtimeɺศརʹศརͳΜ͚ͩͲ… • ใ͔͠ͳ͍͔Βѻ͏ʹ݁ہؔΛ࡞Δඞཁ͕͋Δ • ศརϝιου͕ੜ͑ͨΦϒδΣΫτͰฦͯ͠΄͘͠ͳ͍ʁ
Time::Piece • Timepiece࣌ܭͱ͍͏ҙຯ • localtime, gmtime͕Time::PieceΦϒδΣΫτͰؼͬͯ͘Δ • ཉ͍͠ػೳେମἧ͍ͬͯΔ
Time::PieceͰՃࢉɾݮࢉ • Time::SecondsͰ1ʢONE_MINUTEʣͳͲͷఆ͕ٛݺͼग़ͤΔ • Time::PieceʹTime::SecondsͰՃࢉɾݮࢉ͢Δ͜ͱ͕Ͱ͖Δ • localtime + ONE_DAY •
Time::Pieceಉ࢜Ͱݮࢉ͢ΔͱTime::SecondsͰؼͬͯ͘Δʢඵʣ • localtime - gmtime
Time::PieceͰൺֱ • Time::Pieceಉ࢜Ͱൺֱ͢ΔࣄͰ͖Δ • return if (localtime - gmtime ==
ONE_HOUR * 9); • Time::Pieceศར͗͢ͳ͍ʁ
ͰͲ͏ͬͯՃࢉൺֱΛͯ͠Δʁ • ͪΐͬͱدΓಓ • Α͘ߟ͑ͨΒTime::PieceΦϒδΣΫτ͔ͩΒී௨ͷԋࢉࢠͰܭࢉ Ͱ͖Δͷ͓͔͍͠
͜͏͍͏ͱ͖ίʔυΛಡΉͷ͕ૣ͍ • ͱ͏͍͏͜ͱͰmeta::cpan͔ΒBrowseͰίʔυΛݟͯΔͱ Time::Seconndsʹoverloadͱ͍͏໊લ͕ग़ͯ͘Δ
overload • perldoc.jpΛݟͯΈΔͱʮPerl ͷԋࢉࢠͷΦʔόʔϩʔυΛߦ͏ύο έʔδʯͱ͋Δ • ͭ·Γࢉज़ԋࢉࢠൺֱԋࢉࢠΛผͷؔʹ্ॻ͖Ͱ͖Δ • Time::SecondsͰ+ԋࢉࢠͷ߹ࠨӈ͔ΒΛऔͬͯؔʹೖΕͯ ܭࢉͨ͠ͷΛฦ͍ͯ͠Δ
• ͳΔ΄ͲͶ
Ͱେମѻ͍͍ͨͷMySQLͷͱ͖… • ͬͯɺ࣌ؒͱ͍͑MySQLͰͷѻ͍ͳ͔ͳ͔໘ • fracʢখҎԼʣ͕Ճ͞Ε͍ͯΔ͜ͱ͋Δ • DATETIMEͱTIMESTAMPಉ͡ϑΥʔϚοτͰɺ • αϙʔτ͞Ε͍ͯΔൣғ͕ڱ͍, DATETIME݄ɾʹ00Λڐ༰
• ಉ͡Ͱҧ͏Ͱొ͞ΕΔ͕࣌͋Δ • ͜Μͳͷී௨ʹѻ͍ͨ͘ͳ͍ʂ
Time::Piece::MySQL • Time::Pieceͷ֦ுϝιου • Time::Piece->mysql_dateͰMySQLͷDATEܕʹม • Time::Piece->from_mysql_date($datetime)ͰMySQLͷDATEܕ͔Β Time::PieceΦϒδΣΫτʹม • ͜ΕͰMySQLͰͷ࣌ؒͷॲཧʹۤ࿑͢Δ͜ͱͳ͘ͳͬͨ…ʂ
ͬͨʂੈքʹฏ͕๚ΕͨʂͰ… • ϛϦඵɾϚΠΫϩඵͷѻ͍Ͳ͏͢Δͷʁ • ϓϩάϥϜͷ࣮ߦ࣌ؒΛѻ͍͍ͨΜ͚ͩͲ • Q: Ұఆ࣌ؒॲཧΛsleepͤ͞Δʹ • Λྐྵʹม͍ͨ͠
• ͷൣғʹ͋Δ͔Ͳ͏͔Λָʹܭࢉ͍ͨ͠ • ຊҎ֎ͷ࣌ࠁΛϩέʔϧ͍ͨ͠ • ҧ͏ϩέʔϧ࣌ؒͲ͏͠ͰࠩΛग़͍ͨ͠ • etc…
͝ΊΜʂLT͡Ό࣌ؒΓͳ͍͔Β ࣗͰௐͯʂ