1
Fork 0
mirror of https://github.com/pds-nest/nest.git synced 2024-11-22 21:14:18 +00:00
pds-2021-g2-nest/nest_frontend/objects/TimeRay.js

31 lines
745 B
JavaScript
Raw Normal View History

/**
* An half-line of time, defined by a `date` and a boolean `isBefore` indicating if the time before or after the
* specified date should be selected.
*/
export default class TimeRay {
isBefore
date
/**
* @param isBefore - `true` to select times earlier than the date, `false` to select times after the date.
* @param date - The date to start measurements from.
*/
constructor(isBefore, date) {
this.isBefore = isBefore
this.date = date
}
/**
* @returns {string}
*/
toString() {
return `${this.isBefore ? "<" : ">"} ${this.date.toISOString()}`
}
2021-05-22 02:32:47 +00:00
includes(date) {
2021-05-23 14:20:53 +00:00
return Boolean((
this.date > date
) ^ this.isBefore)
2021-05-22 02:32:47 +00:00
}
}