Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

luxon

Package Overview
Dependencies
Maintainers
1
Versions
145
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

luxon - npm Package Compare versions

Comparing version 1.2.1 to 1.3.0

12

changelog.md
# Changelog
## 1.3.0
* **mildly breaking change** Duration.toFormat now floors its outputs instead of rounding them (see #224)
* Added 'floor' option to Duration.toFormat and deprecated the 'round' option
* Added `Dateime.toBSON`
* Fixed infinite loop when passing invalid or zero-length durations to Interval#splitBy
* Added better error handling to Duration.fromObject()
## 1.2.1
* 222x speed-up in DateTime creation for non-en locales
* `DateTime#toMillis` alias for `DateTime#valueOf`
* Fix types on zone exports
* Added `DateTime#toMillis` alias for `DateTime#valueOf`
* Fixed types on zone exports

@@ -9,0 +17,0 @@ ## 1.2.0

2

package.json
{
"name": "luxon",
"version": "1.2.1",
"version": "1.3.0",
"description": "Immutable date wrapper",

@@ -5,0 +5,0 @@ "author": "Isaac Cambron",

@@ -222,3 +222,4 @@ import { isUndefined, isNumber, normalizeObject } from './impl/util';

/**
* Create an Duration from a Javascript object with keys like 'years' and 'hours'.
* Create a Duration from a Javascript object with keys like 'years' and 'hours.
* If this object is empty then zero milliseconds duration is returned.
* @param {Object} obj - the object to create the DateTime from

@@ -240,2 +241,7 @@ * @param {number} obj.years

static fromObject(obj) {
if (obj == null || typeof obj !== 'object') {
throw new InvalidArgumentError(
'Duration.fromObject: argument expected to be an object.'
);
}
return new Duration({

@@ -338,8 +344,17 @@ values: normalizeObject(obj, Duration.normalizeUnit, true),

* @param {Object} opts - options
* @param {boolean} opts.round - round numerical values
* @param {boolean} [opts.floor=true] - floor numerical values
* @return {string}
*/
toFormat(fmt, opts = {}) {
// reverse-compat since 1.2; we always round down now, never up, and we do it by default. So:
// 1. always turn off rounding in the underlying formatter
// 2. turn off flooring if either rounding is turned off or flooring is turned off, otherwise leave it on
const fmtOpts = Object.assign({}, opts, { floor: true, round: false });
if (opts.round === false || opts.floor === false) {
fmtOpts.floor = false;
}
return this.isValid
? Formatter.create(this.loc, opts).formatDurationFromString(this, fmt)
? Formatter.create(this.loc, fmtOpts).formatDurationFromString(this, fmt)
: INVALID;

@@ -414,2 +429,10 @@ }

/**
* Returns an milliseconds value of this Duration.
* @return {number}
*/
valueOf() {
return this.as('milliseconds');
}
/**
* Returns a string representation of this Duration appropriate for the REPL.

@@ -416,0 +439,0 @@ * @return {string}

@@ -0,0 +0,0 @@ import Duration from '../duration';

@@ -97,2 +97,3 @@ import { hasFormatToParts, hasIntl, padStart, roundTo } from './util';

this.round = opts.round || false;
this.floor = opts.floor || false;
}

@@ -102,8 +103,30 @@

// to match the browser's numberformatter defaults
const digits = this.round ? 0 : 3,
rounded = roundTo(i, digits);
return padStart(rounded, this.padTo);
const fixed = this.floor ? Math.floor(i) : roundTo(i, this.round ? 0 : 3);
return padStart(fixed, this.padTo);
}
}
class IntlNumberFormatter {
constructor(intl, opts) {
const intlOpts = { useGrouping: false };
if (opts.padTo > 0) {
intlOpts.minimumIntegerDigits = opts.padTo;
}
if (opts.round) {
intlOpts.maximumFractionDigits = 0;
}
this.floor = opts.floor;
this.intl = new Intl.NumberFormat(intl, intlOpts);
}
format(i) {
const fixed = this.floor ? Math.floor(i) : i;
return this.intl.format(fixed);
}
}
/**

@@ -226,3 +249,3 @@ * @private

get fastNumbers() {
if (this.fastNumbersCached !== null) {
if (this.fastNumbersCached == null) {
this.fastNumbersCached = supportsFastNumbers(this);

@@ -352,20 +375,8 @@ }

numberFormatter(opts = {}) {
// this option is never used (the only caller short-circuits on it, but it seems safer to leave)
// (in contrast, the || is used heavily)
if (opts.forceSimple || this.fastNumbers) {
// this forcesimple option is never used (the only caller short-circuits on it, but it seems safer to leave)
// (in contrast, the rest of the condition is used heavily)
if (opts.forceSimple || this.fastNumbers || !hasIntl()) {
return new SimpleNumberFormatter(opts);
} else if (hasIntl()) {
const intlOpts = { useGrouping: false };
if (opts.padTo > 0) {
intlOpts.minimumIntegerDigits = opts.padTo;
}
if (opts.round) {
intlOpts.maximumFractionDigits = 0;
}
return new Intl.NumberFormat(this.intl, intlOpts);
} else {
return new SimpleNumberFormatter(opts);
return new IntlNumberFormatter(this.intl, opts);
}

@@ -372,0 +383,0 @@ }

@@ -260,5 +260,8 @@ import DateTime, { friendlyDateTime } from './datetime';

splitBy(duration) {
if (!this.isValid) return [];
const dur = friendlyDuration(duration),
results = [];
const dur = friendlyDuration(duration);
if (!this.isValid || !dur.isValid || dur.as("milliseconds") === 0) {
return [];
}
let { s } = this,

@@ -268,2 +271,3 @@ added,

const results = [];
while (s < this.e) {

@@ -334,2 +338,6 @@ added = s.plus(dur);

equals(other) {
if (!this.isValid || !other.isValid) {
return false;
}
return this.s.equals(other.s) && this.e.equals(other.e);

@@ -336,0 +344,0 @@ }

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc