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

Commit

Permalink
Add in missing duration units. (#4195)
Browse files Browse the repository at this point in the history
  • Loading branch information
pjhampton authored and moollaza committed May 12, 2017
1 parent 07d1553 commit 1ce7de6
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 3 deletions.
1 change: 0 additions & 1 deletion lib/DDG/Goodie/Conversions.pm
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ handle query => sub {

return unless defined $result->{'result'};

# TODO: it's not clear what this does exactly. Come back and comment
my $computable_factor = $styler->for_computation($factor);
if (magnitude_order($computable_factor) > 2*$accuracy + 1) {
$factor = sprintf('%g', $computable_factor);
Expand Down
12 changes: 11 additions & 1 deletion share/goodie/conversions/conversions.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ DDH.conversions = DDH.conversions || {};
leftValue: "",
rightValue: "",

customUnits: [
customUnits: [
// CUSTOM AREA UNITS
{name: 'barn', factor: '0.00000000000000000000000000000001 hectare'},
{name: 'rood', factor: '0.10117141 hectare'},
Expand All @@ -51,6 +51,12 @@ DDH.conversions = DDH.conversions || {};
{name: 'sqdecimeter', factor: '0.000001 hectare'},
{name: 'sqcentimeter', factor: '0.0001 m2'},
{name: 'sqmillimeter', factor: '100 sqcentimeter'},

// CUSTOM DURATION UNITS
{name: "femtosecond", factor: "0.000000000000001 second"},
{name: "picosecond", factor: "0.000000000001 second"},
{name: "fortnight", factor: "2 week"},
{name: "siderealyear", factor: "1.00001741 year"},

// CUSTOM ENERGY UNITS
{name: 'kilojoule', factor: '1000 joules'},
Expand Down Expand Up @@ -246,6 +252,10 @@ DDH.conversions = DDH.conversions || {};
{ symbol: 'decade', name: 'Decade' },
{ symbol: 'century', name: 'Century' },
{ symbol: 'millennium', name: 'Millennium' },
{ symbol: 'femtosecond', name: 'Femtosecond'},
{ symbol: 'picosecond', name: 'Picosecond'},
{ symbol: 'fortnight', name: 'Fortnight'},
{ symbol: 'siderealyear', name: 'Sidereal Year'},
],
defaults: ['minute', 'second']
},
Expand Down
40 changes: 40 additions & 0 deletions share/goodie/conversions/triggers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,34 @@ type: duration
unit: second
symbols: [s]
---
aliases:
- femtosecond
- femtoseconds
- femto second
- femto seconds
- fsecond
- fseconds
type: duration
unit: femtosecond
---
aliases:
- picosecond
- picoseconds
- pico second
- pico seconds
- psecond
- pseconds
type: duration
unit: picosecond
---
aliases:
- fortnight
- fortnights
- fort night
- fort nights
type: duration
unit: fortnight
---
aliases:
- millisec
- millisecs
Expand Down Expand Up @@ -685,6 +713,18 @@ type: duration
unit: year
symbols: [a]
---
aliases:
- sidereal yr
- sidereal yrs
- sidereal year
- sidereal years
- side real yr
- side real yrs
- side real year
- side real years
type: duration
unit: siderealyear
---
aliases:
- decade
- decades
Expand Down
18 changes: 18 additions & 0 deletions spec/conversions_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,24 @@ describe("Conversion of Custom Units", function() {
expect(conversion).toEqual("5e+5");
});

/**
* CUSTOM DURATION UNITS
*/
it("should convert picoseconds to femtoseconds", function() {
var conversion = stripUnit(math.eval("6picosecond to femtosecond"));
expect(conversion).toEqual("6000");
});

it("should convert fortnight to days", function() {
var conversion = stripUnit(math.eval("2fortnight to day"));
expect(conversion).toEqual("28");
});

it("should sidereal years to years", function() {
var conversion = stripUnit(math.eval("2siderealyear to year"));
expect(conversion).toEqual("2.00003482");
});

/**
* CUSTOM ENERGY UNITS
*/
Expand Down
25 changes: 24 additions & 1 deletion t/Conversions.t
Original file line number Diff line number Diff line change
Expand Up @@ -1449,6 +1449,30 @@ ddg_goodie_test(
physical_quantity => 'area'
})
),
'fortnight to days' => test_zci(
'', structured_answer => make_answer({
raw_input => '1',
from_unit => 'fortnight',
to_unit => 'day',
physical_quantity => 'duration'
})
),
'7 picoseconds to fseconds' => test_zci(
'', structured_answer => make_answer({
raw_input => '7',
from_unit => 'picosecond',
to_unit => 'femtosecond',
physical_quantity => 'duration'
})
),
'10 years to sidereal years' => test_zci(
'', structured_answer => make_answer({
raw_input => '10',
from_unit => 'year',
to_unit => 'siderealyear',
physical_quantity => 'duration'
})
),
'10 barns to cm2' => test_zci(
'', structured_answer => make_answer({
raw_input => '10',
Expand Down Expand Up @@ -1537,7 +1561,6 @@ ddg_goodie_test(
physical_quantity => 'frequency'
})
),

# natural language queries
'unit converter' => test_zci(
'',
Expand Down

0 comments on commit 1ce7de6

Please sign in to comment.