(dateString, timezone, format)
| 26 | } |
| 27 | |
| 28 | export 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. |
no outgoing calls
no test coverage detected