Skip to content

Commit

Permalink
Merge pull request #10 from djmartinnz/master
Browse files Browse the repository at this point in the history
Bug Fixes from Canadian METAR
  • Loading branch information
esamattis committed Oct 27, 2014
2 parents e898a6a + 640b467 commit 50401a3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
13 changes: 12 additions & 1 deletion metar.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,16 @@ METAR.prototype.parseAuto = function() {
if (this.result.auto) this.next();
};

METAR.prototype.parseCorrection = function() {
var token = this.peek();
this.result.correction = false;

if (token.lastIndexOf('CC', 0) == 0) {
this.result.correction = token.substr(2,1);
this.next();
}
};

var variableWind = /^([0-9]{3})V([0-9]{3})$/;
METAR.prototype.parseWind = function() {
this.next();
Expand Down Expand Up @@ -236,7 +246,7 @@ METAR.prototype.parseClouds = function() {

METAR.prototype.parseTempDewpoint = function() {
this.next();
var replaced = this.current.replace("M", "-");
var replaced = this.current.replace(/M/g, "-");
var a = replaced.split("/");
if( 2 !== a.length ) return; // expecting XX/XX
this.result.temperature = asInt( a[0] );
Expand Down Expand Up @@ -265,6 +275,7 @@ METAR.prototype.parse = function() {
this.parseStation();
this.parseDate();
this.parseAuto();
this.parseCorrection();
this.parseWind();
this.parseCavok();
this.parseVisibility();
Expand Down
11 changes: 11 additions & 0 deletions test/parse_metar_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ describe("METAR parser", function() {
assert.equal(true, m.auto);
});

it("can parse correction", function() {
var m = parseMetar("CYZF 241700Z CCA 32012G18KT 12SM BKN007 OVC042 M02/M05 A2956");
assert.equal("A", m.correction);
});

it("can parse metar without auto", function() {
var m = parseMetar("EFJY 171750Z 29007KT CAVOK 15/12 Q1006");
assert.equal(290, m.wind.direction);
Expand Down Expand Up @@ -228,6 +233,12 @@ describe("METAR parser", function() {
assert.equal(-2, m.dewpoint);
});

it("can parse both neg", function() {
var m = parseMetar("CYZF 241700Z 32012G18KT 12SM BKN007 OVC042 M02/M03 A2956 RMK SC7SC1 SLP024");
assert.equal(-2, m.temperature);
assert.equal(-3, m.dewpoint);
});

});

describe("for altimeter", function() {
Expand Down

0 comments on commit 50401a3

Please sign in to comment.