Skip to content

Commit

Permalink
dhms et al. iterate
Browse files Browse the repository at this point in the history
  • Loading branch information
johnkerl committed Aug 30, 2015
1 parent 7977fc8 commit df48440
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions c/mapping/mlr_val.c
Original file line number Diff line number Diff line change
Expand Up @@ -451,16 +451,22 @@ mv_t f_s_hms2fsec_func(mv_t* pval1) {
long long h = 0LL, m = 0LL;
double s = 0.0;
double sec = 0.0;
if (sscanf(pval1->u.strv, "%lld:%lld:%lf", &h, &m, &s) == 3) {
char* p = pval1->u.strv;
long long sign = 1LL;
if (*p == '-') {
p++;
sign = -1LL;
}
if (sscanf(p, "%lld:%lld:%lf", &h, &m, &s) == 3) {
sec = 3600*h + 60*m + s;
} else if (sscanf(pval1->u.strv, "%lld:%lf", &m, &s) == 2) {
} else if (sscanf(p, "%lld:%lf", &m, &s) == 2) {
sec = 60*m + s;
} else if (sscanf(pval1->u.strv, "%lf", &s) == 2) {
} else if (sscanf(p, "%lf", &s) == 2) {
sec = s;
} else {
return MV_ERROR;
}
return (mv_t) {.type = MT_DOUBLE, .u.dblv = sec};
return (mv_t) {.type = MT_DOUBLE, .u.dblv = sec * sign};
}

mv_t i_s_dhms2sec_func(mv_t* pval1) {
Expand Down

0 comments on commit df48440

Please sign in to comment.