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
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
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
AI巻き込み型コードレビューのススメ
nealle
1
150
AIによる開発の民主化を支える コンテキスト管理のこれまでとこれから
mulyu
3
190
CSC307 Lecture 09
javiergs
PRO
1
830
今こそ知るべき耐量子計算機暗号(PQC)入門 / PQC: What You Need to Know Now
mackey0225
3
370
KIKI_MBSD Cybersecurity Challenges 2025
ikema
0
1.3k
AI時代のキャリアプラン「技術の引力」からの脱出と「問い」へのいざない / tech-gravity
minodriven
21
7.1k
CSC307 Lecture 08
javiergs
PRO
0
670
AIによる高速開発をどう制御するか? ガードレール設置で開発速度と品質を両立させたチームの事例
tonkotsuboy_com
7
2.2k
ThorVG Viewer In VS Code
nors
0
770
Fluid Templating in TYPO3 14
s2b
0
130
Data-Centric Kaggle
isax1015
2
770
インターン生でもAuth0で認証基盤刷新が出来るのか
taku271
0
190
Featured
See All Featured
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
240
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
150
Discover your Explorer Soul
emna__ayadi
2
1.1k
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
55
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.4k
What's in a price? How to price your products and services
michaelherold
247
13k
Git: the NoSQL Database
bkeepers
PRO
432
66k
Raft: Consensus for Rubyists
vanstee
141
7.3k
Six Lessons from altMBA
skipperchong
29
4.1k
A better future with KSS
kneath
240
18k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
92
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