unsigned long long crm_get_interval(const char * input) { ha_time_t *interval = NULL; char *input_copy = crm_strdup(input); char *input_copy_mutable = input_copy; unsigned long long msec = 0; if(input == NULL) { return 0; } else if(input[0] != 'P') { crm_free(input_copy); return crm_get_msec(input); } interval = parse_time_duration(&input_copy_mutable); msec = date_in_seconds(interval); free_ha_date(interval); crm_free(input_copy); return msec * 1000; }
int main(int argc, char **argv) { int argerr = 0; int flag; int index = 0; int print_options = 0; char *input_s = NULL; char *mutable_s = NULL; crm_log_cli_init("iso8601"); crm_set_options(NULL, "command [output modifier] ", long_options, "Display and parse ISO8601 dates and times"); if (argc < 2) { argerr++; } while (1) { flag = crm_get_option(argc, argv, &index); if (flag == -1) break; switch (flag) { case 'V': crm_bump_log_level(); break; case '?': case '$': crm_help(flag, 0); break; case 'n': command = flag; break; case 'd': case 'p': case 'D': command = flag; input_s = strdup(optarg); break; case 'W': print_options |= ha_date_weeks; break; case 'O': print_options |= ha_date_ordinal; break; case 'L': print_options |= ha_log_local; break; } } if (input_s == NULL && command != 'n') { crm_help('?', 1); } mutable_s = input_s; if (command == 'd') { ha_time_t *date_time = parse_date(&mutable_s); if (date_time == NULL) { fprintf(stderr, "Invalid date/time specified: %s\n", input_s); crm_help('?', 1); } log_date(-1, "parsed", date_time, print_options | ha_log_date | ha_log_time); } else if (command == 'p') { ha_time_period_t *interval = parse_time_period(&mutable_s); if (interval == NULL) { fprintf(stderr, "Invalid interval specified: %s\n", input_s); crm_help('?', 1); } log_time_period(-1, interval, print_options | ha_log_date | ha_log_time); } else if (command == 'D') { ha_time_t *duration = parse_time_duration(&mutable_s); if (duration == NULL) { fprintf(stderr, "Invalid duration specified: %s\n", input_s); crm_help('?', 1); } log_date(-1, "Duration", duration, print_options | ha_log_date | ha_log_time | ha_log_local); } else if (command == 'n') { ha_time_t *now = new_ha_date(TRUE); if (now == NULL) { fprintf(stderr, "Internal error: couldnt determin 'now' !\n"); crm_help('?', 1); } log_date(-1, "Current date/time", now, print_options | ha_log_date | ha_log_time); } return 0; }