Skip to content

Commit 2066220

Browse files
authored
feat: Add Ah charge unit (#3617)
Note that an `Ah` is equal to an `amp hour` but reflects standard usage that makes this an integrated unit rather than simply the product of an `amp` and an `hour`. * Also adds a Ah and Wh tests
1 parent 685da0f commit 2066220

5 files changed

Lines changed: 39 additions & 1 deletion

File tree

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ Richard Taylor <richard.taylor@claconnect.com>
282282
NilsDietrich <61544566+NilsDietrich@users.noreply.github.com>
283283
anslem chibuike <144047596+AnslemHack@users.noreply.github.com>
284284
Ayomide Bamigbade <iamtryve@gmail.com>
285+
Adriano Fantini <a.fantini@higecomore.com>
285286
Anadian <willanad@yandex.com>
286287
Dheemanth D <165369664+Dheemanth07@users.noreply.github.com>
287288

HISTORY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- Chore: Provide TypeScript types for [and/or]TransformDependencies (#3639).
66
Thanks @NilsDietrich.
7+
- Feat: Add amp-hour charge unit `Ah` (#3617). Thanks @adrfantini.
78

89
# 2026-02-10, 15.1.1
910

docs/datatypes/units.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ Force | newton (N), dyne (dyn), poundforce (lbf), kip
318318
Energy | joule (J), erg, Wh, BTU, electronvolt (eV)
319319
Power | watt (W), hp
320320
Pressure | Pa, psi, atm, torr, bar, mmHg, mmH2O, cmH2O
321-
Electricity and magnetism | ampere (A), coulomb (C), watt (W), volt (V), ohm, farad (F), weber (Wb), tesla (T), henry (H), siemens (S), electronvolt (eV)
321+
Electricity and magnetism | ampere (A), ampere-hour (Ah), coulomb (C), watt (W), volt (V), ohm, farad (F), weber (Wb), tesla (T), henry (H), siemens (S), electronvolt (eV)
322322
Binary | bits (b), bytes (B)
323323

324324
Note: all time units are based on the Julian year, with one month being 1/12th of a Julian year, a year being one Julian year, a decade being 10 Julian years, a century being 100, and a millennium being 1000.

src/type/unit/Unit.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2660,6 +2660,13 @@ export const createUnitClass = /* #__PURE__ */ factory(name, dependencies, ({
26602660
value: 1,
26612661
offset: 0
26622662
},
2663+
Ah: {
2664+
name: 'Ah',
2665+
base: BASE_UNITS.ELECTRIC_CHARGE,
2666+
prefixes: PREFIXES.SHORT,
2667+
value: 3600,
2668+
offset: 0
2669+
},
26632670
// Electric capacitance
26642671
farad: {
26652672
name: 'farad',

test/unit-tests/type/unit/Unit.test.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ describe('Unit', function () {
6767
assert.strictEqual(unit1.units[0].unit.name, 'm3')
6868
})
6969

70+
it('should create ampere-hour correctly', function () {
71+
const n = 1.4
72+
const unit1 = new Unit(n, 'Ah')
73+
assert.strictEqual(unit1.value, n * 3600)
74+
assert.strictEqual(unit1.units[0].unit.name, 'Ah')
75+
})
76+
7077
it('should create a unit from an existing unit', function () {
7178
const unit1 = new Unit(null, 'm/s^2')
7279
const unit2 = new Unit(5, unit1)
@@ -1070,6 +1077,28 @@ describe('Unit', function () {
10701077
assert.strictEqual(unit1.pow(2).skipAutomaticSimplification, false)
10711078
})
10721079

1080+
it('should be able to combine A and h into Ah', function () {
1081+
// by default, this stays Ah, due to the default unit system
1082+
const n1 = 2
1083+
const n2 = 3
1084+
const unit1 = new Unit(n1, 'A')
1085+
const unit2 = new Unit(n2, 'h')
1086+
const unitM = unit1.multiply(unit2).simplify()
1087+
assert.strictEqual(unitM.units[0].unit.name, 'Ah')
1088+
assert.strictEqual(unitM.value, n1 * n2 * 3600)
1089+
})
1090+
1091+
it('should be able to combine W and h into J', function () {
1092+
// by default, this converts to J, due to the default unit system using J for ENERGY
1093+
const n1 = 2
1094+
const n2 = 3
1095+
const unit1 = new Unit(n1, 'W')
1096+
const unit2 = new Unit(n2, 'h')
1097+
const unitM = unit1.multiply(unit2).simplify()
1098+
assert.strictEqual(unitM.units[0].unit.name, 'J')
1099+
assert.strictEqual(unitM.value, n1 * n2 * 3600)
1100+
})
1101+
10731102
it('should retain the units of their operands without simplifying', function () {
10741103
const unit1 = new Unit(10, 'N/s')
10751104
const unit2 = new Unit(10, 'h')

0 commit comments

Comments
 (0)