(
value: number | string | Date,
isUTC: boolean
)
| 368 | } |
| 369 | |
| 370 | export function getUnitFromValue( |
| 371 | value: number | string | Date, |
| 372 | isUTC: boolean |
| 373 | ): PrimaryTimeUnit { |
| 374 | const date = numberUtil.parseDate(value); |
| 375 | const M = (date as any)[monthGetterName(isUTC)]() + 1; |
| 376 | const d = (date as any)[dateGetterName(isUTC)](); |
| 377 | const h = (date as any)[hoursGetterName(isUTC)](); |
| 378 | const m = (date as any)[minutesGetterName(isUTC)](); |
| 379 | const s = (date as any)[secondsGetterName(isUTC)](); |
| 380 | const S = (date as any)[millisecondsGetterName(isUTC)](); |
| 381 | |
| 382 | const isSecond = S === 0; |
| 383 | const isMinute = isSecond && s === 0; |
| 384 | const isHour = isMinute && m === 0; |
| 385 | const isDay = isHour && h === 0; |
| 386 | const isMonth = isDay && d === 1; |
| 387 | const isYear = isMonth && M === 1; |
| 388 | |
| 389 | if (isYear) { |
| 390 | return 'year'; |
| 391 | } |
| 392 | else if (isMonth) { |
| 393 | return 'month'; |
| 394 | } |
| 395 | else if (isDay) { |
| 396 | return 'day'; |
| 397 | } |
| 398 | else if (isHour) { |
| 399 | return 'hour'; |
| 400 | } |
| 401 | else if (isMinute) { |
| 402 | return 'minute'; |
| 403 | } |
| 404 | else if (isSecond) { |
| 405 | return 'second'; |
| 406 | } |
| 407 | else { |
| 408 | return 'millisecond'; |
| 409 | } |
| 410 | } |
| 411 | |
| 412 | // export function getUnitValue( |
| 413 | // value: number | Date, |
no test coverage detected
searching dependent graphs…