-
-
Notifications
You must be signed in to change notification settings - Fork 405
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
First portion of the Temporal implementation #3277
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
7330da9
Started with the Temporal implementation
Razican 4ebb098
Implemented some useful functions
Razican 37e509d
Updaating some spec references
Razican 4f3414b
Initial work on TimeZone and Instant
nekevss 16afd23
More work completed on Temporal.Duration and Temporal.Instant
nekevss e2e9883
General scaffolding and heavy work on Instant and Duration complete
nekevss 0da33f4
ZonedDateTime and Calendar started with further work on duration abst…
nekevss 69d957a
Further work on temporal work and clippy fixes
nekevss e4d2b8c
Post rebase fixes/reverts
nekevss 5e54f0d
Add BuiltinCalendar and begin IsoCalendar impl
nekevss 5de602f
More work completed on calendar/date/yearmonth/monthday
nekevss d71b896
Calendar and iso impl close to completion - no datelike parsing
nekevss 529687b
Initial work on temporal ISO8601 parsing and grammar
nekevss 8d497c4
Post rebase fixes and updates
nekevss 168c323
More on parser/Duration and work through clippy lints
nekevss 2fa4e10
Fix bug on peek_n and add temporal cfg
nekevss bfee590
Fix clippy lints on parser tests
nekevss d2568ed
Build out calendar with icu_calendar, add some tests, and misc.
nekevss 30f1372
Fix spec hyperlinks
jedel1043 b173fcd
Parser clean up and invalid annotations
nekevss 94cea39
Add Duration and Temporal Parsing
nekevss 1b39512
Remove IsoYearMonthRecord
nekevss 2e692ab
Post rebase update
nekevss aecf583
Fix and add to ISO Parser docs
nekevss 2762c03
Parser/ast cleanup and duration refactor/additions
nekevss b5a6e4e
Review feedback, options update, and duration changes
nekevss 6eb3b15
Review changes, general cleanup, and post rebase fixes
nekevss 9db8b47
Fix time zone parsing issue/test logic
nekevss b52631b
Clean up parse output nodes
nekevss dc311e6
Apply review feedback and various fixes
nekevss c127bb1
Review feedback and get_option changes
nekevss 26f6334
Review feedback
nekevss File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
//! AST nodes for Temporal's implementation of ISO8601 grammar. | ||
|
||
/// An ISO Date Node consisting of non-validated date fields and calendar value. | ||
#[derive(Default, Debug)] | ||
pub struct IsoDate { | ||
/// Date Year | ||
pub year: i32, | ||
/// Date Month | ||
pub month: i32, | ||
/// Date Day | ||
pub day: i32, | ||
/// The calendar value. | ||
pub calendar: Option<String>, | ||
} | ||
|
||
/// The `IsoTime` node consists of non-validated time fields. | ||
#[derive(Default, Debug, Clone, Copy)] | ||
pub struct IsoTime { | ||
/// An hour value between 0-23 | ||
pub hour: u8, | ||
/// A minute value between 0-59 | ||
pub minute: u8, | ||
/// A second value between 0-60 | ||
pub second: u8, | ||
/// A millisecond value between 0-999 | ||
pub millisecond: u16, | ||
/// A microsecond value between 0-999 | ||
pub microsecond: u16, | ||
/// A nanosecond value between 0-999 | ||
pub nanosecond: u16, | ||
} | ||
|
||
impl IsoTime { | ||
#[must_use] | ||
#[allow(clippy::cast_possible_truncation, clippy::cast_sign_loss)] | ||
/// A utility initialization function to create `ISOTime` from the `TimeSpec` components. | ||
pub fn from_components(hour: u8, minute: u8, second: u8, fraction: f64) -> Self { | ||
// Note: Precision on nanoseconds drifts, so opting for round over floor or ceil for now. | ||
// e.g. 0.329402834 becomes 329.402833.999 | ||
let millisecond = fraction * 1000.0; | ||
let micros = millisecond.rem_euclid(1.0) * 1000.0; | ||
let nanos = micros.rem_euclid(1.0) * 1000.0; | ||
|
||
Self { | ||
hour, | ||
minute, | ||
second, | ||
millisecond: millisecond.floor() as u16, | ||
microsecond: micros.floor() as u16, | ||
nanosecond: nanos.round() as u16, | ||
} | ||
} | ||
} | ||
|
||
/// The `IsoDateTime` node output by the ISO parser | ||
#[derive(Default, Debug)] | ||
pub struct IsoDateTime { | ||
/// The `ISODate` record | ||
pub date: IsoDate, | ||
/// The `ISOTime` record | ||
pub time: IsoTime, | ||
/// The `TimeZone` value for this `ISODateTime` | ||
pub tz: Option<TimeZone>, | ||
} | ||
|
||
/// `TimeZone` data | ||
#[derive(Default, Debug, Clone)] | ||
pub struct TimeZone { | ||
/// TimeZoneIANAName | ||
pub name: Option<String>, | ||
/// TimeZoneOffset | ||
pub offset: Option<UTCOffset>, | ||
} | ||
|
||
/// A full precision `UtcOffset` | ||
#[derive(Debug, Clone, Copy)] | ||
pub struct UTCOffset { | ||
/// The `+`/`-` sign of this `UtcOffset` | ||
pub sign: i8, | ||
/// The hour value of the `UtcOffset` | ||
pub hour: u8, | ||
/// The minute value of the `UtcOffset`. | ||
pub minute: u8, | ||
/// The second value of the `UtcOffset`. | ||
pub second: u8, | ||
/// Any sub second components of the `UTCOffset` | ||
pub fraction: f64, | ||
} | ||
|
||
/// An `IsoDuration` Node output by the ISO parser. | ||
#[derive(Debug, Default, Clone, Copy)] | ||
pub struct IsoDuration { | ||
/// Years value. | ||
pub years: i32, | ||
/// Months value. | ||
pub months: i32, | ||
/// Weeks value. | ||
pub weeks: i32, | ||
/// Days value. | ||
pub days: i32, | ||
/// Hours value. | ||
pub hours: i32, | ||
/// Minutes value. | ||
pub minutes: f64, | ||
/// Seconds value. | ||
pub seconds: f64, | ||
/// Milliseconds value. | ||
pub milliseconds: f64, | ||
/// Microseconds value. | ||
pub microseconds: f64, | ||
/// Nanoseconds value. | ||
pub nanoseconds: f64, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
//! [spec]: https://tc39.es/ecma262/#sec-date-objects | ||
//! [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date | ||
|
||
mod utils; | ||
pub(crate) mod utils; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why was the visibility of utils changed? Whats now using it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 14.8.1 |
||
use utils::{make_date, make_day, make_time, replace_params, time_clip, DateParameters}; | ||
|
||
#[cfg(test)] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In other cases, we have used more specific feature names (such as
intl
). Should we just name the featuretemporal
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We opted for this approach because
temporal
would be removed anyways when it reaches stage 4. Do other engines use a broadexperimental
flag for Temporal, or a specifictemporal
flag?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense... but going forward, we might want to have features specific to some JavaScript characteristics (maybe a feature per built-in, things like that), so it might not hurt to have a
temporal
feature, andexperimental
would just depend ontemporal
. Could make it easier to support other experimental features in the future.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense, since it allows users to reduce binary size if they need to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the feature flag update be included in this PR or a different PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be done separately :)