@@ -576,7 +576,7 @@ const ensureArray = (it, force_array) => {
576576
577577const localized_isodate = ( date ) => {
578578 // Return a iso date (date only) in the current timezone instead of a
579- // UTC ISO 8602 date+time component which toISOString returns.
579+ // UTC ISO 8601 date+time component which toISOString returns.
580580
581581 const day = date . getDate ( ) . toString ( ) . padStart ( 2 , "0" ) ;
582582 const month = ( date . getMonth ( ) + 1 ) . toString ( ) . padStart ( 2 , "0" ) ;
@@ -628,6 +628,20 @@ const unescape_html = (escaped_html) => {
628628 . replace ( / & q u o t ; / g, '"' ) ;
629629} ;
630630
631+ /**
632+ * Return true, if the given value is a valid ISO 8601 date/time string with or without an optional time component.
633+ *
634+ * @param {String } value - The date/time value to be checked.
635+ * @param {Boolean } [optional_time=false] - True, if time component is optional.
636+ * @return {Boolean } - True, if the given value is a valid Date string. False if not.
637+ */
638+ const is_iso_date_time = ( value , optional_time = false ) => {
639+ const re_date_time = optional_time
640+ ? / ^ \d { 4 } - [ 0 1 ] \d - [ 0 - 3 ] \d ( T [ 0 - 2 ] \d : [ 0 - 5 ] \d ) ? $ /
641+ : / ^ \d { 4 } - [ 0 1 ] \d - [ 0 - 3 ] \d T [ 0 - 2 ] \d : [ 0 - 5 ] \d $ / ;
642+ return re_date_time . test ( value ) ;
643+ } ;
644+
631645var utils = {
632646 // pattern pimping - own module?
633647 jqueryPlugin : jqueryPlugin ,
@@ -658,6 +672,7 @@ var utils = {
658672 localized_isodate : localized_isodate ,
659673 escape_html : escape_html ,
660674 unescape_html : unescape_html ,
675+ is_iso_date_time : is_iso_date_time ,
661676 getCSSValue : dom . get_css_value , // BBB: moved to dom. TODO: Remove in upcoming version.
662677} ;
663678
0 commit comments