-
Notifications
You must be signed in to change notification settings - Fork 153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypedArray interface #964
Comments
Hi @alippai - There are two questions you're raising:
For (1), I'm not sure what thinking (if any) has been happening on that topic so I'll leave it to others. It's a good question. For (2), a core concept in Temporal is the idea of "exact time" (measured in nanoseconds since epoch) and "local time" which displays human-readable values we think of as calendar dates and clock time. Converting exact time to a number is easy, using the Temporal.Instant type: instant = Temporal.Instant.from('2020-01-01T00:00Z');
instant.getOffsetNanoseconds(); // this is a `bigint`
instant.getOffsetMilliseconds(); // this is a `number`
instant.toZonedDateTime('Europe/Budapest'); // coming soon
instant.toDateTime('Europe/Budapest'); Other than Your question about Temporal.Date is an interesting one. The problem is that Temporal.Date stores (at least) four values internally: calendar (usually |
@justingrant yes, it's indeed doable in userland. My idea was making a "fastpath" for the 80% of the use-cases both for:
I wasn't aware of the different calendars, but having a default serialization at least of the "default" types (so Temporal.Date with iso calendar as int32 or Temporal.DateTime without timezone as something derived from int64 as it's not part of JSON). Adding a recommendation to reduce the overhead of parsing/serializing could be a nice touch - for a single date it's not that important, but this is why I was asking about typed data. We don't have dataframe-like operations in JS, but there are use-cases where you want to keep a date array standard and compact, charting (x-axis) is one, often you pass thousands of values (coming from an API or generated in WASM). My end-to-end example would be:
Tldr; Highcharts, uPlot and others uses int timestamps for temporal data, this might be a use-case we want to support better |
We discussed this in the Oct. 8 meeting and have concluded that WASM code (or other code that requires a binary serialization of Temporal types) is not likely to have one binary serialization that we could prefer above all others. So, we will include an example of binary serialization in the cookbook, but we don't believe that there is one particular format that is used generally enough in interchange to be part of the API. A possible route to achieving that might be to try to get an "ISO 8601 binary format" standardized. |
(author of uPlot here) there's definitely a void that needs to be filled in frontend applications that must deal with nanosecond resolution timestamps. right now all the options are rather awkward BigNum math or slow and reliant on string parsing like https://github.com/jcgertig/nano-date. uPlot tries to minimize its use of Date objects in general and does a lot of the math externally on timestamps, only using Date for sanity-checking leap years, DST rollovers, etc. |
Cookbook example to be written after the freeze and before Stage 3 |
On further reflection this isn't a requirement for Stage 3. To be done later. |
Linking +1 related (and deferred) discussion: tc39/proposal-record-tuple#4 |
I read that discussion, but I don't quite understand how it relates to this? |
You are right that they might not be strongly connected. My understanding was having a stable binary representation and string / binary serialization might be a requirement for supporting Temporal in Records. This might be a wrong assumption. |
I asked around and it seems that this would not be a requirement. Temporal objects would be stored in a "Box" in a Record or Tuple, because although their state is immutable, the objects themselves aren't sealed or otherwise deeply immutable. |
@leeoniya thats hurtful it not that slow 🥲 |
Would adding a 32-bit date representation for Temporal.Date (eg. days since 1970-01-01 like Apache Arrow does) be in scope of this spec? Similarly 64-bit datetime for Temporal.DateTime could work.
Maybe this would help WASM interoperability too.
I know anybody can map the Date and DateTime to 32 and 64bit numbers resp., but adding the reference values would make sense. Adding a few extra methods to a Uint32Array/Float64Array subclass would make the developer experience better, too.
The text was updated successfully, but these errors were encountered: