Skip to content

Commit

Permalink
Merge branch 'bug/123'
Browse files Browse the repository at this point in the history
* bug/123:
  minor, condense %s%N to DT_SPFL_N_EPOCHNS, fixes issue 123
  test, add regression case for issue 123
  • Loading branch information
hroptatyr committed Feb 22, 2021
2 parents 16e2f68 + 0144b15 commit a975812
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 3 deletions.
10 changes: 8 additions & 2 deletions lib/dt-core-strpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,8 @@ __strpdt_card(struct strpdt_s *d, const char *sp, struct dt_spec_s s, char **ep)
res = __strpt_card(&d->st, sp, s, ep);
goto out_direct;

case DT_SPFL_N_EPOCH: {
case DT_SPFL_N_EPOCH:
case DT_SPFL_N_EPOCHNS: {
/* read over @ */
const char *tp = sp;
tp += *tp == '@';
Expand All @@ -287,6 +288,10 @@ __strpdt_card(struct strpdt_s *d, const char *sp, struct dt_spec_s s, char **ep)
} else {
sp = tp;
}
if (s.spfl == DT_SPFL_N_EPOCHNS) {
d->st.ns = d->i % 1000000000;
d->i /= 1000000000;
}
break;
}

Expand Down Expand Up @@ -358,7 +363,8 @@ __strfdt_card(
res = __strft_card(buf, bsz, s, &d->st, that.t);
break;

case DT_SPFL_N_EPOCH: {
case DT_SPFL_N_EPOCH:
case DT_SPFL_N_EPOCHNS: {
/* convert to sexy */
int64_t sexy = dt_conv_to_sexy(that).sexy;
res = snprintf(buf, bsz, "%" PRIi64, sexy);
Expand Down
2 changes: 1 addition & 1 deletion lib/dt-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ dt_strpdt(const char *str, const char *fmt, char **ep)

if (spec.spfl == DT_SPFL_UNK) {
/* must be literal */
if (*fp_sav != *sp++) {
if (UNLIKELY(*fp_sav != *sp++)) {
goto fucked;
}
} else if (LIKELY(!spec.rom)) {
Expand Down
4 changes: 4 additions & 0 deletions lib/token.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ __tok_spec(const char *fp, const char **ep)
break;
case 's':
res.spfl = DT_SPFL_N_EPOCH;
if (fp[1U] == '%' && fp[2U] == 'N') {
res.spfl = DT_SPFL_N_EPOCHNS;
fp += 2U;
}
break;
case 'Z':
res.spfl = DT_SPFL_N_ZDIFF;
Expand Down
2 changes: 2 additions & 0 deletions lib/token.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ typedef enum {
/* date/time specs */
/* %s epoch spec, non-standard */
DT_SPFL_N_EPOCH,
/* %s%N epoch spec, non-standard */
DT_SPFL_N_EPOCHNS,
/* %Z zone difference */
DT_SPFL_N_ZDIFF,
DT_SPFL_N_DTLAST = DT_SPFL_N_ZDIFF,
Expand Down
1 change: 1 addition & 0 deletions test/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,7 @@ dt_tests += dtdiff.047.clit
dt_tests += dtdiff.048.clit
dt_tests += dtdiff.049.clit
dt_tests += dtdiff.050.clit
dt_tests += dtdiff.051.clit

dt_tests += dtround.001.clit
dt_tests += dtround.002.clit
Expand Down
7 changes: 7 additions & 0 deletions test/dtdiff.051.clit
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/clitoris ## -*- shell-script -*-

$ ddiff -i "%s%N" 1100000000000000000 1000000000000000000
-100000000s
$

## dtdiff.051.clit ends here

0 comments on commit a975812

Please sign in to comment.