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.10.1 to 1.11.0

464

assembly/__tests__/plaindate.spec.ts

@@ -5,2 +5,5 @@ import { PlainDate } from "..";

import { DateLike } from "../plaindate";
import { PlainDateTime } from "../plaindatetime";
import { PlainTime } from "../plaintime";
import { TimeZone } from "../timezone";

@@ -84,50 +87,50 @@ let date: PlainDate;

describe("Date.toPlainDateTime() works", () => {
// const date = PlainDate.from('1976-11-18');
// const dt = date.toPlainDateTime(Temporal.PlainTime.from('11:30:23'));
// it('returns a Temporal.PlainDateTime', () => assert(dt instanceof Temporal.PlainDateTime));
// it('combines the date and time', () => expect(dt.toString()).toBe('1976-11-18T11:30:23'))
// it('casts argument', () => {
// expect(date.toPlainDateTime({ hour: 11, minute: 30, second: 23 }).toString()).toBe('1976-11-18T11:30:23')
// expect(date.toPlainDateTime('11:30:23').toString()).toBe('1976-11-18T11:30:23')
// });
// it('object must contain at least one correctly-spelled property', () => {
// throws(() => date.toPlainDateTime({}), TypeError);
// throws(() => date.toPlainDateTime({ minutes: 30 }), TypeError);
// });
// it('optional argument defaults to midnight', () => {
// expect(date.toPlainDateTime().toString()).toBe('1976-11-18T00:00:00')
// });
it("combines the date and time", () => {
expect(
PlainDate.from("1976-11-18")
.toPlainDateTime(PlainTime.from("11:30:23"))
.toString()
).toBe("1976-11-18T11:30:23");
});
it("defaults to zero hours / mins / seconds", () => {
expect(PlainDate.from("1976-11-18").toPlainDateTime().toString()).toBe(
"1976-11-18T00:00:00"
);
});
});
describe("Date.toPlainYearMonth() works", () => {
it("combines the date and time", () => {
expect(PlainDate.from("1976-11-18").toPlainYearMonth().toString()).toBe(
"1976-11"
);
});
});
describe("Date.toPlainMonthDay() works", () => {
it("combines the date and time", () => {
expect(PlainDate.from("1976-11-18").toPlainMonthDay().toString()).toBe(
"11-18"
);
});
});
describe("Date.toZonedDateTime()", function () {
// it('works', () => {
// const date = PlainDate.from('2020-01-01');
// const time = Temporal.PlainTime.from('12:00');
// const tz = Temporal.TimeZone.from('America/Los_Angeles');
// const zdt = date.toZonedDateTime({ timeZone: tz, plainTime: time });
// expect(zdt.toString()).toBe('2020-01-01T12:00:00-08:00[America/Los_Angeles]')
// });
// it('works with time omitted (timeZone argument)', () => {
// const date = PlainDate.from('2020-01-01');
// const tz = Temporal.TimeZone.from('America/Los_Angeles');
// const zdt = date.toZonedDateTime(tz);
// expect(zdt.toString()).toBe('2020-01-01T00:00:00-08:00[America/Los_Angeles]')
// });
// it('works with time omitted (timeZone property)', () => {
// const date = PlainDate.from('2020-01-01');
// const tz = Temporal.TimeZone.from('America/Los_Angeles');
// const zdt = date.toZonedDateTime({ timeZone: tz });
// expect(zdt.toString()).toBe('2020-01-01T00:00:00-08:00[America/Los_Angeles]')
// });
// it('casts timeZone property', () => {
// const date = PlainDate.from('2020-07-08');
// const time = Temporal.PlainTime.from('12:00');
// const zdt = date.toZonedDateTime({ timeZone: 'America/Los_Angeles', plainTime: time });
// expect(zdt.toString()).toBe('2020-07-08T12:00:00-07:00[America/Los_Angeles]')
// });
// it('casts time property', () => {
// const date = PlainDate.from('2020-07-08');
// const tz = Temporal.TimeZone.from('America/Los_Angeles');
// const zdt = date.toZonedDateTime({ timeZone: tz, plainTime: '12:00' });
// expect(zdt.toString()).toBe('2020-07-08T12:00:00-07:00[America/Los_Angeles]')
// });
it("works", () => {
const date = PlainDate.from("2020-01-01");
const time = PlainTime.from("12:00");
const tz = TimeZone.from("America/Los_Angeles");
const zdt = date.toZonedDateTime(tz, time);
expect(zdt.toString()).toBe(
"2020-01-01T12:00:00-08:00[America/Los_Angeles]"
);
});
it("works with time omitted (timeZone argument)", () => {
const date = PlainDate.from("2020-01-01");
const tz = TimeZone.from("America/Los_Angeles");
const zdt = date.toZonedDateTime(tz);
expect(zdt.toString()).toBe(
"2020-01-01T00:00:00-08:00[America/Los_Angeles]"
);
});
});

@@ -180,5 +183,7 @@

});
xit("casts argument", () => {
// expect(date.until({ year: 2019, month: 7, day: 24 }).toString()).toBe('P18262D');
// expect(date.until('2019-07-24').toString()).toBe('P18262D');
it("casts argument", () => {
expect(date.until({ year: 2019, month: 7, day: 24 }).toString()).toBe(
"P18262D"
);
expect(date.until("2019-07-24").toString()).toBe("P18262D");
});

@@ -411,5 +416,7 @@ it("takes days per month into account", () => {

});
xit("casts argument", () => {
// expect(date.since({ year: 2019, month: 11, day: 5 }).toString()).toBe('-P15692D')
// expect(date.since('2019-11-05').toString()).toBe('-P15692D')
it("casts argument", () => {
expect(date.since({ year: 2019, month: 11, day: 5 }).toString()).toBe(
"-P15692D"
);
expect(date.since("2019-11-05").toString()).toBe("-P15692D");
});

@@ -608,37 +615,23 @@ xit("takes days per month into account", () => {

// @ts-ignore
expect(
date
.add({ years: 43 })
.toString()
).toBe("2019-11-18");
expect(date.add({ years: 43 }).toString()).toBe("2019-11-18");
});
it("date.add({ months: 3 })", () => {
// @ts-ignore
expect(
date
.add({ months: 3 })
.toString()
).toBe("1977-02-18");
expect(date.add({ months: 3 }).toString()).toBe("1977-02-18");
});
it("date.add({ days: 20 })", () => {
// @ts-ignore
expect(
date
.add({ days: 20 })
.toString()
).toBe("1976-12-08");
expect(date.add({ days: 20 }).toString()).toBe("1976-12-08");
});
it("new Date(2019, 1, 31).add({ months: 1 })", () => {
// @ts-ignore
expect(
new PlainDate(2019, 1, 31)
.add({ months: 1 })
.toString()
).toBe("2019-02-28");
expect(new PlainDate(2019, 1, 31).add({ months: 1 }).toString()).toBe(
"2019-02-28"
);
});
xit("date.add(durationObj)", () => {
it("date.add(durationObj)", () => {
expect(date.add(new Duration(43)).toString()).toBe("2019-11-18");
});
xit("casts argument", () => {
// expect(date.add('P43Y').toString()).toBe('2019-11-18');
it("casts argument", () => {
expect(date.add("P43Y").toString()).toBe("2019-11-18");
});

@@ -652,4 +645,3 @@ xit("constrain when overflowing result", () => {

throws("TypeError", () => {
new PlainDate(2020, 1, 31)
.add({ months: 1 }, Overflow.Reject)
new PlainDate(2020, 1, 31).add({ months: 1 }, Overflow.Reject);
});

@@ -659,101 +651,45 @@ });

// @ts-ignore
expect(
PlainDate.from("2019-11-18")
.add({ years: -43 })
.toString()
).toBe("1976-11-18");
expect(PlainDate.from("2019-11-18").add({ years: -43 }).toString()).toBe(
"1976-11-18"
);
// @ts-ignore
expect(
PlainDate.from("1977-02-18")
.add({ months: -3 })
.toString()
).toBe("1976-11-18");
expect(PlainDate.from("1977-02-18").add({ months: -3 }).toString()).toBe(
"1976-11-18"
);
// @ts-ignore
expect(
PlainDate.from("1976-12-08")
.add({ days: -20 })
.toString()
).toBe("1976-11-18");
expect(PlainDate.from("1976-12-08").add({ days: -20 }).toString()).toBe(
"1976-11-18"
);
// @ts-ignore
expect(
PlainDate.from("2019-02-28")
.add({ months: -1 })
.toString()
).toBe("2019-01-28");
expect(PlainDate.from("2019-02-28").add({ months: -1 }).toString()).toBe(
"2019-01-28"
);
});
it("ignores lower units that don't balance up to a day", () => {
// @ts-ignore
expect(
date
.add({ hours: 1 })
.toString()
).toBe("1976-11-18");
expect(date.add({ hours: 1 }).toString()).toBe("1976-11-18");
// @ts-ignore
expect(
date
.add({ minutes: 1 })
.toString()
).toBe("1976-11-18");
expect(date.add({ minutes: 1 }).toString()).toBe("1976-11-18");
// @ts-ignore
expect(
date
.add({ seconds: 1 })
.toString()
).toBe("1976-11-18");
expect(date.add({ seconds: 1 }).toString()).toBe("1976-11-18");
// @ts-ignore
expect(
date
.add({ milliseconds: 1 })
.toString()
).toBe("1976-11-18");
expect(date.add({ milliseconds: 1 }).toString()).toBe("1976-11-18");
// @ts-ignore
expect(
date
.add({ microseconds: 1 })
.toString()
).toBe("1976-11-18");
expect(date.add({ microseconds: 1 }).toString()).toBe("1976-11-18");
// @ts-ignore
expect(
date
.add({ nanoseconds: 1 })
.toString()
).toBe("1976-11-18");
expect(date.add({ nanoseconds: 1 }).toString()).toBe("1976-11-18");
});
it("adds lower units that balance up to a day or more", () => {
// @ts-ignore
expect(
date
.add({ hours: 24 })
.toString()
).toBe("1976-11-19");
expect(date.add({ hours: 24 }).toString()).toBe("1976-11-19");
// @ts-ignore
expect(
date
.add({ hours: 36 })
.toString()
).toBe("1976-11-19");
expect(date.add({ hours: 36 }).toString()).toBe("1976-11-19");
// @ts-ignore
expect(
date
.add({ hours: 48 })
.toString()
).toBe("1976-11-20");
expect(date.add({ hours: 48 }).toString()).toBe("1976-11-20");
// @ts-ignore
expect(
date
.add({ minutes: 1440 })
.toString()
).toBe("1976-11-19");
expect(date.add({ minutes: 1440 }).toString()).toBe("1976-11-19");
// @ts-ignore
expect(
date
.add({ seconds: 86400 })
.toString()
).toBe("1976-11-19");
expect(date.add({ seconds: 86400 }).toString()).toBe("1976-11-19");
// @ts-ignore
expect(
date
.add({ milliseconds: 86400000 })
.toString()
).toBe("1976-11-19");
expect(date.add({ milliseconds: 86400000 }).toString()).toBe("1976-11-19");
// expect(date.add({ microseconds: 86400000000 }).toString()).toBe('1976-11-19');

@@ -782,23 +718,11 @@ // expect(date.add({ nanoseconds: 86400000000000 }).toString()).toBe('1976-11-19');

// @ts-ignore
expect(
date
.subtract({ years: 43 })
.toString()
).toBe("1976-11-18");
expect(date.subtract({ years: 43 }).toString()).toBe("1976-11-18");
});
it("date.subtract({ months: 11 })", () => {
// @ts-ignore
expect(
date
.subtract({ months: 11 })
.toString()
).toBe("2018-12-18");
expect(date.subtract({ months: 11 }).toString()).toBe("2018-12-18");
});
it("date.subtract({ days: 20 })", () => {
// @ts-ignore
expect(
date
.subtract({ days: 20 })
.toString()
).toBe("2019-10-29");
expect(date.subtract({ days: 20 }).toString()).toBe("2019-10-29");
});

@@ -808,14 +732,10 @@ it('Date.from("2019-02-28").subtract({ months: 1 })', () => {

// @ts-ignore
PlainDate.from("2019-02-28")
.subtract({ months: 1 })
.toString()
PlainDate.from("2019-02-28").subtract({ months: 1 }).toString()
).toBe("2019-01-28");
});
xit("Date.subtract(durationObj)", () => {
expect(date.subtract(new Duration(43)).toString()).toBe(
"1976-11-18"
);
it("Date.subtract(durationObj)", () => {
expect(date.subtract(new Duration(43)).toString()).toBe("1976-11-18");
});
xit("casts argument", () => {
// expect(date.subtract('P43Y').toString()).toBe('1976-11-18');
it("casts argument", () => {
expect(date.subtract("P43Y").toString()).toBe("1976-11-18");
});

@@ -834,23 +754,15 @@ xit("constrain when overflowing result", () => {

// @ts-ignore
PlainDate.from("1976-11-18")
.subtract({ years: -43 })
.toString()
PlainDate.from("1976-11-18").subtract({ years: -43 }).toString()
).toBe("2019-11-18");
expect(
// @ts-ignore
PlainDate.from("2018-12-18")
.subtract({ months: -11 })
.toString()
PlainDate.from("2018-12-18").subtract({ months: -11 }).toString()
).toBe("2019-11-18");
expect(
// @ts-ignore
PlainDate.from("2019-10-29")
.subtract({ days: -20 })
.toString()
PlainDate.from("2019-10-29").subtract({ days: -20 }).toString()
).toBe("2019-11-18");
expect(
// @ts-ignore
PlainDate.from("2019-01-28")
.subtract({ months: -1 })
.toString()
PlainDate.from("2019-01-28").subtract({ months: -1 }).toString()
).toBe("2019-02-28");

@@ -860,25 +772,9 @@ });

// @ts-ignore
expect(
date
.subtract({ hours: 1 })
.toString()
).toBe("2019-11-18");
expect(date.subtract({ hours: 1 }).toString()).toBe("2019-11-18");
// @ts-ignore
expect(
date
.subtract({ minutes: 1 })
.toString()
).toBe("2019-11-18");
expect(date.subtract({ minutes: 1 }).toString()).toBe("2019-11-18");
// @ts-ignore
expect(
date
.subtract({ seconds: 1 })
.toString()
).toBe("2019-11-18");
expect(date.subtract({ seconds: 1 }).toString()).toBe("2019-11-18");
// @ts-ignore
expect(
date
.subtract({ milliseconds: 1 })
.toString()
).toBe("2019-11-18");
expect(date.subtract({ milliseconds: 1 }).toString()).toBe("2019-11-18");
// expect(date.subtract({ microseconds: 1 }).toString()).toBe('2019-11-18');

@@ -889,31 +785,11 @@ // expect(date.subtract({ nanoseconds: 1 }).toString()).toBe('2019-11-18');

// @ts-ignore
expect(
date
.subtract({ hours: 24 })
.toString()
).toBe("2019-11-17");
expect(date.subtract({ hours: 24 }).toString()).toBe("2019-11-17");
// @ts-ignore
expect(
date
.subtract({ hours: 36 })
.toString()
).toBe("2019-11-17");
expect(date.subtract({ hours: 36 }).toString()).toBe("2019-11-17");
// @ts-ignore
expect(
date
.subtract({ hours: 48 })
.toString()
).toBe("2019-11-16");
expect(date.subtract({ hours: 48 }).toString()).toBe("2019-11-16");
// @ts-ignore
expect(
date
.subtract({ minutes: 1440 })
.toString()
).toBe("2019-11-17");
expect(date.subtract({ minutes: 1440 }).toString()).toBe("2019-11-17");
// @ts-ignore
expect(
date
.subtract({ seconds: 86400 })
.toString()
).toBe("2019-11-17");
expect(date.subtract({ seconds: 86400 }).toString()).toBe("2019-11-17");
// expect(date.subtract({ milliseconds: 86400_000 }).toString()).toBe('2019-11-17');

@@ -1138,61 +1014,61 @@ // expect(date.subtract({ microseconds: 86400_000_000 }).toString()).toBe('2019-11-17');

describe('Min/max range', () => {
it('constructing from numbers', () => {
describe("Min/max range", () => {
it("constructing from numbers", () => {
// throws("RangeError", () => { new PlainDate(-271821, 4, 18) });
// throws("RangeError", () => { new PlainDate(275760, 9, 14) });
expect(new PlainDate(-271821, 4, 19).toString()).toBe('-271821-04-19');
expect(new PlainDate(275760, 9, 13).toString()).toBe('275760-09-13');
expect(new PlainDate(-271821, 4, 19).toString()).toBe("-271821-04-19");
expect(new PlainDate(275760, 9, 13).toString()).toBe("275760-09-13");
});
// it('constructing from property bag', () => {
// const tooEarly = { year: -271821, month: 4, day: 18 };
// const tooLate = { year: 275760, month: 9, day: 14 };
// ['reject', 'constrain'].forEach((overflow) => {
// [tooEarly, tooLate].forEach((props) => {
// throws(() => PlainDate.from(props, { overflow }), RangeError);
// });
// });
// expect(PlainDate.from({ year: -271821, month: 4, day: 19 }).toString()).toBe('-271821-04-19');
// expect(PlainDate.from({ year: 275760, month: 9, day: 13 }).toString()).toBe('+275760-09-13');
// });
// it('constructing from ISO string', () => {
// ['reject', 'constrain'].forEach((overflow) => {
// ['-271821-04-18', '+275760-09-14'].forEach((str) => {
// throws(() => PlainDate.from(str, { overflow }), RangeError);
// });
// });
// expect(PlainDate.from('-271821-04-19').toString()).toBe('-271821-04-19');
// expect(PlainDate.from('+275760-09-13').toString()).toBe('+275760-09-13');
// });
// it('converting from DateTime', () => {
// const min = Temporal.PlainDateTime.from('-271821-04-19T00:00:00.000000001');
// const max = Temporal.PlainDateTime.from('+275760-09-13T23:59:59.999999999');
// expect(min.toPlainDate().toString()).toBe('-271821-04-19');
// expect(max.toPlainDate().toString()).toBe('+275760-09-13');
// });
// it('converting from YearMonth', () => {
// const min = Temporal.PlainYearMonth.from('-271821-04');
// const max = Temporal.PlainYearMonth.from('+275760-09');
// throws(() => min.toPlainDate({ day: 1 }), RangeError);
// throws(() => max.toPlainDate({ day: 30 }), RangeError);
// expect(min.toPlainDate({ day: 19 }).toString()).toBe('-271821-04-19');
// expect(max.toPlainDate({ day: 13 }).toString()).toBe('+275760-09-13');
// });
// it('converting from MonthDay', () => {
// const jan1 = Temporal.PlainMonthDay.from('01-01');
// const dec31 = Temporal.PlainMonthDay.from('12-31');
// const minYear = -271821;
// const maxYear = 275760;
// throws(() => jan1.toPlainDate({ year: minYear }), RangeError);
// throws(() => dec31.toPlainDate({ year: maxYear }), RangeError);
// expect(jan1.toPlainDate({ year: minYear + 1 }).toString()).toBe('-271820-01-01');
// expect(dec31.toPlainDate({ year: maxYear - 1 }).toString()).toBe('+275759-12-31');
// });
// it('adding and subtracting beyond limit', () => {
// const min = PlainDate.from('-271821-04-19');
// const max = PlainDate.from('+275760-09-13');
// ['reject', 'constrain'].forEach((overflow) => {
// throws(() => min.subtract({ days: 1 }, { overflow }), RangeError);
// throws(() => max.add({ days: 1 }, { overflow }), RangeError);
// });
// });
// it('constructing from property bag', () => {
// const tooEarly = { year: -271821, month: 4, day: 18 };
// const tooLate = { year: 275760, month: 9, day: 14 };
// ['reject', 'constrain'].forEach((overflow) => {
// [tooEarly, tooLate].forEach((props) => {
// throws(() => PlainDate.from(props, { overflow }), RangeError);
// });
// });
// expect(PlainDate.from({ year: -271821, month: 4, day: 19 }).toString()).toBe('-271821-04-19');
// expect(PlainDate.from({ year: 275760, month: 9, day: 13 }).toString()).toBe('+275760-09-13');
// });
// it('constructing from ISO string', () => {
// ['reject', 'constrain'].forEach((overflow) => {
// ['-271821-04-18', '+275760-09-14'].forEach((str) => {
// throws(() => PlainDate.from(str, { overflow }), RangeError);
// });
// });
// expect(PlainDate.from('-271821-04-19').toString()).toBe('-271821-04-19');
// expect(PlainDate.from('+275760-09-13').toString()).toBe('+275760-09-13');
// });
// it('converting from DateTime', () => {
// const min = Temporal.PlainDateTime.from('-271821-04-19T00:00:00.000000001');
// const max = Temporal.PlainDateTime.from('+275760-09-13T23:59:59.999999999');
// expect(min.toPlainDate().toString()).toBe('-271821-04-19');
// expect(max.toPlainDate().toString()).toBe('+275760-09-13');
// });
// it('converting from YearMonth', () => {
// const min = Temporal.PlainYearMonth.from('-271821-04');
// const max = Temporal.PlainYearMonth.from('+275760-09');
// throws(() => min.toPlainDate({ day: 1 }), RangeError);
// throws(() => max.toPlainDate({ day: 30 }), RangeError);
// expect(min.toPlainDate({ day: 19 }).toString()).toBe('-271821-04-19');
// expect(max.toPlainDate({ day: 13 }).toString()).toBe('+275760-09-13');
// });
// it('converting from MonthDay', () => {
// const jan1 = Temporal.PlainMonthDay.from('01-01');
// const dec31 = Temporal.PlainMonthDay.from('12-31');
// const minYear = -271821;
// const maxYear = 275760;
// throws(() => jan1.toPlainDate({ year: minYear }), RangeError);
// throws(() => dec31.toPlainDate({ year: maxYear }), RangeError);
// expect(jan1.toPlainDate({ year: minYear + 1 }).toString()).toBe('-271820-01-01');
// expect(dec31.toPlainDate({ year: maxYear - 1 }).toString()).toBe('+275759-12-31');
// });
// it('adding and subtracting beyond limit', () => {
// const min = PlainDate.from('-271821-04-19');
// const max = PlainDate.from('+275760-09-13');
// ['reject', 'constrain'].forEach((overflow) => {
// throws(() => min.subtract({ days: 1 }, { overflow }), RangeError);
// throws(() => max.add({ days: 1 }, { overflow }), RangeError);
// });
// });
});

@@ -1199,0 +1075,0 @@

@@ -6,2 +6,3 @@ import { Duration, DurationLike } from "../duration";

import { PlainTime, TimeLike } from "../plaintime";
import { TimeZone } from "../timezone";

@@ -206,2 +207,14 @@ let time: PlainTime,

describe("time.toZonedDateTime()", function () {
it("works", () => {
const date = PlainDate.from("2020-01-01");
const time = PlainTime.from("12:00");
const tz = TimeZone.from("America/Los_Angeles");
const zdt = time.toZonedDateTime(tz, date);
expect(zdt.toString()).toBe(
"2020-01-01T12:00:00-08:00[America/Los_Angeles]"
);
});
});
describe("time.toPlainDateTime() works", () => {

@@ -226,10 +239,2 @@ time = PlainTime.from("11:30:23.123456789");

});
xit("casts argument string like", () => {
// expect(time.toPlainDateTime("1976-11-18").toString()).toBe(
// "1976-11-18T11:30:23.123456789"
// );
});
// it("object must contain at least the required properties", () => {
// throws(() => time.toPlainDateTime({ year: 1976 }), TypeError);
// });
});

@@ -262,3 +267,3 @@

);
xit(
it(
"(" +

@@ -274,13 +279,11 @@ time.toString() +

() => {
// expect(time.until(two).toString()).toBe(two.since(time).toString());
expect(time.until(two).toString()).toBe(two.since(time).toString());
}
);
xit("casts argument", () => {
// expect(time.until({ hour: 16, minute: 34 }).toString()).toBe( "PT1H10M29.876543211S");
// expect(time.until("16:34").toString()).toBe( "PT1H10M29.876543211S");
it("casts argument", () => {
expect(time.until({ hour: 16, minute: 34 }).toString()).toBe(
"PT1H10M29.876543211S"
);
expect(time.until("16:34").toString()).toBe("PT1H10M29.876543211S");
});
// xit("object must contain at least one correctly-spelled property", () => {
// throws(() => time.until({}), TypeError);
// throws(() => time.until({ minutes: 30 }), TypeError);
// });
t1 = PlainTime.from("10:23:15");

@@ -737,5 +740,7 @@ t2 = PlainTime.from("17:15:57");

);
xit("casts argument", () => {
// equal(`${time.since({ hour: 16, minute: 34 })}", '-PT1H10M29.876543211S');
// equal(`${time.since('16:34')}", '-PT1H10M29.876543211S');
it("casts argument", () => {
expect(`${time.since({ hour: 16, minute: 34 })}`).toBe(
"-PT1H10M29.876543211S"
);
expect(`${time.since("16:34")}`).toBe("-PT1H10M29.876543211S");
});

@@ -1077,9 +1082,10 @@ // it('object must contain at least one correctly-spelled property', () => {

});
// it("time.add(durationObj)", () => {
// expect(time.add(Duration.from("PT16H")).toString()).toBe(
// "07:23:30.123456789"
// );
// });
// it("casts argument", () =>
// expect(time.add("PT16H").toString()).toBe("07:23:30.123456789"));
it("time.add(durationObj)", () => {
expect(time.add(Duration.from("PT16H")).toString()).toBe(
"07:23:30.123456789"
);
});
it("casts argument", () => {
expect(time.add("PT16H").toString()).toBe("07:23:30.123456789");
});
// it("ignores higher units", () => {

@@ -1187,9 +1193,10 @@ // expect(time.add({ days: 1 }).toString()).toBe("15:23:30.123456789");

});
// it("time.subtract(durationObj)", () => {
// expect(time.subtract(Temporal.Duration.from("PT16H")).toString()).toBe(
// "23:23:30.123456789"
// );
// });
// it("casts argument", () =>
// expect(time.subtract("PT16H").toString()).toBe("23:23:30.123456789"));
it("time.subtract(durationObj)", () => {
expect(time.subtract(Duration.from("PT16H")).toString()).toBe(
"23:23:30.123456789"
);
});
it("casts argument", () => {
expect(time.subtract("PT16H").toString()).toBe("23:23:30.123456789");
});
it("ignores higher units", () => {

@@ -1196,0 +1203,0 @@ expect(time.subtract({ days: 1 }).toString()).toBe("15:23:30.123456789");

@@ -412,3 +412,3 @@ /// <reference types="@as-pect/assembly/types/as-pect" />

diff = nov94.until(jun13);
xit(
it(
"(" +

@@ -424,3 +424,3 @@ jun13.toString() +

() => {
// expect(jun13.until(nov94).toString()).toBe(diff.negated())
expect(jun13.until(nov94).toString()).toBe(diff.negated().toString())
}

@@ -467,5 +467,5 @@ );

);
xit("casts argument", () => {
// equal("${nov94.until({ year: 2013, month: 6 })}", "" + diff.toString() + "");
// equal("${nov94.until("2013-06")}", "" + diff.toString() + "");
it("casts argument", () => {
expect(`${nov94.until({ year: 2013, month: 6 })}`).toBe(diff.toString());
expect(`${nov94.until("2013-06")}`).toBe(diff.toString());
});

@@ -906,4 +906,5 @@ // it("object must contain at least the required properties", () => {

});
xit("casts argument", () => {});
// expect(ym.add("P2M").toString()).toBe("2020-01"));
it("casts argument", () => {;
expect(ym.add("P2M").toString()).toBe("2020-01");
});
it("ignores lower units that don't balance up to the length of the month", () => {

@@ -1021,4 +1022,5 @@ expect(ym.add({ days: 1 }).toString()).toBe("2019-11");

});
xit("casts argument", () => {});
// expect(ym.subtract("P11M").toString()).toBe("2018-12"));
it("casts argument", () => {;
expect(ym.subtract("P11M").toString()).toBe("2018-12");
});
it("ignores lower units that don't balance up to the length of the month", () => {

@@ -1025,0 +1027,0 @@ expect(ym.subtract({ days: 1 }).toString()).toBe("2019-11");

@@ -41,8 +41,10 @@ import { RegExp } from "assemblyscript-regex";

export class Duration {
static from<T = DurationLike>(date: T): Duration {
static from<T = DurationLike>(duration: T): Duration {
if (isString<T>()) {
// @ts-ignore: cast
return this.fromString(<string>date);
} else if (date instanceof DurationLike) {
return this.fromDurationLike(date);
return Duration.fromString(<string>duration);
} else if (duration instanceof DurationLike) {
return Duration.fromDurationLike(duration);
} else if (duration instanceof Duration) {
return Duration.fromDuration(duration);
}

@@ -52,2 +54,17 @@ throw new TypeError("invalid duration type");

private static fromDuration(duration: Duration): Duration {
return new Duration(
duration.years,
duration.months,
duration.weeks,
duration.days,
duration.hours,
duration.minutes,
duration.seconds,
duration.milliseconds,
duration.microseconds,
duration.nanoseconds
);
}
private static fromString(duration: string): Duration {

@@ -176,7 +193,3 @@ const regex = new RegExp(

add<T = DurationLike>(durationToAdd: T, relativeTo: PlainDateTime | null = null): Duration {
const duration =
durationToAdd instanceof DurationLike
? durationToAdd.toDuration()
// @ts-ignore TS2352
: durationToAdd as Duration;
const duration = Duration.from(durationToAdd);

@@ -208,7 +221,3 @@ return addDuration(this.years,

subtract<T = DurationLike>(durationToAdd: T, relativeTo: PlainDateTime | null = null): Duration {
const duration =
durationToAdd instanceof DurationLike
? durationToAdd.toDuration()
// @ts-ignore TS2352
: durationToAdd as Duration;
const duration = Duration.from(durationToAdd);

@@ -215,0 +224,0 @@ return addDuration(this.years,

@@ -5,2 +5,8 @@ import { RegExp } from "assemblyscript-regex";

import { Overflow, TimeComponent } from "./enums";
import { Instant } from "./instant";
import { PlainDateTime } from "./plaindatetime";
import { PlainMonthDay } from "./plainmonthday";
import { PlainTime } from "./plaintime";
import { PlainYearMonth } from "./plainyearmonth";
import { TimeZone } from "./timezone";
import {

@@ -23,2 +29,3 @@ addDate,

} from "./utils";
import { ZonedDateTime } from "./zoneddatetime";

@@ -36,9 +43,9 @@ export class DateLike {

// @ts-ignore: cast
return this.fromString(<string>date);
return PlainDate.fromString(<string>date);
} else {
if (isReference<T>()) {
if (date instanceof PlainDate) {
return this.fromPlainDate(date);
return PlainDate.fromPlainDate(date);
} else if (date instanceof DateLike) {
return this.fromDateLike(date);
return PlainDate.fromDateLike(date);
}

@@ -65,7 +72,3 @@ }

const parsed = parseISOString(date);
return new PlainDate(
parsed.year,
parsed.month,
parsed.day
);
return new PlainDate(parsed.year, parsed.month, parsed.day);
}

@@ -146,3 +149,7 @@

until(date: PlainDate, largestUnit: TimeComponent = TimeComponent.Days): Duration {
until<T = DateLike>(
dateLike: T,
largestUnit: TimeComponent = TimeComponent.Days
): Duration {
const date = PlainDate.from(dateLike);
return differenceDate(

@@ -159,3 +166,7 @@ this.year,

since(date: PlainDate, largestUnit: TimeComponent = TimeComponent.Days): Duration {
since<T = DateLike>(
dateLike: T,
largestUnit: TimeComponent = TimeComponent.Days
): Duration {
const date = PlainDate.from(dateLike);
return differenceDate(

@@ -180,8 +191,7 @@ date.year,

add<T = DurationLike>(durationToAdd: T, overflow: Overflow = Overflow.Constrain): PlainDate {
const duration =
durationToAdd instanceof DurationLike
? durationToAdd.toDuration()
// @ts-ignore TS2352
: durationToAdd as Duration;
add<T = DurationLike>(
durationToAdd: T,
overflow: Overflow = Overflow.Constrain
): PlainDate {
const duration = Duration.from(durationToAdd);

@@ -211,8 +221,7 @@ const balancedDuration = balanceDuration(

subtract<T = DurationLike>(durationToSubtract: T, overflow: Overflow = Overflow.Constrain): PlainDate {
const duration =
durationToSubtract instanceof DurationLike
? durationToSubtract.toDuration()
// @ts-ignore TS2352
: durationToSubtract as Duration;
subtract<T = DurationLike>(
durationToSubtract: T,
overflow: Overflow = Overflow.Constrain
): PlainDate {
const duration = Duration.from(durationToSubtract);

@@ -244,2 +253,34 @@ const balancedDuration = balanceDuration(

toPlainDateTime(time: PlainTime | null = null): PlainDateTime {
if (time) {
return new PlainDateTime(
this.year,
this.month,
this.day,
time.hour,
time.minute,
time.second,
time.millisecond,
time.microsecond,
time.nanosecond
);
} else {
return new PlainDateTime(this.year, this.month, this.day);
}
}
toPlainYearMonth(): PlainYearMonth {
return new PlainYearMonth(this.year, this.month);
}
toPlainMonthDay(): PlainMonthDay {
return new PlainMonthDay(this.month, this.day);
}
toZonedDateTime(tz: TimeZone, time: PlainTime | null = null): ZonedDateTime {
const dt = this.toPlainDateTime(time);
const offset = tz.getOffsetNanosecondsFor(new Instant(dt.epochNanoseconds));
return new ZonedDateTime(dt.epochNanoseconds - offset, tz);
}
static compare(a: PlainDate, b: PlainDate): i32 {

@@ -246,0 +287,0 @@ if (a === b) return 0;

@@ -6,4 +6,8 @@ import { RegExp } from "assemblyscript-regex";

import { PlainTime } from "./plaintime";
import { MICROS_PER_SECOND, MILLIS_PER_SECOND, NANOS_PER_SECOND } from "./constants";
import {
MICROS_PER_SECOND,
MILLIS_PER_SECOND,
NANOS_PER_SECOND,
} from "./constants";
import {
dayOfWeek,

@@ -23,2 +27,7 @@ dayOfYear,

import { PlainDate } from "./plaindate";
import { PlainYearMonth } from "./plainyearmonth";
import { PlainMonthDay } from "./plainmonthday";
import { TimeZone } from "./timezone";
import { Instant } from "./instant";
import { ZonedDateTime } from "./zoneddatetime";

@@ -42,9 +51,9 @@ export class DateTimeLike {

// @ts-ignore: cast
return this.fromString(<string>date);
return PlainDateTime.fromString(<string>date);
} else {
if (isReference<T>()) {
if (date instanceof PlainDateTime) {
return this.fromPlainDateTime(date);
return PlainDateTime.fromPlainDateTime(date);
} else if (date instanceof DateTimeLike) {
return this.fromDateTimeLike(date);
return PlainDateTime.fromDateTimeLike(date);
}

@@ -158,4 +167,13 @@ }

get epochNanoseconds(): i64 {
return epochFromParts(this.year, this.month, this.day, this.hour, this.minute,
this.second, this.millisecond, this.microsecond, this.nanosecond)
return epochFromParts(
this.year,
this.month,
this.day,
this.hour,
this.minute,
this.second,
this.millisecond,
this.microsecond,
this.nanosecond
);
}

@@ -191,12 +209,11 @@

toPaddedString(this.second) +
(this.nanosecond != 0 ||
this.microsecond != 0 ||
this.millisecond != 0
(this.nanosecond != 0 || this.microsecond != 0 || this.millisecond != 0
? (
f64(this.nanosecond) / NANOS_PER_SECOND +
f64(this.nanosecond) / NANOS_PER_SECOND +
f64(this.microsecond) / MICROS_PER_SECOND +
f64(this.millisecond) / MILLIS_PER_SECOND
).toString().substring(1)
: ""
)
)
.toString()
.substring(1)
: "")
);

@@ -217,9 +234,20 @@ }

toPlainDate(): PlainDate {
return new PlainDate(
this.year,
this.month,
this.day
return new PlainDate(this.year, this.month, this.day);
}
toZonedDateTime(tz: TimeZone): ZonedDateTime {
const offset = tz.getOffsetNanosecondsFor(
new Instant(this.epochNanoseconds)
);
return new ZonedDateTime(this.epochNanoseconds - offset, tz);
}
toPlainYearMonth(): PlainYearMonth {
return new PlainYearMonth(this.year, this.month);
}
toPlainMonthDay(): PlainMonthDay {
return new PlainMonthDay(this.month, this.day);
}
static compare(a: PlainDateTime, b: PlainDateTime): i32 {

@@ -265,8 +293,7 @@ if (a === b) return 0;

add<T = DurationLike>(durationToAdd: T, overflow: Overflow = Overflow.Constrain): PlainDateTime {
const duration =
durationToAdd instanceof DurationLike
? durationToAdd.toDuration()
// @ts-ignore TS2352
: durationToAdd as Duration;
add<T = DurationLike>(
durationToAdd: T,
overflow: Overflow = Overflow.Constrain
): PlainDateTime {
const duration = Duration.from(durationToAdd);

@@ -308,8 +335,7 @@ const newDate = addDateTime(

subtract<T = DurationLike>(durationToSubtract: T, overflow: Overflow = Overflow.Constrain): PlainDateTime {
const duration =
durationToSubtract instanceof DurationLike
? durationToSubtract.toDuration()
// @ts-ignore TS2352
: durationToSubtract as Duration;
subtract<T = DurationLike>(
durationToSubtract: T,
overflow: Overflow = Overflow.Constrain
): PlainDateTime {
const duration = Duration.from(durationToSubtract);

@@ -316,0 +342,0 @@ const newDate = addDateTime(

@@ -5,3 +5,3 @@ import { Duration, DurationLike } from "./duration";

import { PlainDateTime } from "./plaindatetime";
import { DateLike } from "./plaindate";
import { DateLike, PlainDate } from "./plaindate";
import {

@@ -19,2 +19,4 @@ sign,

} from "./utils";
import { TimeZone } from "./timezone";
import { ZonedDateTime } from "./zoneddatetime";

@@ -35,11 +37,11 @@ export class TimeLike {

// @ts-ignore: cast
return this.fromString(<string>time);
return PlainTime.fromString(<string>time);
} else {
if (isReference<T>()) {
if (time instanceof PlainTime) {
return this.fromPlainTime(time);
return PlainTime.fromPlainTime(time);
} else if (time instanceof TimeLike) {
return this.fromTimeLike(time);
return PlainTime.fromTimeLike(time);
} else if (time instanceof PlainDateTime) {
return this.fromPlainDateTime(time);
return PlainTime.fromPlainDateTime(time);
}

@@ -210,4 +212,8 @@ }

until(
other: PlainTime,
toZonedDateTime(tz: TimeZone, date: PlainDate): ZonedDateTime {
return date.toZonedDateTime(tz, this);
}
until<T = TimeLike>(
otherLike: T,
largestUnit: TimeComponent = TimeComponent.Hours

@@ -219,2 +225,4 @@ ): Duration {

const other = PlainTime.from(otherLike);
let diffTime = differenceTime(

@@ -247,4 +255,4 @@ this.hour,

since(
other: PlainTime,
since<T = TimeLike>(
otherLike: T,
largestUnit: TimeComponent = TimeComponent.Hours

@@ -256,2 +264,4 @@ ): Duration {

const other = PlainTime.from(otherLike);
let diffTime = differenceTime(

@@ -318,7 +328,3 @@ this.hour,

add<T = DurationLike>(durationToAdd: T): PlainTime {
const duration =
durationToAdd instanceof DurationLike
? durationToAdd.toDuration()
// @ts-ignore TS2352
: durationToAdd as Duration;
const duration = Duration.from(durationToAdd);

@@ -360,7 +366,3 @@ const newTime = addTime(

subtract<T = DurationLike>(durationToSubtract: T): PlainTime {
const duration =
durationToSubtract instanceof DurationLike
? durationToSubtract.toDuration()
// @ts-ignore TS2352
: durationToSubtract as Duration;
const duration = Duration.from(durationToSubtract);

@@ -367,0 +369,0 @@ const newTime = addTime(

@@ -30,9 +30,9 @@ import { RegExp } from "assemblyscript-regex";

// @ts-ignore: cast
return this.fromString(<string>yearMonth);
return PlainYearMonth.fromString(<string>yearMonth);
} else {
if (isReference<T>()) {
if (yearMonth instanceof PlainYearMonth) {
return this.fromPlainYearMonth(yearMonth);
return PlainYearMonth.fromPlainYearMonth(yearMonth);
} else if (yearMonth instanceof YearMonthLike) {
return this.fromYearMonthLike(yearMonth);
return PlainYearMonth.fromYearMonthLike(yearMonth);
}

@@ -148,6 +148,11 @@ }

until(yearMonth: PlainYearMonth, largestUnit: TimeComponent = TimeComponent.Years): Duration {
until<T = YearMonthLike>(
yearMonthLike: T,
largestUnit: TimeComponent = TimeComponent.Years
): Duration {
if (largestUnit > TimeComponent.Months)
throw new RangeError("lower units are not allowed");
const yearMonth = PlainYearMonth.from(yearMonthLike);
const thisDate = new PlainDate(this.year, this.month, this.referenceISODay);

@@ -163,6 +168,11 @@ const otherDate = new PlainDate(

since(yearMonth: PlainYearMonth, largestUnit: TimeComponent = TimeComponent.Years): Duration {
since<T = YearMonthLike>(
yearMonthLike: T,
largestUnit: TimeComponent = TimeComponent.Years
): Duration {
if (largestUnit > TimeComponent.Months)
throw new RangeError("lower units are not allowed");
const yearMonth = PlainYearMonth.from(yearMonthLike);
const thisDate = new PlainDate(this.year, this.month, this.referenceISODay);

@@ -186,8 +196,7 @@ const otherDate = new PlainDate(

add<T = DurationLike>(durationToAdd: T, overflow: Overflow = Overflow.Constrain): PlainYearMonth {
const duration =
durationToAdd instanceof DurationLike
? durationToAdd.toDuration()
// @ts-ignore TS2352
: durationToAdd as Duration;
add<T = DurationLike>(
durationToAdd: T,
overflow: Overflow = Overflow.Constrain
): PlainYearMonth {
const duration = Duration.from(durationToAdd);

@@ -218,8 +227,7 @@ const balancedDuration = balanceDuration(

subtract<T = DurationLike>(durationToAdd: T, overflow: Overflow = Overflow.Constrain): PlainYearMonth {
let duration =
durationToAdd instanceof DurationLike
? durationToAdd.toDuration()
// @ts-ignore TS2352
: durationToAdd as Duration;
subtract<T = DurationLike>(
durationToAdd: T,
overflow: Overflow = Overflow.Constrain
): PlainYearMonth {
let duration = Duration.from(durationToAdd);

@@ -226,0 +234,0 @@ duration = new Duration(

@@ -6,3 +6,3 @@ import { Instant } from "./instant";

balanceDateTime,
formatTimeZoneOffsetString
formatTimeZoneOffsetString,
} from "./utils";

@@ -15,2 +15,6 @@ import { offsetForTimezoneNanos, offsetForTimezone } from "./tz/index";

export class TimeZone {
static from(id: string): TimeZone {
return new TimeZone(id);
}
constructor(public id: string) {}

@@ -61,3 +65,6 @@

const epochNanos = dateTime.epochNanoseconds;
const earliest = offsetForTimezoneNanos(this.id, epochNanos - NANOS_PER_DAY);
const earliest = offsetForTimezoneNanos(
this.id,
epochNanos - NANOS_PER_DAY
);
const latest = offsetForTimezoneNanos(this.id, epochNanos + NANOS_PER_DAY);

@@ -64,0 +71,0 @@

@@ -172,13 +172,3 @@ import { RegExp } from "assemblyscript-regex";

// add<T = DurationLike>(durationToAdd: T, overflow: Overflow = Overflow.Constrain): ZonedDateTime {
// const duration =
// durationToAdd instanceof DurationLike
// ? durationToAdd.toDuration()
// // @ts-ignore TS2352
// : durationToAdd as Duration;
// }
}

@@ -67,6 +67,6 @@ ## Development and roadmap

- [ ] valueOf
- [ ] toZonedDateTime
- [ ] toPlainDateTime
- [ ] toPlainYearMonth
- [ ] toPlainMonthDay
- [x] toZonedDateTime
- [x] toPlainDateTime
- [x] toPlainYearMonth
- [x] toPlainMonthDay
- [ ] getISOFields

@@ -115,3 +115,3 @@

- [ ] valueOf
- [ ] toZonedDateTime
- [x] toZonedDateTime
- [x] toPlainDateTime

@@ -250,7 +250,7 @@ - [ ] getISOFields

- [ ] valueOf
- [ ] toZonedDateTime
- [x] toZonedDateTime
- [x] toPlainDate
- [x] toPlainTime
- [ ] toPlainYearMonth
- [ ] toPlainMonthDay
- [x] toPlainYearMonth
- [x] toPlainMonthDay
- [ ] getISOFields

@@ -271,3 +271,3 @@

- [ ] from
- [x] from
- [ ] compare

@@ -274,0 +274,0 @@

{
"name": "assemblyscript-temporal",
"version": "1.10.1",
"version": "1.11.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",

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