Skip to content
This repository was archived by the owner on Oct 15, 2022. It is now read-only.

Commit 687f7de

Browse files
jc86035pjhampton
authored andcommitted
Conversions: Add light years, astronomical units, parsecs (#4438)
* Update conversions.js * Update conversions.js * Update conversions.js * Update conversions.js * Update triggers.yml * Update triggers.yml * Add some tests for new units * ce * Update Conversions.t
1 parent 6052a49 commit 687f7de

File tree

3 files changed

+122
-35
lines changed

3 files changed

+122
-35
lines changed

share/goodie/conversions/conversions.js

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ DDH.conversions = DDH.conversions || {};
129129

130130
// CUSTOM LENGTH UNITS
131131
{name: 'nauticalmile', factor: '1.15078 miles'},
132+
{name: 'astronomicalunit', factor: '149597870700 meters'},
133+
{name: 'lightyear', factor: '9460730472580800 meters'},
134+
{name: 'parsec', factor: '30856775814913673 meters'},
132135

133136
// CUSTOM FORCE UNITS
134137
{name: 'kilonewton', factor: '1000 newton'},
@@ -151,7 +154,7 @@ DDH.conversions = DDH.conversions || {};
151154
{name: 'carat', factor: '0.2 grams'},
152155
{name: 'atomicmassunit', factor: '0.000000001660538921 femtograms'},
153156

154-
// CUSTOM POWER UNIT
157+
// CUSTOM POWER UNITS
155158
{name: 'kilowatt', factor: '1000 watt'},
156159
{name: 'megawatt', factor: '1000 kilowatt'},
157160
{name: 'gigawatt', factor: '1000 megawatt'},
@@ -162,13 +165,13 @@ DDH.conversions = DDH.conversions || {};
162165
// CUSTOM PRESSURE UNITS
163166
{name: 'barye', factor: '0.000001 bar'},
164167
{name: 'Satm', factor: '1 atm'},
165-
{name: 'at', factor:'0.980665 bar'},
168+
{name: 'at', factor: '0.980665 bar'},
166169
{name: 'mbar', factor: '0.001 bar'},
167-
{name: 'cbar', factor:'0.01 bar'},
168-
{name: 'dbar', factor:'0.1 bar'},
169-
{name: 'kbar', factor:'1000 bar'},
170-
{name: 'Mbar', factor:'100000 bar'},
171-
{name: 'Gbar', factor:'100000000 bar'},
170+
{name: 'cbar', factor: '0.01 bar'},
171+
{name: 'dbar', factor: '0.1 bar'},
172+
{name: 'kbar', factor: '1000 bar'},
173+
{name: 'Mbar', factor: '100000 bar'},
174+
{name: 'Gbar', factor: '100000000 bar'},
172175

173176
// CUSTOM SPEED UNITS
174177
{name: 'knot', factor: '1.15078 mi/h'},
@@ -485,26 +488,29 @@ DDH.conversions = DDH.conversions || {};
485488
length: {
486489
name: "Length",
487490
units: [
488-
{ symbol: 'decameter', name: 'Decameter' },
489-
{ symbol: 'millimeter', name: 'Millimeter' },
490-
{ symbol: 'micrometer', name: 'Micrometer' },
491-
{ symbol: 'micrometer', name: 'Micrometer' },
492-
{ symbol: 'nanometer', name: 'Nanometer' },
493-
{ symbol: 'picometer', name: 'Picometer' },
494-
{ symbol: 'kilometer', name: 'Kilometer' },
495-
{ symbol: 'meter', name: 'Meter' },
496-
{ symbol: 'cm', name: 'Centimeter' },
497-
{ symbol: 'hectometer', name: 'Hectometer' },
498-
{ symbol: 'chains', name: 'Chains' },
499-
{ symbol: 'inch', name: 'Inch' },
500-
{ symbol: 'foot', name: 'Feet' },
501-
{ symbol: 'yard', name: 'Yard' },
502-
{ symbol: 'mile', name: 'Mile' },
503-
{ symbol: 'nauticalmile', name: 'Nautical mile'},
504-
{ symbol: 'link', name: 'Link' },
505-
{ symbol: 'rod', name: 'Rod' },
506-
{ symbol: 'angstrom', name: 'Angstrom' },
507-
{ symbol: 'mil', name: 'Mil' },
491+
{ symbol: 'decameter', name: 'Decameter' },
492+
{ symbol: 'millimeter', name: 'Millimeter' },
493+
{ symbol: 'micrometer', name: 'Micrometer' },
494+
{ symbol: 'micrometer', name: 'Micrometer' },
495+
{ symbol: 'nanometer', name: 'Nanometer' },
496+
{ symbol: 'picometer', name: 'Picometer' },
497+
{ symbol: 'kilometer', name: 'Kilometer' },
498+
{ symbol: 'meter', name: 'Meter' },
499+
{ symbol: 'cm', name: 'Centimeter' },
500+
{ symbol: 'hectometer', name: 'Hectometer' },
501+
{ symbol: 'chains', name: 'Chains' },
502+
{ symbol: 'inch', name: 'Inch' },
503+
{ symbol: 'foot', name: 'Feet' },
504+
{ symbol: 'yard', name: 'Yard' },
505+
{ symbol: 'mile', name: 'Mile' },
506+
{ symbol: 'nauticalmile', name: 'Nautical mile'},
507+
{ symbol: 'link', name: 'Link' },
508+
{ symbol: 'rod', name: 'Rod' },
509+
{ symbol: 'astronomicalunit', name: 'Astronomical unit'},
510+
{ symbol: 'lightyear', name: 'Light year'},
511+
{ symbol: 'parsec', name: 'Parsec'},
512+
{ symbol: 'angstrom', name: 'Angstrom' },
513+
{ symbol: 'mil', name: 'Mil' },
508514
],
509515
defaults: ['meter', 'cm']
510516
},
@@ -523,20 +529,20 @@ DDH.conversions = DDH.conversions || {};
523529
{ symbol: 'hectogram', name: 'Hectogram'},
524530
{ symbol: 'megagram', name: 'Megagram'},
525531
{ symbol: 'ton', name: 'Ton' },
526-
{ symbol: 'metricton', name: 'Metric Ton'},
527-
{ symbol: 'longton', name: 'Long Ton'},
528-
{ symbol: 'shortton', name: 'Short Ton'},
532+
{ symbol: 'metricton', name: 'Metric Ton'},
533+
{ symbol: 'longton', name: 'Long Ton'},
534+
{ symbol: 'shortton', name: 'Short Ton'},
529535
{ symbol: 'grain', name: 'Grain' },
530536
{ symbol: 'dram', name: 'Dram' },
531537
{ symbol: 'ounce', name: 'Ounce' },
532538
{ symbol: 'poundmass', name: 'Pound' },
533539
{ symbol: 'hundredweight', name: 'Hundredweight' },
534540
{ symbol: 'stick', name: 'Stick' },
535541
{ symbol: 'stone', name: 'Stone' },
536-
{ symbol: 'metricquintal', name: 'Metric Quintal'},
537-
{ symbol: 'usquintal', name: 'US Quintal'},
538-
{ symbol: 'frenchquintal', name: 'French Quintal'},
539-
{ symbol: 'troyounce', name: 'Troy Ounce'},
542+
{ symbol: 'metricquintal', name: 'Metric Quintal'},
543+
{ symbol: 'usquintal', name: 'US Quintal'},
544+
{ symbol: 'frenchquintal', name: 'French Quintal'},
545+
{ symbol: 'troyounce', name: 'Troy Ounce'},
540546
{ symbol: 'slug', name: 'Slug'},
541547
{ symbol: 'tola', name: 'Tola'},
542548
{ symbol: 'carat', name: 'Carat'},

share/goodie/conversions/triggers.yml

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,11 +433,60 @@ symbols: [yd]
433433
---
434434
aliases:
435435
- angstrom
436+
- angstroms
436437
- ångström
437-
- Å
438+
- ångströms
439+
- ångstrom
440+
- ångstroms
441+
- å
438442
type: length
439443
unit: angstrom
440444
---
445+
aliases:
446+
- lightyear
447+
- lightyears
448+
- light year
449+
- light years
450+
- light-year
451+
- light-years
452+
- lichtjahr
453+
- lichtjahre
454+
- lichtjahren
455+
- année-lumière
456+
- années-lumière
457+
- lichtjaar
458+
- lichtjaren
459+
type: length
460+
unit: lightyear
461+
symbols: [ly]
462+
---
463+
aliases:
464+
- astronomicalunit
465+
- astronomicalunits
466+
- astronomical unit
467+
- astronomical units
468+
- unité astronomique
469+
- unités astronomiques
470+
- astronomische einheit
471+
- astronomische einheiten
472+
- au
473+
- aus
474+
- ua
475+
type: length
476+
unit: astronomicalunit
477+
symbols: [AU]
478+
---
479+
aliases:
480+
- parsec
481+
- parsecs
482+
- parallax second
483+
- parallax seconds
484+
- pc
485+
- pcs
486+
type: length
487+
unit: parsec
488+
symbols: [pc]
489+
---
441490
aliases:
442491
- ft
443492
- international foot

t/Conversions.t

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,38 @@ ddg_goodie_test(
436436
physical_quantity => 'length'
437437
})
438438
),
439+
'20000 ångströms to cm' => test_zci(
440+
'', structured_answer => make_answer({
441+
raw_input => '20000',
442+
from_unit => 'angstrom',
443+
to_unit => 'cm',
444+
physical_quantity => 'length'
445+
})
446+
),
447+
'1 light-year in nanometres' => test_zci(
448+
'', structured_answer => make_answer({
449+
raw_input => '1',
450+
from_unit => 'lightyear',
451+
to_unit => 'nanometer',
452+
physical_quantity => 'length'
453+
})
454+
),
455+
'0.1 astronomische einheit in kilometer' => test_zci(
456+
'', structured_answer => make_answer({
457+
raw_input => '0.1',
458+
from_unit => 'astronomicalunit',
459+
to_unit => 'kilometer',
460+
physical_quantity => 'length'
461+
})
462+
),
463+
'12 parsecs in light years' => test_zci(
464+
'', structured_answer => make_answer({
465+
raw_input => '12',
466+
from_unit => 'parsec',
467+
to_unit => 'lightyear',
468+
physical_quantity => 'length'
469+
})
470+
),
439471
# TEMPERATURE
440472
'1 degree fahrenheit to celsius' => test_zci(
441473
'',

0 commit comments

Comments
 (0)