(
dateString,
{ timezone, format } = {}
)
| 47 | // Take a date published string, and hopefully return a date out of |
| 48 | // it. Return none if we fail. |
| 49 | export 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 | } |
no test coverage detected
searching dependent graphs…