* Parse epoch from list of possible element attributes, returning the first one * that is truthy. * @param {Element} element * @param {Array } dateAttrs list of attribute names * @return {?TimestampDef}
(element, dateAttrs)
| 46 | * @return {?TimestampDef} |
| 47 | */ |
| 48 | function parseEpoch(element, dateAttrs) { |
| 49 | // Validate provided dateAttrs outside the loop so it will fail when an |
| 50 | // invalid attr is provided, even if that attribute isn't present on the |
| 51 | // element. |
| 52 | /** @type {Array<DateParserDef>} */ |
| 53 | const parsers = dateAttrs.map((attrName) => { |
| 54 | devAssert( |
| 55 | dateAttrParsers[attrName], |
| 56 | 'Invalid date attribute "%s"', |
| 57 | attrName |
| 58 | ); |
| 59 | return dateAttrParsers[attrName]; |
| 60 | }); |
| 61 | |
| 62 | for (let i = 0; i < dateAttrs.length; ++i) { |
| 63 | const attrVal = element.getAttribute(dateAttrs[i]); |
| 64 | if (attrVal) { |
| 65 | return parsers[i](attrVal); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | return null; |
| 70 | } |
no test coverage detected