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
350
Pull Request Trigger について ~Expose for Pull Request?~
satoshin
1
120
User Notification for UX!
satoshin
0
150
Using various views on Notification Content app extension
satoshin
2
960
Getting step count on iOS
satoshin
4
3k
Other Decks in Programming
See All in Programming
DevFest Android in Korea 2024 - 안드로이드의 문단속 : 앱을 지키는 암호화 이야기
mdb1217
1
160
C#および.NETに対する誤解をひも解く
ymd65536
0
300
Competitionsだけじゃない! Kaggle Notebooks Grandmasterのすすめ
corochann
2
570
コードレビューと私の過去と未来
jxmtst
0
280
Повторное использование кода в ML: почему ML-пайплайны могут помочь?
lamodatech
0
200
NEWTにおけるiOS18対応の進め方
ryu1sazae
0
240
Beyond Laravel Octane - Hyperf for Laravel Artisans
albertcht
1
140
Cancel Next.js Page Navigation: Full Throttle
ypresto
1
200
色んなオートローダーを覗き見る #phpcon_okinawa
o0h
PRO
5
400
ML-прайсинг_на_Lamoda__вошли_и_вышли__приключение_на_20_минут__Слава_Цыганков.pdf
lamodatech
0
200
Hi, have you met Kotlin Multiplatform? | DevFest Vienna 2024
prof18
0
160
MLOps in Mercari Group’s Trust and Safety ML Team
cjhj
1
120
Featured
See All Featured
XXLCSS - How to scale CSS and keep your sanity
sugarenia
246
1.3M
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.8k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
46
2k
Into the Great Unknown - MozCon
thekraken
31
1.4k
Learning to Love Humans: Emotional Interface Design
aarron
272
40k
Statistics for Hackers
jakevdp
796
220k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
225
22k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
355
29k
Why Our Code Smells
bkeepers
PRO
334
57k
How to train your dragon (web standard)
notwaldorf
87
5.6k
Building Adaptive Systems
keathley
38
2.2k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
1
300
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