Skip to content

Commit

Permalink
Removed date from PrimeTime
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelverschoof committed Mar 16, 2020
1 parent 280b055 commit dc88cdb
Showing 1 changed file with 8 additions and 18 deletions.
26 changes: 8 additions & 18 deletions src/prime-time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,16 @@ import { Timespan } from './types';

const Timestamps = Calc.Timestamps;

export function primetime (date ?: number | string | Date | PrimeTime) : PrimeTime {
return From.anything(date);
export function primetime (from ?: number | string | Date | PrimeTime) : PrimeTime {
return From.anything(from);
}

export class PrimeTime {

private timestamp : number;
private readonly date : Date;

// private locale : string;
// private timezone : string;

constructor (timestamp : number) {
this.timestamp = timestamp;
this.date = new Date(timestamp);
}

add (amount : number, timespan : string | Timespan) : PrimeTime {
Expand All @@ -46,20 +41,20 @@ export class PrimeTime {
return Timestamps.difference(this.timestamp, to.timestamp, timespan)
}

after (date : PrimeTime, timespan ?: string | Timespan, inclusivity ?: boolean) : boolean {
return this.difference(date, timespan) <= (inclusivity ? 0 : -1);
after (other : PrimeTime, timespan ?: string | Timespan, inclusivity ?: boolean) : boolean {
return this.difference(other, timespan) <= (inclusivity ? 0 : -1);
}

before (date : PrimeTime, timespan ?: string | Timespan, inclusivity ?: boolean) : boolean {
return this.difference(date, timespan) >= (inclusivity ? 0 : 1);
before (other : PrimeTime, timespan ?: string | Timespan, inclusivity ?: boolean) : boolean {
return this.difference(other, timespan) >= (inclusivity ? 0 : 1);
}

between (from : PrimeTime, to : PrimeTime, timespan ?: string | Timespan, inclusivity ?: boolean) : boolean {
return this.after(from, timespan, inclusivity) && this.before(to, timespan, inclusivity);
}

equals (date : PrimeTime, timespan ?: string | Timespan) : boolean {
return this.difference(date, timespan) === 0;
equals (other : PrimeTime, timespan ?: string | Timespan) : boolean {
return this.difference(other, timespan) === 0;
}

leapYear () : boolean {
Expand All @@ -80,16 +75,11 @@ export class PrimeTime {

update (milliseconds : number) : PrimeTime {
this.timestamp = milliseconds;
this.date.setTime(milliseconds);
return this;
}

getTimestamp () : number {
return this.timestamp;
}

getDate () : Date {
return this.date;
}

}

0 comments on commit dc88cdb

Please sign in to comment.