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
Using boolean logic to deal with dates
Search
Irina Bednova
October 30, 2014
Programming
0
460
Using boolean logic to deal with dates
The unexpected application of Karnaugh maps in a Rails project
Irina Bednova
October 30, 2014
Tweet
Share
Other Decks in Programming
See All in Programming
個人アプリを2年ぶりにアプデしたから褒めて / I just updated my personal app, praise me!
lovee
0
300
知られざるDMMデータエンジニアの生態 〜かつてツチノコと呼ばれし者〜
takaha4k
3
1.1k
ASP.NET Core の OpenAPIサポート
h455h1
0
160
ESLintプラグインを使用してCDKのセオリーを適用する
yamanashi_ren01
2
380
月刊 競技プログラミングをお仕事に役立てるには
terryu16
1
1.3k
WebDriver BiDiとは何なのか
yotahada3
1
100
Spring gRPC について / About Spring gRPC
mackey0225
0
180
Simple組み合わせ村から大都会Railsにやってきた俺は / Coming to Rails from the Simple
moznion
3
3.7k
DevFest - Serverless 101 with Google Cloud Functions
tunmise
0
140
『改訂新版 良いコード/悪いコードで学ぶ設計入門』活用方法−爆速でスキルアップする!効果的な学習アプローチ / effective-learning-of-good-code
minodriven
29
4.8k
社内フレームワークとその依存性解決 / in-house framework and its dependency management
vvakame
1
500
AWSマネコンに複数のアカウントで入れるようになりました
yuhta28
2
150
Featured
See All Featured
The Language of Interfaces
destraynor
156
24k
Automating Front-end Workflow
addyosmani
1367
200k
Being A Developer After 40
akosma
89
590k
Unsuck your backbone
ammeep
669
57k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5.1k
Building an army of robots
kneath
302
45k
A designer walks into a library…
pauljervisheath
205
24k
How STYLIGHT went responsive
nonsquared
96
5.3k
Scaling GitHub
holman
459
140k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
113
50k
Rails Girls Zürich Keynote
gr2m
94
13k
Designing for humans not robots
tammielis
250
25k
Transcript
For fun Using Boolean logic to deal with dates
The problem
The problem Parse a string to a Date object
The problem • Date could be in the mm/dd/yyyy format
The problem • Date could be in the mm/dd/yyyy format
• Date could be in any format recognisable by Date.parse
The problem • Date could be in the mm/dd/yyyy format
• Date could be in any format recognisable by Date.parse • Except the dd/mm/yyyy format
month_day_year = Date.strptime(string, "%m/%d/%Y") rescue nil
month_day_year = Date.strptime(string, "%m/%d/%Y") rescue nil generic_parse = Date.parse(string) rescue
nil
month_day_year = Date.strptime(string, "%m/%d/%Y") rescue nil generic_parse = Date.parse(string) rescue
nil day_month_year = Date.strptime(string, "%d/%m/%Y") rescue nil
month_day_year generic_parse day_month_year result 0 0 0 0 0 0
1 0 1 0 0 1 1 1 0 0 1 0 1 1 1 0 1 1 1
month_day_year generic_parse day_month_year result 0 0 0 0 0 0
1 X 0 1 0 0 1 1 1 0 0 1 0 1 X 1 1 0 1 1 1
month_day_year generic_parse day_month_year result 0 0 0 0 0 0
1 X 0 1 0 1 0 1 1 1 0 0 1 0 1 X 1 1 0 1 1 1
month_day_year generic_parse day_month_year result 0 0 0 0 0 0
1 X 0 1 0 1 0 1 1 0 1 0 0 1 0 1 X 1 1 0 1 1 1
month_day_year generic_parse day_month_year result 0 0 0 0 0 0
1 X 0 1 0 1 0 1 1 0 1 0 0 1 1 0 1 X 1 1 0 1 1 1
month_day_year generic_parse day_month_year result 0 0 0 0 0 0
1 X 0 1 0 1 0 1 1 0 1 0 0 1 1 0 1 X 1 1 0 X 1 1 1
month_day_year generic_parse day_month_year result 0 0 0 0 0 0
1 X 0 1 0 1 0 1 1 0 1 0 0 1 1 0 1 X 1 1 0 X 1 1 1 1
Makes your boolean functions simpler! Karnaugh map
0 X 0 1 1 X 1 X generic_parse *
day_month_year month_day_year 1 0 00 01 11 10
0 X 0 1 1 X 1 X generic_parse *
day_month_year month_day_year 1 0 00 01 11 10
0 X 0 1 1 X 1 X generic_parse *
day_month_year month_day_year 1 0 00 01 11 10
0 X 0 1 1 X 1 X generic_parse *
day_month_year month_day_year 1 0 00 01 11 10
month_day_year 0 X 0 1 1 X 1 X generic_parse
* day_month_year month_day_year 0 00 01 11 10 1
month_day_year ∨ ¬generic_parse ∧ day_month_year 0 X 0 1 1
X 1 X generic_parse * day_month_year month_day_year 0 00 01 11 10 1
month_day_year ∨ ¬generic_parse ∧ day_month_year ∨ generic_parse ∧ ¬day_month_year 0
X 0 1 1 X 1 X generic_parse * day_month_year month_day_year 0 00 01 11 10 1
((month_day_year ? 1 : 0) + ((day_month_year ? 1 :
0) ^ (generic_parse ? 1 : 0)) == 0) month_day_year || generic_parse
Thank you! Irina Bednova @jafrog www.jafrog.com