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
430
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
The Shape of a Service Object
inem
0
510
Using Livebook to build and deploy internal tools @ ElixirConf 2024
hugobarauna
0
250
Desafios e Lições Aprendidas na Migração de Monólitos para Microsserviços em Java
jessilyneh
2
140
rails_girls_is_my_gate_to_join_the_ruby_commuinty
maimux2x
0
200
仮想ファイルシステムを導入して開発環境のストレージ課題を解消する
segadevtech
2
540
Scala アプリケーションのビルドを改善してデプロイ時間を 1/4 にした話 | How I improved the build of my Scala application and reduced deployment time by 4x
nomadblacky
1
170
Amebaチョイス立ち上げの裏側 ~依存システムとの闘い~
daichi_igarashi
0
230
事業フェーズの変化に対応する 開発生産性向上のゼロイチ
masaygggg
0
190
Go1.23で入った errorsパッケージの小さなアプデ
kuro_kurorrr
2
380
Swiftコードバトル必勝法
toshi0383
0
150
Jakarta EE meets AI
ivargrimstad
1
440
connect-go で面倒くささと戦う / 2024-08-27 #newmo_layerx_go
izumin5210
2
640
Featured
See All Featured
Creatively Recalculating Your Daily Design Routine
revolveconf
215
12k
Why Our Code Smells
bkeepers
PRO
334
56k
Docker and Python
trallard
39
3k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
8.9k
Speed Design
sergeychernyshev
22
430
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
28
1.6k
Bootstrapping a Software Product
garrettdimon
PRO
304
110k
Fantastic passwords and where to find them - at NoRuKo
philnash
48
2.8k
4 Signs Your Business is Dying
shpigford
179
21k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
502
140k
Building Better People: How to give real-time feedback that sticks.
wjessup
359
18k
Robots, Beer and Maslow
schacon
PRO
157
8.2k
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