Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clock validate mode #10

Merged
merged 11 commits into from Jan 16, 2018
Merged

Clock validate mode #10

merged 11 commits into from Jan 16, 2018

Conversation

sebres
Copy link
Owner

@sebres sebres commented Dec 28, 2017

Clock validate feature (option -valid 1|0 for validity check) re-implemented for tclclockmod, see ticket 3475995 for previous tcl'ed variant.

Tenor

  • clock scan get an new option -validate 0|1 in order to control validity of the scanned date-time (for both methods: format-scan and free-scan). Example:
% clock scan "30 February 2018"
1519945200
% clock scan "30 February 2018" -valid 1
unable to convert input string: invalid day
  • additionally provided an opportunity to choice the default validity mode (general interpreter option via clock configure -validate 1);
  • completely re-implemented in C (many times faster as the tcl'ed variant, so the execution overhead by -valid on is almost to neglect);
  • backwards compatible to the original tcl-clock ensemble (currently -valid off used as default mode);
  • test-cases are extended in order to cover both valid-modes.

Summary

If valid mode used, the scans of "not valid" date-time (like in the tests clock-11.x) or similar like 30 February cause an error:

% clock configure -valid 1; #default validate is on for this interpreter

% clock scan 01010021970 -format %d%m%j%Y -gmt 1
unable to convert date-time string "01010021970": invalid julian day
% clock format [clock scan "2008-02-30"] -format "%Y-%m-%d"
unable to convert date-time string "2008-02-30": invalid day
% clock format [clock scan "24:62:80"] -format "%T"
unable to convert date-time string "24:62:80": invalid time

% clock configure -valid 0; # the same without validate...

% clock scan 01010021970 -format %d%m%j%Y -gmt 1
0
% clock format [clock scan "2008-02-30" -valid 0] -format "%Y-%m-%d"
2008-03-01
% clock format [clock scan "24:62:80" -valid 0] -format "%T"
23:59:59

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant