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
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
今から始めるClaude Code超入門
448jp
7
8.3k
MDN Web Docs に日本語翻訳でコントリビュート
ohmori_yusuke
0
640
Oxlint JS plugins
kazupon
1
580
AIによるイベントストーミング図からのコード生成 / AI-powered code generation from Event Storming diagrams
nrslib
2
1.8k
CSC307 Lecture 01
javiergs
PRO
0
690
ZJIT: The Ruby 4 JIT Compiler / Ruby Release 30th Anniversary Party
k0kubun
1
400
CSC307 Lecture 02
javiergs
PRO
1
770
OCaml 5でモダンな並列プログラミングを Enjoyしよう!
haochenx
0
120
CSC307 Lecture 07
javiergs
PRO
0
550
Vibe codingでおすすめの言語と開発手法
uyuki234
0
220
副作用をどこに置くか問題:オブジェクト指向で整理する設計判断ツリー
koxya
1
590
dchart: charts from deck markup
ajstarks
3
990
Featured
See All Featured
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
1.9k
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
1
640
Measuring & Analyzing Core Web Vitals
bluesmoon
9
750
Heart Work Chapter 1 - Part 1
lfama
PRO
5
35k
The SEO identity crisis: Don't let AI make you average
varn
0
64
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
jQuery: Nuts, Bolts and Bling
dougneiner
65
8.4k
KATA
mclloyd
PRO
34
15k
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
0
310
The Limits of Empathy - UXLibs8
cassininazir
1
210
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
72
Writing Fast Ruby
sferik
630
62k
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