Skip to content

Commit

Permalink
Auto merge of #14086 - chajath:time-datetime-attribute, r=<try>
Browse files Browse the repository at this point in the history
[WIP] Add DateTime string attribute to Time

<!-- Please describe your changes on the following line: -->

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix part of #12967, content parsing will come as a separate PR.

<!-- Either: -->
- [X] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->

---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/14086)
<!-- Reviewable:end -->
  • Loading branch information
bors-servo committed Nov 16, 2016
2 parents afc60be + 735d104 commit 1025184
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
26 changes: 24 additions & 2 deletions components/script/dom/htmltimeelement.rs
Expand Up @@ -2,23 +2,27 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use dom::bindings::codegen::Bindings::ElementBinding::ElementBinding::ElementMethods;
use dom::bindings::codegen::Bindings::HTMLTimeElementBinding;
use dom::bindings::codegen::Bindings::HTMLTimeElementBinding::HTMLTimeElementMethods;
use dom::bindings::inheritance::Castable;
use dom::bindings::js::Root;
use dom::bindings::str::DOMString;
use dom::document::Document;
use dom::element::Element;
use dom::htmlelement::HTMLElement;
use dom::node::Node;
use html5ever_atoms::LocalName;

#[dom_struct]
pub struct HTMLTimeElement {
htmlelement: HTMLElement
htmlelement: HTMLElement,
}

impl HTMLTimeElement {
fn new_inherited(local_name: LocalName, prefix: Option<DOMString>, document: &Document) -> HTMLTimeElement {
HTMLTimeElement {
htmlelement: HTMLElement::new_inherited(local_name, prefix, document)
htmlelement: HTMLElement::new_inherited(local_name, prefix, document),
}
}

Expand All @@ -31,3 +35,21 @@ impl HTMLTimeElement {
HTMLTimeElementBinding::Wrap)
}
}

impl HTMLTimeElementMethods for HTMLTimeElement {
// https://html.spec.whatwg.org/multipage/#dom-time-datetime
fn DateTime(&self) -> DOMString {
let element = self.upcast::<Element>();
if element.has_attribute(&local_name!("datetime")) {
return element.get_string_attribute(&local_name!("datetime"))
} else {
match element.GetInnerHTML() {
Ok(x) => x,
_ => DOMString::new(),
}
}
}

// https://html.spec.whatwg.org/multipage/#dom-time-datetime
make_setter!(SetDateTime, "datetime");
}
2 changes: 1 addition & 1 deletion components/script/dom/webidls/HTMLTimeElement.webidl
Expand Up @@ -4,5 +4,5 @@

// https://html.spec.whatwg.org/multipage/#htmltimeelement
interface HTMLTimeElement : HTMLElement {
// attribute DOMString dateTime;
attribute DOMString dateTime;
};
Expand Up @@ -47,21 +47,23 @@
//dateTime
test(function () {
assert_equals( makeTime('2000-02-01T03:04:05Z','2001-02-01T03:04:05Z').dateTime, '2000-02-01T03:04:05Z' );
}, 'the datetime attribute should be reflected by the .dateTime property');
}, 'the datetime attribute should be reflected by the dateTime IDL property');
test(function () {
assert_equals( typeof makeTime().dateTime, 'string', 'typeof test' );
assert_equals( makeTime().dateTime, '', 'value test' );
}, 'the dateTime IDL property should default to an empty string');
test(function () {
assert_equals( makeTime(false,false,'2000-02-01T03:04:05Z').dateTime, '2000-02-01T03:04:05Z' );
}, 'the dateTime property should be read/write');
}, 'the dateTime IDL property should be read/write');
test(function () {
assert_equals( makeTime('go fish').dateTime, 'go fish' );
}, 'the datetime attribute should be reflected by the .dateTime property even if it is invalid');
test(function () {
assert_equals( makeTime(false,'2000-02-01T03:04:05Z').dateTime, '' );
}, 'the datetime attribute should not reflect the textContent');

assert_equals( makeTime(false,'2000-02-01T03:04:05Z', '2000-02-01').dateTime, '2000-02-01' );
}, 'the datetime content attribute should not reflect the textContent when datetime attribute is present.');
test(function () {
assert_equals( makeTime(false,'2000-02-01T03:04:05Z').dateTime, '2000-02-01T03:04:05Z' );
}, 'the datetime content attribute should reflect the textContent when datetime attribute is absent.');
</script>

</body>
Expand Down

0 comments on commit 1025184

Please sign in to comment.