MCPcopy Create free account
hub / github.com/postlight/parser / createDate

Function createDate

src/cleaners/date-published.js:28–45  ·  view source on GitHub ↗
(dateString, timezone, format)

Source from the content-addressed store, hash-verified

26}
27
28export function createDate(dateString, timezone, format) {
29 if (TIME_WITH_OFFSET_RE.test(dateString)) {
30 return moment(new Date(dateString));
31 }
32
33 if (TIME_AGO_STRING.test(dateString)) {
34 const fragments = TIME_AGO_STRING.exec(dateString);
35 return moment().subtract(fragments[1], fragments[2]);
36 }
37
38 if (TIME_NOW_STRING.test(dateString)) {
39 return moment();
40 }
41
42 return timezone
43 ? moment.tz(dateString, format || parseFormat(dateString), timezone)
44 : moment(dateString, format || parseFormat(dateString));
45}
46
47// Take a date published string, and hopefully return a date out of
48// it. Return none if we fail.

Callers 1

cleanDatePublishedFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected