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
カスタマーサクセス業務を変革したヘルススコアの実現と学び
_hummer0724
0
650
LLM Observabilityによる 対話型音声AIアプリケーションの安定運用
gekko0114
2
420
AI Agent の開発と運用を支える Durable Execution #AgentsInProd
izumin5210
7
2.3k
Basic Architectures
denyspoltorak
0
660
Package Management Learnings from Homebrew
mikemcquaid
0
210
Honoを使ったリモートMCPサーバでAIツールとの連携を加速させる!
tosuri13
1
170
Amazon Bedrockを活用したRAGの品質管理パイプライン構築
tosuri13
4
250
AIで開発はどれくらい加速したのか?AIエージェントによるコード生成を、現場の評価と研究開発の評価の両面からdeep diveしてみる
daisuketakeda
1
970
今こそ知るべき耐量子計算機暗号(PQC)入門 / PQC: What You Need to Know Now
mackey0225
3
370
Automatic Grammar Agreementと Markdown Extended Attributes について
kishikawakatsumi
0
180
そのAIレビュー、レビューしてますか? / Are you reviewing those AI reviews?
rkaga
6
4.5k
Fluid Templating in TYPO3 14
s2b
0
130
Featured
See All Featured
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.6k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
196
71k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
9.9k
SEO Brein meetup: CTRL+C is not how to scale international SEO
lindahogenes
0
2.3k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.1k
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
Everyday Curiosity
cassininazir
0
130
The Power of CSS Pseudo Elements
geoffreycrofte
80
6.1k
Evolving SEO for Evolving Search Engines
ryanjones
0
120
Why Our Code Smells
bkeepers
PRO
340
58k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
7.9k
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