Using boolean logic to deal with dates

Using boolean logic to deal with dates

The unexpected application of Karnaugh maps in a Rails project

E0f3a12b1ce60c13f52fd723152d810a?s=128

Irina Bednova

October 30, 2014
Tweet

Transcript

  1. 5.

    The problem • Date could be in the mm/dd/yyyy format

    • Date could be in any format recognisable by Date.parse
  2. 6.

    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
  3. 9.
  4. 10.
  5. 11.

    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
  6. 12.

    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
  7. 13.

    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
  8. 14.

    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
  9. 15.

    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
  10. 16.

    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
  11. 18.

    0 X 0 1 1 X 1 X generic_parse *

    day_month_year month_day_year 1 0 00 01 11 10
  12. 19.

    0 X 0 1 1 X 1 X generic_parse *

    day_month_year month_day_year 1 0 00 01 11 10
  13. 20.

    0 X 0 1 1 X 1 X generic_parse *

    day_month_year month_day_year 1 0 00 01 11 10
  14. 21.

    0 X 0 1 1 X 1 X generic_parse *

    day_month_year month_day_year 1 0 00 01 11 10
  15. 22.

    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
  16. 23.

    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
  17. 24.

    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
  18. 25.

    ((month_day_year ? 1 : 0) + ((day_month_year ? 1 :

    0) ^ (generic_parse ? 1 : 0)) == 0) month_day_year || generic_parse