-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for next forecast by remark (#107)
- Loading branch information
Showing
8 changed files
with
161 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { format, _ } from "commons/i18n"; | ||
import { UnexpectedParseError } from "commons/errors"; | ||
import { IBaseRemark, RemarkType, Remark } from "../remark"; | ||
import { Command } from "./Command"; | ||
|
||
export interface INextForecastByRemark extends IBaseRemark { | ||
type: RemarkType.NextForecastBy; | ||
|
||
day: number; | ||
hour: number; | ||
minute: number; | ||
} | ||
|
||
export interface INextForecastByRemarkDated extends INextForecastByRemark { | ||
type: RemarkType.NextForecastBy; | ||
|
||
date: Date; | ||
} | ||
|
||
export class NextForecastByCommand extends Command { | ||
#regex = /^NXT FCST BY (\d{2})(\d{2})(\d{2})Z/; | ||
|
||
canParse(code: string): boolean { | ||
return this.#regex.test(code); | ||
} | ||
|
||
execute(code: string, remark: Remark[]): [string, Remark[]] { | ||
const matches = code.match(this.#regex); | ||
|
||
if (!matches) throw new UnexpectedParseError("Match not found"); | ||
|
||
const day = +matches[1]; | ||
const hour = matches[2]; | ||
const minute = matches[3]; | ||
|
||
const description = format( | ||
_("Remark.Next.Forecast.By", this.locale), | ||
day, | ||
hour, | ||
minute, | ||
); | ||
|
||
remark.push({ | ||
type: RemarkType.NextForecastBy, | ||
description, | ||
raw: matches[0], | ||
|
||
day, | ||
hour: +hour, | ||
minute: +minute, | ||
}); | ||
|
||
return [code.replace(this.#regex, "").trim(), remark]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import en from "locale/en"; | ||
import { Remark, RemarkType } from "command/remark"; | ||
import { NextForecastByCommand } from "command/remark/NextForecastByCommand"; | ||
|
||
describe("NextForecastByCommand", () => { | ||
const command = new NextForecastByCommand(en); | ||
const code = "NXT FCST BY 160300Z"; | ||
|
||
describe(code, () => { | ||
test("canParse", () => { | ||
expect(command.canParse(code)).toBe(true); | ||
}); | ||
|
||
test("execute", () => { | ||
const [res, remarks] = command.execute(code, []); | ||
|
||
expect(res).toBe(""); | ||
expect(remarks).toEqual<Remark[]>([ | ||
{ | ||
type: RemarkType.NextForecastBy, | ||
description: "next forecast by 16, 03:00Z", | ||
raw: code, | ||
|
||
day: 16, | ||
hour: 3, | ||
minute: 0, | ||
}, | ||
]); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters