assemblyscript-temporal
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -5,8 +5,4 @@ // TODO: This functionality will likely be moved into the AssemblyScript Standard Library | ||
import { YMD } from "./utils"; | ||
import { MILLIS_PER_DAY, MILLIS_PER_HOUR, MILLIS_PER_MINUTE, MILLIS_PER_SECOND } from "./constants"; | ||
const MILLIS_PER_DAY = 1_000 * 60 * 60 * 24; | ||
const MILLIS_PER_HOUR = 1_000 * 60 * 60; | ||
const MILLIS_PER_MINUTE = 1_000 * 60; | ||
const MILLIS_PER_SECOND = 1_000; | ||
export class Date { | ||
@@ -13,0 +9,0 @@ epochMilliseconds: i64; |
import { durationSign } from "./utils"; | ||
import { MICROS_PER_SECOND, MILLIS_PER_SECOND, NANOS_PER_SECOND } from "./constants"; | ||
@@ -73,5 +74,5 @@ export class DurationLike { | ||
// sort in ascending order for better sum precision | ||
f64(this.nanoseconds) / 1000000000.0 + | ||
f64(this.microseconds) / 1000000.0 + | ||
f64(this.milliseconds) / 1000.0 + | ||
f64(this.nanoseconds) / NANOS_PER_SECOND + | ||
f64(this.microseconds) / MICROS_PER_SECOND + | ||
f64(this.milliseconds) / MILLIS_PER_SECOND + | ||
f64(this.seconds), | ||
@@ -78,0 +79,0 @@ "S" |
@@ -5,2 +5,3 @@ import { RegExp } from "../node_modules/assemblyscript-regex/assembly/index"; | ||
import { Overflow, TimeComponent } from "./enums"; | ||
import { MICROS_PER_SECOND, MILLIS_PER_SECOND, NANOS_PER_SECOND } from "./constants"; | ||
import { | ||
@@ -187,5 +188,5 @@ dayOfWeek, | ||
? ( | ||
f64(this.nanosecond) / 1_000_000_000.0 + | ||
f64(this.microsecond) / 1_000_000.0 + | ||
f64(this.millisecond) / 1_000.0 | ||
f64(this.nanosecond) / NANOS_PER_SECOND + | ||
f64(this.microsecond) / MICROS_PER_SECOND + | ||
f64(this.millisecond) / MILLIS_PER_SECOND | ||
).toString().substring(1) | ||
@@ -238,3 +239,3 @@ : "" | ||
add<T = DurationLike>(durationToAdd: T): PlainDateTime { | ||
add<T = DurationLike>(durationToAdd: T, overflow: Overflow = Overflow.Constrain): PlainDateTime { | ||
const duration = | ||
@@ -266,3 +267,3 @@ durationToAdd instanceof DurationLike | ||
duration.nanoseconds, | ||
Overflow.Constrain | ||
overflow | ||
); | ||
@@ -282,3 +283,3 @@ return new PlainDateTime( | ||
subtract<T = DurationLike>(durationToSubtract: T): PlainDateTime { | ||
subtract<T = DurationLike>(durationToSubtract: T, overflow: Overflow = Overflow.Constrain): PlainDateTime { | ||
const duration = | ||
@@ -310,3 +311,3 @@ durationToSubtract instanceof DurationLike | ||
-duration.nanoseconds, | ||
Overflow.Constrain | ||
overflow | ||
); | ||
@@ -313,0 +314,0 @@ return new PlainDateTime( |
@@ -11,2 +11,3 @@ // for the proposal-temporal implementation, most of the business logic | ||
import { Overflow, TimeComponent } from "./enums"; | ||
import { MILLIS_PER_SECOND, NANOS_PER_SECOND } from "./constants"; | ||
import { log } from "./env"; | ||
@@ -363,3 +364,3 @@ | ||
seconds += minutes * 60; | ||
milliseconds += seconds * 1000; | ||
milliseconds += seconds * MILLIS_PER_SECOND; | ||
microseconds += milliseconds * 1000; | ||
@@ -370,3 +371,3 @@ return nanoseconds + microseconds * 1000; | ||
function nanosecondsToDays(ns: i64): NanoDays { | ||
const oneDayNs: i64 = 24 * 60 * 60 * 1_000_000_000; | ||
const oneDayNs: i64 = 24 * 60 * 60 * NANOS_PER_SECOND; | ||
return ns == 0 | ||
@@ -432,3 +433,3 @@ ? { days: 0, nanoseconds: 0, dayLengthNs: oneDayNs } | ||
seconds = milliseconds / 1000; | ||
seconds = milliseconds / MILLIS_PER_SECOND; | ||
milliseconds = milliseconds % 1000; | ||
@@ -450,3 +451,3 @@ | ||
seconds = milliseconds / 1000; | ||
seconds = milliseconds / MILLIS_PER_SECOND; | ||
milliseconds = milliseconds % 1000; | ||
@@ -465,3 +466,3 @@ | ||
seconds = milliseconds / 1000; | ||
seconds = milliseconds / MILLIS_PER_SECOND; | ||
milliseconds = milliseconds % 1000; | ||
@@ -468,0 +469,0 @@ break; |
@@ -65,3 +65,3 @@ ### Implementation approach | ||
- [ ] overflow modes (current implementation defaults to constrain) | ||
- [x] overflow modes (current implementation defaults to constrain) | ||
- [ ] non ISO 8601 calendars | ||
@@ -127,3 +127,3 @@ | ||
- [ ] overflow modes (current implementation defaults to constrain) | ||
- [x] overflow modes (current implementation defaults to constrain) | ||
- [ ] non ISO 8601 calendars | ||
@@ -130,0 +130,0 @@ |
{ | ||
"name": "assemblyscript-temporal", | ||
"version": "1.1.0", | ||
"version": "1.2.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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
201175
26
4679