Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/datatypes/units.md
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ Force | newton (N), dyne (dyn), poundforce (lbf), kip
Energy | joule (J), erg, Wh, BTU, electronvolt (eV)
Power | watt (W), hp
Pressure | Pa, psi, atm, torr, bar, mmHg, mmH2O, cmH2O
Electricity and magnetism | ampere (A), coulomb (C), watt (W), volt (V), ohm, farad (F), weber (Wb), tesla (T), henry (H), siemens (S), electronvolt (eV)
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)
Binary | bits (b), bytes (B)

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.
Expand Down
7 changes: 7 additions & 0 deletions src/type/unit/Unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2660,6 +2660,13 @@ export const createUnitClass = /* #__PURE__ */ factory(name, dependencies, ({
value: 1,
offset: 0
},
Ah: {
name: 'Ah',
base: BASE_UNITS.ELECTRIC_CHARGE,
prefixes: PREFIXES.SHORT,
value: 3600,
offset: 0
},
// Electric capacitance
farad: {
name: 'farad',
Expand Down
29 changes: 29 additions & 0 deletions test/unit-tests/type/unit/Unit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ describe('Unit', function () {
assert.strictEqual(unit1.units[0].unit.name, 'm3')
})

it('should create ampere-hour correctly', function () {
const n = 1.4
const unit1 = new Unit(n, 'Ah')
assert.strictEqual(unit1.value, n * 3600)
assert.strictEqual(unit1.units[0].unit.name, 'Ah')
})

it('should create a unit from an existing unit', function () {
const unit1 = new Unit(null, 'm/s^2')
const unit2 = new Unit(5, unit1)
Expand Down Expand Up @@ -1070,6 +1077,28 @@ describe('Unit', function () {
assert.strictEqual(unit1.pow(2).skipAutomaticSimplification, false)
})

it('should be able to combine A and h into Ah', function () {
// by default, this stays Ah, due to the default unit system
const n1 = 2
const n2 = 3
const unit1 = new Unit(n1, 'A')
const unit2 = new Unit(n2, 'h')
const unitM = unit1.multiply(unit2).simplify()
assert.strictEqual(unitM.units[0].unit.name, 'Ah')
assert.strictEqual(unitM.value, n1 * n2 * 3600)
})

it('should be able to combine W and h into J', function () {
// by default, this converts to J, due to the default unit system using J for ENERGY
const n1 = 2
const n2 = 3
const unit1 = new Unit(n1, 'W')
const unit2 = new Unit(n2, 'h')
const unitM = unit1.multiply(unit2).simplify()
assert.strictEqual(unitM.units[0].unit.name, 'J')
assert.strictEqual(unitM.value, n1 * n2 * 3600)
})

it('should retain the units of their operands without simplifying', function () {
const unit1 = new Unit(10, 'N/s')
const unit2 = new Unit(10, 'h')
Expand Down