Skip to content

Commit

Permalink
Merge pull request #35 from nightskylark/prepare_17_2
Browse files Browse the repository at this point in the history
Prepare release 17.2
  • Loading branch information
nightskylark authored Nov 16, 2017
2 parents 579cb63 + 8186862 commit 90d99b5
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 17 deletions.
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ Using *Intl* is an alternative to the *Globalize* based mechanism [documented he
Add a script tag for `devextreme-intl` behind your tag for the `devextreme` script:

```html
<script src="https://unpkg.com/devextreme-intl/dist/devextreme-intl.js"></script>
<script src="https://unpkg.com/devextreme-intl@17.2/dist/devextreme-intl.js"></script>
```
or
```html
<script src="https://unpkg.com/devextreme-intl/dist/devextreme-intl.min.js"></script>
<script src="https://unpkg.com/devextreme-intl@17.2/dist/devextreme-intl.min.js"></script>
```

See [this example with the relevant script tag in place](/examples/bundled.html).
Expand All @@ -43,9 +43,9 @@ See [this example using modules](/examples/modular.html).

## API

In addition to the [DevExtreme format object structure](https://js.devexpress.com/Documentation/17_1/ApiReference/Common/Object_Structures/format/), formats can be specified which are compatible with the `options` parameter of the Intl [NumberFormat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat#Parameters) and [DateTimeFormat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat#Parameters).
In addition to the [DevExtreme format object structure](https://js.devexpress.com/Documentation/ApiReference/Common/Object_Structures/format/), formats can be specified which are compatible with the `options` parameter of the Intl [NumberFormat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat#Parameters) and [DateTimeFormat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat#Parameters).

Note that the [DevExtreme format object structure](https://js.devexpress.com/Documentation/17_1/ApiReference/Common/Object_Structures/format/) documentation page refers to special structures supported by *Globalize*. When using *DevExtreme-Intl*, these structures are either unsupported or need to adhere to [Intl](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Intl) structural requirements instead.
Note that the [DevExtreme format object structure](https://js.devexpress.com/Documentation/ApiReference/Common/Object_Structures/format/) documentation page refers to special structures supported by *Globalize*. When using *DevExtreme-Intl*, these structures are either unsupported or need to adhere to [Intl](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Intl) structural requirements instead.

Here is an example for the use of Intl formats in DataGrid columns:

Expand All @@ -64,10 +64,12 @@ $("#datagrid").dxDataGrid({

See [more examples here](/examples).

You can find full documentation of the localization API in the [DevExtreme documentation](https://js.devexpress.com/Documentation/17_1/Guide/Widgets/Common/UI_Widgets/Localization/).
You can find full documentation of the localization API in the [DevExtreme documentation](https://js.devexpress.com/Documentation/Guide/Widgets/Common/UI_Widgets/Localization/).

## Restrictions

**NOTE**: Starting with version 17.2, these restrictions are not relevant.

Date parsing is not supported by the ECMAScript Internationalization API. You can read about the position of the ECMAScript community [here](https://bugs.ecmascript.org/show_bug.cgi?id=770).
As a result, some minor DevExtreme functionality is restricted.

Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "devextreme-intl",
"description": "Integrates ECMAScript Internationalization API with DevExtreme",
"version": "17.1.7",
"version": "17.2.3",
"author": "Developer Express Inc.",
"license": "MIT",
"repository": {
Expand All @@ -14,12 +14,12 @@
"dist/devextreme-intl.min.js"
],
"peerDependencies": {
"devextreme": "16.2.4 - 17.1"
"devextreme": "16.2.4 - 17.2"
},
"devDependencies": {
"devextreme": "16.2.4 - 17.1",
"cldr-core": "^30.0.2",
"cldrjs": "^0.3.1",
"devextreme": "16.2.4 - 17.2",
"eslint": "^3.10.2",
"intl": "^1.2.5",
"jquery": "^2.0.0 || ^3.0.0",
Expand Down
4 changes: 3 additions & 1 deletion shippable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ build:

ci:
- shippable_retry npm install --unsafe-perm
- npm run test
- npm run test
- shippable_retry npm install [email protected] --unsafe-perm
- npm run test
16 changes: 16 additions & 0 deletions src/date.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,22 @@ dateLocalization.inject({
return result;
},

getPeriodNames: function() {
var hour12Formatter = getIntlFormatter({ hour: 'numeric', hour12: true, timeZone: 'UTC' });

return [ 1, 13 ].map(function(hours) {
var timeParts = hour12Formatter(new Date(Date.UTC(0, 0, 1, hours))).split('1');

if(timeParts.length !== 2) {
return '';
}

var biggerPart = timeParts[0].length > timeParts[1].length ? timeParts[0] : timeParts[1];

return biggerPart.trim();
});
},

format: function(date, format) {
if(!date) {
return;
Expand Down
65 changes: 58 additions & 7 deletions tests/date-tests.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
var QUnit = require('qunitjs');
var locale = require('devextreme/localization').locale;
var dateLocalization = require('devextreme/localization/date');
var dxVersion = require('devextreme/core/version');

require('../src/date');

var SYMBOLS_TO_REMOVE_REGEX = /[\u200E\u200F]/g;

[ 'de', 'en', 'ja', 'ru', 'zh', 'hr', 'ar' ].forEach(function(localeId) {
var locales = [ 'de', 'en', 'ja', 'ru' ];
if(dxVersion >= '17.2.3') {
Array.prototype.push.apply(locales, [ 'zh', 'hr', 'ar' ]);
}

locales.forEach(function(localeId) {
var getIntlFormatter = function(format) {
return function(date) {
return (new Intl.DateTimeFormat(localeId, format)).format(date).replace(SYMBOLS_TO_REMOVE_REGEX, '');
Expand All @@ -17,6 +23,16 @@ var SYMBOLS_TO_REMOVE_REGEX = /[\u200E\u200F]/g;
return (new Intl.NumberFormat(localeId)).format(number);
};

var localizeDigits = function(string) {
return string && string.split('').map(function(sign) {
if(/[0-9]/.test(sign)) {
return formatNumber(Number(sign));
}

return sign;
}).join('');
};

QUnit.module('date - ' + localeId, {
beforeEach: function() {
locale(localeId);
Expand Down Expand Up @@ -126,7 +142,7 @@ var SYMBOLS_TO_REMOVE_REGEX = /[\u200E\u200F]/g;
{ format: 'longdate', intlFormat: { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' }},
{ format: 'longdatelongtime', intlFormat: { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric', hour: 'numeric', minute: 'numeric', second: 'numeric' }},
{ format: 'longtime', intlFormat: { hour: 'numeric', minute: 'numeric', second: 'numeric' }},
{ format: 'millisecond', expected: formatNumber(0) + formatNumber(0) + formatNumber(6) },
{ format: 'millisecond', expected: localizeDigits('006') },
{ format: 'minute', intlFormat: { minute: 'numeric' }},
{ format: 'month', intlFormat: { month: 'long' }},
{ format: 'monthandday', intlFormat: { month: 'long', day: 'numeric' }},
Expand Down Expand Up @@ -211,18 +227,18 @@ var SYMBOLS_TO_REMOVE_REGEX = /[\u200E\u200F]/g;
});

quarterData.forEach(function(data) {
testFormat('quarter', data.date, data.expected);
testFormat('quarter', data.date, localizeDigits(data.expected));
});

testFormat('quarterandyear', quarterandyearData.date, quarterandyearData.expected);
testFormat('quarterandyear', quarterandyearData.date, localizeDigits(quarterandyearData.expected));

assert.equal(dateLocalization.format(new Date(2015, 2, 2, 3, 4, 5, 6)), String(new Date(2015, 2, 2, 3, 4, 5)), 'without format');
assert.notOk(dateLocalization.format(), 'without date');
});

QUnit.test('parse', function(assert) {
var currentDate = new Date();
[
var testData = [
{ format: 'shortDate', date: new Date(2016, 10, 17) },
{ format: 'shortDate', date: new Date(2016, 11, 31) },
{ format: 'shortDate', date: new Date(2016, 0, 1) },
Expand All @@ -240,11 +256,46 @@ var SYMBOLS_TO_REMOVE_REGEX = /[\u200E\u200F]/g;
{ format: 'longtime', date: new Date(currentDate.getFullYear(), currentDate.getMonth(), currentDate.getDate(), 4, 22, 15) },
{ format: 'longtime', date: new Date(currentDate.getFullYear(), currentDate.getMonth(), currentDate.getDate(), 18, 56, 56) },
{ format: 'longtime', date: new Date(currentDate.getFullYear(), currentDate.getMonth(), currentDate.getDate(), 0, 0, 0) },
{ format: 'longtime', date: new Date(currentDate.getFullYear(), currentDate.getMonth(), currentDate.getDate(), 12, 59, 59) }
].forEach(function(config) {
{ format: 'longtime', date: new Date(currentDate.getFullYear(), currentDate.getMonth(), currentDate.getDate(), 12, 59, 59) },
];

if(dxVersion >= '17.2.3') {
Array.prototype.push.apply(testData, [
{ format: 'longDate', date: new Date(2016, 10, 17) },
{ format: 'longDate', date: new Date(2016, 11, 31) },
{ format: 'longDate', date: new Date(2016, 0, 1) },

{ format: 'longDateLongTime', date: new Date(2016, 11, 31, 4, 44) },
{ format: 'longDateLongTime', date: new Date(2016, 11, 31, 12, 32) },
{ format: 'longDateLongTime', date: new Date(2016, 0, 1, 0, 16) },
{ format: 'longDateLongTime', date: new Date(2016, 0, 1, 12, 48) },

{ format: 'monthAndYear', date: new Date(2016, 9, 1) },
{ format: 'monthAndDay', date: new Date(currentDate.getFullYear(), 9, 17) },

{ format: 'year', date: new Date(2013, 0, 1) },
{ format: 'shortyear', date: new Date(2013, 0, 1) },
{ format: 'month', date: new Date(currentDate.getFullYear(), 9, 1) },
{ format: 'day', date: new Date(currentDate.getFullYear(), currentDate.getMonth(), 17) },
{ format: 'hour', date: new Date(currentDate.getFullYear(), currentDate.getMonth(), currentDate.getDate(), 16) },
{ format: 'minute', date: new Date(currentDate.getFullYear(), currentDate.getMonth(), currentDate.getDate(), currentDate.getHours(), 56) }
]);
}

testData.forEach(function(config) {
var format = config.format;
var date = config.date;

// https://github.com/DevExpress/DevExtreme-Intl/issues/33
if(localeId.substr(0, 2) === 'zh' && format === 'month') {
return;
}

// https://github.com/DevExpress/DevExtreme-Intl/issues/34
if(localeId.substr(0, 2) === 'ar' && (format === 'longDate' || format === 'longDateLongTime')) {
return;
}

var formattedDate = dateLocalization.format(date, format);
var parsedDate = dateLocalization.parse(formattedDate, format);

Expand Down
3 changes: 2 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ module.exports = {
},
externals: {
'devextreme/core/config': { root: [ 'DevExpress', 'config' ], amd: 'devextreme/core/config', commonjs2: 'devextreme/core/config' },
'devextreme/localization': { root: [ 'DevExpress', 'localization' ], amd: 'devextreme/localization', commonjs2: 'devextreme/localization' }
'devextreme/localization': { root: [ 'DevExpress', 'localization' ], amd: 'devextreme/localization', commonjs2: 'devextreme/localization' },
'devextreme/core/version': { root: [ 'DevExpress', 'VERSION' ], amd: 'devextreme/core/version', commonjs2: 'devextreme/core/version' }
},
plugins: plugins,
devtool: argv.dev ? 'eval' : null,
Expand Down

0 comments on commit 90d99b5

Please sign in to comment.