From fafc805e4d60db893f379b62ab4f1628594af207 Mon Sep 17 00:00:00 2001 From: cupcakearmy Date: Sat, 23 Mar 2019 19:31:08 +0100 Subject: [PATCH] consistent naming --- src/index.ts | 13 ++++++------- test/main.js | 14 +++++++------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/index.ts b/src/index.ts index 683f27a..96518da 100644 --- a/src/index.ts +++ b/src/index.ts @@ -42,12 +42,11 @@ export class Duration { private duration: number constructor(amount: number, interval: Intervals) { - this.duration = Duration.ProcessInterval(amount, interval) } private static ProcessInterval(amount: number, interval: Intervals): number { - switch (interval) { + switch (interval.toLowerCase()) { case 'millisecond': case 'milliseconds': return amount * Millisecond @@ -92,23 +91,23 @@ export class Duration { return this.duration / Second } - public asMinute(): number { + public asMinutes(): number { return this.duration / Minute } - public asHour(): number { + public asHours(): number { return this.duration / Hour } - public asDay(): number { + public asDays(): number { return this.duration / Day } - public asWeek(): number { + public asWeeks(): number { return this.duration / Week } - public asYear(): number { + public asYears(): number { return this.duration / Year } diff --git a/test/main.js b/test/main.js index ef1b5f9..34bde41 100644 --- a/test/main.js +++ b/test/main.js @@ -12,19 +12,19 @@ describe('Duration', () => { a.strictEqual(d.asMilliseconds(), 1000 * 60 * 60 * 24 * 365.25 / 2) a.strictEqual(d.asSeconds(), 60 * 60 * 24 * 365.25 / 2) - a.strictEqual(d.asMinute(), 60 * 24 * 365.25 / 2) - a.strictEqual(d.asHour(), 24 * 365.25 / 2) - a.strictEqual(d.asDay(), 365.25 / 2) - a.strictEqual(d.asWeek(), 365.25 / 7 / 2) - a.strictEqual(d.asYear(), .5) + a.strictEqual(d.asMinutes(), 60 * 24 * 365.25 / 2) + a.strictEqual(d.asHours(), 24 * 365.25 / 2) + a.strictEqual(d.asDays(), 365.25 / 2) + a.strictEqual(d.asWeeks(), 365.25 / 7 / 2) + a.strictEqual(d.asYears(), .5) }) it('add / subtract', () => { const d = new Duration(1, 'day') d.add(4, 'hours') - a.strictEqual(d.asHour(), 28) + a.strictEqual(d.asHours(), 28) d.subtract(.5, 'day') - a.strictEqual(d.asHour(), 16) + a.strictEqual(d.asHours(), 16) }) it('exact units', () => {