reagent-project / reagent-forms

Bootstrap form components for Reagent
339 stars 78 forks source link

Datepicker: Day of week calculated wrong at times #81

Closed dmarjenburgh closed 8 years ago

dmarjenburgh commented 8 years ago

The datepicker shows the wrong day-of-weeks sometimes.

The first-day-of-week function https://github.com/reagent-project/reagent-forms/blob/master/src/reagent_forms/datepicker.cljs#L82 sometimes returns the wrong value.

When the current day is higher than the number of days of the next month, the extra days spill over. This is how the js function works. For example, the current day is (as I'm writing this) is Jan 31, 2016. When calling setMonth(1) (setting it to february), the returned day is actually Mar 02, 2016 and the function returns the first day of March instead of february:

(def d (js/Date.)) ;=> #inst "2016-01-31"
(.getMonth d) ; => 0
(.setMonth d 1)
(.getMonth d) ; => 2       

I haven't tested this, but I'm sure it will be fixed by first setting the day to 1, then the month.

I can make a pull request if you like.

yogthos commented 8 years ago

A great catch, and a pr would be fantastic. I can cut a new release once we test it.