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.12.0 to 2.0.0

24

assembly/__tests__/plaindate.spec.ts
import { PlainDate } from "..";
import { Duration, DurationLike } from "../duration";
import { TimeComponent, Overflow } from "../enums";
import { PlainTime } from "../plaintime";
import { DateLike } from "../plaindate";
import { PlainDateTime } from "../plaindatetime";
import { PlainTime } from "../plaintime";
import { TimeZone } from "../timezone";

@@ -116,22 +114,2 @@ let date: PlainDate;

describe("Date.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 = 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]"
);
});
});
let feb20: PlainDate,

@@ -138,0 +116,0 @@ feb21: PlainDate,

import { Duration, DurationLike } from "../duration";
import { TimeComponent } from "../enums";
import { PlainDate } from "../plaindate";
import { PlainDateTime } from "../plaindatetime";
import { PlainTime, TimeLike } from "../plaintime";
import { TimeZone } from "../timezone";

@@ -206,14 +204,2 @@ 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", () => {

@@ -220,0 +206,0 @@ time = PlainTime.from("11:30:23.123456789");

@@ -9,3 +9,1 @@ import "./env";

export * from "./now";
export * from "./timezone";
export * from "./zoneddatetime";

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

import { Overflow, TimeComponent } from "./enums";
import { Instant } from "./instant";
import { PlainDateTime } from "./plaindatetime";

@@ -11,3 +10,2 @@ import { PlainMonthDay } from "./plainmonthday";

import { PlainYearMonth } from "./plainyearmonth";
import { TimeZone } from "./timezone";
import {

@@ -30,3 +28,2 @@ addDate,

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

@@ -148,2 +145,3 @@ export class DateLike {

// @ts-ignore
until<T = DateLike>(

@@ -275,8 +273,2 @@ dateLike: T,

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 {

@@ -283,0 +275,0 @@ if (a === b) return 0;

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

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

@@ -300,9 +297,2 @@ // @ts-ignore

toZonedDateTime(tz: TimeZone): ZonedDateTime {
const offset = tz.getOffsetNanosecondsFor(
new Instant(this.epochNanoseconds)
);
return new ZonedDateTime(this.epochNanoseconds - offset, tz);
}
toPlainYearMonth(): PlainYearMonth {

@@ -309,0 +299,0 @@ return new PlainYearMonth(this.year, this.month);

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

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

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

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

@@ -211,6 +209,2 @@ export class TimeLike {

toZonedDateTime(tz: TimeZone, date: PlainDate): ZonedDateTime {
return date.toZonedDateTime(tz, this);
}
until<T = TimeLike>(

@@ -217,0 +211,0 @@ otherLike: T,

@@ -15,5 +15,2 @@ // for the proposal-temporal implementation, most of the business logic

import { JsDate } from "./date";
import { TimeZone } from "./timezone";
import { Instant } from "./instant";
import { PlainDate } from "./plaindate";
import { PlainDateTime } from "./plaindatetime";

@@ -20,0 +17,0 @@

@@ -10,3 +10,3 @@ ## Development and roadmap

So far much of (1) has been implemented. Also a 'spike' implementation of (3) has been added to determine a suitable approach for implementing timezone offsets.
So far much of (1 & 2) have been implemented. Also a 'spike' implementation of (3) has been created to determine a suitable approach for implementing timezone offsets.

@@ -68,3 +68,3 @@

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

@@ -116,3 +116,3 @@ - [x] toPlainYearMonth

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

@@ -251,3 +251,3 @@ - [ ] getISOFields

- [ ] valueOf
- [x] toZonedDateTime
- [ ] toZonedDateTime
- [x] toPlainDate

@@ -308,67 +308,2 @@ - [x] toPlainTime

#### ZonedDateTime
Constructor
- [x] new Temporal.ZonedDateTime
Static methods
- [ ] from
- [ ] compare
Properties
- [x] year
- [x] month
- [x] day
- [x] hour
- [x] minute
- [x] second
- [x] millisecond
- [x] microsecond
- [x] nanosecond
- [x] epochSeconds
- [x] epochMilliseconds
- [x] epochMicroseconds
- [x] epochNanoseconds
- [ ] calendar
- [x] timeZone
- [ ] era
- [ ] eraYear
- [x] dayOfWeek
- [x] dayOfYear
- [x] weekOfYear
- [x] daysInWeek
- [x] daysInMonth
- [x] daysInYear
- [x] monthsInYear
- [x] inLeapYear
- [x] hoursInDay
- [ ] startOfDay
- [x] offsetNanoseconds
- [x] offset
Methods
- [ ] with
- [ ] withPlainTime
- [ ] withPlainDate
- [ ] withTimeZone
- [ ] withCalendar
- [ ] add
- [ ] subtract
- [ ] until
- [ ] since
- [ ] round
- [ ] equals
- [ ] toString
- [ ] toLocaleString
- [ ] toJSON
- [ ] valueOf
- [ ] toInstant
- [ ] toPlainDate
- [ ] toPlainTime
- [ ] toPlainDateTime
- [ ] toPlainYearMonth
- [ ] toPlainMonthDay
- [ ] getISOFields
#### Instant

@@ -405,24 +340,2 @@

- [ ] toJSON
- [ ] valueOf
#### TimeZone
Constructor
- [x] new Temporal.TimeZone
Static methods
- [ ] from
Properties
- [x] id
Methods
- [x] getOffsetNanosecondsFor
- [x] getOffsetStringFor
- [x] getPlainDateTimeFor
- [ ] getInstantFor
- [x] getPossibleInstantsFor
- [ ] getNextTransition
- [ ] getPreviousTransition
- [ ] toString
- [ ] toJSON
- [ ] valueOf

2

package.json
{
"name": "assemblyscript-temporal",
"version": "1.12.0",
"version": "2.0.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",

## assemblyscript-temporal
An implementation of temporal within AssemblyScript, with an initial focus on non-timezone-aware classes and functionality.
An implementation of [TC39 Temporal}(https://github.com/tc39/proposal-temporal) for AssemblyScript, with an focus on non-timezone-aware classes and functionality.
### Why?
AssemblyScript has minimal `Date` support, however, the JS Date API itself is terrible and people tend not to use it that often. As a result libraries like moment / luxon have become staple replacements. However, there is now a [relatively mature TC39 proposal](https://github.com/tc39/proposal-temporal) that adds greatly improved date support to JS. The goal of this project is to implement Temporal for AssemblyScript.
AssemblyScript has minimal `Date` support, however, the JS Date API itself is terrible and people tend not to use it that often. As a result libraries like moment / luxon have become staple replacements. However, there is now a [relatively mature TC39 proposal](https://github.com/tc39/proposal-temporal) that adds greatly improved date support to JS.

@@ -96,2 +96,18 @@ ### Usage

#### `Duration`
A `Duration` represents a duration of time which can be used in date/time arithmetic. For detailed documentation see the
[TC39 Temporal proposal website](https://tc39.es/proposal-temporal/docs/duration.html)
Here's a small example, showing just some of wha you can do with durations:
```javascript
// create a duration
const duration = Duration.from({ days: 1, minutes: 5 });
// add another duration to the first one
const duration2 = duration.add({ days: 2, minutes: 5 })};
duration2.toString(); // "P3DT10M"
```
#### `now`

@@ -98,0 +114,0 @@

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