Comparing version 3.0.4 to 3.1.0
{ | ||
"name": "luxon", | ||
"version": "3.0.4", | ||
"version": "3.1.0", | ||
"description": "Immutable date wrapper", | ||
@@ -5,0 +5,0 @@ "author": "Isaac Cambron", |
@@ -158,2 +158,13 @@ import { InvalidArgumentError, InvalidDurationError, InvalidUnitError } from "./errors.js"; | ||
// Remove all properties with a value of 0 from an object | ||
function removeZeroes(vals) { | ||
const newVals = {}; | ||
for (const [key, value] of Object.entries(vals)) { | ||
if (value !== 0) { | ||
newVals[key] = value; | ||
} | ||
} | ||
return newVals; | ||
} | ||
/** | ||
@@ -706,2 +717,13 @@ * A Duration object represents a period of time, like "2 months" or "1 day, 1 hour". Conceptually, it's just a map of units to their quantities, accompanied by some additional configuration and methods for creating, parsing, interrogating, transforming, and formatting them. They can be used on their own or in conjunction with other Luxon types; for example, you can use {@link DateTime#plus} to add a Duration object to a DateTime, producing another DateTime. | ||
/** | ||
* Rescale units to its largest representation | ||
* @example Duration.fromObject({ milliseconds: 90000 }).rescale().toObject() //=> { minutes: 1, seconds: 30 } | ||
* @return {Duration} | ||
*/ | ||
rescale() { | ||
if (!this.isValid) return this; | ||
const vals = removeZeroes(this.normalize().shiftToAll().toObject()); | ||
return clone(this, { values: vals }, true); | ||
} | ||
/** | ||
* Convert this Duration into its representation in a different set of units. | ||
@@ -771,2 +793,21 @@ * @example Duration.fromObject({ hours: 1, seconds: 30 }).shiftTo('minutes', 'milliseconds').toObject() //=> { minutes: 60, milliseconds: 30000 } | ||
/** | ||
* Shift this Duration to all available units. | ||
* Same as shiftTo("years", "months", "weeks", "days", "hours", "minutes", "seconds", "milliseconds") | ||
* @return {Duration} | ||
*/ | ||
shiftToAll() { | ||
if (!this.isValid) return this; | ||
return this.shiftTo( | ||
"years", | ||
"months", | ||
"weeks", | ||
"days", | ||
"hours", | ||
"minutes", | ||
"seconds", | ||
"milliseconds" | ||
); | ||
} | ||
/** | ||
* Return the negative of this Duration. | ||
@@ -773,0 +814,0 @@ * @example Duration.fromObject({ hours: 1, seconds: 30 }).negate().toObject() //=> { hours: -1, seconds: -30 } |
@@ -12,3 +12,3 @@ import DateTime from "./datetime.js"; | ||
const VERSION = "3.0.4"; | ||
const VERSION = "3.1.0"; | ||
@@ -15,0 +15,0 @@ export { |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3916318
41510