Bug 62639 - DataFormatter can never set its provided locale
Summary: DataFormatter can never set its provided locale
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: POI Overall (show other bugs)
Version: 3.17-FINAL
Hardware: PC All
: P2 major (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords: APIBug
Depends on:
Blocks:
 
Reported: 2018-08-20 09:18 UTC by Patrice ROCHEMONT
Modified: 2018-08-20 23:28 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Patrice ROCHEMONT 2018-08-20 09:18:31 UTC
Hi, 
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;
        localeChangedObservable.addObserver(this);
        // localeIsAdapting must be true prior to this first checkForLocaleChange call.
        localeChangedObservable.checkForLocaleChange(locale);
        // 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.

https://github.com/apache/poi/commit/a611b66fd195952c6262cb5eb49da1a740cf2aaa
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