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
flutterkaigi_2024.pdf
kyoheig3
0
150
ヤプリ新卒SREの オンボーディング
masaki12
0
130
CSC509 Lecture 13
javiergs
PRO
0
110
受け取る人から提供する人になるということ
little_rubyist
0
250
Realtime API 入門
riofujimon
0
150
Snowflake x dbtで作るセキュアでアジャイルなデータ基盤
tsoshiro
2
520
as(型アサーション)を書く前にできること
marokanatani
10
2.7k
Contemporary Test Cases
maaretp
0
140
OSSで起業してもうすぐ10年 / Open Source Conference 2024 Shimane
furukawayasuto
0
110
Jakarta EE meets AI
ivargrimstad
0
210
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
100
Compose 1.7のTextFieldはPOBox Plusで日本語変換できない
tomoya0x00
0
190
Featured
See All Featured
Keith and Marios Guide to Fast Websites
keithpitt
409
22k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.5k
Building Flexible Design Systems
yeseniaperezcruz
327
38k
Scaling GitHub
holman
458
140k
Building an army of robots
kneath
302
43k
Documentation Writing (for coders)
carmenintech
65
4.4k
Automating Front-end Workflow
addyosmani
1366
200k
Site-Speed That Sticks
csswizardry
0
28
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
Bash Introduction
62gerente
608
210k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
364
24k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
44
2.2k
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