| 590 | } |
| 591 | |
| 592 | int av_parse_time(int64_t *timeval, const char *timestr, int duration) |
| 593 | { |
| 594 | const char *p, *q; |
| 595 | int64_t t, now64; |
| 596 | time_t now; |
| 597 | struct tm dt = { 0 }, tmbuf; |
| 598 | int today = 0, negative = 0, microseconds = 0, suffix = 1000000; |
| 599 | int i; |
| 600 | static const char * const date_fmt[] = { |
| 601 | "%Y - %m - %d", |
| 602 | "%Y%m%d", |
| 603 | }; |
| 604 | static const char * const time_fmt[] = { |
| 605 | "%H:%M:%S", |
| 606 | "%H%M%S", |
| 607 | }; |
| 608 | static const char * const tz_fmt[] = { |
| 609 | "%H:%M", |
| 610 | "%H%M", |
| 611 | "%H", |
| 612 | }; |
| 613 | |
| 614 | p = timestr; |
| 615 | q = NULL; |
| 616 | *timeval = INT64_MIN; |
| 617 | if (!duration) { |
| 618 | now64 = av_gettime(); |
| 619 | now = now64 / 1000000; |
| 620 | |
| 621 | if (!av_strcasecmp(timestr, "now")) { |
| 622 | *timeval = now64; |
| 623 | return 0; |
| 624 | } |
| 625 | |
| 626 | /* parse the year-month-day part */ |
| 627 | for (i = 0; i < FF_ARRAY_ELEMS(date_fmt); i++) { |
| 628 | q = av_small_strptime(p, date_fmt[i], &dt); |
| 629 | if (q) |
| 630 | break; |
| 631 | } |
| 632 | |
| 633 | /* if the year-month-day part is missing, then take the |
| 634 | * current year-month-day time */ |
| 635 | if (!q) { |
| 636 | today = 1; |
| 637 | q = p; |
| 638 | } |
| 639 | p = q; |
| 640 | |
| 641 | if (*p == 'T' || *p == 't') |
| 642 | p++; |
| 643 | else |
| 644 | while (av_isspace(*p)) |
| 645 | p++; |
| 646 | |
| 647 | /* parse the hour-minute-second part */ |
| 648 | for (i = 0; i < FF_ARRAY_ELEMS(time_fmt); i++) { |
| 649 | q = av_small_strptime(p, time_fmt[i], &dt); |