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
420
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
継続的な活動で築く地方エンジニアの道
myamashii
2
360
さきがけから振り返るアーキテクチャ刷新 / Reflecting on the Architectural Renewal from the Vanguard
nrslib
2
780
Webエディタライブラリ 「CodeMirror」から学ぶ Webアプリ開発のテクニック
ryosukeigarashi
0
250
OpenAI/Gemini APIを使って EPUBを翻訳するCLIツールをつくってみた
tomiyan
0
790
Harnessing Large Language Models for Training-free Video Anomaly Detection
tereka114
1
1.3k
유연한 Composable 설계
l2hyunwoo
0
380
GraphQL はいいぞ! ~Laravel で学ぶ GraphQL 入門~
azuki
1
160
Google's Recipe for Scaling (Web) Security – LocoMocoSec 2024
lweichselbaum
0
170
Exploring the Gradually Lost Technical Skills in the Cloud Native Era
hwchiu
2
3.9k
君たちはどうコードをレビューする (される) か / 大吉祥寺.pm
utgwkk
15
8.5k
大規模マルチテナントを解決するYugabyteDBという選択肢
nnaka2992
1
250
CSC307 Lecture 10
javiergs
PRO
0
310
Featured
See All Featured
Building Applications with DynamoDB
mza
89
5.8k
Creatively Recalculating Your Daily Design Routine
revolveconf
214
11k
GraphQLの誤解/rethinking-graphql
sonatard
59
9.6k
10 Git Anti Patterns You Should be Aware of
lemiorhan
652
58k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
26
1.6k
Atom: Resistance is Futile
akmur
261
25k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
360
22k
What’s in a name? Adding method to the madness
productmarketing
PRO
21
2.9k
The Straight Up "How To Draw Better" Workshop
denniskardys
229
130k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
26
1.8k
Fontdeck: Realign not Redesign
paulrobertlloyd
79
5.1k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
189
16k
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