zul/src/main/resources/web/js/zul/db/datefmt.ts

Summary

Maintainability
F
2 wks
Test Coverage

Function parseDate has a Cognitive Complexity of 340 (exceeds 5 allowed). Consider refactoring.
Open

    parseDate(
        txt: string,
        fmt: string,
        nonLenient?: boolean,
        refval?: DateImpl,
Severity: Minor
Found in zul/src/main/resources/web/js/zul/db/datefmt.ts - About 1 wk to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function formatDate has a Cognitive Complexity of 84 (exceeds 5 allowed). Consider refactoring.
Open

    formatDate(val: DateImpl, fmt?: string, localizedSymbols?: zk.LocalizedSymbols): string {
        if (!fmt) fmt = 'yyyy/MM/dd';

        localizedSymbols ??= {
            DOW_1ST: zk.DOW_1ST,
Severity: Minor
Found in zul/src/main/resources/web/js/zul/db/datefmt.ts - About 1 day to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

File datefmt.ts has 642 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/* datefmt.ts

    Purpose:

    Description:
Severity: Major
Found in zul/src/main/resources/web/js/zul/db/datefmt.ts - About 1 day to fix

    Function parseDate has 251 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        parseDate(
            txt: string,
            fmt: string,
            nonLenient?: boolean,
            refval?: DateImpl,
    Severity: Major
    Found in zul/src/main/resources/web/js/zul/db/datefmt.ts - About 1 day to fix

      Function _parseTextToArray has a Cognitive Complexity of 39 (exceeds 5 allowed). Consider refactoring.
      Open

      function _parseTextToArray(txt: string, fmt: string): string[] | undefined {
          //ZK-5423
          var literals = extractLiteral(fmt); //extract literal token from format
          //remove literal from format and text
          fmt = fmt.replace(/'.*?'/g, ' ');  //remove any string enclosed by single quotes
      Severity: Minor
      Found in zul/src/main/resources/web/js/zul/db/datefmt.ts - About 5 hrs to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function formatDate has 115 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          formatDate(val: DateImpl, fmt?: string, localizedSymbols?: zk.LocalizedSymbols): string {
              if (!fmt) fmt = 'yyyy/MM/dd';
      
              localizedSymbols ??= {
                  DOW_1ST: zk.DOW_1ST,
      Severity: Major
      Found in zul/src/main/resources/web/js/zul/db/datefmt.ts - About 4 hrs to fix

        Function _parseTextToArray has 44 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        function _parseTextToArray(txt: string, fmt: string): string[] | undefined {
            //ZK-5423
            var literals = extractLiteral(fmt); //extract literal token from format
            //remove literal from format and text
            fmt = fmt.replace(/'.*?'/g, ' ');  //remove any string enclosed by single quotes
        Severity: Minor
        Found in zul/src/main/resources/web/js/zul/db/datefmt.ts - About 1 hr to fix

          Consider simplifying this complex logical expression.
          Open

                  } else if ((mindex >= 0 && mindex <= i /*&& mmindex >= i location French will lose last char */)
                      || (eindex >= 0 && eindex <= i) || (aa > -1 && aa <= i) || (gg > -1 && gg <= i)) {
                      if (c.match(/\w/)) {
                          ary.push(c);
                      } else {
          Severity: Critical
          Found in zul/src/main/resources/web/js/zul/db/datefmt.ts - About 1 hr to fix

            Function parseDate has 7 arguments (exceeds 4 allowed). Consider refactoring.
            Open

                    txt: string,
                    fmt: string,
                    nonLenient?: boolean,
                    refval?: DateImpl,
                    localizedSymbols?: zk.LocalizedSymbols,
            Severity: Major
            Found in zul/src/main/resources/web/js/zul/db/datefmt.ts - About 50 mins to fix

              Avoid deeply nested control flow statements.
              Open

                                          if (len == 3)
                                              symbols = localizedSymbols.SMON!;
                                          else if (len == 4)
                                              symbols = localizedSymbols.FMON!;
                                          else
              Severity: Major
              Found in zul/src/main/resources/web/js/zul/db/datefmt.ts - About 45 mins to fix

                Function parseDate has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                    parseDate(
                        txt: string,
                        fmt: string,
                        strict?: boolean,
                        refval?: DateImpl,
                Severity: Minor
                Found in zul/src/main/resources/web/js/zul/db/datefmt.ts - About 45 mins to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

                Avoid deeply nested control flow statements.
                Open

                                            if (nosep)
                                                token = _parseToken(token, ts, --i, token.length);//token.length: the length of French month is 4
                Severity: Major
                Found in zul/src/main/resources/web/js/zul/db/datefmt.ts - About 45 mins to fix

                  Avoid deeply nested control flow statements.
                  Open

                                          } else if (len <= 2) {
                                              if (nosep && token && token.length > 2) {//Bug 2560497 : if no separator, token must be assigned.
                                                  ts[--i] = token.substring(2);
                                                  token = token.substring(0, 2);
                                              }
                  Severity: Major
                  Found in zul/src/main/resources/web/js/zul/db/datefmt.ts - About 45 mins to fix

                    Avoid deeply nested control flow statements.
                    Open

                                                for (var index = symbols.length, brkswch; --index >= 0;) {
                                                    var monStr = symbols[index].toLowerCase();
                    
                                                    if ((nonLenient && mon == monStr) || (!nonLenient && mon.startsWith(monStr))) {
                                                        var monStrLen = monStr.length;
                    Severity: Major
                    Found in zul/src/main/resources/web/js/zul/db/datefmt.ts - About 45 mins to fix

                      Avoid deeply nested control flow statements.
                      Open

                                          if (ary.length) {
                                              ts.push(ary.join(''));
                                              ary = [];
                                          }
                      Severity: Major
                      Found in zul/src/main/resources/web/js/zul/db/datefmt.ts - About 45 mins to fix

                        Avoid deeply nested control flow statements.
                        Open

                                                if (fmt.charAt(k) == 'r') k++; // ZK-2964: for nl local uur
                        Severity: Major
                        Found in zul/src/main/resources/web/js/zul/db/datefmt.ts - About 45 mins to fix

                          Avoid deeply nested control flow statements.
                          Open

                                                      if (cc == 'm') min = nv;
                                                      else if (cc == 's') sec = nv;
                                                      else msec = nv;
                          Severity: Major
                          Found in zul/src/main/resources/web/js/zul/db/datefmt.ts - About 45 mins to fix

                            Avoid deeply nested control flow statements.
                            Open

                                                        if (!eraName) return; // no era match
                            Severity: Major
                            Found in zul/src/main/resources/web/js/zul/db/datefmt.ts - About 45 mins to fix

                              Avoid deeply nested control flow statements.
                              Open

                                                          if (len < 3) len = 2;
                              Severity: Major
                              Found in zul/src/main/resources/web/js/zul/db/datefmt.ts - About 45 mins to fix

                                Avoid deeply nested control flow statements.
                                Open

                                                            if (newY < 100 && newY === (y + ydelta) % 100) break; // assume yy is not modified
                                Severity: Major
                                Found in zul/src/main/resources/web/js/zul/db/datefmt.ts - About 45 mins to fix

                                  Avoid deeply nested control flow statements.
                                  Open

                                                              if (d < 0 || d > 31) //restrict since user might input year for day (ok to allow 0 and 31 for easy entry)
                                                                  return; //failed
                                  Severity: Major
                                  Found in zul/src/main/resources/web/js/zul/db/datefmt.ts - About 45 mins to fix

                                    Avoid deeply nested control flow statements.
                                    Open

                                                                if (isNaN(nv = _parseInt(token)))
                                                                    return; // failed, B50-3314513
                                    Severity: Major
                                    Found in zul/src/main/resources/web/js/zul/db/datefmt.ts - About 45 mins to fix

                                      Avoid deeply nested control flow statements.
                                      Open

                                                      while (f == fmt.charAt(i - 1) && f) {
                                                          f = fmt.charAt(++i);
                                                      }
                                      Severity: Major
                                      Found in zul/src/main/resources/web/js/zul/db/datefmt.ts - About 45 mins to fix

                                        Avoid deeply nested control flow statements.
                                        Open

                                                                    if (token && token.length > len) {
                                                                        ts[--i] = token.substring(len);
                                                                        token = token.substring(0, len);
                                                                    }
                                        Severity: Major
                                        Found in zul/src/main/resources/web/js/zul/db/datefmt.ts - About 45 mins to fix

                                          Avoid deeply nested control flow statements.
                                          Open

                                                                      if (ydelta === 0 && newY < 100) { // only handle twoDigitYearStart with ISO calendar for now
                                                                          // ZK-4235: Datefmt parseDate always return date between 1930-2029 when using yy format
                                                                          var twoDigitYearStart = zk.TDYS,
                                                                              lowerBoundary = (Math.floor(twoDigitYearStart / 100) * 100) + newY,
                                                                              upperBoundary = lowerBoundary + 100;
                                          Severity: Major
                                          Found in zul/src/main/resources/web/js/zul/db/datefmt.ts - About 45 mins to fix

                                            Avoid deeply nested control flow statements.
                                            Open

                                                                        if (brkswch)
                                                                            break;
                                            Severity: Major
                                            Found in zul/src/main/resources/web/js/zul/db/datefmt.ts - About 45 mins to fix

                                              Consider simplifying this complex logical expression.
                                              Open

                                                          if (dt.getFullYear() != y || dt.getMonth() != m || dt.getDate() != d
                                                              || dt.getHours() != hr || dt.getMinutes() != min || dt.getSeconds() != sec) //ignore msec (safer though not accurate)
                                                              return; //failed
                                              Severity: Major
                                              Found in zul/src/main/resources/web/js/zul/db/datefmt.ts - About 40 mins to fix

                                                Avoid too many return statements within this function.
                                                Open

                                                                                return; //failed
                                                Severity: Major
                                                Found in zul/src/main/resources/web/js/zul/db/datefmt.ts - About 30 mins to fix

                                                  Avoid too many return statements within this function.
                                                  Open

                                                                                  if (l == 12) return; //failed
                                                  Severity: Major
                                                  Found in zul/src/main/resources/web/js/zul/db/datefmt.ts - About 30 mins to fix

                                                    Avoid too many return statements within this function.
                                                    Open

                                                                                return;
                                                    Severity: Major
                                                    Found in zul/src/main/resources/web/js/zul/db/datefmt.ts - About 30 mins to fix

                                                      Avoid too many return statements within this function.
                                                      Open

                                                                                  if (!eraName) return; // no era match
                                                      Severity: Major
                                                      Found in zul/src/main/resources/web/js/zul/db/datefmt.ts - About 30 mins to fix

                                                        Avoid too many return statements within this function.
                                                        Open

                                                                return +dt == +refval ? refval : dt as DateImpl;
                                                        Severity: Major
                                                        Found in zul/src/main/resources/web/js/zul/db/datefmt.ts - About 30 mins to fix

                                                          Avoid too many return statements within this function.
                                                          Open

                                                                                      return;
                                                          Severity: Major
                                                          Found in zul/src/main/resources/web/js/zul/db/datefmt.ts - About 30 mins to fix

                                                            Avoid too many return statements within this function.
                                                            Open

                                                                                        return;
                                                            Severity: Major
                                                            Found in zul/src/main/resources/web/js/zul/db/datefmt.ts - About 30 mins to fix

                                                              Avoid too many return statements within this function.
                                                              Open

                                                                                              return; // failed, B50-3314513
                                                              Severity: Major
                                                              Found in zul/src/main/resources/web/js/zul/db/datefmt.ts - About 30 mins to fix

                                                                Avoid too many return statements within this function.
                                                                Open

                                                                                            return;//failed
                                                                Severity: Major
                                                                Found in zul/src/main/resources/web/js/zul/db/datefmt.ts - About 30 mins to fix

                                                                  Avoid too many return statements within this function.
                                                                  Open

                                                                                          if (!token) return; //failed
                                                                  Severity: Major
                                                                  Found in zul/src/main/resources/web/js/zul/db/datefmt.ts - About 30 mins to fix

                                                                    Avoid too many return statements within this function.
                                                                    Open

                                                                                                return;
                                                                    Severity: Major
                                                                    Found in zul/src/main/resources/web/js/zul/db/datefmt.ts - About 30 mins to fix

                                                                      Avoid too many return statements within this function.
                                                                      Open

                                                                                                  return;
                                                                      Severity: Major
                                                                      Found in zul/src/main/resources/web/js/zul/db/datefmt.ts - About 30 mins to fix

                                                                        Avoid too many return statements within this function.
                                                                        Open

                                                                                        return; //failed
                                                                        Severity: Major
                                                                        Found in zul/src/main/resources/web/js/zul/db/datefmt.ts - About 30 mins to fix

                                                                          Avoid too many return statements within this function.
                                                                          Open

                                                                                                      return;
                                                                          Severity: Major
                                                                          Found in zul/src/main/resources/web/js/zul/db/datefmt.ts - About 30 mins to fix

                                                                            Avoid too many return statements within this function.
                                                                            Open

                                                                                                return; //failed
                                                                            Severity: Major
                                                                            Found in zul/src/main/resources/web/js/zul/db/datefmt.ts - About 30 mins to fix

                                                                              Function formatDate has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                                                              Open

                                                                                  formatDate(val: DateImpl, fmt?: string, localizedSymbols?: zk.LocalizedSymbols): string {
                                                                                      var d: LeapDay | undefined;
                                                                                      if (localizedSymbols) {
                                                                                          var localeDateTimeFormat = new Intl.DateTimeFormat(localizedSymbols.LAN_TAG, { year: 'numeric' });
                                                                                          this._offset = localizedSymbols.YDELTA || zk.fmt.Date.getYDelta(val._moment.toDate(), localeDateTimeFormat);
                                                                              Severity: Minor
                                                                              Found in zul/src/main/resources/web/js/zul/db/datefmt.ts - About 25 mins to fix

                                                                              Cognitive Complexity

                                                                              Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                                                                              A method's cognitive complexity is based on a few simple rules:

                                                                              • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                                                                              • Code is considered more complex for each "break in the linear flow of the code"
                                                                              • Code is considered more complex when "flow breaking structures are nested"

                                                                              Further reading

                                                                              Identical blocks of code found in 2 locations. Consider refactoring.
                                                                              Open

                                                                                      localizedSymbols ??= {
                                                                                          DOW_1ST: zk.DOW_1ST,
                                                                                          MINDAYS: zk.MINDAYS,
                                                                                          ERA: zk.ERA,
                                                                                          YDELTA: zk.YDELTA,
                                                                              Severity: Major
                                                                              Found in zul/src/main/resources/web/js/zul/db/datefmt.ts and 1 other location - About 4 hrs to fix
                                                                              zul/src/main/resources/web/js/zul/db/datefmt.ts on lines 519..532

                                                                              Duplicated Code

                                                                              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                                                              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                                                              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                                                              Tuning

                                                                              This issue has a mass of 116.

                                                                              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                                                              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                                                              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                                                              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                                                              Refactorings

                                                                              Further Reading

                                                                              Identical blocks of code found in 2 locations. Consider refactoring.
                                                                              Open

                                                                                      localizedSymbols ??= {
                                                                                          DOW_1ST: zk.DOW_1ST,
                                                                                          MINDAYS: zk.MINDAYS,
                                                                                          ERA: zk.ERA,
                                                                                          YDELTA: zk.YDELTA,
                                                                              Severity: Major
                                                                              Found in zul/src/main/resources/web/js/zul/db/datefmt.ts and 1 other location - About 4 hrs to fix
                                                                              zul/src/main/resources/web/js/zul/db/datefmt.ts on lines 230..243

                                                                              Duplicated Code

                                                                              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                                                              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                                                              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                                                              Tuning

                                                                              This issue has a mass of 116.

                                                                              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                                                              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                                                              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                                                              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                                                              Refactorings

                                                                              Further Reading

                                                                              There are no issues that match your filters.

                                                                              Category
                                                                              Status