MCPcopy Index your code
hub / github.com/postlight/parser / cleanDatePublished

Function cleanDatePublished

src/cleaners/date-published.js:49–69  ·  view source on GitHub ↗
(
  dateString,
  { timezone, format } = {}
)

Source from the content-addressed store, hash-verified

47// Take a date published string, and hopefully return a date out of
48// it. Return none if we fail.
49export default function cleanDatePublished(
50 dateString,
51 { timezone, format } = {}
52) {
53 // If string is in milliseconds or seconds, convert to int and return
54 if (MS_DATE_STRING.test(dateString)) {
55 return new Date(parseInt(dateString, 10)).toISOString();
56 }
57 if (SEC_DATE_STRING.test(dateString)) {
58 return new Date(parseInt(dateString, 10) * 1000).toISOString();
59 }
60
61 let date = createDate(dateString, timezone, format);
62
63 if (!date.isValid()) {
64 dateString = cleanDateString(dateString);
65 date = createDate(dateString, timezone, format);
66 }
67
68 return date.isValid() ? date.toISOString() : null;
69}

Callers 2

extractFunction · 0.90

Calls 2

createDateFunction · 0.85
cleanDateStringFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…