consistent naming

This commit is contained in:
cupcakearmy 2019-03-23 19:31:08 +01:00
parent 6b654c88b6
commit fafc805e4d
2 changed files with 13 additions and 14 deletions

View File

@ -42,12 +42,11 @@ export class Duration {
private duration: number private duration: number
constructor(amount: number, interval: Intervals) { constructor(amount: number, interval: Intervals) {
this.duration = Duration.ProcessInterval(amount, interval) this.duration = Duration.ProcessInterval(amount, interval)
} }
private static ProcessInterval(amount: number, interval: Intervals): number { private static ProcessInterval(amount: number, interval: Intervals): number {
switch (interval) { switch (interval.toLowerCase()) {
case 'millisecond': case 'millisecond':
case 'milliseconds': case 'milliseconds':
return amount * Millisecond return amount * Millisecond
@ -92,23 +91,23 @@ export class Duration {
return this.duration / Second return this.duration / Second
} }
public asMinute(): number { public asMinutes(): number {
return this.duration / Minute return this.duration / Minute
} }
public asHour(): number { public asHours(): number {
return this.duration / Hour return this.duration / Hour
} }
public asDay(): number { public asDays(): number {
return this.duration / Day return this.duration / Day
} }
public asWeek(): number { public asWeeks(): number {
return this.duration / Week return this.duration / Week
} }
public asYear(): number { public asYears(): number {
return this.duration / Year return this.duration / Year
} }

View File

@ -12,19 +12,19 @@ describe('Duration', () => {
a.strictEqual(d.asMilliseconds(), 1000 * 60 * 60 * 24 * 365.25 / 2) a.strictEqual(d.asMilliseconds(), 1000 * 60 * 60 * 24 * 365.25 / 2)
a.strictEqual(d.asSeconds(), 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.asMinutes(), 60 * 24 * 365.25 / 2)
a.strictEqual(d.asHour(), 24 * 365.25 / 2) a.strictEqual(d.asHours(), 24 * 365.25 / 2)
a.strictEqual(d.asDay(), 365.25 / 2) a.strictEqual(d.asDays(), 365.25 / 2)
a.strictEqual(d.asWeek(), 365.25 / 7 / 2) a.strictEqual(d.asWeeks(), 365.25 / 7 / 2)
a.strictEqual(d.asYear(), .5) a.strictEqual(d.asYears(), .5)
}) })
it('add / subtract', () => { it('add / subtract', () => {
const d = new Duration(1, 'day') const d = new Duration(1, 'day')
d.add(4, 'hours') d.add(4, 'hours')
a.strictEqual(d.asHour(), 28) a.strictEqual(d.asHours(), 28)
d.subtract(.5, 'day') d.subtract(.5, 'day')
a.strictEqual(d.asHour(), 16) a.strictEqual(d.asHours(), 16)
}) })
it('exact units', () => { it('exact units', () => {