Bug 62639

Summary: DataFormatter can never set its provided locale
Product: POI Reporter: Patrice ROCHEMONT <patrice.rochemont>
Component: POI OverallAssignee: POI Developers List <dev>
Severity: major Keywords: APIBug
Priority: P2    
Version: 3.17-FINAL   
Target Milestone: ---   
Hardware: PC   
OS: All   

Description Patrice ROCHEMONT 2018-08-20 09:18:31 UTC
I use POI 3.17 version. 
And i found that the formated date cell for instance allways follow the current locale. 

Analysis : 

With "this.localeIsAdapting = true;" in the constructor with 3 arguments 
we can never set localsAdapting to <code>false</code> in the Construstor with 2 arguments. 

it will always be <code>true</code> for field localIsAdapting. 
in  "this(locale, false, emulateCSV);"

//snipppet org.apache.poi.ss.usermodel.DataFormatter -------------

     * Creates a formatter using the given locale.
     * @param  emulateCSV whether to emulate CSV output.
    public DataFormatter(Locale locale, boolean emulateCSV) {
        this(locale, false, emulateCSV);

     * Creates a formatter using the given locale.
     * @param  localeIsAdapting (true only if locale is not user-specified)
     * @param  emulateCSV whether to emulate CSV output.
    private DataFormatter(Locale locale, boolean localeIsAdapting, boolean emulateCSV) {
        this.localeIsAdapting = true;
        // localeIsAdapting must be true prior to this first checkForLocaleChange call.
        // set localeIsAdapting so subsequent checks perform correctly
        // (whether a specific locale was provided to this DataFormatter or DataFormatter should
        // adapt to the current user locale as the locale changes)
        this.localeIsAdapting = localeIsAdapting;
        this.emulateCSV = emulateCSV;

Best Regards,
Rochemont Patrice.
Comment 1 PJ Fanning 2018-08-20 10:05:11 UTC
Resolved in trunk and will appear in 4.0.0 release.

Comment 2 Patrice ROCHEMONT 2018-08-20 23:28:10 UTC
Why not enable to use the exact locale used when creating the cell style in the document ?

see https://stackoverflow.com/a/51939623/10252155