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
DateComponentsと仲良くなる
Search
sato-shin
September 19, 2021
Programming
3
2.8k
DateComponentsと仲良くなる
iOSDC 2021で発表したスライドです。
* asken tech blog:
https://tech.asken.inc
* youtube link: アップロードされたら
sato-shin
September 19, 2021
Tweet
Share
More Decks by sato-shin
See All by sato-shin
Bitriseのビルド回数が 10倍以上になって変わったコト
satoshin
1
360
Pull Request Trigger について ~Expose for Pull Request?~
satoshin
1
120
User Notification for UX!
satoshin
0
160
Using various views on Notification Content app extension
satoshin
2
970
Getting step count on iOS
satoshin
4
3k
Other Decks in Programming
See All in Programming
ECS Service Connectのこれまでのアップデートと今後のRoadmapを見てみる
tkikuc
2
250
どうして僕の作ったクラスが手続き型と言われなきゃいけないんですか
akikogoto
1
120
CSC509 Lecture 09
javiergs
PRO
0
140
初めてDefinitelyTypedにPRを出した話
syumai
0
400
광고 소재 심사 과정에 AI를 도입하여 광고 서비스 생산성 향상시키기
kakao
PRO
0
170
Compose 1.7のTextFieldはPOBox Plusで日本語変換できない
tomoya0x00
0
190
アジャイルを支えるテストアーキテクチャ設計/Test Architecting for Agile
goyoki
9
3.3k
『ドメイン駆動設計をはじめよう』のモデリングアプローチ
masuda220
PRO
8
540
型付き API リクエストを実現するいくつかの手法とその選択 / Typed API Request
euxn23
8
2.2k
macOS でできる リアルタイム動画像処理
biacco42
9
2.4k
Jakarta Concurrencyによる並行処理プログラミングの始め方 (JJUG CCC 2024 Fall)
tnagao7
1
290
RubyLSPのマルチバイト文字対応
notfounds
0
120
Featured
See All Featured
Designing for humans not robots
tammielis
250
25k
The Cost Of JavaScript in 2023
addyosmani
45
6.7k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
109
49k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
26
1.4k
Adopting Sorbet at Scale
ufuk
73
9.1k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
GraphQLとの向き合い方2022年版
quramy
43
13k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
8
860
Six Lessons from altMBA
skipperchong
27
3.5k
Facilitating Awesome Meetings
lara
50
6.1k
Transcript
TBUPTIJO!BTLFO*OD %BUF$PNQPOFOUTͱ ྑ͘ͳΔɹ J04%$+BQBO
ຊηογϣϯʹ͍ͭͯ %BUF$PNQPOFOUTͱྑ͘ͳΔɹ
ຊηογϣϯʹ͍ͭͯ %BUF$PNQPOFOUTͱྑ͘ͳΔɹ ࠓɺ͍ʁ
ຊηογϣϯʹ͍ͭͯ %BUF$PNQPOFOUTͱྑ͘ͳΔɹ ࠓɺ͍ʁ %BUF$PNQPOFOUTJ04
ຊηογϣϯʹ͍ͭͯ %BUF$PNQPOFOUTͱྑ͘ͳΔɹ J04ʹؔ͢Δʁ
ຊηογϣϯʹ͍ͭͯ %BUF$PNQPOFOUTͱྑ͘ͳΔɹ J04ʹؔ͢Δʁ
ຊηογϣϯʹ͍ͭͯ %BUF$PNQPOFOUTͱྑ͘ͳΔɹ ࣌ܭࢉΛ%BUFͰࡁ·ͤͪΌͬͯΔਓ %BUF$PNQPOFOUTΛ͋Μ·Γͬͨ͜ͱ͕ͳ͍ਓ ͦΜͳਓͷͨΊͷηογϣϯͰ͢ɻ
࣌ؒͷجૅ
࣌ؒͲͷΑ͏ʹఆٛ͞ΕΔʁ
࣌ؒͲͷΑ͏ʹఆٛ͞ΕΔʁ ࣌ؒ࣠
࣌ؒͲͷΑ͏ʹఆٛ͞ΕΔʁ ࠓ ࣌ؒ࣠
࣌ؒͲͷΑ͏ʹఆٛ͞ΕΔʁ ࠓ ج४ ࣌ؒ࣠
࣌ؒͲͷΑ͏ʹఆٛ͞ΕΔʁ ࠓ ج४ ͞ ࣌ؒ࣠
࣌ؒͲͷΑ͏ʹఆٛ͞ΕΔʁ ࠓ ج४ ͞ ࣌ؒ࣠ ༗໊ͳج४ɿ 6/*9ΤϙοΫ 65$
࣌ؒͲͷΑ͏ʹఆٛ͞ΕΔʁ ࠓ ج४ ͞<ඵ> ࠃࡍ୯Ґܥʢ4*ʣͰఆٛ͞ΕΔ࣌ؒͷ୯Ґ͕ඵ ࣌ؒ࣠ ༗໊ͳج४ɿ 6/*9ΤϙοΫ 65$
4XJGUͰ࣌ؒΛදݱ͢Δܕʁ %BUF
4XJGUͰͲͷΑ͏ʹදݱ͞ΕΔʁ %BUF init(timeIntervalSinceNow: ) init(timeIntervalSince1970: ) init(timeIntervalSinceReferenceDate: ) init(timeInterval: since:
) init()
4XJGUͰͲͷΑ͏ʹදݱ͞ΕΔʁ init(timeIntervalSinceNow: ) init(timeIntervalSince1970: ) init(timeIntervalSinceReferenceDate: ) init(timeInterval: since: )
init() %BUF
4XJGUͰͲͷΑ͏ʹදݱ͞ΕΔʁ init(timeIntervalSinceNow: ) init(timeIntervalSince1970: ) init(timeIntervalSinceReferenceDate: ) init(timeInterval: since: )
init() = init(timeIntervalSinceNow: 0) %BUF
%BUF㱠 %BUF࣌ؒͷ
ʁ݄ʁʁ ඵ͔͠Βͳ͍Αʂ %BUF㱠 %BUF࣌ؒͷ
࣌ܭࢉͷ͠͞
͠ࢉ͢Δ let after10Sec = Date() + 10 let after1Minute =
Date() + 60 let after1Day = Date() + (60 * 60 * 24) let after1Month = Date() + (60 * 60 * 24 * 30)
͠ࢉ͢Δ ! let after10Sec = Date() + 10 let after1Minute
= Date() + 60 let after1Day = Date() + (60 * 60 * 24) let after1Month = Date() + (60 * 60 * 24 * 30)
࣌ܭࢉͰߟྀ͠ͳ͚Ε͍͚ͳ͍͜ͱ ͏Δ͏ͷଘࡏ ϲ݄ͷఆٛ αϚʔλΠϜ ͏Δ͏ඵͷଘࡏ ϲ݄
࣌ؒ ඵ
ʌůɾ㱼ɾA ŷžŷž
࣌ܭࢉΫϥε$BMFOEBS
࣌ܭࢉΫϥε$BMFOEBS let calendar = Calendar(identifier: .gregorian) let after1Month = calendar.date(byAdding:
.month, value: 1, to: Date())
ʮੜ݄Λ%BUFͰදݱͰ͖Δ͔ʁʯ
ੜ݄Λ%BUFͰදݱͯ͠ΈΔ let birthday = Date(timeIntervalSince1970: 656_175_600) let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd" formatter.timeZone = TimeZone(abbreviation: "UTC") print(formatter.string(from: birthday))
ੜ݄Λ%BUFͰදݱͯ͠ΈΔ let birthday = Date(timeIntervalSince1970: 656_175_600) let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd" formatter.timeZone = TimeZone(abbreviation: "UTC") print(formatter.string(from: birthday)) 1990-10-18 00:00:00 +09:00
ੜ݄Λ%BUFͰදݱͯ͠ΈΔ let birthday = Date(timeIntervalSince1970: 656_175_600) let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd" formatter.timeZone = TimeZone(abbreviation: "UTC") print(formatter.string(from: birthday)) 1990-10-18 00:00:00 +09:00 1990-10-17
%BUF࣌ؒͷ ੜͳͲͷදݱʹ͔ͳ͍
%BUF࣌ؒͷ ੜ݄ͳͲͷදݱʹ͔ͳ͍
%BUF࣌ؒͷ ੜ݄ͳͲͷදݱʹ͔ͳ͍ ࠓɺࠓ݄ɺࠓɺه೦ɺFUD λΠϜκʔϯʹґଘ͠ͳ͍࣌Λਖ਼֬ʹදݱͰ͖ͳ͍
ͰදݱͰ͖Δܕ͕͋ͬͨΒͳ͊ɻɻɻ
%BUF$PNQPOFOUT
let calendar = Calendar(identifier: .gregorian) let birthday = DateComponents(calendar: calendar,
year: 1990, month: 10, day: 18)
%BUF$PNQPOFOUTͷ *OJUJBMJ[FS͔ΒಛΛݟΔ
%BUF$PNQPOFOUT JOJUJBMJ[FS DateComponents(calendar: Calendar?, timeZone: TimeZone?, era: Int?, year: Int?,
month: Int?, day: Int?, hour: Int?, minute: Int?, second: Int?, nanosecond: Int?, weekday: Int?, weekdayOrdinal: Int?, quarter: Int?, weekOfMonth: Int?, weekOfYear: Int?, yearForWeekOfYear: Int?)
ͭш㱬 ŠƄŢŠƄŢ
%BUF$PNQPOFOUT JOJUJBMJ[FS DateComponents(calendar: Calendar?, timeZone: TimeZone?, era: Int?, year: Int?,
month: Int?, day: Int?, hour: Int?, minute: Int?, second: Int?, nanosecond: Int?, weekday: Int?, weekdayOrdinal: Int?, quarter: Int?, weekOfMonth: Int?, weekOfYear: Int?, yearForWeekOfYear: Int?)
%BUF$PNQPOFOUT JOJUJBMJ[FS ͳΜͱҾݸʂ DateComponents(calendar: Calendar?, timeZone: TimeZone?, era: Int?, year:
Int?, month: Int?, day: Int?, hour: Int?, minute: Int?, second: Int?, nanosecond: Int?, weekday: Int?, weekdayOrdinal: Int?, quarter: Int?, weekOfMonth: Int?, weekOfYear: Int?, yearForWeekOfYear: Int?)
%BUF$PNQPOFOUT ࣌Λߏ͢Δཁૉ܈
%BUF$PNQPOFOUT JOJUJBMJ[FS શͯ࣌ͷߏཁૉ DateComponents(calendar: Calendar?, timeZone: TimeZone?, era: Int?, year:
Int?, month: Int?, day: Int?, hour: Int?, minute: Int?, second: Int?, nanosecond: Int?, weekday: Int?, weekdayOrdinal: Int?, quarter: Int?, weekOfMonth: Int?, weekOfYear: Int?, yearForWeekOfYear: Int?)
ͭͷཁૉຖ؆୯
%BUF$PNQPOFOUT JOJUJBMJ[FS ΧϨϯμʔ DateComponents(calendar: Calendar?, timeZone: TimeZone?, era: Int?, year:
Int?, month: Int?, day: Int?, hour: Int?, minute: Int?, second: Int?, nanosecond: Int?, weekday: Int?, weekdayOrdinal: Int?, quarter: Int?, weekOfMonth: Int?, weekOfYear: Int?, yearForWeekOfYear: Int?)
%BUF$PNQPOFOUT JOJUJBMJ[FS λΠϜκʔϯ DateComponents(calendar: Calendar?, timeZone: TimeZone?, era: Int?, year:
Int?, month: Int?, day: Int?, hour: Int?, minute: Int?, second: Int?, nanosecond: Int?, weekday: Int?, weekdayOrdinal: Int?, quarter: Int?, weekOfMonth: Int?, weekOfYear: Int?, yearForWeekOfYear: Int?)
%BUF$PNQPOFOUT JOJUJBMJ[FS ࣌ ݩ߸ HSFHPSJBOΧϨϯμʔͷ߹ لݩલ ྐྵ ྐྵΧϨϯμʔͷ߹ େԽ ฏ
ྩ DateComponents(calendar: Calendar?, timeZone: TimeZone?, era: Int?, year: Int?, month: Int?, day: Int?, hour: Int?, minute: Int?, second: Int?, nanosecond: Int?, weekday: Int?, weekdayOrdinal: Int?, quarter: Int?, weekOfMonth: Int?, weekOfYear: Int?, yearForWeekOfYear: Int?)
%BUF$PNQPOFOUT JOJUJBMJ[FS ݄࣌ඵφϊඵ DateComponents(calendar: Calendar?, timeZone: TimeZone?, era: Int?, year:
Int?, month: Int?, day: Int?, hour: Int?, minute: Int?, second: Int?, nanosecond: Int?, weekday: Int?, weekdayOrdinal: Int?, quarter: Int?, weekOfMonth: Int?, weekOfYear: Int?, yearForWeekOfYear: Int?)
%BUF$PNQPOFOUT JOJUJBMJ[FS ༵ DateComponents(calendar: Calendar?, timeZone: TimeZone?, era: Int?, year:
Int?, month: Int?, day: Int?, hour: Int?, minute: Int?, second: Int?, nanosecond: Int?, weekday: Int?, weekdayOrdinal: Int?, quarter: Int?, weekOfMonth: Int?, weekOfYear: Int?, yearForWeekOfYear: Int?)
%BUF$PNQPOFOUT JOJUJBMJ[FS ͦͷ༵͕Կ൪͔ DateComponents(calendar: Calendar?, timeZone: TimeZone?, era: Int?, year:
Int?, month: Int?, day: Int?, hour: Int?, minute: Int?, second: Int?, nanosecond: Int?, weekday: Int?, weekdayOrdinal: Int?, quarter: Int?, weekOfMonth: Int?, weekOfYear: Int?, yearForWeekOfYear: Int?) ݄ͷୈ ༵
%BUF$PNQPOFOUT JOJUJBMJ[FS ࢛ظ DateComponents(calendar: Calendar?, timeZone: TimeZone?, era: Int?, year:
Int?, month: Int?, day: Int?, hour: Int?, minute: Int?, second: Int?, nanosecond: Int?, weekday: Int?, weekdayOrdinal: Int?, quarter: Int?, weekOfMonth: Int?, weekOfYear: Int?, yearForWeekOfYear: Int?)
%BUF$PNQPOFOUT JOJUJBMJ[FS ͦͷ݄ͷԿि͔ DateComponents(calendar: Calendar?, timeZone: TimeZone?, era: Int?, year:
Int?, month: Int?, day: Int?, hour: Int?, minute: Int?, second: Int?, nanosecond: Int?, weekday: Int?, weekdayOrdinal: Int?, quarter: Int?, weekOfMonth: Int?, weekOfYear: Int?, yearForWeekOfYear: Int?) ݄ͷୈि
%BUF$PNQPOFOUT JOJUJBMJ[FS ͦͷͷԿि͔ DateComponents(calendar: Calendar?, timeZone: TimeZone?, era: Int?, year:
Int?, month: Int?, day: Int?, hour: Int?, minute: Int?, second: Int?, nanosecond: Int?, weekday: Int?, weekdayOrdinal: Int?, quarter: Int?, weekOfMonth: Int?, weekOfYear: Int?, yearForWeekOfYear: Int?)
%BUF$PNQPOFOUT JOJUJBMJ[FS ʢXFFLPGZFBS༻ʣ DateComponents(calendar: Calendar?, timeZone: TimeZone?, era: Int?, year:
Int?, month: Int?, day: Int?, hour: Int?, minute: Int?, second: Int?, nanosecond: Int?, weekday: Int?, weekdayOrdinal: Int?, quarter: Int?, weekOfMonth: Int?, weekOfYear: Int?, yearForWeekOfYear: Int?)
%BUF$PNQPOFOUTͲ͏͏ʁ
ࡾͭͷׂ ࣌ ྔ ύλʔϯϚον
ࡾͭͷׂ ࣌ %BUF$PNQPOFOUT%BUF
࣌ DateComponents => Date let today = DateComponents(calendar: gregorianCalendar, year:
2021, month: 9, day: 19) var todayInJp = today todayInJp.timeZone = TimeZone(abbreviation: "JST") todayInJp.date // 2021-09-19 00:00:00 +09:00
࣌ DateComponents => Date let today = DateComponents(calendar: gregorianCalendar, year:
2021, month: 9, day: 19) var todayInJp = today todayInJp.timeZone = TimeZone(abbreviation: "JST") todayInJp.date // 2021-09-19 00:00:00 +09:00
࣌ Date => DateComponents let today = gregorianCalendar .dateComponents([.calendar, .year,
.month, .day], from: Date())
࣌ let today = gregorianCalendar .dateComponents([.calendar, .year, .month, .day], from:
Date()) Date͔Β Calendarͱ݄͕ઃఆ͞Εͨ DateComponentsΛੜ Date => DateComponents
ʮࠓʯͷදݱྫ
ʮࠓʯͷදݱྫ
࣌ ʮࠓʯͷදݱྫ // 20219݄19 let today = DateComponents(calendar: gregorianCalendar, year:
2021, month: 9, day: 19) today.isValidDate // true
࣌ ʮࠓʯͷදݱྫ // 20219݄ͷୈ3,༵ let today = DateComponents(calendar: gregorianCalendar, year:
2021, month: 9, weekday: 1, weekdayOrdinal: 3) today.isValidDate // true
࣌ ʮࠓʯͷදݱྫ // 2021ͷ262 let today = DateComponents(calendar: gregorianCalendar, year:
2021, day: 262) today.isValidDate // false
࣌ ʮࠓʯͷදݱྫʢ❌ʣ // 2021ͷ262 let today = DateComponents(calendar: gregorianCalendar, year:
2021, day: 262) today.isValidDate // false 20211݄262ͱఆ͞Εɺfalse
࣌ ʮࠓʯͷදݱྫ // 2021ͷୈ38,༵ let today = DateComponents(calendar: gregorianCalendar, year:
2021, weekday: 1, weekdayOrdinal: 38) today.isValidDate // false
࣌ ʮࠓʯͷදݱྫʢ❌ʣ // 2021ͷୈ38,༵ let today = DateComponents(calendar: gregorianCalendar, year:
2021, weekday: 1, weekdayOrdinal: 38) today.isValidDate // false 20211݄ͷୈ38,༵ͱ ఆ͞Εɺfalse
ࡾͭͷׂ ྔ ͞
ྔ ࣌ܭࢉͷ͓ڙʹ let oneMonth = DateComponents(month: 1) // ̍ϲ݄ let
oneMonthLater = calendar.date(byAdding: oneMonth, to: Date())
ྔ ࣌ܭࢉͷ͓ڙʹ let oneMonth = DateComponents(month: 1) // ̍ϲ݄ let
oneMonthLater = calendar.date(byAdding: oneMonth, to: Date())
ࡾͭͷׂ ύλʔϯϚον
ύλʔϯϚον UserNotificationͷTriggerදݱͳͲ let wakeUpAlertTime = DateComponents(hour: 8, minute: 30) let
trigger = UNCalendarNotificationTrigger( dateMatching: wakeUpAlertTime, repeats: true)
ύλʔϯϚον UserNotificationͷTriggerදݱͳͲ let wakeUpAlertTime = DateComponents(hour: 8, minute: 30) let
trigger = UNCalendarNotificationTrigger( dateMatching: wakeUpAlertTime, repeats: true)
ύλʔϯϚον UserNotificationͷTriggerදݱͳͲ let wakeUpAlertTime = DateComponents(hour: 8, minute: 30 weekday:
1) let trigger = UNCalendarNotificationTrigger( dateMatching: wakeUpAlertTime, repeats: true)
ύλʔϯϚον UserNotificationͷTriggerදݱͳͲ let wakeUpAlertTime = DateComponents(hour: 8, minute: 30 weekday:
1) let trigger = UNCalendarNotificationTrigger( dateMatching: wakeUpAlertTime, repeats: true) ༵ͷ8࣌30
5JQT
5JQT DateComponents(hour: 12)
5JQT ྔΛද͢ͷ࣌ؒʁ ύλʔϯϚονͷ࣌ʁ DateComponents(hour: 12)
5JQT %BUF$PNQPOFOUT͕ͲΜͳҙຯΛ͔࣋ͭɺίϯςΩετʹΑͬͯҟͳΔɻ ࠞཚ͢Δ߹ʹɺϥούʔΫϥεΛ࡞Δͷ͕͓͢͢Ίɻ // ྔతදݱʹݶఆ͢Δ struct DateLength { var value:
DateComponents }
·ͱΊ %BUF࣌ؒͷͰ͋Γɺѻ͏୯ҐඵͷΈ ඵҎ֎୯ҐͰܭࢉΛߦ͏߹$BMFOEBSΛ͏ %BUF$PNQPOFOUT࣌Λߏ͢Δཁૉ܈Ͱ ओʹʮ࣌ɺྔɺύλʔϯϚονʯͷׂͰΘΕΔ
͚͋͢Μઈࢍ֦େதʂ J04%$ΰʔϧυεϙϯαʔɻ͚͋͢ΜϝΨω১͖ͬͯͶʂ ࠃʮϔϧεέΞʯΧςΰϦͰͷ%-ɺऩӹ/Pʂ 5FDIϒϩά࢝Ί·ͨ͠ʂ 🥇 📖 🎩
͚͋͢Μઈࢍ֦େதʂ 5FDIϒϩάϦϯΫ ຊηογϣϯͷิهࣄॻ͖·ͨ͠ɻ ͥͻνΣοΫͯ͠Έ͍ͯͩ͘͞ʂ https://tech.asken.inc
None