JFXtras / jfxtras

A supporting library for JavaFX, containing helper classes, extended layouts, controls and other interesting widgets.
http://jfxtras.org
Other
599 stars 123 forks source link

Week end highlight can be wrong #45

Closed Maxoudela closed 8 years ago

Maxoudela commented 8 years ago

Hi,

In the Calendar, the weekend days are highlighted. If you look at CalendarPickerMonthlySkinAbstract, you will have that :

/**
     * check if a certain weekday name is a certain day-of-the-week
     */
    protected boolean isWeekdayWeekend(int idx) 
    {
        return (isWeekday(idx, java.util.Calendar.SATURDAY) || isWeekday(idx, java.util.Calendar.SUNDAY));
    }

But if your Calendar is set at Israel Locale, the week end is the friday and saturday. Therefore, the highlight is no good.

I've seen this issue in StackOverflow, https://stackoverflow.com/questions/17927854/how-to-check-if-a-certain-date-is-a-weekend-taking-into-account-the-current-loca.

A guy coded this solution quickly :

private static final List<String> sunWeekendDaysCountries = Arrays.asList(new String[]{"GQ", "IN", "TH", "UG"});
private static final List<String> fryWeekendDaysCountries = Arrays.asList(new String[]{"DJ", "IR"});
private static final List<String> frySunWeekendDaysCountries = Arrays.asList(new String[]{"BN"});
private static final List<String> thuFryWeekendDaysCountries = Arrays.asList(new String[]{"AF"});
private static final List<String> frySatWeekendDaysCountries = Arrays.asList(new String[]{"AE", "DZ", "BH", "BD", "EG", "IQ", "IL", "JO", "KW", "LY", "MV", "MR", "OM", "PS", "QA", "SA", "SD", "SY", "YE"});

public static int[] getWeekendDays(Locale locale) {
    if (thuFryWeekendDaysCountries.contains(locale.getCountry())) {
        return new int[]{Calendar.THURSDAY, Calendar.FRIDAY};
    }
    else if (frySunWeekendDaysCountries.contains(locale.getCountry())) {
        return new int[]{Calendar.FRIDAY, Calendar.SUNDAY};
    }
    else if (fryWeekendDaysCountries.contains(locale.getCountry())) {
        return new int[]{Calendar.FRIDAY};
    }
    else if (sunWeekendDaysCountries.contains(locale.getCountry())) {
        return new int[]{Calendar.SUNDAY};
    }
    else if (frySatWeekendDaysCountries.contains(locale.getCountry())) {
        return new int[]{Calendar.FRIDAY, Calendar.SATURDAY};
    }
    else {
        return new int[]{Calendar.SATURDAY, Calendar.SUNDAY};
    }
}

What do you think?

tbee commented 8 years ago

Seems like I learned again something today. Great improvement.

Maxoudela commented 8 years ago

Yes me too.. I also noticed that the default Font on Windows is not supporting Hebrew characters.. I looked upon the different solutions on the StackOverflow issue but the one I posted seems good.

At least it will work in my case, if someone ever have an issue we could then improve the algorithm.