Skip to content
This repository was archived by the owner on Apr 14, 2021. It is now read-only.

Commit 6057ef3

Browse files
committed
fixes #178: duplicate values when formatting numbers of dates
1 parent e1b81ae commit 6057ef3

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

src/11.numberformat.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -436,8 +436,8 @@ function FormatNumberToParts(numberFormat, x) {
436436
// 3. Let n be 0.
437437
let n = 0;
438438
// 4. For each part in parts, do:
439-
for (let idx in parts) {
440-
let part = parts[idx];
439+
for (let i = 0; parts.length > i; i++) {
440+
let part = parts[i];
441441
// a. Let O be ObjectCreate(%ObjectPrototype%).
442442
let O = {};
443443
// a. Perform ? CreateDataPropertyOrThrow(O, "type", part.[[type]]).
@@ -570,7 +570,7 @@ function PartitionNumberPattern(numberFormat, x) {
570570
// a. Let groupSepSymbol be the ILND String representing the grouping separator.
571571
let groupSepSymbol = ild.group;
572572
// a. Let groups be a List whose elements are, in left to right order, the substrings defined by ILND set of locations within the integer.
573-
let groups = new List();
573+
let groups = [];
574574
// ----> implementation:
575575
// Primary group represents the group closest to the decimal
576576
let pgSize = data.patterns.primaryGroupSize || 3;

src/12.datetimeformat.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -1053,19 +1053,21 @@ export function FormatDateTime(dateTimeFormat, x) {
10531053
let parts = CreateDateTimeParts(dateTimeFormat, x);
10541054
let result = '';
10551055

1056-
for (let part in parts) {
1057-
result += parts[part].value;
1056+
for (let i = 0; parts.length > i; i++) {
1057+
let part = parts[i];
1058+
result += part.value;
10581059
}
10591060
return result;
10601061
}
10611062

10621063
function FormatToPartsDateTime(dateTimeFormat, x) {
10631064
let parts = CreateDateTimeParts(dateTimeFormat, x);
10641065
let result = [];
1065-
for (let part in parts) {
1066+
for (let i = 0; parts.length > i; i++) {
1067+
let part = parts[i];
10661068
result.push({
1067-
type: parts[part].type,
1068-
value: parts[part].value,
1069+
type: part.type,
1070+
value: part.value,
10691071
});
10701072
}
10711073
return result;

0 commit comments

Comments
 (0)