Skip to content

Commit

Permalink
Hide unit count if 2 in Arabic
Browse files Browse the repository at this point in the history
See [#222](#222).

Co-Authored-By: Evan Hahn <[email protected]>
  • Loading branch information
6km and EvanHahn committed May 25, 2024
1 parent 17362ec commit 10ad3dd
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 30 deletions.
28 changes: 18 additions & 10 deletions humanize-duration.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
* @prop {string} [delimiter]
* @prop {DigitReplacements} [_digitReplacements]
* @prop {boolean} [_numberFirst]
* @prop {boolean} [_hideCountIf2]
*/

/**
Expand Down Expand Up @@ -186,6 +187,7 @@
),
{
delimiter: " ﻭ ",
_hideCountIf2: true,
_digitReplacements: ["۰", "١", "٢", "٣", "٤", "٥", "٦", "٧", "٨", "٩"]
}
),
Expand Down Expand Up @@ -1668,19 +1670,25 @@
: Math.floor(unitCount * Math.pow(10, maxDecimalPoints)) /
Math.pow(10, maxDecimalPoints);
var countStr = normalizedUnitCount.toString();
if (digitReplacements) {

if (language._hideCountIf2 && unitCount === 2) {
formattedCount = "";
for (var i = 0; i < countStr.length; i++) {
var char = countStr[i];
if (char === ".") {
formattedCount += decimal;
} else {
// @ts-ignore because `char` should always be 0-9 at this point.
formattedCount += digitReplacements[char];
spacer = "";
} else {
if (digitReplacements) {
formattedCount = "";
for (var i = 0; i < countStr.length; i++) {
var char = countStr[i];
if (char === ".") {
formattedCount += decimal;
} else {
// @ts-ignore because `char` should always be 0-9 at this point.
formattedCount += digitReplacements[char];
}
}
} else {
formattedCount = countStr.replace(".", decimal);
}
} else {
formattedCount = countStr.replace(".", decimal);
}

var languageWord = language[unitName];
Expand Down
40 changes: 20 additions & 20 deletions test/definitions/ar.tsv
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
0 ۰ جزء من الثانية
1 ١ جزء من الثانية
1.2 ١,٢ جزء من الثانية
2 ٢ جزآن من الثانية
1000 ١ ثانية
2000 ٢ ثانيتان
60000 ١ دقيقة
120000 ٢ دقيقتان
1200000 ٢۰ دقيقة
300000 ٥ دقائق
3600000 ١ ساعة
7200000 ٢ ساعتين
86400000 ١ يوم
172800000 ٢ يومين
604800000 ١ أسبوع
1209600000 ٢ أسبوعين
2629800000 ١ شهر
5259600000 ٢ شهران
31557600000 ١ سنة
63115200000 ٢ سنتان
0 ۰ جزء من الثانية
1 ١ جزء من الثانية
1.2 ١,٢ جزء من الثانية
2 جزآن من الثانية
1000 ١ ثانية
2000 ثانيتان
60000 ١ دقيقة
120000 دقيقتان
1200000 ٢۰ دقيقة
300000 ٥ دقائق
3600000 ١ ساعة
7200000 ساعتين
86400000 ١ يوم
172800000 يومين
604800000 ١ أسبوع
1209600000 أسبوعين
2629800000 ١ شهر
5259600000 شهران
31557600000 ١ سنة
63115200000 سنتان

0 comments on commit 10ad3dd

Please sign in to comment.