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
asdf-ecspresso作って 友達が増えた話 / Fujiwara Tech Conference 2025
koluku
0
1.1k
日常業務のカイゼンで図る開発チームへの貢献 - YAPC::Kyoto 2023
koluku
4
1.8k
Other Decks in Programming
See All in Programming
AHC041解説
terryu16
0
300
AIレシート読み取り機能をRuby on Rails on AWSで実現するLLMにまつわるアレコレ / AI-based receipt reading function powered by LLM on Ruby on Rails on AWS
moznion
3
120
Package Traits
ikesyo
1
200
DMMオンラインサロンアプリのSwift化
hayatan
0
150
Lookerは可視化だけじゃない。UIコンポーネントもあるんだ!
ymd65536
1
130
快速入門可觀測性
blueswen
0
490
カンファレンス動画鑑賞会のススメ / Osaka.swift #1
hironytic
0
160
テストコードのガイドライン 〜作成から運用まで〜
riku929hr
7
1.4k
バグを見つけた?それAppleに直してもらおう!
uetyo
0
220
React 19でお手軽にCSS-in-JSを自作する
yukukotani
5
560
Оптимизируем производительность блока Казначейство
lamodatech
0
940
Swiftコンパイラ超入門+async関数の仕組み
shiz
0
170
Featured
See All Featured
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
Gamification - CAS2011
davidbonilla
80
5.1k
Bash Introduction
62gerente
610
210k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
27
1.5k
It's Worth the Effort
3n
183
28k
RailsConf 2023
tenderlove
29
970
Measuring & Analyzing Core Web Vitals
bluesmoon
5
200
Embracing the Ebb and Flow
colly
84
4.5k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
98
18k
What's in a price? How to price your products and services
michaelherold
244
12k
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͡Ό࣌ؒΓͳ͍͔Β ࣗͰௐͯʂ