# HG changeset patch # User Rik # Date 1642187324 28800 # Node ID c7a515aa767e00085a861ebd2b3230c97b27940a # Parent e9bfb92dab01b1cd5c86860bf58b5a3f07679e90 datevec.m: Tweaks to cset e9bfb92dab01 for performance and documentation (bug #47627) * datevec.m: Use strchr() rather than ismember() for 2.25X speedup. Change warning ID for bad date format specification to follow Octave conventions. Add BIST tests for new warning. * warning_ids.m: Document new "Octave:datevec:date-format-spec" warning. diff -r e9bfb92dab01 -r c7a515aa767e scripts/help/warning_ids.m --- a/scripts/help/warning_ids.m Fri Jan 14 18:27:06 2022 +0100 +++ b/scripts/help/warning_ids.m Fri Jan 14 11:08:44 2022 -0800 @@ -178,6 +178,13 @@ ## different file target than the programmer intended is being used. ## By default, the @code{Octave:data-file-in-path} warning is enabled. ## +## @item Octave:datevec:date-format-spec +## If the @code{Octave:datevec:date-format-spec} warning is enabled, a warning +## is printed if the date format specification contains questionable date or +## time specifiers. Typical bad patterns are using upper case date specifiers +## or lower case time specifiers. +## By default, the @code{Octave:datevec:date-format-spec} warning is enabled. +## ## @item Octave:deprecated-function ## If the @code{Octave:deprecated-function} warning is enabled, a ## warning is issued when Octave encounters a function that is obsolete and diff -r e9bfb92dab01 -r c7a515aa767e scripts/time/datevec.m --- a/scripts/time/datevec.m Fri Jan 14 18:27:06 2022 +0100 +++ b/scripts/time/datevec.m Fri Jan 14 11:08:44 2022 -0800 @@ -208,8 +208,8 @@ original_f = f; # Store for error messages. - if (any (ismember (f, "hsfYD"))) - warning ("Octave:date-format-spec:wrong-case", ... + if (any (strchr (f, "hsfYD", 1))) + warning ("Octave:datevec:date-format-spec", ... ["datevec: Format specifiers for dates should be lower case,", ... " format specifiers for time should be upper case. ", ... " Possible issue with 'm' (month) and 'M' (minutes)?"]); @@ -468,3 +468,8 @@ %!error datevec ("15:38:21.251", "HH:HH:SS") %!error datevec ("15:38:21.251", "MM:MM:SS") %!error datevec ("15:38:21.251", "HH:SS:SS") +%!fail ("datevec ('2015-03-31 0:00','YYYY-mm-DD HH:MM')", ... +%! "warning", "Format specifiers for dates should be lower case"); +%!fail ("datevec ('2015-03-31 0:00','yyyy-mm-dd hh:mm')", ... +%! "warning", "Format specifiers for time should be upper case"); +