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
98
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
210
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
47
iContinuousIntegration
dodikk
0
63
Other Decks in Programming
See All in Programming
try!Swift Tokyo 2024 参加報告 LT
akidon0000
1
230
GitHub Copilotのススメ
marcy731
1
210
Netty Chicago Java User Group 2024-04-17
sullis
0
190
禅の心を手に入れよ
eltociear
1
230
Ruby Function Composition
bkuhlmann
1
340
Fast JSX: Don't clone props object #28768
yossydev
1
150
ゆるい個人開発のススメ
kuroppe1819
10
1k
Anthropic Cookbook のおすすめレシピ
schroneko
7
1.1k
敵対的ポイフル
futabato
0
120
From Spring Boot 2 to Spring Boot 3 with Java 21 and Jakarta EE
ivargrimstad
0
320
初心者のためのRubyKaigi入門/RubyKaigi Introduction
a_matsuda
7
1.2k
Behind VS Code Extensions for JavaScript / TypeScript Linnting and Formatting
unvalley
5
1.1k
Featured
See All Featured
Happy Clients
brianwarren
92
6.4k
What's new in Ruby 2.0
geeforr
337
31k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
41
4.4k
A designer walks into a library…
pauljervisheath
201
23k
The World Runs on Bad Software
bkeepers
PRO
61
6.7k
Statistics for Hackers
jakevdp
790
220k
Navigating Team Friction
lara
179
13k
No one is an island. Learnings from fostering a developers community.
thoeni
16
2.1k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
501
140k
The Invisible Side of Design
smashingmag
294
49k
Web development in the modern age
philhawksworth
203
10k
Pencils Down: Stop Designing & Start Developing
hursman
117
11k
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