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
120
0
Share
Week based calendar and iOS
This talk covers some aspects of working with dates, calendars in iOS and SQLite
Oleksandr Dodatko
December 22, 2012
More Decks by Oleksandr Dodatko
See All by Oleksandr Dodatko
From Objective-C to Xamarin
dodikk
1
240
Building libraries for iOS — Going native (v2)
dodikk
3
300
Building libraries for iOS — Going native
dodikk
2
210
iAsync Functional Programming in Objective-C
dodikk
1
200
RubyMotion : A fly in the ointment
dodikk
0
76
iContinuousIntegration
dodikk
0
100
Other Decks in Programming
See All in Programming
Stage 3 Decorators でできること / できないこと / TSKaigi 2026
susisu
1
1.5k
Copilot CLI の継戦能力を高める コンテキスト管理
nozomutu
1
1.2k
ReactとSvelteのその先、Ripple-TS / Beyond React and Svelte: Ripple-TS
ssssota
3
2k
決定論的オーケストレーションの設計と実装 / Design and Implementation of Deterministic Orchestration
nrslib
3
920
[2026年度第1回ORセミナー] 計画最適化ベンチャーと競技プログラミング人材
terryu16
0
240
ユニットテストの先へ:テスト技法で要求・仕様を整理するJava開発実践 / Beyond_Unit_Testing_Practical_Java_Development_Techniques_for_Organizing_Requirements_and_Specifications
shimashima35
0
340
次世代リンターで探る、tsgo 時代における型認識カスタムルールの現実解
ytakahashii
3
1.4k
メソッドのジェネリクスでGoの夢は広がるか? / Kyoto.go #65
utgwkk
3
460
エージェンティックRAGにAWSで入門しよう!
har1101
5
330
Migrations : C'est une question d'hygiène !
vinceamstoutz
0
3.2k
Lemonade + Foundry Toolkit でお手軽アプリ開発
seosoft
1
270
AI駆動開発勉強会 広島支部 第一回勉強会 AI駆動開発概要とワークショップ
hayatoshimiu
0
430
Featured
See All Featured
What's in a price? How to price your products and services
michaelherold
247
13k
How Software Deployment tools have changed in the past 20 years
geshan
0
34k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.5k
Information Architects: The Missing Link in Design Systems
soysaucechin
0
960
Color Theory Basics | Prateek | Gurzu
gurzu
0
330
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
930
The SEO identity crisis: Don't let AI make you average
varn
0
480
Practical Orchestrator
shlominoach
191
11k
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
5
1.1k
Designing for Performance
lara
611
70k
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
The Cult of Friendly URLs
andyhume
79
6.9k
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