Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
assemblyscript-temporal
Advanced tools
An implementation of temporal within AssemblyScript, with an initial focus on non-timezone-aware classes and functionality.
An implementation of temporal within AssemblyScript, with an initial focus on non-timezone-aware classes and functionality.
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 that adds greatly improved date support to JS. The goal of this project is to implement Temporal for AssemblyScript.
This library currently supports the following types:
PlainDateTime
A PlainDateTime
represents a calendar date and wall-clock time that does not carry time zone information, e.g. December 7th, 1995 at 3:00 PM (in the Gregorian calendar). For detailed documentation see the TC39 Temporal proposal website, this implementation follows the specification as closely as possible.
You can create a PlainDateTime
from individual components, a string or an object literal:
datetime = new PlainDateTime(1976, 11, 18, 15, 23, 30, 123, 456, 789);
datetime.year; // 2019;
datetime.month; // 11;
// ...
datetime.nanosecond; // 789;
datetime = PlainDateTime.fromString("1976-11-18T12:34:56");
datetime.toString(); // "1976-11-18T12:34:56"
datetime = PlainDateTime.from({ year: 1966, month: 3, day: 3 });
datetime.toString(); // "1966-03-03T00:00:00"
There are various ways you can manipulate a date:
// use 'with' to copy a date but with various property values overriden
datetime = new PlainDateTime(1976, 11, 18, 15, 23, 30, 123, 456, 789);
datetime.with({ year: 2019 }).toString(); // "2019-11-18T15:23:30.123456789"
// use 'add' or 'substract' to add / subtract a duration
datetime = PlainDateTime.from("2020-01-12T15:00");
datetime.add({ months: 1 }).toString(); // "2020-02-12T15:00:00");
// add / subtract support Duration objects or object literals
datetime.add(new Duration(1)).toString(); // "2021-01-12T15:00:00");
You can compare dates and check for equality
dt1 = PlainDateTime.fromString("1976-11-18");
dt2 = PlainDateTime.fromString("2019-10-29");
PlainDateTime.compare(dt1, dt1); // 0
PlainDateTime.compare(dt1, dt2); // -1
dt1.equals(dt1); // true
Currently PlainDateTime
only supports the ISO 8601 (Gregorian) calendar.
PlainDate
A PlainDate
object represents a calendar date that is not associated with a particular time or time zone, e.g. August 24th, 2006. For detailed documentation see the TC39 Temporal proposal website, this implementation follows the specification as closely as possible.
The PlainDate
API is almost identical to PlainDateTime
, so see above for API usage examples.
now
The now
object has several methods which give information about the current time and date.
dateTime = now.plainDateTimeISO();
dateTime.toString(); // 2021-04-01T12:05:47.357
This project is open source, MIT licenced and your contributions are very much welcomed.
FAQs
An implementation of temporal within AssemblyScript, with an initial focus on non-timezone-aware classes and functionality.
The npm package assemblyscript-temporal receives a total of 56 weekly downloads. As such, assemblyscript-temporal popularity was classified as not popular.
We found that assemblyscript-temporal demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.