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
Date / Time / Calendar / Time zone
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Lukasz Pikor
May 25, 2017
Programming
0
69
Date / Time / Calendar / Time zone
Presentation about classes from iOS SDK: Date / Time / Calendar / Time zone
Lukasz Pikor
May 25, 2017
Tweet
Share
More Decks by Lukasz Pikor
See All by Lukasz Pikor
Chat apps: my observations based on 2 projects and 3 chat services
pikor
1
38
Mobile app release strategies
pikor
0
120
Hashable in Swift
pikor
0
35
Other Decks in Programming
See All in Programming
IFSによる形状設計/デモシーンの魅力 @ 慶應大学SFC
gam0022
1
300
インターン生でもAuth0で認証基盤刷新が出来るのか
taku271
0
190
Spinner 軸ズレ現象を調べたらレンダリング深淵に飲まれた #レバテックMeetup
bengo4com
1
230
OCaml 5でモダンな並列プログラミングを Enjoyしよう!
haochenx
0
130
AIエージェントの設計で注意するべきポイント6選
har1101
7
3.4k
【卒業研究】会話ログ分析によるユーザーごとの関心に応じた話題提案手法
momok47
0
190
HTTPプロトコル正しく理解していますか? 〜かわいい猫と共に学ぼう。ฅ^•ω•^ฅ ニャ〜
hekuchan
2
680
React 19でつくる「気持ちいいUI」- 楽観的UIのすすめ
himorishige
11
5.9k
AI によるインシデント初動調査の自動化を行う AI インシデントコマンダーを作った話
azukiazusa1
1
690
Architectural Extensions
denyspoltorak
0
270
SourceGeneratorのススメ
htkym
0
190
MUSUBIXとは
nahisaho
0
130
Featured
See All Featured
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
62
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.4k
YesSQL, Process and Tooling at Scale
rocio
174
15k
Building a Scalable Design System with Sketch
lauravandoore
463
34k
We Analyzed 250 Million AI Search Results: Here's What I Found
joshbly
1
670
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
0
100
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
47
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
130
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
0
400
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
Stop Working from a Prison Cell
hatefulcrawdad
273
21k
Reflections from 52 weeks, 52 projects
jeffersonlam
356
21k
Transcript
Date / Time / Calendar / Time zone Date /
Time / Calendar / Time zone
60, 3600, 86 400 Date / Time / Calendar /
Time zone
Date / Time / Calendar / Time zone
60, 3600, 86 400 60 * 60 (60 * 60
* 7, 60 * 60 * 17) [2, 3, 4, 5, 6]
60, 3600, 86 400 // extension Date var isTomorrow: Bool
{ let dayInterval = TimeInterval(60 * 60 * 24) let tomorrow = Date().addingTimeInterval(dayInterval) guard let endOfTomorrow = tomorrow.endOfDay else { return false } return isBetween(startDate: tomorrow.startOfDay, endDate: endOfTomorrow) }
60, 3600, 86 400 // extension Date var isTomorrow: Bool
{ let dayInterval = TimeInterval(60 * 60 * 24) let tomorrow = Date().addingTimeInterval(dayInterval) guard let endOfTomorrow = tomorrow.endOfDay else { return false } return isBetween(startDate: tomorrow.startOfDay, endDate: endOfTomorrow) } let dayInterval = TimeInterval(60 * 60 * 24)
60, 3600, 86 400 // extension Date var isTomorrow: Bool
{ let dayInterval = TimeInterval(60 * 60 * 24) let tomorrow = Date().addingTimeInterval(dayInterval) guard let endOfTomorrow = tomorrow.endOfDay else { return false } return isBetween(startDate: tomorrow.startOfDay, endDate: endOfTomorrow) } let tomorrow = Date().addingTimeInterval(dayInterval)
60, 3600, 86 400 // extension Date var isTomorrow: Bool
{ let dayInterval = TimeInterval(60 * 60 * 24) let tomorrow = Date().addingTimeInterval(dayInterval) guard let endOfTomorrow = tomorrow.endOfDay else { return false } return isBetween(startDate: tomorrow.startOfDay, endDate: endOfTomorrow) } guard let endOfTomorrow = tomorrow.endOfDay else { return false }
60, 3600, 86 400 // extension Date var isTomorrow: Bool
{ let dayInterval = TimeInterval(60 * 60 * 24) let tomorrow = Date().addingTimeInterval(dayInterval) guard let endOfTomorrow = tomorrow.endOfDay else { return false } return isBetween(startDate: tomorrow.startOfDay, endDate: endOfTomorrow) } return isBetween(startDate: tomorrow.startOfDay, endDate: endOfTomorrow)
System API’s to the rescue! System API’s to the rescue!
System API’s to the rescue! Session 124: Understanding Foundation, WWDC
2010
Date Date
Date Date() init(timeIntervalSinceNow: TimeInterval) init(timeInterval: TimeInterval, since: Date)
Date init(timeIntervalSinceReferenceDate: TimeInterval) // reference date: 00:00:00 UTC on 1
January 2001 init(timeIntervalSince1970: TimeInterval) // Unix Epoch: 00:00:00 UTC on 1 January 1970
Calendar Calendar
Calendar Calendar.current Calendar.autoupdatingCurrent
TimeZone TimeZone
TimeZone init?(secondsFromGMT seconds: Int) // 3600
TimeZone init?(abbreviation: String) // CET, CEST init?(identifier: String) // „Europe/Warsaw”
a.k.a tz database
DateComponents DateComponents
DateComponents let calendar = Calendar.current let timezone = TimeZone(identifier: "Europe/Warsaw")
var dateComps = DateComponents() dateComps.calendar = calendar dateComps.year = 2017 dateComps.month = 5 dateComps.day = 25 dateComps.hour = 19 dateComps.timeZone = timezone let dateToPrint = dateComps.date! print("Date: \(dateToPrint)”) // Date: 2017-05-25 17:00:00 +0000
DateComponents let calendar = Calendar.current let timezone = TimeZone(identifier: "Europe/Warsaw")
var dateComps = DateComponents() dateComps.calendar = calendar dateComps.year = 2017 dateComps.month = 5 dateComps.day = 25 dateComps.hour = 19 dateComps.timeZone = timezone let dateToPrint = dateComps.date! print("Date: \(dateToPrint)”) // Date: 2017-05-25 17:00:00 +0000 var dateComps = DateComponents() dateComps.calendar = calendar dateComps.year = 2017 dateComps.month = 5 dateComps.day = 25 dateComps.hour = 19 dateComps.timeZone = timezone
DateComponents let calendar = Calendar.current let timezone = TimeZone(identifier: "America/Los_Angeles")
var dateComps = DateComponents() dateComps.calendar = calendar dateComps.year = 2017 dateComps.month = 5 dateComps.day = 25 dateComps.hour = 19 dateComps.timeZone = timezone let dateToPrint = dateComps.date! print("Date: \(dateToPrint)”) // Date: 2017-05-26 02:00:00 +0000 let dateToPrint = dateComps.date! print("Date: \(dateToPrint)”) // Date: 2017-05-26 02:00:00 +0000
DateComponents let now = Date() var comps = DateComponents() comps.month
= -1 comps.day = -1 comps.hour = -1 comps.timeZone = timezone let calendar = Calendar.current let newDate = calendar.date(byAdding: comps, to: now) // Apr 24, 2017, 5:30 PM let now = Date() var comps = DateComponents() comps.month = -1 comps.day = -1 comps.hour = -1 comps.timeZone = timezone
DateComponents let now = Date() var comps = DateComponents() comps.month
= -1 comps.day = -1 comps.hour = -1 comps.timeZone = timezone let calendar = Calendar.current let newDate = calendar.date(byAdding: comps, to: now) // Apr 24, 2017, 5:30 PM let calendar = Calendar.current let newDate = calendar.date(byAdding: comps, to: now) // Apr 24, 2017, 5:30 PM
DateFormatter DateComponents
DateFormatter
DateFormatter let now = Date(timeIntervalSince1970: 1495737000) let formatter = DateFormatter()
formatter.locale = Locale.autoupdatingCurrent formatter.dateStyle = .medium formatter.timeStyle = .medium let output = formatter.string(from: now) // shorter version: DateFormatter.localizedString(from: now, dateStyle: .medium, timeStyle: .medium) // "May 25, 2017, 8:30:00 PM" // "2017年年5⽉月25⽇日 下午8:30:00"
So… DateComponents
So… let tuple = (60 * 60 * 7, 60
* 60 * 17) var sevenAM = DateComponents() sevenAM.hour = 7 sevenAM.minute = 00 var fivePM = DateComponents() sevenAM.hour = 17 sevenAM.minute = 00
So… let weekdays = [2, 3, 4, 5, 6] calendar.isDateInWeekend(myDate)
So… // extension Date var isTomorrow: Bool { let dayInterval
= TimeInterval(60 * 60 * 24) let tomorrow = Date().addingTimeInterval(dayInterval) guard let endOfTomorrow = tomorrow.endOfDay else { return false } return isBetween(startDate: tomorrow.startOfDay, endDate: endOfTomorrow) } calendar.isDateInTomorrow(myDate)
Pikor @pikorpikorpikor