diff options
Diffstat (limited to 'gui/src/types/currency')
| -rw-r--r-- | gui/src/types/currency/currency.ts | 6 | ||||
| -rw-r--r-- | gui/src/types/currency/gbp.ts | 54 |
2 files changed, 0 insertions, 60 deletions
diff --git a/gui/src/types/currency/currency.ts b/gui/src/types/currency/currency.ts deleted file mode 100644 index 7c15324..0000000 --- a/gui/src/types/currency/currency.ts +++ /dev/null @@ -1,6 +0,0 @@ -interface Currency { - valueOf(): number; - toString(): string; -} - -export default Currency; diff --git a/gui/src/types/currency/gbp.ts b/gui/src/types/currency/gbp.ts deleted file mode 100644 index b88aae3..0000000 --- a/gui/src/types/currency/gbp.ts +++ /dev/null @@ -1,54 +0,0 @@ -import Currency from "./currency"; - -class Gbp implements Currency { - private readonly sign: 1 | -1; - private readonly pounds: number; - private readonly pence: number; - - constructor(pounds: number, pence: number, sign?: 1 | -1) { - sign = sign ?? 1; - - if (Math.round(pounds) !== pounds) { - throw new Error( - `Cannot construct GBP with non-whole number of pounds: ${pounds}`, - ); - } - if (Math.round(pence) !== pence) { - throw new Error( - `Cannot construct GBP with non-whole number of pence: ${pence}`, - ); - } - if (pounds < 0) { - throw new Error( - `Cannot construct GBP with negative number of pounds: ${pounds}`, - ); - } - if (pence < 0) { - throw new Error( - `Cannot construct GBP with negative number of pounds: ${pounds}`, - ); - } - - this.sign = sign; - this.pounds = pounds; - this.pence = pence; - } - - valueOf(): number { - return this.sign * (this.pounds * 100 + this.pence); - } - - toString(): string { - return `£${this.pounds}·${this.pence < 10 ? `0${this.pence}` : this.pence}`; - } -} - -function newGbpFromDto(dto: unknown): Gbp { - const signedPence = dto as number; - const pounds = Math.floor(Math.abs(signedPence) / 100); - const pence = Math.abs(signedPence) % 100; - const sign = signedPence < 0 ? -1 : 1; - return new Gbp(pounds, pence, sign); -} - -export { Gbp, newGbpFromDto }; |
