UNPKG

react-period-of-stay-input

Version:

React.js component for entering a period of stay in a hotel: check-in + check-out date

35 lines (34 loc) 1.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var moment = require("moment"); exports.FORMAT = 'YYYY-MM-DD'; function isValidDate(stringValue) { return /^\d{4}-\d{2}-\d{2}$/.test(stringValue) && moment.utc(stringValue, exports.FORMAT).isValid(); } var Day = /** @class */ (function () { function Day(value) { if (typeof value === 'string') { if (!isValidDate(value)) { throw new Error(value + " isn't a valid ISO 8601 date literal"); } this.stringValue = value; } else { this.stringValue = value.format(exports.FORMAT); } } Day.prototype.toString = function () { return this.stringValue; }; Day.prototype.toMoment = function () { return moment.utc(this.stringValue); }; Day.prototype.next = function () { return new Day(this.toMoment().add(1, 'days')); }; Day.prototype.previous = function () { return new Day(this.toMoment().subtract(1, 'days')); }; return Day; }()); exports.default = Day;