Skip to content

Commit

Permalink
feat: add dateTime property of HTMLTimeElement (#272)
Browse files Browse the repository at this point in the history
  • Loading branch information
TechQuery authored Jun 26, 2024
1 parent 7a9720d commit b07b109
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 2 deletions.
14 changes: 13 additions & 1 deletion cjs/html/time-element.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
'use strict';
const {stringAttribute} = require('../shared/attributes.js');
const {registerHTMLClass} = require('../shared/register-html-class.js');

const {HTMLElement} = require('./element.js');

/**
Expand All @@ -8,5 +11,14 @@ class HTMLTimeElement extends HTMLElement {
constructor(ownerDocument, localName = 'time') {
super(ownerDocument, localName);
}

/**
* @type {string}
*/
get dateTime() { return stringAttribute.get(this, 'datetime'); }
set dateTime(value) { stringAttribute.set(this, 'datetime', value); }
}
exports.HTMLTimeElement = HTMLTimeElement

registerHTMLClass('time', HTMLTimeElement)

exports.HTMLTimeElement = HTMLTimeElement;
15 changes: 14 additions & 1 deletion esm/html/time-element.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
import {stringAttribute} from '../shared/attributes.js';
import {registerHTMLClass} from '../shared/register-html-class.js';

import {HTMLElement} from './element.js';

/**
* @implements globalThis.HTMLTimeElement
*/
export class HTMLTimeElement extends HTMLElement {
class HTMLTimeElement extends HTMLElement {
constructor(ownerDocument, localName = 'time') {
super(ownerDocument, localName);
}

/**
* @type {string}
*/
get dateTime() { return stringAttribute.get(this, 'datetime'); }
set dateTime(value) { stringAttribute.set(this, 'datetime', value); }
}

registerHTMLClass('time', HTMLTimeElement)

export {HTMLTimeElement};
13 changes: 13 additions & 0 deletions test/html/time-element.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const assert = require('../assert.js').for('HTMLTImeElement');

const {parseHTML} = global[Symbol.for('linkedom')];

const {document} = parseHTML('<time datetime="1989-06-03 16:00:00">A big event</time>');

const {lastElementChild: time} = document;

assert(time.dateTime, '1989-06-03 16:00:00');
time.setAttribute('datetime', '1989-06-04 00:00:00');
assert(time.dateTime, '1989-06-04 00:00:00');
time.dateTime = '2022-11-26 16:00:00';
assert(time.getAttribute('datetime'), '2022-11-26 16:00:00');
5 changes: 5 additions & 0 deletions types/esm/html/time-element.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,10 @@
* @implements globalThis.HTMLTimeElement
*/
export class HTMLTimeElement extends HTMLElement implements globalThis.HTMLTimeElement {
set dateTime(value: string);
/**
* @type {string}
*/
get dateTime(): string;
}
import { HTMLElement } from './element.js';
8 changes: 8 additions & 0 deletions worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -10848,8 +10848,16 @@ class HTMLTimeElement extends HTMLElement {
constructor(ownerDocument, localName = 'time') {
super(ownerDocument, localName);
}

/**
* @type {string}
*/
get dateTime() { return stringAttribute.get(this, 'datetime'); }
set dateTime(value) { stringAttribute.set(this, 'datetime', value); }
}

registerHTMLClass('time', HTMLTimeElement);

/**
* @implements globalThis.HTMLFieldSetElement
*/
Expand Down

0 comments on commit b07b109

Please sign in to comment.