diff --git a/src/datetime.js b/src/datetime.js index 80d96c260..f98d183f5 100644 --- a/src/datetime.js +++ b/src/datetime.js @@ -1935,6 +1935,18 @@ export default class DateTime { return this.isValid ? this.toISO() : INVALID; } + /** + * Returns a string representation of this DateTime appropriate for the REPL. + * @return {string} + */ + [Symbol.for("nodejs.util.inspect.custom")]() { + if (this.isValid) { + return `DateTime { ts: ${this.toISO()}, zone: ${this.zone.name}, locale: ${this.locale} }`; + } else { + return `DateTime { Invalid, reason: ${this.invalidReason} }`; + } + } + /** * Returns the epoch milliseconds of this DateTime. Alias of {@link DateTime#toMillis} * @return {number} diff --git a/src/duration.js b/src/duration.js index 0f1bd354a..c1135defe 100644 --- a/src/duration.js +++ b/src/duration.js @@ -608,6 +608,18 @@ export default class Duration { return this.toISO(); } + /** + * Returns a string representation of this Duration appropriate for the REPL. + * @return {string} + */ + [Symbol.for("nodejs.util.inspect.custom")]() { + if (this.isValid) { + return `Duration { values: ${JSON.stringify(this.values)} }`; + } else { + return `Duration { Invalid, reason: ${this.invalidReason} }`; + } + } + /** * Returns an milliseconds value of this Duration. * @return {number} diff --git a/src/interval.js b/src/interval.js index 9df385584..dfb58d06b 100644 --- a/src/interval.js +++ b/src/interval.js @@ -539,6 +539,18 @@ export default class Interval { return `[${this.s.toISO()} – ${this.e.toISO()})`; } + /** + * Returns a string representation of this Interval appropriate for the REPL. + * @return {string} + */ + [Symbol.for("nodejs.util.inspect.custom")]() { + if (this.isValid) { + return `Interval { start: ${this.s.toISO()}, end: ${this.e.toISO()} }`; + } else { + return `Interval { Invalid, reason: ${this.invalidReason} }`; + } + } + /** * Returns a localized string representing this Interval. Accepts the same options as the * Intl.DateTimeFormat constructor and any presets defined by Luxon, such as