henninghall / react-native-date-picker

React Native Date Picker is datetime picker for Android and iOS. It includes date, time and datetime picker modes. The datepicker is customizable and is supporting different languages. It's written with native code to achieve the best possible look, feel and performance.
MIT License
2.25k stars 346 forks source link

[Android] Date order is wrong according to the locale's preference #91

Closed UnableHead closed 5 years ago

UnableHead commented 5 years ago

Hello,

I have a problem about the date order on Android. I try on iOS it works fine.

It set the locale props at fr-FR, the month name translation is correct, and the order date is MM-DD-YYYY but the correct French order should be DD-MM-YYYY.

I search in code and I found this in the file ./node_modules/react-native-date-picker/android/src/main/java/com/henninghall/date_picker/WheelOrderUpdater.java at the line 27 :

private ArrayList<Wheel> localeToWheelOrder(final Locale locale) {
        final ArrayList<Wheel> wheelList = new ArrayList<Wheel>();
        if (Utils.monthNameBeforeMonthDate(locale)) {
            wheelList.add(this.pickerView.dateWheel);
            wheelList.add(this.pickerView.monthWheel);
        }
        else {
            wheelList.add(this.pickerView.monthWheel);
            wheelList.add(this.pickerView.dateWheel);
        }
        return wheelList;
    }

I guess as the function name means monthNameBeforeMonthDate that we should swap the lines in the if like this :

private ArrayList<Wheel> localeToWheelOrder(final Locale locale) {
        final ArrayList<Wheel> wheelList = new ArrayList<Wheel>();
        if (Utils.monthNameBeforeMonthDate(locale)) {
            wheelList.add(this.pickerView.monthWheel);
            wheelList.add(this.pickerView.dateWheel);
        }
        else {
            wheelList.add(this.pickerView.dateWheel);
            wheelList.add(this.pickerView.monthWheel);
        }
        return wheelList;
    }

I hope this will help to fix the problem. If needed, I could do a pull request (never done this before).

henninghall commented 5 years ago

Thanks for reporting this! It would be awesome if you could provide a PR with this fix and I will test it out.

henninghall commented 5 years ago

@UnableHead I have now verified that this issue exists. I will wait a day or so if you would like to make a PR, otherwise I will just fix it myself 🙂

UnableHead commented 5 years ago

Good.

I can do it this Monday. 😀

henninghall commented 5 years ago

Great!

henninghall commented 5 years ago

Fixed by https://github.com/henninghall/react-native-date-picker/pull/93

henninghall commented 5 years ago

Released in v2.6.1