diff --git a/lib/DDG/Goodie/Conversions.pm b/lib/DDG/Goodie/Conversions.pm index 296c8fb792d..a166c170844 100755 --- a/lib/DDG/Goodie/Conversions.pm +++ b/lib/DDG/Goodie/Conversions.pm @@ -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); diff --git a/share/goodie/conversions/conversions.js b/share/goodie/conversions/conversions.js index e1a2d15bde3..cab419b017c 100644 --- a/share/goodie/conversions/conversions.js +++ b/share/goodie/conversions/conversions.js @@ -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'}, @@ -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'}, @@ -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'] }, diff --git a/share/goodie/conversions/triggers.yml b/share/goodie/conversions/triggers.yml index a032e7e20b7..2c65e1075c7 100755 --- a/share/goodie/conversions/triggers.yml +++ b/share/goodie/conversions/triggers.yml @@ -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 @@ -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 diff --git a/spec/conversions_spec.js b/spec/conversions_spec.js index 4ea91f228ce..ca41385074f 100644 --- a/spec/conversions_spec.js +++ b/spec/conversions_spec.js @@ -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 */ diff --git a/t/Conversions.t b/t/Conversions.t index b767ce504db..0fbb99b8f87 100755 --- a/t/Conversions.t +++ b/t/Conversions.t @@ -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', @@ -1537,7 +1561,6 @@ ddg_goodie_test( physical_quantity => 'frequency' }) ), - # natural language queries 'unit converter' => test_zci( '',