@@ -6,8 +6,8 @@ authors: boa-dev
6
6
7
7
This will be a series of posts primarily about implementing a new
8
8
JavaScript feature in Rust, specifically the new date/time builtin:
9
- Temporal. We'll go over general lessons and to discuss the library we've
10
- been working on .
9
+ Temporal. We'll be going over the general implementation of Temporal in
10
+ Boa as well as the crates supporting that implementation .
11
11
12
12
Why should you care? Well we are not only implementing it for
13
13
JavaScript, but Rust as well ... more on that in a bit.
@@ -54,19 +54,19 @@ few things became evident.
54
54
55
55
So after the prototype was merged, the prototype was pulled out of Boa's
56
56
internal builtins and externalized into its own crate,
57
- [ temporal_rs] [ temporal-rs-repo ] , which then first landed behind an
57
+ [ ` temporal_rs ` ] [ temporal-rs-repo ] , which then first landed behind an
58
58
experimental flag in Boa v0.18.
59
59
60
60
After over a year and a half of development, Boa now sits at about 90%
61
61
overall conformance for Temporal and growing with the entire
62
62
implementation backed by ` temporal_rs ` .
63
63
64
- For its part, ` temporal_rs ` is shaping out to be a proper Rust date/time
64
+ For its part, ` temporal_rs ` is shaping up to be a proper Rust date/time
65
65
library that can be used to implement temporal in a JavaScript engine or
66
66
for general usage purposes.
67
67
68
68
So let's take a look at Temporal: it's JavaScript API, it's Rust API in
69
- temporal_rs, and how temporal_rs supports implementing the
69
+ ` temporal_rs ` , and how ` temporal_rs ` supports implementing the
70
70
specification.
71
71
72
72
## Important core differences
@@ -82,7 +82,7 @@ is not ideal for implementing deep language specifications where an
82
82
object or string may need to be cloned. Furthermore, it's just not great
83
83
for an API in a typed language like Rust.
84
84
85
- To work around this, we use liberally ` FromStr ` and a ` FiniteF64 ` custom
85
+ To work around this, we routinely use ` FromStr ` and a ` FiniteF64 ` custom
86
86
primitive to handle casting and constraining, respectively, to adapt
87
87
values for use with a typed API.
88
88
@@ -105,7 +105,7 @@ let overflow: Option<ArithmeticOverflow> = get_option::<ArithmeticOverflow>(
105
105
)? ;
106
106
```
107
107
108
- This is the core glue between Boa and the temporal_rs API that we will
108
+ This is the core glue between Boa and the ` temporal_rs ` API that we will
109
109
be going over below.
110
110
111
111
## Implementing constructors
@@ -158,14 +158,14 @@ let plain_date = PlainDate::try_new(2025, 6, 9, Calendar::default())?;
158
158
```
159
159
160
160
We actually learn some interesting things immediately about the
161
- JavaScript API from looking at the temporal_rs API:
161
+ JavaScript API from looking at the ` temporal_rs ` API:
162
162
163
163
1 . Temporal.PlainDate constructor can throw.
164
164
2 . When the calendar is omitted, the default calendar is used (this will
165
165
default to the ` iso8601 ` calendar)
166
166
167
167
Of course, if you somewhat prefer the brevity of the JavaScript API and
168
- don't want to list the default Calendar, temporal_rs provides the
168
+ don't want to list the default Calendar, ` temporal_rs ` provides the
169
169
additional constructors ` new_iso ` and ` try_new_iso ` .
170
170
171
171
## Let's discuss Now
@@ -213,7 +213,7 @@ invoking the abstract operations: `SystemTimeZoneIdentifier` and
213
213
suspects ` SystemTime ` and ` iana-time-zone ` , merge it, and call it a day
214
214
on the implementation, right?
215
215
216
- Except the core purpose of temporal_rs is that it can be used in any
216
+ Except the core purpose of ` temporal_rs ` is that it can be used in any
217
217
engine implementation, accessing a system clock and system time zone are
218
218
not in scope and must be left up to the engine or runtime to provide
219
219
that functionality.
@@ -277,7 +277,7 @@ for you!
277
277
278
278
Simple, right?
279
279
280
- Well we're pleased to announce that temporal_rs won't be supporting
280
+ Well we're pleased to announce that ` temporal_rs ` won't be supporting
281
281
that! ... At least in one method.
282
282
283
283
Again, the goal of ` temporal_rs ` is to implement the specification to
@@ -320,9 +320,11 @@ exists for each of the components that can then be provided to that
320
320
components ` from_partial ` method.
321
321
322
322
With this, we have fully implemented support for the ` from ` method in
323
- ` temporal_rs `
323
+ ` temporal_rs ` :
324
324
325
325
``` rust
326
+ use core :: str :: FromStr ;
327
+ use temporal_rs :: {PlainDate , PlainDateTime , partial :: PartialDate };
326
328
let pdt = PlainDateTime :: try_new_iso (2025 , 1 , 1 )? ;
327
329
// We can use the `PlainDateTime` (`ZonedDateTime` / `PlainDate` are also options).
328
330
let pd_from_pdt = PlainDate :: from (pdt );
@@ -349,21 +351,31 @@ interesting and everyone totally 100% loves them. No, time zones aren't
349
351
in this post, because they are still being polished and deserve an
350
352
entire post of their own.
351
353
354
+ So stay tuned for our next post on implementing Temporal! The one where
355
+ we'll hopefully go over everyone's favorite subject, time zones; and
356
+ answer the question that some of you may have if you happen to take a
357
+ glance at ` temporal_rs ` 's docs or try out our ` no_std ` support: what in
358
+ the world is a provider API?
359
+
352
360
## Conclusion
353
361
354
362
In conclusion, we're implementing Temporal in Rust to support engine
355
363
implementors as well as to have the API available in native Rust in
356
364
general.
357
365
358
- Boa currently sit at a [ 90% conformance rate] [ boa-test262 ] for Temporal
359
- completely backed by temporal_rs v0.0.8, and we're aiming to be 100%
366
+ Boa currently sits at a [ 90% conformance rate] [ boa-test262 ] for Temporal
367
+ completely backed by ` temporal_rs ` v0.0.8, and we're aiming to be 100%
360
368
conformant before the end of the year.
361
369
362
370
If you're interested in trying Temporal using Boa, you can use it in
363
371
Boa's CLI or enable it in ` boa_engine ` with the ` experimental ` flag.
364
372
373
+ Outside of Boa's implementation, ` temporal_rs ` has implemented or
374
+ supports the implementation for a large portion of the Temporal's API in
375
+ native Rust.
376
+
365
377
If you're interested in trying out ` temporal_rs ` , feel free to add to
366
- your project with cargo :
378
+ your project with Cargo :
367
379
368
380
``` bash
369
381
cargo add temporal_rs
@@ -394,8 +406,8 @@ the API.
394
406
3 . Partial objects may need some adjustments to handle differences
395
407
between ` from_partial ` and ` with `
396
408
4 . Time zone provider's and the ` TimeZoneProvider ` trait are still
397
- largely unstable (although the APIs that use them are expected to be
398
- stable)
409
+ largely unstable. Although, the provider APIs that use them are
410
+ expected to be stable (spoilers! )
399
411
5 . Era and month code are still be discussed in the intl-era-month-code
400
412
proposal, so some calendars and calendar methods may have varying
401
413
levels of support.
0 commit comments