bleenco / ng2-datepicker

Angular2 Datepicker Component
http://ng2-datepicker.jankuri.com
MIT License
311 stars 236 forks source link

firstWeekdaySunday option not working properly; dates showing incorrectly. #165

Open elliotwesoff opened 7 years ago

elliotwesoff commented 7 years ago

This appears to be a two part bug.

  1. The dates are not being displayed under the proper weekday. I didn't notice this until I tried to implement the firstWeekdaySunday option.

  2. The firstWeekdaySunday option doesn't respond to a boolean value like shown in the interface options.

The options hash in the following block of code doesn't do anything at all.

<ng2-datepicker
    [options]="{ firstWeekdaySunday: false }"
    [(ngModel)]="date">
</ng2-datepicker>

However, when the firstWeekdaySunday option is provided any string, it adjusts the dates accordingly.

The calendar will display correctly (although with Sunday still being the first day) after using this block of code:

<ng2-datepicker
    [options]="{ firstWeekdaySunday: 'false' }"
    [(ngModel)]="date">
</ng2-datepicker>

Example of part one - displaying calendar days incorrectly: calendar-incorrect

jkuri commented 7 years ago

hi @elliotwesoff I really love this styling, would you mind to make this as default and make a PR if you have time to do so please?

elliotwesoff commented 7 years ago

Sure thing. What about the bug though? ;)

gaabmarquez commented 7 years ago

Hi, i have the same bug, but i think its because the names of days are harcoded in the HTML you can see this in ng2-datepicker.component.html

<div class="datepicker-calendar-day-names"> <span>S</span> <span>M</span> <span>T</span> <span>W</span> <span>T</span> <span>F</span> <span>S</span> </div>

elliotwesoff commented 7 years ago

Oh yeah. Hmmmmm....

jkuri commented 7 years ago

in the near future I'll plan to drop moment and integrate date-fns. I will solve both issues then.

overtureweb commented 7 years ago

@elliotwesoff It actually is working correctly when you set the [options]="{ firstWeekdaySunday: false }" A value of false results in the week starting on Monday. If you set it [options]="{ firstWeekdaySunday: true }" it will start on Sunday. You have it currently set to a 'false' string which actually evaluates as truthy if you look at this property in the class constructor: this.firstWeekdaySunday = obj && obj.firstWeekdaySunday ? obj.firstWeekdaySunday : false;

My recommendation to the developer would be to set the value to true by default as doing so will align the calendar with the days of the week in the static html for the calendar and will presumably satisfy the vast majority of use cases.

elliotwesoff commented 7 years ago

@overtureweb I know I've got a string there. I wrote that to illustrate the strange behavior. Of course it shouldn't work when you use a string, but it does... sort of. I'll update my datepicker and try it again. If it works I'll close the issue.

samrantmedia commented 7 years ago

This issue is still in the latest version with angular2 version 4.0.0

firanto commented 7 years ago

@jkuri The default theme is nice. But the day title header's (S M T W....) color are too dark rendering them nearly unreadable which can be seen here:

screen shot 2017-08-23 at 9 39 32 pm