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.7k
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
自分だけの世界を創るクリエイティブコーディング / Creative Coding: Creating Your Own World
chobishiba
2
340
Pydantic x Database API:turu-pyの開発
yassun7010
1
480
Modern Functional Fluent CFML REST by Luis Majano
ortus24
0
130
Cohesion in Modeling and Design
mploed
3
180
上手に付き合うコンポーネントテスト
quramy
3
1.2k
Compose Multiplatform과 Ktor로 플랫폼의 경계를 넘어보자
kwakeuijin
0
230
"型"のあるRailsアプリケーション開発 / Typed Rails application development
sinsoku
8
2.2k
Infrastructure as Code でセキュリティを楽にしよう!
konokenj
5
1.4k
CSC305 Lecture 01
javiergs
PRO
1
140
Pythonによるイベントソーシングへの挑戦と現状に対する考察 / Challenging Event Sourcing with Python and Reflections on the Current State
nrslib
3
890
MLOps in Mercari Group’s Trust and Safety ML Team
cjhj
1
110
ファーストペンギンBot @Qiita Hackathon 2024 予選
dyson_web
0
210
Featured
See All Featured
What's in a price? How to price your products and services
michaelherold
243
11k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
7
560
4 Signs Your Business is Dying
shpigford
180
21k
Typedesign – Prime Four
hannesfritz
39
2.3k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
30
2.6k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
249
21k
Debugging Ruby Performance
tmm1
73
12k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
246
1.3M
Building Flexible Design Systems
yeseniaperezcruz
327
38k
Put a Button on it: Removing Barriers to Going Fast.
kastner
58
3.5k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.8k
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