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
Week based calendar and iOS
Search
Oleksandr Dodatko
December 22, 2012
Programming
0
99
Week based calendar and iOS
This talk covers some aspects of working with dates, calendars in iOS and SQLite
Oleksandr Dodatko
December 22, 2012
Tweet
Share
More Decks by Oleksandr Dodatko
See All by Oleksandr Dodatko
From Objective-C to Xamarin
dodikk
1
220
Building libraries for iOS — Going native (v2)
dodikk
3
270
Building libraries for iOS — Going native
dodikk
2
180
iAsync Functional Programming in Objective-C
dodikk
1
170
RubyMotion : A fly in the ointment
dodikk
0
58
iContinuousIntegration
dodikk
0
69
Other Decks in Programming
See All in Programming
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
120
LLM生成文章の精度評価自動化とプロンプトチューニングの効率化について
layerx
PRO
2
190
Nurturing OpenJDK distribution: Eclipse Temurin Success History and plan
ivargrimstad
0
950
Streams APIとTCPフロー制御 / Web Streams API and TCP flow control
tasshi
2
350
型付き API リクエストを実現するいくつかの手法とその選択 / Typed API Request
euxn23
8
2.2k
Ethereum_.pdf
nekomatu
0
460
CSC509 Lecture 11
javiergs
PRO
0
180
카카오페이는 어떻게 수천만 결제를 처리할까? 우아한 결제 분산락 노하우
kakao
PRO
0
110
Generative AI Use Cases JP (略称:GenU)奮闘記
hideg
1
300
ふかぼれ!CSSセレクターモジュール / Fukabore! CSS Selectors Module
petamoriken
0
150
ヤプリ新卒SREの オンボーディング
masaki12
0
130
Remix on Hono on Cloudflare Workers
yusukebe
1
300
Featured
See All Featured
How to Think Like a Performance Engineer
csswizardry
20
1.1k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
27
840
Automating Front-end Workflow
addyosmani
1366
200k
A designer walks into a library…
pauljervisheath
204
24k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
The Cost Of JavaScript in 2023
addyosmani
45
6.8k
How To Stay Up To Date on Web Technology
chriscoyier
788
250k
Teambox: Starting and Learning
jrom
133
8.8k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
246
1.3M
What's in a price? How to price your products and services
michaelherold
243
12k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
229
52k
Docker and Python
trallard
40
3.1k
Transcript
Dodatko Alexander November 2012
None
How many months does the year consist of?
What is the first day of the year?
What day does a new week start on?
Right, but did you know that ...
Jewish calendar consists of 13 months. And month #6 is
a leaping one.
In Japan the calendar may return to year #1 at
the day of the emperor's death
In Russia week starts on Monday. In the USA the
first day is Sunday
None
Dates must look in the way the user expects
None
None
-(NSDate*)parseDate:( NSString* )date_ { NSDateFormatter* df_ = [ NSDateFormatter new
]; df_.dateFormat = @"yyyy-MM-dd"; return [ df_ dateFromString: date_ ]; } The Typical Solution
-(NSDate*)parseDate:( NSString* )date_ { NSDateFormatter* df_ = [ NSDateFormatter new
]; df_.dateFormat = @"yyyy-MM-dd"; return [ df_ dateFromString: date_ ]; } WRONG !
None
Use en_US_POSIX locale for dates from the network Use Gregorian
calendar too
None
Do not forget to set the same Locale for both
NSCalendar and NSDateFormatter
Or let my library do it for you dodikk /
ESLocale
Ok. How about SQLite?
None
SELECT SUM( Visits) FROM VisitsLog WHERE Date BETWEEN x AND
y GROUP BY week
What should I take as week ?
SELECT SUM( Visits) FROM VisitsLog WHERE Date BETWEEN x AND
y GROUP BY Strftime('%Y-%W', Date )
SELECT SUM( Visits) FROM VisitsLog WHERE Date BETWEEN x AND
y GROUP BY Strftime('%Y-%W', Date )
None
SELECT SUM( Visits) FROM VisitsLog WHERE Date BETWEEN x AND
y GROUP BY ObjcFormatDate('YYYY-ww', Date, 'en_US_POSIX' )
None
int sqlite3_create_function( dbHandle, "ObjcFormatDate", 3, //int nArg, SQLITE_UTF8, NULL, //
sqlite user data functionPointer, NULL, NULL // for aggregates );
Plan of attack Convert C strings to NSString Convert date
string to NSDate Format NSDate using locale
SQLite uses ANSI format yyyy-MM-dd
Demo
One More Thing
None
1000 times slower than strftime 10K records Creating NSDateFormatter on-the-fly
None
Same speed as strftime Same 10K records Singletone NSDateFormatter
Thread Safety
dodikk / ESLocale
Contacts Oleksandr Dodatko mail/jabber :
[email protected]
Skype : alexander.dodatko.work Twitter
: @dodikk88 Github : https://github.com/dodikk https://github.com/EmbeddedSources
None