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

Commit

Permalink
Conversions: Add light years, astronomical units, parsecs (#4438)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
jc86035 authored and pjhampton committed Sep 2, 2017
1 parent 6052a49 commit 687f7de
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 35 deletions.
74 changes: 40 additions & 34 deletions share/goodie/conversions/conversions.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ DDH.conversions = DDH.conversions || {};

// CUSTOM LENGTH UNITS
{name: 'nauticalmile', factor: '1.15078 miles'},
{name: 'astronomicalunit', factor: '149597870700 meters'},
{name: 'lightyear', factor: '9460730472580800 meters'},
{name: 'parsec', factor: '30856775814913673 meters'},

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

// CUSTOM POWER UNIT
// CUSTOM POWER UNITS
{name: 'kilowatt', factor: '1000 watt'},
{name: 'megawatt', factor: '1000 kilowatt'},
{name: 'gigawatt', factor: '1000 megawatt'},
Expand All @@ -162,13 +165,13 @@ DDH.conversions = DDH.conversions || {};
// CUSTOM PRESSURE UNITS
{name: 'barye', factor: '0.000001 bar'},
{name: 'Satm', factor: '1 atm'},
{name: 'at', factor:'0.980665 bar'},
{name: 'at', factor: '0.980665 bar'},
{name: 'mbar', factor: '0.001 bar'},
{name: 'cbar', factor:'0.01 bar'},
{name: 'dbar', factor:'0.1 bar'},
{name: 'kbar', factor:'1000 bar'},
{name: 'Mbar', factor:'100000 bar'},
{name: 'Gbar', factor:'100000000 bar'},
{name: 'cbar', factor: '0.01 bar'},
{name: 'dbar', factor: '0.1 bar'},
{name: 'kbar', factor: '1000 bar'},
{name: 'Mbar', factor: '100000 bar'},
{name: 'Gbar', factor: '100000000 bar'},

// CUSTOM SPEED UNITS
{name: 'knot', factor: '1.15078 mi/h'},
Expand Down Expand Up @@ -485,26 +488,29 @@ DDH.conversions = DDH.conversions || {};
length: {
name: "Length",
units: [
{ symbol: 'decameter', name: 'Decameter' },
{ symbol: 'millimeter', name: 'Millimeter' },
{ symbol: 'micrometer', name: 'Micrometer' },
{ symbol: 'micrometer', name: 'Micrometer' },
{ symbol: 'nanometer', name: 'Nanometer' },
{ symbol: 'picometer', name: 'Picometer' },
{ symbol: 'kilometer', name: 'Kilometer' },
{ symbol: 'meter', name: 'Meter' },
{ symbol: 'cm', name: 'Centimeter' },
{ symbol: 'hectometer', name: 'Hectometer' },
{ symbol: 'chains', name: 'Chains' },
{ symbol: 'inch', name: 'Inch' },
{ symbol: 'foot', name: 'Feet' },
{ symbol: 'yard', name: 'Yard' },
{ symbol: 'mile', name: 'Mile' },
{ symbol: 'nauticalmile', name: 'Nautical mile'},
{ symbol: 'link', name: 'Link' },
{ symbol: 'rod', name: 'Rod' },
{ symbol: 'angstrom', name: 'Angstrom' },
{ symbol: 'mil', name: 'Mil' },
{ symbol: 'decameter', name: 'Decameter' },
{ symbol: 'millimeter', name: 'Millimeter' },
{ symbol: 'micrometer', name: 'Micrometer' },
{ symbol: 'micrometer', name: 'Micrometer' },
{ symbol: 'nanometer', name: 'Nanometer' },
{ symbol: 'picometer', name: 'Picometer' },
{ symbol: 'kilometer', name: 'Kilometer' },
{ symbol: 'meter', name: 'Meter' },
{ symbol: 'cm', name: 'Centimeter' },
{ symbol: 'hectometer', name: 'Hectometer' },
{ symbol: 'chains', name: 'Chains' },
{ symbol: 'inch', name: 'Inch' },
{ symbol: 'foot', name: 'Feet' },
{ symbol: 'yard', name: 'Yard' },
{ symbol: 'mile', name: 'Mile' },
{ symbol: 'nauticalmile', name: 'Nautical mile'},
{ symbol: 'link', name: 'Link' },
{ symbol: 'rod', name: 'Rod' },
{ symbol: 'astronomicalunit', name: 'Astronomical unit'},
{ symbol: 'lightyear', name: 'Light year'},
{ symbol: 'parsec', name: 'Parsec'},
{ symbol: 'angstrom', name: 'Angstrom' },
{ symbol: 'mil', name: 'Mil' },
],
defaults: ['meter', 'cm']
},
Expand All @@ -523,20 +529,20 @@ DDH.conversions = DDH.conversions || {};
{ symbol: 'hectogram', name: 'Hectogram'},
{ symbol: 'megagram', name: 'Megagram'},
{ symbol: 'ton', name: 'Ton' },
{ symbol: 'metricton', name: 'Metric Ton'},
{ symbol: 'longton', name: 'Long Ton'},
{ symbol: 'shortton', name: 'Short Ton'},
{ symbol: 'metricton', name: 'Metric Ton'},
{ symbol: 'longton', name: 'Long Ton'},
{ symbol: 'shortton', name: 'Short Ton'},
{ symbol: 'grain', name: 'Grain' },
{ symbol: 'dram', name: 'Dram' },
{ symbol: 'ounce', name: 'Ounce' },
{ symbol: 'poundmass', name: 'Pound' },
{ symbol: 'hundredweight', name: 'Hundredweight' },
{ symbol: 'stick', name: 'Stick' },
{ symbol: 'stone', name: 'Stone' },
{ symbol: 'metricquintal', name: 'Metric Quintal'},
{ symbol: 'usquintal', name: 'US Quintal'},
{ symbol: 'frenchquintal', name: 'French Quintal'},
{ symbol: 'troyounce', name: 'Troy Ounce'},
{ symbol: 'metricquintal', name: 'Metric Quintal'},
{ symbol: 'usquintal', name: 'US Quintal'},
{ symbol: 'frenchquintal', name: 'French Quintal'},
{ symbol: 'troyounce', name: 'Troy Ounce'},
{ symbol: 'slug', name: 'Slug'},
{ symbol: 'tola', name: 'Tola'},
{ symbol: 'carat', name: 'Carat'},
Expand Down
51 changes: 50 additions & 1 deletion share/goodie/conversions/triggers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -433,11 +433,60 @@ symbols: [yd]
---
aliases:
- angstrom
- angstroms
- ångström
- Å
- ångströms
- ångstrom
- ångstroms
- å
type: length
unit: angstrom
---
aliases:
- lightyear
- lightyears
- light year
- light years
- light-year
- light-years
- lichtjahr
- lichtjahre
- lichtjahren
- année-lumière
- années-lumière
- lichtjaar
- lichtjaren
type: length
unit: lightyear
symbols: [ly]
---
aliases:
- astronomicalunit
- astronomicalunits
- astronomical unit
- astronomical units
- unité astronomique
- unités astronomiques
- astronomische einheit
- astronomische einheiten
- au
- aus
- ua
type: length
unit: astronomicalunit
symbols: [AU]
---
aliases:
- parsec
- parsecs
- parallax second
- parallax seconds
- pc
- pcs
type: length
unit: parsec
symbols: [pc]
---
aliases:
- ft
- international foot
Expand Down
32 changes: 32 additions & 0 deletions t/Conversions.t
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,38 @@ ddg_goodie_test(
physical_quantity => 'length'
})
),
'20000 ångströms to cm' => test_zci(
'', structured_answer => make_answer({
raw_input => '20000',
from_unit => 'angstrom',
to_unit => 'cm',
physical_quantity => 'length'
})
),
'1 light-year in nanometres' => test_zci(
'', structured_answer => make_answer({
raw_input => '1',
from_unit => 'lightyear',
to_unit => 'nanometer',
physical_quantity => 'length'
})
),
'0.1 astronomische einheit in kilometer' => test_zci(
'', structured_answer => make_answer({
raw_input => '0.1',
from_unit => 'astronomicalunit',
to_unit => 'kilometer',
physical_quantity => 'length'
})
),
'12 parsecs in light years' => test_zci(
'', structured_answer => make_answer({
raw_input => '12',
from_unit => 'parsec',
to_unit => 'lightyear',
physical_quantity => 'length'
})
),
# TEMPERATURE
'1 degree fahrenheit to celsius' => test_zci(
'',
Expand Down

0 comments on commit 687f7de

Please sign in to comment.