UNPKG

@publidata/utils-data-manager

Version:

Collection of methods to extract data from publidata

60 lines (49 loc) 1.28 kB
const PublidataObject = require("../"); /** * Class representing a slot object. * @extends PublidataObject */ class PublidataObjectSlot extends PublidataObject { get date() { const date = new Date(this._source.date); return date; } get start() { const date = new Date(this._source.start_at); return date; } get end() { const date = new Date(this._source.end_at); return date; } get weekday() { const date = new Date(this._source.date); return date.toLocaleDateString("fr-FR", { weekday: "long" }); } get available() { return this._source.available; } get capacity() { return this._source.capacity; } get isComplete() { return this._source.available === 0; } get isFullDay() { return this._source.start_at === this._source.end_at; } toJSON() { const json = {}; json.end = this.end; json.date = this.date; json.start = this.start; json.weekday = this.weekday; json.capacity = this.capacity; json.available = this.available; json.isComplete = this.isComplete; return json; } } module.exports = PublidataObjectSlot;