{ /** * Represents time durations at a given granularity. */ TimeUnit: { /** * Construct a TimeUnit object. * * @param {number} scale The number of seconds in this unit * @return {TimeUnit} A new TimeUnit object */ _new: scale => { _scale: scale, /** * Convert the given value from this unit of time to milliseconds */ toMillis: x => this.toSeconds(x) * 1000, /** * Convert the given value from this unit of time to seconds */ toSeconds: x => x * this._scale, /** * Convert the given value from this unit of time to minutes */ toMinutes: x => Math.floor(this.toSeconds(x) / 60), /** * Convert the given value from this unit of time to hours */ toHours: x => Math.floor(this.toSeconds(x) / (60 * 60)), /** * Convert the given value from this unit of time to days */ toDays: x => Math.floor(this.toSeconds(x) / (24 * 60 * 60)) }, MILLIS: this._new(1 / 1000), SECONDS: this._new(1), MINUTES: this._new(60), HOURS: this._new(60 * 60), DAYS: this._new(24 * 60 * 60), }, /** * Represents chronological durations at a given granularity. */ ChronoUnit: { /** * Construct a ChronoUnit object. * * @param {number} scale The number of milliseconds in this unit * @return {ChronoUnit} A new ChronoUnit object */ _new: scale => { _scale: scale, /** * Compute the duration between two Dates in this unit of time */ between: (left, right) => Math.floor(Math.abs(left.getTime() - right.getTime()) / this._scale) }, MILLIS: this._new(__root__.TimeUnit.MILLIS.toMillis(1)), SECONDS: this._new(__root__.TimeUnit.SECONDS.toMillis(1)), MINUTES: this._new(__root__.TimeUnit.MINUTES.toMillis(1)), HOURS: this._new(__root__.TimeUnit.HOURS.toMillis(1)), DAYS: this._new(__root__.TimeUnit.DAYS.toMillis(1)), WEEKS: this._new(__root__.TimeUnit.DAYS.toMillis(7)), MONTHS: this._new(__root__.TimeUnit.DAYS.toMillis(30)), YEARS: this._new(__root__.TimeUnit.DAYS.toMillis(365)), } }