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 0.2.1 to 0.2.2

5

changelog.md
# Changelog
## 0.2.22
* Fixes for `fromSQL`, `toSQL`, `toSQLTime`, and `toSQLDate`
* Add `includeOffset` option to `toISO` and `toISOTime`
## 0.2.1

@@ -4,0 +9,0 @@

2

package.json
{
"name": "luxon",
"version": "0.2.1",
"version": "0.2.2",
"description": "Immutable date wrapper",

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

@@ -1,2 +0,1 @@

import { Util } from './util';
import { DateTime } from '../datetime';

@@ -108,3 +107,3 @@ import { English } from './english';

const hours = Util.towardZero(dt.offset / 60),
const hours = Math.trunc(dt.offset / 60),
minutes = Math.abs(dt.offset % 60),

@@ -191,4 +190,4 @@ sign = hours >= 0 ? '+' : '-',

case 'z':
// like America/New_York
return dt.zoneName;
// like America/New_York
// meridiems

@@ -195,0 +194,0 @@ case 'a':

import { Util } from './util';
import { English } from './english';
import { FixedOffsetZone } from '../zones/fixedOffsetZone';
import { IANAZone } from '../zones/IANAZone';

@@ -60,3 +61,5 @@ /*

// ISO and SQL parsing
const isoTimeRegex = /(\d\d)(?::?(\d\d)(?::?(\d\d)(?:[.,](\d{1,9}))?)?)?(?:(Z)|([+-]\d\d)(?::?(\d\d))?)?/,
const offsetRegex = /(?:(Z)|([+-]\d\d)(?::?(\d\d))?)/,
isoTimeBaseRegex = /(\d\d)(?::?(\d\d)(?::?(\d\d)(?:[.,](\d{1,9}))?)?)?/,
isoTimeRegex = RegExp(`${isoTimeBaseRegex.source}${offsetRegex.source}?`),
isoTimeExtensionRegex = RegExp(`(?:T${isoTimeRegex.source})?`),

@@ -69,3 +72,6 @@ isoYmdRegex = /([+-]\d{6}|\d{4})(?:-?(\d\d)(?:-?(\d\d))?)?/,

sqlYmdRegex = /(\d{4})-(\d\d)-(\d\d)/, // dumbed-down version of the ISO one
sqlTimeExtensionRegex = RegExp(`(?: ${isoTimeRegex.source})?`);
sqlTimeRegex = RegExp(
`${isoTimeBaseRegex.source} ?(?:${offsetRegex.source}|([a-zA-Z_]+/[a-zA-Z_]+))?`
),
sqlTimeExtensionRegex = RegExp(`(?: ${sqlTimeRegex.source})?`);

@@ -83,16 +89,24 @@ function extractISOYmd(match, cursor) {

function extractISOTime(match, cursor) {
const local = !match[cursor + 4] && !match[cursor + 5],
fullOffset = Util.signedOffset(match[cursor + 5], match[cursor + 6]),
nanosecond = Util.padEnd(match[cursor + 3] || '0'),
item = {
hour: parseInt(match[cursor]) || 0,
minute: parseInt(match[cursor + 1]) || 0,
second: parseInt(match[cursor + 2]) || 0,
millisecond: Math.round(parseInt(nanosecond) / 1000000)
},
zone = local ? null : new FixedOffsetZone(fullOffset);
const item = {
hour: parseInt(match[cursor]) || 0,
minute: parseInt(match[cursor + 1]) || 0,
second: parseInt(match[cursor + 2]) || 0,
millisecond: Util.parseMillis(match[cursor + 3])
};
return [item, zone, cursor + 7];
return [item, null, cursor + 4];
}
function extractISOOffset(match, cursor) {
const local = !match[cursor] && !match[cursor + 1],
fullOffset = Util.signedOffset(match[cursor + 1], match[cursor + 2]),
zone = local ? null : FixedOffsetZone.instance(fullOffset);
return [{}, zone, cursor + 3];
}
function extractIANAZone(match, cursor) {
const zone = match[cursor] ? new IANAZone(match[cursor]) : null;
return [{}, zone, cursor + 1];
}
// ISO duration parsing

@@ -131,17 +145,3 @@

function parseSecondFraction(fraction) {
const f = parseFloat('0.' + fraction) * 1000;
return Math.ceil(f);
}
function fromStrings(
weekdayStr,
yearStr,
monthStr,
dayStr,
hourStr,
minuteStr,
secondStr,
fractionStr
) {
function fromStrings(weekdayStr, yearStr, monthStr, dayStr, hourStr, minuteStr, secondStr) {
const result = {

@@ -153,4 +153,3 @@ year: yearStr.length === 2 ? Util.untruncateYear(parseInt(yearStr)) : parseInt(yearStr),

hour: parseInt(hourStr),
minute: parseInt(minuteStr),
millisecond: fractionStr ? parseSecondFraction(fractionStr) : 0
minute: parseInt(minuteStr)
};

@@ -237,7 +236,7 @@

combineRegexes(isoYmdRegex, isoTimeExtensionRegex),
combineExtractors(extractISOYmd, extractISOTime)
combineExtractors(extractISOYmd, extractISOTime, extractISOOffset)
],
[
combineRegexes(isoWeekRegex, isoTimeExtensionRegex),
combineExtractors(extractISOWeekData, extractISOTime)
combineExtractors(extractISOWeekData, extractISOTime, extractISOOffset)
],

@@ -248,3 +247,3 @@ [

],
[combineRegexes(isoTimeRegex), combineExtractors(extractISOTime)]
[combineRegexes(isoTimeRegex), combineExtractors(extractISOTime, extractISOOffset)]
);

@@ -275,7 +274,10 @@ }

combineRegexes(sqlYmdRegex, sqlTimeExtensionRegex),
combineExtractors(extractISOYmd, extractISOTime)
combineExtractors(extractISOYmd, extractISOTime, extractISOOffset, extractIANAZone)
],
[combineRegexes(isoTimeRegex), combineExtractors(extractISOTime)]
[
combineRegexes(sqlTimeRegex),
combineExtractors(extractISOTime, extractISOOffset, extractIANAZone)
]
);
}
}

@@ -252,4 +252,3 @@ import { Util } from './util';

if (!Util.isUndefined(matches.u)) {
const nanoseconds = parseInt(Util.padEnd(matches.u, 9));
matches.S = Math.round(nanoseconds / 1000000);
matches.S = Util.parseMillis(matches.u);
}

@@ -256,0 +255,0 @@

@@ -10,2 +10,8 @@ import { Duration } from '../duration';

/*
This is just a junk drawer, containing anything used across multiple classes.
Because Luxon is small(ish), this should stay small and we won't worry about splitting
it up into, say, parsingUtil.js and basicUtil.js and so on. But they are divided up by feature area.
*/
/**

@@ -16,30 +22,4 @@ * @private

export class Util {
static friendlyDuration(duration) {
if (Util.isNumber(duration)) {
return Duration.fromMillis(duration);
} else if (duration instanceof Duration) {
return duration;
} else if (duration instanceof Object) {
return Duration.fromObject(duration);
} else {
throw new InvalidArgumentError('Unknown duration argument');
}
}
// TYPES
static friendlyDateTime(dateTimeish) {
if (dateTimeish instanceof DateTime) {
return dateTimeish;
} else if (dateTimeish.valueOf && Util.isNumber(dateTimeish.valueOf())) {
return DateTime.fromJSDate(dateTimeish);
} else if (dateTimeish instanceof Object) {
return DateTime.fromObject(dateTimeish);
} else {
throw new InvalidArgumentError('Unknown datetime argument');
}
}
static maybeArray(thing) {
return Array.isArray(thing) ? thing : [thing];
}
static isUndefined(o) {

@@ -61,27 +41,8 @@ return typeof o === 'undefined';

static numberBetween(thing, bottom, top) {
return Util.isNumber(thing) && thing >= bottom && thing <= top;
}
// OBJECTS AND ARRAYS
static padStart(input, n = 2) {
return ('0'.repeat(n) + input).slice(-n);
static maybeArray(thing) {
return Array.isArray(thing) ? thing : [thing];
}
static padEnd(input, n = 9) {
return (input + '0'.repeat(n)).slice(0, n);
}
static towardZero(input) {
return input < 0 ? Math.ceil(input) : Math.floor(input);
}
// http://stackoverflow.com/a/15030117
static flatten(arr) {
return arr.reduce(
(flat, toFlatten) =>
flat.concat(Array.isArray(toFlatten) ? Util.flatten(toFlatten) : toFlatten),
[]
);
}
static bestBy(arr, by, compare) {

@@ -107,2 +68,23 @@ return arr.reduce((best, next) => {

// NUMBERS AND STRINGS
static numberBetween(thing, bottom, top) {
return Util.isNumber(thing) && thing >= bottom && thing <= top;
}
static padStart(input, n = 2) {
return ('0'.repeat(n) + input).slice(-n);
}
static parseMillis(fraction) {
if (fraction) {
const f = parseFloat('0.' + fraction) * 1000;
return Math.round(f);
} else {
return 0;
}
}
// DATE BASICS
static isLeapYear(year) {

@@ -124,2 +106,10 @@ return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);

static untruncateYear(year) {
if (year > 99) {
return year;
} else return year > 60 ? 1900 + year : 2000 + year;
}
// PARSING
static parseZoneInfo(ts, offsetFormat, locale, timeZone = null) {

@@ -129,3 +119,2 @@ const date = new Date(ts),

hour12: false,
// avoid AM/PM
year: 'numeric',

@@ -162,2 +151,36 @@ month: '2-digit',

// signedOffset('-5', '30') -> -330
static signedOffset(offHourStr, offMinuteStr) {
const offHour = parseInt(offHourStr, 10) || 0,
offMin = parseInt(offMinuteStr, 10) || 0,
offMinSigned = offHour < 0 ? -offMin : offMin;
return offHour * 60 + offMinSigned;
}
// COERCION
static friendlyDuration(duration) {
if (Util.isNumber(duration)) {
return Duration.fromMillis(duration);
} else if (duration instanceof Duration) {
return duration;
} else if (duration instanceof Object) {
return Duration.fromObject(duration);
} else {
throw new InvalidArgumentError('Unknown duration argument');
}
}
static friendlyDateTime(dateTimeish) {
if (dateTimeish instanceof DateTime) {
return dateTimeish;
} else if (dateTimeish.valueOf && Util.isNumber(dateTimeish.valueOf())) {
return DateTime.fromJSDate(dateTimeish);
} else if (dateTimeish instanceof Object) {
return DateTime.fromObject(dateTimeish);
} else {
throw new InvalidArgumentError('Unknown datetime argument');
}
}
static normalizeZone(input) {

@@ -205,16 +228,4 @@ if (Util.isUndefined(input) || input === null) {

static untruncateYear(year) {
if (year > 99) {
return year;
} else return year > 60 ? 1900 + year : 2000 + year;
}
// CAPABILITIES
// signedOffset('-5', '30') -> -330
static signedOffset(offHourStr, offMinuteStr) {
const offHour = parseInt(offHourStr, 10) || 0,
offMin = parseInt(offMinuteStr, 10) || 0,
offMinSigned = offHour < 0 ? -offMin : offMin;
return offHour * 60 + offMinSigned;
}
static hasIntl() {

@@ -221,0 +232,0 @@ return typeof Intl !== 'undefined' && Intl.DateTimeFormat;

@@ -399,3 +399,4 @@ import { Util } from './impl/util';

ends = intervals.map(i => [{ time: i.s, type: 's' }, { time: i.e, type: 'e' }]),
arr = Util.flatten(ends).sort((a, b) => a.time - b.time);
flattened = Array.prototype.concat(...ends),
arr = flattened.sort((a, b) => a.time - b.time);

@@ -402,0 +403,0 @@ for (const i of arr) {

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

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