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
1
100
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
100
Micro Frontends Unmasked Opportunities, Challenges, Alternatives
manfredsteyer
PRO
0
110
どうして僕の作ったクラスが手続き型と言われなきゃいけないんですか
akikogoto
1
120
色々なIaCツールを実際に触って比較してみる
iriikeita
0
330
リアーキテクチャxDDD 1年間の取り組みと進化
hsawaji
1
220
聞き手から登壇者へ: RubyKaigi2024 LTでの初挑戦が 教えてくれた、可能性の星
mikik0
1
130
Flutterを言い訳にしない!アプリの使い心地改善テクニック5選🔥
kno3a87
1
200
WebフロントエンドにおけるGraphQL(あるいはバックエンドのAPI)との向き合い方 / #241106_plk_frontend
izumin5210
4
1.4k
C++でシェーダを書く
fadis
6
4.1k
AWS Lambdaから始まった Serverlessの「熱」とキャリアパス / It started with AWS Lambda Serverless “fever” and career path
seike460
PRO
1
260
Jakarta EE meets AI
ivargrimstad
0
690
Featured
See All Featured
VelocityConf: Rendering Performance Case Studies
addyosmani
325
24k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
25
1.8k
Faster Mobile Websites
deanohume
305
30k
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.2k
Six Lessons from altMBA
skipperchong
27
3.5k
Ruby is Unlike a Banana
tanoku
97
11k
The Language of Interfaces
destraynor
154
24k
Imperfection Machines: The Place of Print at Facebook
scottboms
265
13k
Optimizing for Happiness
mojombo
376
70k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
8
900
Git: the NoSQL Database
bkeepers
PRO
427
64k
Rebuilding a faster, lazier Slack
samanthasiow
79
8.7k
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