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

assemblyscript-temporal

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

assemblyscript-temporal - npm Package Compare versions

Comparing version 1.3.0 to 1.4.0

54

assembly/__tests__/plaindate.spec.ts

@@ -157,3 +157,3 @@ import { PlainDate } from "..";

const later = PlainDate.from({ year: 2019, month: 7, day: 24 });
const duration = date.until(later, TimeComponent.years);
const duration = date.until(later, TimeComponent.Years);
expect(duration.years).toBe(50);

@@ -202,8 +202,8 @@ expect(duration.months).toBe(0);

// expect(feb20.until(feb21, TimeComponent.auto).toString()).toBe('P366D');
expect(feb20.until(feb21, TimeComponent.days).toString()).toBe("P366D");
expect(feb20.until(feb21, TimeComponent.Days).toString()).toBe("P366D");
});
it("can return higher units", () => {
expect(feb20.until(feb21, TimeComponent.years).toString()).toBe("P1Y");
expect(feb20.until(feb21, TimeComponent.months).toString()).toBe("P12M");
expect(feb20.until(feb21, TimeComponent.weeks).toString()).toBe("P52W2D");
expect(feb20.until(feb21, TimeComponent.Years).toString()).toBe("P1Y");
expect(feb20.until(feb21, TimeComponent.Months).toString()).toBe("P12M");
expect(feb20.until(feb21, TimeComponent.Weeks).toString()).toBe("P52W2D");
});

@@ -219,6 +219,6 @@ xit("cannot return lower units", () => {

expect(lastFeb20.until(lastFeb21).toString()).toBe("P365D");
expect(lastFeb20.until(lastFeb21, TimeComponent.months).toString()).toBe(
expect(lastFeb20.until(lastFeb21, TimeComponent.Months).toString()).toBe(
"P12M"
);
expect(lastFeb20.until(lastFeb21, TimeComponent.years).toString()).toBe(
expect(lastFeb20.until(lastFeb21, TimeComponent.Years).toString()).toBe(
"P1Y"

@@ -230,6 +230,6 @@ );

laterDate = date.add({ days: 42 });
weeksDifference = date.until(laterDate, TimeComponent.weeks);
weeksDifference = date.until(laterDate, TimeComponent.Weeks);
expect(weeksDifference.weeks).not.toBe(0);
expect(weeksDifference.months).toBe(0);
monthsDifference = date.until(laterDate, TimeComponent.months);
monthsDifference = date.until(laterDate, TimeComponent.Months);
expect(monthsDifference.weeks).toBe(0);

@@ -391,3 +391,3 @@ expect(monthsDifference.months).not.toBe(0);

const later = PlainDate.from({ year: 2019, month: 11, day: 18 });
const duration = later.since(date, TimeComponent.years);
const duration = later.since(date, TimeComponent.Years);
expect(duration.years).toBe(43);

@@ -436,16 +436,16 @@ expect(duration.months).toBe(0);

// expect(feb21.since(feb20, TimeComponent.auto).toString()).toBe('P366D')
expect(feb21.since(feb20, TimeComponent.days).toString()).toBe("P366D");
expect(feb21.since(feb20, TimeComponent.Days).toString()).toBe("P366D");
});
it("can return higher units", () => {
expect(feb21.since(feb20, TimeComponent.years).toString()).toBe("P1Y");
expect(feb21.since(feb20, TimeComponent.months).toString()).toBe("P12M");
expect(feb21.since(feb20, TimeComponent.weeks).toString()).toBe("P52W2D");
expect(feb21.since(feb20, TimeComponent.Years).toString()).toBe("P1Y");
expect(feb21.since(feb20, TimeComponent.Months).toString()).toBe("P12M");
expect(feb21.since(feb20, TimeComponent.Weeks).toString()).toBe("P52W2D");
});
xit("cannot return lower units", () => {
// throws(() => feb21.since(feb20, TimeComponent.hours), RangeError);
// throws(() => feb21.since(feb20, TimeComponent.minutes), RangeError);
// throws(() => feb21.since(feb20, TimeComponent.seconds), RangeError);
// throws(() => feb21.since(feb20, TimeComponent.milliseconds), RangeError);
// throws(() => feb21.since(feb20, TimeComponent.microseconds), RangeError);
// throws(() => feb21.since(feb20, TimeComponent.nanoseconds), RangeError);
// throws(() => feb21.since(feb20, TimeComponent.Hours), RangeError);
// throws(() => feb21.since(feb20, TimeComponent.Minutes), RangeError);
// throws(() => feb21.since(feb20, TimeComponent.Seconds), RangeError);
// throws(() => feb21.since(feb20, TimeComponent.Milliseconds), RangeError);
// throws(() => feb21.since(feb20, TimeComponent.Microseconds), RangeError);
// throws(() => feb21.since(feb20, TimeComponent.Nanoseconds), RangeError);
});

@@ -456,4 +456,4 @@ xit("does not include higher units than necessary", () => {

// expect(lastFeb21.since(lastFeb20).toString()).toBe('P365D')
// expect(lastFeb21.since(lastFeb20, TimeComponent.months).toString()).toBe('P11M28D')
// expect(lastFeb21.since(lastFeb20, TimeComponent.years).toString()).toBe('P11M28D')
// expect(lastFeb21.since(lastFeb20, TimeComponent.Months).toString()).toBe('P11M28D')
// expect(lastFeb21.since(lastFeb20, TimeComponent.Years).toString()).toBe('P11M28D')
});

@@ -463,6 +463,6 @@ xit("weeks and months are mutually exclusive", () => {

const laterDate = date.add({ days: 42 });
const weeksDifference = laterDate.since(date, TimeComponent.weeks);
const weeksDifference = laterDate.since(date, TimeComponent.Weeks);
expect(weeksDifference.weeks).not.toBe(0);
expect(weeksDifference.months).toBe(0);
const monthsDifference = laterDate.since(date, TimeComponent.months);
const monthsDifference = laterDate.since(date, TimeComponent.Months);
expect(monthsDifference.weeks).toBe(0);

@@ -581,5 +581,5 @@ expect(monthsDifference.months).not.toBe(0);

// it('accepts singular units', () => {
// expect(later.since(earlier, TimeComponent.year)}`, `${later.since(earlier).toBe(TimeComponent.years).toString())
// expect(later.since(earlier, TimeComponent.Year)}`, `${later.since(earlier).toBe(TimeComponent.Years).toString())
// expect(later.since(earlier, { smallestUnit: 'year' })}`, `${later.since(earlier).toBe({ smallestUnit: 'years' }).toString())
// expect(later.since(earlier, TimeComponent.month)}`, `${later.since(earlier).toBe(TimeComponent.months).toString())
// expect(later.since(earlier, TimeComponent.Month)}`, `${later.since(earlier).toBe(TimeComponent.Months).toString())
// equal(

@@ -589,3 +589,3 @@ // later.since(earlier, { smallestUnit: 'month' }).toString(),

// );
// expect(later.since(earlier, TimeComponent.day)}`, `${later.since(earlier).toBe(TimeComponent.days).toString())
// expect(later.since(earlier, TimeComponent.Day)}`, `${later.since(earlier).toBe(TimeComponent.Days).toString())
// expect(later.since(earlier, { smallestUnit: 'day' })}`, `${later.since(earlier).toBe({ smallestUnit: 'days' }).toString())

@@ -592,0 +592,0 @@ // });

@@ -286,21 +286,21 @@ import { Duration, DurationLike } from "../duration";

// expect(t1.until(t2, { largestUnit: "auto" }).toString()).toBe( "PT6H52M42S");
expect(t1.until(t2, TimeComponent.hours).toString()).toBe("PT6H52M42S");
expect(t1.until(t2, TimeComponent.Hours).toString()).toBe("PT6H52M42S");
});
it("higher units are not allowed", () => {
expect(() => {
t1.until(t2, TimeComponent.days);
t1.until(t2, TimeComponent.Days);
}).toThrow();
expect(() => {
t1.until(t2, TimeComponent.weeks);
t1.until(t2, TimeComponent.Weeks);
}).toThrow();
expect(() => {
t1.until(t2, TimeComponent.months);
t1.until(t2, TimeComponent.Months);
}).toThrow();
expect(() => {
t1.until(t2, TimeComponent.years);
t1.until(t2, TimeComponent.Years);
}).toThrow();
});
it("can return lower units", () => {
expect(t1.until(t2, TimeComponent.minutes).toString()).toBe("PT412M42S");
expect(t1.until(t2, TimeComponent.seconds).toString()).toBe("PT24762S");
expect(t1.until(t2, TimeComponent.Minutes).toString()).toBe("PT412M42S");
expect(t1.until(t2, TimeComponent.Seconds).toString()).toBe("PT24762S");
});

@@ -314,3 +314,3 @@ it("can return subseconds", () => {

msDiff = t1.until(t3, TimeComponent.milliseconds);
msDiff = t1.until(t3, TimeComponent.Milliseconds);
expect(msDiff.seconds).toBe(0);

@@ -321,3 +321,3 @@ expect(msDiff.milliseconds).toBe(24762250);

µsDiff = t1.until(t3, TimeComponent.microseconds);
µsDiff = t1.until(t3, TimeComponent.Microseconds);
expect(µsDiff.milliseconds).toBe(0);

@@ -327,3 +327,3 @@ expect(µsDiff.microseconds).toBe(<i32>24762250250);

nsDiff = t1.until(t3, TimeComponent.nanoseconds);
nsDiff = t1.until(t3, TimeComponent.Nanoseconds);
expect(nsDiff.microseconds).toBe(0);

@@ -749,21 +749,21 @@ expect(nsDiff.nanoseconds).toBe(<i32>24762250250250);

// expect(t2.since(t1, largestUnit: 'auto)", 'PT6H52M42S');
expect(t2.since(t1, TimeComponent.hours).toString()).toBe("PT6H52M42S");
expect(t2.since(t1, TimeComponent.Hours).toString()).toBe("PT6H52M42S");
});
it("higher units are not allowed", () => {
expect(() => {
t1.until(t2, TimeComponent.days);
t1.until(t2, TimeComponent.Days);
}).toThrow();
expect(() => {
t1.until(t2, TimeComponent.weeks);
t1.until(t2, TimeComponent.Weeks);
}).toThrow();
expect(() => {
t1.until(t2, TimeComponent.months);
t1.until(t2, TimeComponent.Months);
}).toThrow();
expect(() => {
t1.until(t2, TimeComponent.years);
t1.until(t2, TimeComponent.Years);
}).toThrow();
});
it("can return lower units", () => {
expect(t2.since(t1, TimeComponent.minutes).toString()).toBe("PT412M42S");
expect(t2.since(t1, TimeComponent.seconds).toString()).toBe("PT24762S");
expect(t2.since(t1, TimeComponent.Minutes).toString()).toBe("PT412M42S");
expect(t2.since(t1, TimeComponent.Seconds).toString()).toBe("PT24762S");
});

@@ -773,3 +773,3 @@ it("can return subseconds", () => {

msDiff = t3.since(t1, TimeComponent.milliseconds);
msDiff = t3.since(t1, TimeComponent.Milliseconds);
expect(msDiff.seconds).toBe(0);

@@ -780,3 +780,3 @@ expect(msDiff.milliseconds).toBe(24762250);

µsDiff = t3.since(t1, TimeComponent.microseconds);
µsDiff = t3.since(t1, TimeComponent.Microseconds);
expect(µsDiff.milliseconds).toBe(0);

@@ -786,3 +786,3 @@ expect(µsDiff.microseconds).toBe(24762250250 as i32);

nsDiff = t3.since(t1, TimeComponent.nanoseconds);
nsDiff = t3.since(t1, TimeComponent.Nanoseconds);
expect(nsDiff.microseconds).toBe(0);

@@ -789,0 +789,0 @@ expect(nsDiff.nanoseconds).toBe(24762250250250 as i32);

@@ -7,12 +7,12 @@ export const enum Overflow {

export const enum TimeComponent {
years,
months,
weeks,
days,
hours,
minutes,
seconds,
milliseconds,
microseconds,
nanoseconds,
Years,
Months,
Weeks,
Days,
Hours,
Minutes,
Seconds,
Milliseconds,
Microseconds,
Nanoseconds,
}

@@ -154,3 +154,3 @@ import { RegExp } from "../node_modules/assemblyscript-regex/assembly/index";

date: PlainDate,
largestUnit: TimeComponent = TimeComponent.days
largestUnit: TimeComponent = TimeComponent.Days
): Duration {

@@ -170,3 +170,3 @@ return differenceDate(

date: PlainDate,
largestUnit: TimeComponent = TimeComponent.days
largestUnit: TimeComponent = TimeComponent.Days
): Duration {

@@ -207,3 +207,3 @@ return differenceDate(

duration.nanoseconds,
TimeComponent.days
TimeComponent.Days
);

@@ -238,3 +238,3 @@ const newDate = addDate(

duration.nanoseconds,
TimeComponent.days
TimeComponent.Days
);

@@ -241,0 +241,0 @@

@@ -28,3 +28,22 @@ import {

@inline
static fromPlainTime(time: PlainTime): PlainTime {
static from<T = TimeLike>(time: T): PlainTime {
if (isString<T>()) {
// @ts-ignore: cast
return this.fromString(<string>time);
} else {
if (isReference<T>()) {
if (time instanceof PlainTime) {
return this.fromPlainTime(time);
} else if (time instanceof TimeLike) {
return this.fromTimeLike(time);
} else if (time instanceof PlainDateTime) {
return this.fromPlainDateTime(time);
}
}
throw new TypeError("invalid time type");
}
}
@inline
private static fromPlainTime(time: PlainTime): PlainTime {
return new PlainTime(

@@ -41,3 +60,3 @@ time.hour,

@inline
static fromPlainDateTime(date: PlainDateTime): PlainTime {
private static fromPlainDateTime(date: PlainDateTime): PlainTime {
return new PlainTime(

@@ -54,3 +73,3 @@ date.hour,

@inline
static fromTimeLike(time: TimeLike): PlainTime {
private static fromTimeLike(time: TimeLike): PlainTime {
return new PlainTime(

@@ -66,3 +85,3 @@ coalesce(time.hour, 0),

static fromString(time: string): PlainTime {
private static fromString(time: string): PlainTime {
const timeRegex = new RegExp(

@@ -116,3 +135,3 @@ "^(\\d{2})(?::(\\d{2})(?::(\\d{2})(?:[.,](\\d{1,9}))?)?|(\\d{2})(?:(\\d{2})(?:[.,](\\d{1,9}))?)?)?(?:(?:([zZ])|(?:([+\u2212-])([01][0-9]|2[0-3])(?::?([0-5][0-9])(?::?([0-5][0-9])(?:[.,](\\d{1,9}))?)?)?)?)(?:\\[((?:(?:\\.[-A-Za-z_]|\\.\\.[-A-Za-z._]{1,12}|\\.[-A-Za-z_][-A-Za-z._]{0,12}|[A-Za-z_][-A-Za-z._]{0,13})(?:\\/(?:\\.[-A-Za-z_]|\\.\\.[-A-Za-z._]{1,12}|\\.[-A-Za-z_][-A-Za-z._]{0,12}|[A-Za-z_][-A-Za-z._]{0,13}))*|Etc\\/GMT[-+]\\d{1,2}|(?:[+\\u2212-][0-2][0-9](?::?[0-5][0-9](?::?[0-5][0-9](?:[.,]\\d{1,9})?)?)?)))\\])?)?(?:\\[u-ca=((?:[A-Za-z0-9]{3,8}(?:-[A-Za-z0-9]{3,8})*))\\])?$",

} else {
const dateTime = PlainDateTime.fromString(time);
const dateTime = PlainDateTime.from(time);
return new PlainTime(

@@ -129,21 +148,2 @@ dateTime.hour,

@inline
static from<T = TimeLike>(time: T): PlainTime {
if (isString<T>()) {
// @ts-ignore: cast
return this.fromString(<string>time);
} else {
if (isReference<T>()) {
if (time instanceof PlainTime) {
return this.fromPlainTime(time);
} else if (time instanceof TimeLike) {
return this.fromTimeLike(time);
} else if (time instanceof PlainDateTime) {
return this.fromPlainDateTime(time);
}
}
throw new TypeError("invalid time type");
}
}
constructor(

@@ -157,13 +157,10 @@ readonly hour: i32 = 0,

) {
if (
!(
checkRange(hour, 0, 23) &&
checkRange(minute, 0, 59) &&
checkRange(second, 0, 59) &&
checkRange(millisecond, 0, 999) &&
checkRange(microsecond, 0, 999) &&
checkRange(nanosecond, 0, 999)
)
)
throw new RangeError("invalid plain time");
if (!(
checkRange(hour, 0, 23) &&
checkRange(minute, 0, 59) &&
checkRange(second, 0, 59) &&
checkRange(millisecond, 0, 999) &&
checkRange(microsecond, 0, 999) &&
checkRange(nanosecond, 0, 999)
)) throw new RangeError("invalid plain time");
}

@@ -224,9 +221,9 @@

other: PlainTime,
largestUnit: TimeComponent = TimeComponent.hours
largestUnit: TimeComponent = TimeComponent.Hours
): Duration {
if (
largestUnit == TimeComponent.years ||
largestUnit == TimeComponent.months ||
largestUnit == TimeComponent.weeks ||
largestUnit == TimeComponent.days
largestUnit == TimeComponent.Years ||
largestUnit == TimeComponent.Months ||
largestUnit == TimeComponent.Weeks ||
largestUnit == TimeComponent.Days
) {

@@ -265,9 +262,9 @@ throw new RangeError("higher units are not allowed");

other: PlainTime,
largestUnit: TimeComponent = TimeComponent.hours
largestUnit: TimeComponent = TimeComponent.Hours
): Duration {
if (
largestUnit == TimeComponent.years ||
largestUnit == TimeComponent.months ||
largestUnit == TimeComponent.weeks ||
largestUnit == TimeComponent.days
largestUnit == TimeComponent.Years ||
largestUnit == TimeComponent.Months ||
largestUnit == TimeComponent.Weeks ||
largestUnit == TimeComponent.Days
) {

@@ -274,0 +271,0 @@ throw new RangeError("higher units are not allowed");

@@ -188,3 +188,5 @@ // for the proposal-temporal implementation, most of the business logic

export function sign<T extends number>(x: T): T {
// x < 0 ? -1 : 1 -> x >> 31 | 1
// optimized variant of x < 0 ? -1 : 1
// i32: x >> 31 | 1
// i64: x >> 63 | 1
// @ts-ignore

@@ -418,4 +420,4 @@ return (x >> (sizeof<T>() * 8 - 1)) | 1;

if (
largestUnit >= TimeComponent.years &&
largestUnit <= TimeComponent.days
largestUnit >= TimeComponent.Years &&
largestUnit <= TimeComponent.Days
) {

@@ -434,7 +436,7 @@ const _ES$NanosecondsToDays = nanosecondsToDays(durationNs);

switch (largestUnit) {
case TimeComponent.years:
case TimeComponent.months:
case TimeComponent.weeks:
case TimeComponent.days:
case TimeComponent.hours:
case TimeComponent.Years:
case TimeComponent.Months:
case TimeComponent.Weeks:
case TimeComponent.Days:
case TimeComponent.Hours:
microsecondsI64 = nanosecondsI64 / 1000;

@@ -456,3 +458,3 @@ nanosecondsI64 = nanosecondsI64 % 1000;

case TimeComponent.minutes:
case TimeComponent.Minutes:
microsecondsI64 = nanosecondsI64 / 1000;

@@ -471,3 +473,3 @@ nanosecondsI64 = nanosecondsI64 % 1000;

case TimeComponent.seconds:
case TimeComponent.Seconds:
microsecondsI64 = nanosecondsI64 / 1000;

@@ -483,3 +485,3 @@ nanosecondsI64 = nanosecondsI64 % 1000;

case TimeComponent.milliseconds:
case TimeComponent.Milliseconds:
microsecondsI64 = nanosecondsI64 / 1000;

@@ -492,3 +494,3 @@ nanosecondsI64 = nanosecondsI64 % 1000;

case TimeComponent.microseconds:
case TimeComponent.Microseconds:
microsecondsI64 = nanosecondsI64 / 1000;

@@ -498,3 +500,3 @@ nanosecondsI64 = nanosecondsI64 % 1000;

case TimeComponent.nanoseconds:
case TimeComponent.Nanoseconds:
break;

@@ -569,7 +571,7 @@ }

d2: i32,
largestUnit: TimeComponent = TimeComponent.days
largestUnit: TimeComponent = TimeComponent.Days
): Duration {
switch (largestUnit) {
case TimeComponent.years:
case TimeComponent.months: {
case TimeComponent.Years:
case TimeComponent.Months: {
let sign = -compareTemporalDate(y1, m1, d1, y2, m2, d2);

@@ -590,3 +592,3 @@ if (sign == 0) return new Duration();

if (midSign === 0) {
return largestUnit === TimeComponent.years
return largestUnit === TimeComponent.Years
? new Duration(years)

@@ -607,3 +609,3 @@ : new Duration(0, years * 12);

if (midSign === 0) {
return largestUnit === TimeComponent.years
return largestUnit === TimeComponent.Years
? new Duration(years, months)

@@ -647,3 +649,3 @@ : new Duration(0, months + years * 12);

if (largestUnit === TimeComponent.months) {
if (largestUnit === TimeComponent.Months) {
months += years * 12;

@@ -656,4 +658,4 @@ years = 0;

case TimeComponent.weeks:
case TimeComponent.days: {
case TimeComponent.Weeks:
case TimeComponent.Days: {
let neg = compareTemporalDate(y1, m1, d1, y2, m2, d2) < 0;

@@ -684,3 +686,3 @@

let weeks = 0;
if (largestUnit === TimeComponent.weeks) {
if (largestUnit === TimeComponent.Weeks) {
weeks = floorDiv(days, 7);

@@ -687,0 +689,0 @@ days -= weeks * 7;

{
"name": "assemblyscript-temporal",
"version": "1.3.0",
"version": "1.4.0",
"description": "An implementation of temporal within AssemblyScript, with an initial focus on non-timezone-aware classes and functionality.",

@@ -5,0 +5,0 @@ "main": "index.js",

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