forked from EvanHahn/HumanizeDuration.js
-
Notifications
You must be signed in to change notification settings - Fork 1
/
a6946b2686d825121bee8558ae99e38cd7695be6..upstream_main.diff
167 lines (164 loc) · 5.19 KB
/
a6946b2686d825121bee8558ae99e38cd7695be6..upstream_main.diff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
diff --git a/HISTORY.md b/HISTORY.md
index 391cb69..bd1aa48 100644
--- a/HISTORY.md
+++ b/HISTORY.md
@@ -1,3 +1,7 @@
+# 3.32.1 / 2024-05-25
+
+- fix: hide unit count if 2 in Arabic (see [#222](https://github.com/EvanHahn/HumanizeDuration.js/issues/222))
+
# 3.32.0 / 2024-03-29
- new: Amharic support (`am`)
diff --git a/README.md b/README.md
index bb3350f..5f9bb13 100644
--- a/README.md
+++ b/README.md
@@ -460,3 +460,4 @@ Licensed under the permissive [Unlicense](https://unlicense.org/). Enjoy!
- [HumanizeDuration.ts](https://github.com/Nightapes/HumanizeDuration.ts), a TypeScript version of this module
- [aurelia-time](https://github.com/shahabganji/aurelia-time)
- [Fork that adds a `timeAdverb` option](https://github.com/cmldk/HumanizeDuration.js)
+- [Fork that provides the duration in an abbreviated format](https://github.com/rasa/HumanizeDuration.js), ex: `1d 2h 3m 4s`
diff --git a/bower.json b/bower.json
index 6b570d1..150a377 100644
--- a/bower.json
+++ b/bower.json
@@ -35,7 +35,7 @@
"Batmend Ganbaatar (https://github.com/theironbatka)",
"Mikias Menjeta (https://github.com/OMikiasO)"
],
- "version": "3.32.0",
+ "version": "3.32.1",
"description": "Convert millisecond durations to English and many other languages.",
"main": "humanize-duration.js",
"homepage": "https://github.com/EvanHahn/HumanizeDuration.js",
diff --git a/humanize-duration.js b/humanize-duration.js
index 90cf42d..4681646 100644
--- a/humanize-duration.js
+++ b/humanize-duration.js
@@ -41,6 +41,7 @@
* @prop {string} [delimiter]
* @prop {DigitReplacements} [_digitReplacements]
* @prop {boolean} [_numberFirst]
+ * @prop {boolean} [_hideCountIf2]
*/
/**
@@ -186,6 +187,7 @@
),
{
delimiter: " ﻭ ",
+ _hideCountIf2: true,
_digitReplacements: ["۰", "١", "٢", "٣", "٤", "٥", "٦", "٧", "٨", "٩"]
}
),
@@ -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];
diff --git a/package-lock.json b/package-lock.json
index 0d48c91..666f599 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "humanize-duration",
- "version": "3.32.0",
+ "version": "3.32.1",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "humanize-duration",
- "version": "3.32.0",
+ "version": "3.32.1",
"license": "Unlicense",
"devDependencies": {
"@types/ms": "^0.7.34",
diff --git a/package.json b/package.json
index ffea1fc..2b58257 100644
--- a/package.json
+++ b/package.json
@@ -35,7 +35,7 @@
"Batmend Ganbaatar (https://github.com/theironbatka)",
"Mikias Menjeta (https://github.com/OMikiasO)"
],
- "version": "3.32.0",
+ "version": "3.32.1",
"description": "Convert millisecond durations to English and many other languages.",
"homepage": "https://github.com/EvanHahn/HumanizeDuration.js",
"main": "humanize-duration.js",
diff --git a/test/definitions/ar.tsv b/test/definitions/ar.tsv
index 4d8d21c..46e0c34 100644
--- a/test/definitions/ar.tsv
+++ b/test/definitions/ar.tsv
@@ -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 سنتان