[ 
https://issues.apache.org/jira/browse/CB-7972?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14238329#comment-14238329
 ] 

ASF GitHub Bot commented on CB-7972:
------------------------------------

Github user daserge commented on a diff in the pull request:

    
https://github.com/apache/cordova-plugin-globalization/pull/31#discussion_r21478290
  
    --- Diff: src/windows/GlobalizationProxy.js ---
    @@ -0,0 +1,294 @@
    +/*  
    +   Licensed under the Apache License, Version 2.0 (the "License");
    +   you may not use this file except in compliance with the License.
    +   You may obtain a copy of the License at
    +   
    +   http://www.apache.org/licenses/LICENSE-2.0
    +   
    +   Unless required by applicable law or agreed to in writing, software
    +   distributed under the License is distributed on an "AS IS" BASIS,
    +   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    +   See the License for the specific language governing permissions and
    +   limitations under the License.
    +*/
    +
    +var GlobalizationError = require('./GlobalizationError');
    +var locale = navigator.userLanguage;
    +
    +var decimalFormatter;
    +var currencyFormatter;
    +var percentFormatter;
    +
    +function createRoundingAlgorithm() {
    +    // This is undefined in case of Windows 8.0
    +    if (Windows.Globalization.NumberFormatting.IncrementNumberRounder) {
    +        var rounder = new 
Windows.Globalization.NumberFormatting.IncrementNumberRounder();
    +        rounder.roundingAlgorithm = 
Windows.Globalization.NumberFormatting.RoundingAlgorithm.roundHalfUp;
    +        rounder.increment = 0.01;
    +
    +        return rounder;
    +    }
    +
    +    return null;
    +}
    +
    +function createDecimalFormatter(regionName) {
    +    decimalFormatter = new 
Windows.Globalization.NumberFormatting.DecimalFormatter([locale], regionName);
    +
    +    decimalFormatter.numberRounder = createRoundingAlgorithm();
    +    decimalFormatter.isGrouped = false;
    +
    +    return decimalFormatter;
    +}
    +
    +function getDecimalFormatter(regionName) {
    +    return decimalFormatter || createDecimalFormatter(regionName);
    +}
    +
    +function createCurrencyFormatter(regionName) {
    +    var regionObj = new Windows.Globalization.GeographicRegion(regionName);
    +    var currency = regionObj.currenciesInUse[0];
    +
    +    currencyFormatter = new 
Windows.Globalization.NumberFormatting.CurrencyFormatter(currency, [locale], 
regionName);
    +
    +    currencyFormatter.numberRounder = createRoundingAlgorithm();
    +    currencyFormatter.isGrouped = true;
    +
    +    return currencyFormatter;
    +}
    +
    +function getCurrencyFormatter(regionName) {
    +    return currencyFormatter || createCurrencyFormatter(regionName);
    +}
    +
    +function createPercentFormatter(regionName) {
    +    percentFormatter = new 
Windows.Globalization.NumberFormatting.PercentFormatter([locale], regionName);
    +
    +    percentFormatter.numberRounder = createRoundingAlgorithm();
    +    percentFormatter.fractionDigits = 0;
    +    percentFormatter.isGrouped = false;
    +
    +    return percentFormatter;
    +}
    +
    +function getPercentFormatter(regionName) {
    +    return percentFormatter || createPercentFormatter(regionName);
    +}
    +
    +function getNumberFormatter(options) {
    +    options = options || { type: 'decimal' };
    +    options.type = options.type || 'decimal';
    +
    +    var tags = locale.split('-');
    +    var regionName = tags[tags.length - 1];
    +
    +    switch (options.type) {
    +        case 'decimal':
    +        {
    +            return getDecimalFormatter(regionName);
    +        }
    +        case 'currency':
    +        {
    +            return getCurrencyFormatter(regionName);
    +        }
    +        case 'percent':
    +        {
    +            return getPercentFormatter(regionName);
    +        }
    +        default:
    +            throw "The options.type can be 'decimal', 'percent', or 
'currency' only";
    +    };
    +}
    +
    +module.exports = {
    +    getPreferredLanguage: function (win, fail) {
    +        try {
    +            var language = 
Windows.System.UserProfile.GlobalizationPreferences.languages[0];
    +
    +            win({ value: language });
    +        } catch (e) {
    +            fail(e);
    +        }
    +    },
    +
    +    getLocaleName: function (win, fail) {
    +        // Corresponds to a user-selected regional format
    +        win({ value: locale });
    +    },
    +
    +    dateToString: function (win, fail, args) {
    +        tryDoAction(GlobalizationProxy.GlobalizationProxy.dateToString,
    +            JSON.stringify({
    +                date: args[0].date,
    +                options: args[0].options || { formatLength: "short", 
selector: "date and time" }
    +            }), win, fail);
    +    },
    +
    +    stringToDate: function (win, fail, args) {
    +        tryDoAction(GlobalizationProxy.GlobalizationProxy.stringToDate, 
    +            JSON.stringify({
    +                dateString: args[0].dateString,
    +                options: args[0].options || { formatLength: "short", 
selector: "date and time" }
    +            }), win, fail);
    +    },
    +
    +    getDateNames: function (win, fail, args) {
    +        try {
    +            var options = args[0].options || { type: 'wide', item: 
'months' };
    +            var type = options.type || 'wide';
    +            var item = options.item || 'months';
    +
    +            var monthFormat = 
Windows.Globalization.DateTimeFormatting.MonthFormat.none;
    +            var dayOfWeekFormat = 
Windows.Globalization.DateTimeFormatting.DayOfWeekFormat.none;
    +
    +            if (item === 'months' && type === 'wide') {
    +                monthFormat = 
Windows.Globalization.DateTimeFormatting.MonthFormat.full;
    +            } else if (item === 'months' && type === 'narrow') {
    +                monthFormat = 
Windows.Globalization.DateTimeFormatting.MonthFormat.abbreviated;
    +            } else if (item === 'days' && type === 'wide') {
    +                dayOfWeekFormat = 
Windows.Globalization.DateTimeFormatting.DayOfWeekFormat.full;
    +            } else if (item === 'days' && type === 'narrow') {
    +                dayOfWeekFormat = 
Windows.Globalization.DateTimeFormatting.DayOfWeekFormat.abbreviated;
    +            } else {
    +                throw "Incorrect item type";
    +            }
    +
    +            var formatter = new 
Windows.Globalization.DateTimeFormatting.DateTimeFormatter(
    +                Windows.Globalization.DateTimeFormatting.YearFormat.none,
    +                monthFormat, 
    +                Windows.Globalization.DateTimeFormatting.DayFormat.none, 
    +                dayOfWeekFormat, 
    +                Windows.Globalization.DateTimeFormatting.HourFormat.none, 
    +                
Windows.Globalization.DateTimeFormatting.MinuteFormat.none, 
    +                
Windows.Globalization.DateTimeFormatting.SecondFormat.none, 
    +                [locale]);
    +
    +            var result = [];
    +            if (item === 'months') {
    +                for (var i = 0; i < 12; i++) {
    +                    var date = new Date(2014, i, 20, 0, 0, 0, 0);
    +                    result[i] = formatter.format(date);
    +                }
    +            } else {
    +                for (i = 0; i < 7; i++) {
    +                    date = new Date(2014, 5, i + 1, 0, 0, 0, 0);
    --- End diff --
    
    As Jesse correctly stated:
    > It looks like it's just to generate names of days, using a known 
month/year which starts on a Sunday by the looks of it. 
    
    We are taking 2014 June 1st and a week forward starting with Sunday to 
generate the weekdays.
    The day week starts on actually can be different and it is defined in 
getFirstDayOfWeek method.


> Add cordova-plugin-globalization support for Windows platform
> -------------------------------------------------------------
>
>                 Key: CB-7972
>                 URL: https://issues.apache.org/jira/browse/CB-7972
>             Project: Apache Cordova
>          Issue Type: Improvement
>          Components: Plugin Globalization
>            Reporter: Sergey Shakhnazarov
>




--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to