0000KT not parsed
Closed this issue · 4 comments
Describe the bug
Sometimes, when wind is very light/nothing, it is represented as 0000KT
(four zeroes). However, this is not parsed.
Please see upstream bug: aeharding/metar-taf-parser#66
To Reproduce
Steps to reproduce the behavior:
- Use
KATW 022045Z 0000KT 10SM SCT120 00/M08 A2996
- See it doesn't parse
Expected behavior
Should parse with wind group
Helllo @aeharding
Thank you for reporting the bug. I agree with the fix proposed in https://github.com/aeharding/metar-taf-parser/pull/66/files.
However the token does not match the wind regex and it will be ignored. Maybe the wind regex should be updated but i am afraid it will collide with the Mainvisibility one...
Hey @mivek. Yeah, I also thought it would be nice if the wind regex was matched. I was playing around with the following patch. It works, passes all tests, but I'm not sure if there are any unintended side affects? Let me know what you think.
diff --git a/src/command/common.ts b/src/command/common.ts
index 3530b43..c3aa903 100644
--- a/src/command/common.ts
+++ b/src/command/common.ts
@@ -98,7 +98,7 @@ export class MainVisibilityCommand implements ICommand {
}
export class WindCommand implements ICommand {
- #regex = /^(VRB|[0-3]\d{2})(\d{2})G?(\d{2})?(KT|MPS|KM\/H)?/;
+ #regex = /^(VRB|00|[0-3]\d{2})(\d{2})G?(\d{2})?(KT|MPS|KM\/H)?/;
canParse(windString: string): boolean {
return this.#regex.test(windString);
@@ -200,7 +200,7 @@ export class VerticalVisibilityCommand implements ICommand {
}
export class MinimalVisibilityCommand implements ICommand {
- #regex = /^(\d{4}[NESW]{1,2})$/;
+ #regex = /^(\d{4}[NnEeSsWw]{1,2})$/;
execute(
container: IAbstractWeatherContainer,
diff --git a/tests/parser/parser.test.ts b/tests/parser/parser.test.ts
index cf8d1da..3a1a2db 100644
--- a/tests/parser/parser.test.ts
+++ b/tests/parser/parser.test.ts
@@ -383,6 +383,20 @@ describe("MetarParser", () => {
});
});
+ test("wind of 0000KT should not parse as minVisibility", () => {
+ const metar = new MetarParser(en).parse(
+ "KATW 022045Z 0000KT 10SM SCT120 00/M08 A2996"
+ );
+
+ expect(metar.wind).toStrictEqual({
+ degrees: 0,
+ speed: 0,
+ unit: "KT",
+ gust: undefined,
+ direction: "N",
+ });
+ });
+
test("wind variation", () => {
const metar = new MetarParser(en).parse("LFPG 161430Z 24015G25KT 180V300");
I like this fix, I tested it and does not break existing tests.
Awesome, I merged this into the typescript port.