Added moment duration for intervals (issue acosom/ziit#11) - Commit 78c18ace - acosom/ziit/ziit-cli
| skipped 414 lines |
415 | 415 | | seconds = 0; |
416 | 416 | | |
417 | 417 | | pos = (char *)str; |
418 | | - | |
419 | | - | if (!isdigit(*pos)) { |
420 | | - | return -1; |
421 | | - | } |
| 418 | + | char moment[] = "moment"; |
422 | 419 | | |
423 | | - | while (isdigit(*pos)) { |
424 | | - | n = strtol(pos, &pos, 10); |
425 | | - | if (*pos == 'h' || *pos == 'H') { |
426 | | - | hours += n; |
427 | | - | } else if (*pos == 'm' || *pos == 'M') { |
428 | | - | minutes += n; |
429 | | - | } else if (*pos == 's' || *pos == 'S') { |
430 | | - | seconds += n; |
431 | | - | } else { |
| 420 | + | if (strncmp(str, moment, strlen(moment)) == 0) { |
| 421 | + | pos += strlen(moment); |
| 422 | + | *duration = 0; |
| 423 | + | } else { |
| 424 | + | if (!isdigit(*pos)) { |
432 | 425 | | return -1; |
433 | 426 | | } |
434 | | - | ++pos; |
| 427 | + | |
| 428 | + | while (isdigit(*pos)) { |
| 429 | + | n = strtol(pos, &pos, 10); |
| 430 | + | if (*pos == 'h' || *pos == 'H') { |
| 431 | + | hours += n; |
| 432 | + | } else if (*pos == 'm' || *pos == 'M') { |
| 433 | + | minutes += n; |
| 434 | + | } else if (*pos == 's' || *pos == 'S') { |
| 435 | + | seconds += n; |
| 436 | + | } else { |
| 437 | + | return -1; |
| 438 | + | } |
| 439 | + | ++pos; |
| 440 | + | } |
| 441 | + | |
| 442 | + | *duration = hours * 60 * 60 + minutes * 60 + seconds; |
435 | 443 | | } |
436 | | - | |
437 | | - | *duration = hours * 60 * 60 + minutes * 60 + seconds; |
438 | 444 | | |
439 | 445 | | if (*pos == '\0') { |
440 | 446 | | *ts = time(NULL) - *duration; |
| skipped 40 lines |
Page is in error, reload to recover