* @param {TimeScale} scale * @param {*} input * @return {number}
(scale, input)
| 44 | * @return {number} |
| 45 | */ |
| 46 | function parse(scale, input) { |
| 47 | if (isNullOrUndef(input)) { |
| 48 | return null; |
| 49 | } |
| 50 | |
| 51 | const adapter = scale._adapter; |
| 52 | const {parser, round, isoWeekday} = scale._parseOpts; |
| 53 | let value = input; |
| 54 | |
| 55 | if (typeof parser === 'function') { |
| 56 | value = parser(value); |
| 57 | } |
| 58 | |
| 59 | // Only parse if it's not a timestamp already |
| 60 | if (!isFinite(value)) { |
| 61 | value = typeof parser === 'string' |
| 62 | ? adapter.parse(value, parser) |
| 63 | : adapter.parse(value); |
| 64 | } |
| 65 | |
| 66 | if (value === null) { |
| 67 | return null; |
| 68 | } |
| 69 | |
| 70 | if (round) { |
| 71 | value = round === 'week' && (isNumber(isoWeekday) || isoWeekday === true) |
| 72 | ? adapter.startOf(value, 'isoWeek', isoWeekday) |
| 73 | : adapter.startOf(value, round); |
| 74 | } |
| 75 | |
| 76 | return +value; |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Figures out what unit results in an appropriate number of auto-generated ticks |
no test coverage detected