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.9k
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
980
Getting step count on iOS
satoshin
4
3k
Other Decks in Programming
See All in Programming
Go の GC の不得意な部分を克服したい
taiyow
2
770
急成長期の品質とスピードを両立するフロントエンド技術基盤
soarteclab
0
930
今年のアップデートで振り返るCDKセキュリティのシフトレフト/2024-cdk-security-shift-left
tomoki10
0
200
複雑な仕様に立ち向かうアーキテクチャ
myohei
0
170
Keeping it Ruby: Why Your Product Needs a Ruby SDK - RubyWorld 2024
envek
0
180
menu基盤チームによるGoogle Cloudの活用事例~Application Integration, Cloud Tasks編~
yoshifumi_ishikura
0
110
Итераторы в Go 1.23: зачем они нужны, как использовать, и насколько они быстрые?
lamodatech
0
710
今年一番支援させていただいたのは認証系サービスでした
satoshi256kbyte
1
250
RWC 2024 DICOM & ISO/IEC 2022
m_seki
0
210
ブラウザ単体でmp4書き出すまで - muddy-web - 2024-12
yue4u
2
460
Symfony Mapper Component
soyuka
2
730
数十万行のプロジェクトを Scala 2から3に完全移行した
xuwei_k
0
270
Featured
See All Featured
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
2
170
How To Stay Up To Date on Web Technology
chriscoyier
789
250k
The Pragmatic Product Professional
lauravandoore
32
6.3k
4 Signs Your Business is Dying
shpigford
181
21k
Into the Great Unknown - MozCon
thekraken
33
1.5k
Unsuck your backbone
ammeep
669
57k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
2
290
How GitHub (no longer) Works
holman
311
140k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
6
510
Fireside Chat
paigeccino
34
3.1k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
28
900
Product Roadmaps are Hard
iamctodd
PRO
49
11k
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