Browse Source

Date refactor (#1488)

* Handle high and negative values in `new Date()`

* Refactor `Date` setter methods

* Refactor some `Date` getter methods

* Adhere to spec in `Date.prototype[Symbol.toPrimitive]`
pull/1498/head
raskad 3 years ago committed by GitHub
parent
commit
eaaae85440
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1031
      boa/src/builtins/date/mod.rs
  2. 12
      boa/src/builtins/date/tests.rs

1031
boa/src/builtins/date/mod.rs

File diff suppressed because it is too large Load Diff

12
boa/src/builtins/date/tests.rs

@ -408,7 +408,7 @@ fn date_proto_get_timezone_offset() -> Result<(), Box<dyn std::error::Error>> {
let actual = forward_val(
&mut context,
"new Date('August 19, 1975 23:15:30 GMT+07:00').getTimezoneOffset() === new Date('August 19, 1975 23:15:30 GMT-02:00').getTimezoneOffset()",
"new Date('1975-08-19T23:15:30+07:00').getTimezoneOffset() === new Date('1975-08-19T23:15:30-02:00').getTimezoneOffset()",
);
// NB: Host Settings, not TZ specified in the DateTime.
@ -416,17 +416,17 @@ fn date_proto_get_timezone_offset() -> Result<(), Box<dyn std::error::Error>> {
let actual = forward_val(
&mut context,
"new Date('August 19, 1975 23:15:30 GMT+07:00').getTimezoneOffset()",
"new Date('1975-08-19T23:15:30+07:00').getTimezoneOffset()",
);
// The value of now().offset() depends on the host machine, so we have to replicate the method code here.
let offset_seconds = chrono::Local::now().offset().local_minus_utc() as f64;
let offset_minutes = offset_seconds / 60f64;
let offset_minutes = -offset_seconds / 60f64;
assert_eq!(Ok(JsValue::new(offset_minutes)), actual);
let actual = forward_val(
&mut context,
"new Date(1/0, 06, 08, 09, 16, 15, 779).getTimezoneOffset()",
"new Date('1975-08-19T23:15:30+07:00').getTimezoneOffset()",
);
assert_eq!(Ok(JsValue::new(offset_minutes)), actual);
Ok(())
@ -1282,7 +1282,7 @@ fn date_proto_to_string() -> Result<(), Box<dyn std::error::Error>> {
))
.earliest()
.unwrap()
.format("Wed Jul 08 2020 09:16:15 GMT%:z")
.format("Wed Jul 08 2020 09:16:15 GMT%z")
.to_string()
)),
actual
@ -1310,7 +1310,7 @@ fn date_proto_to_time_string() -> Result<(), Box<dyn std::error::Error>> {
))
.earliest()
.unwrap()
.format("09:16:15 GMT%:z")
.format("09:16:15 GMT%z")
.to_string()
)),
actual

Loading…
Cancel
Save