lib/timeline/DateUtil.js

Summary

Maintainability
F
3 days
Test Coverage

Function updateHiddenDates has a Cognitive Complexity of 67 (exceeds 5 allowed). Consider refactoring.
Open

exports.updateHiddenDates = function (moment, body, hiddenDates) {
  if (hiddenDates && !Array.isArray(hiddenDates)) {
    return exports.updateHiddenDates(moment, body, [hiddenDates])
  }

Severity: Minor
Found in lib/timeline/DateUtil.js - 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

Function updateHiddenDates has 117 lines of code (exceeds 25 allowed). Consider refactoring.
Open

exports.updateHiddenDates = function (moment, body, hiddenDates) {
  if (hiddenDates && !Array.isArray(hiddenDates)) {
    return exports.updateHiddenDates(moment, body, [hiddenDates])
  }

Severity: Major
Found in lib/timeline/DateUtil.js - About 4 hrs to fix

    File DateUtil.js has 332 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    
    /**
     * used in Core to convert the options into a volatile variable
     * 
     * @param {function} moment
    Severity: Minor
    Found in lib/timeline/DateUtil.js - About 4 hrs to fix

      Function removeDuplicates has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
      Open

      exports.removeDuplicates = function(body) {
        var hiddenDates = body.hiddenDates;
        var safeDates = [];
        for (var i = 0; i < hiddenDates.length; i++) {
          for (var j = 0; j < hiddenDates.length; j++) {
      Severity: Minor
      Found in lib/timeline/DateUtil.js - About 2 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 snapAwayFromHidden has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

      exports.snapAwayFromHidden = function(hiddenDates, time, direction, correctionEnabled) {
        var isHidden = exports.isHidden(time, hiddenDates);
        if (isHidden.hidden == true) {
          if (direction < 0) {
            if (correctionEnabled == true) {
      Severity: Minor
      Found in lib/timeline/DateUtil.js - About 1 hr 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 convertHiddenOptions has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

      exports.convertHiddenOptions = function(moment, body, hiddenDates) {
        if (hiddenDates && !Array.isArray(hiddenDates)) {
          return exports.convertHiddenOptions(moment, body, [hiddenDates])
        }
      
      
      Severity: Minor
      Found in lib/timeline/DateUtil.js - About 1 hr 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 removeDuplicates has 28 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      exports.removeDuplicates = function(body) {
        var hiddenDates = body.hiddenDates;
        var safeDates = [];
        for (var i = 0; i < hiddenDates.length; i++) {
          for (var j = 0; j < hiddenDates.length; j++) {
      Severity: Minor
      Found in lib/timeline/DateUtil.js - About 1 hr to fix

        Function toScreen has 27 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        exports.toScreen = function (Core, time, width) {
          var conversion;
          if (Core.body.hiddenDates.length == 0) {
              conversion = Core.range.conversion(width);
              return (time.valueOf() - conversion.offset) * conversion.scale;
        Severity: Minor
        Found in lib/timeline/DateUtil.js - About 1 hr to fix

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

          exports.stepOverHiddenDates = function(moment, timeStep, previousTime) {
            var stepInHidden = false;
            var currentValue = timeStep.current.valueOf();
            for (var i = 0; i < timeStep.hiddenDates.length; i++) {
              var startDate = timeStep.hiddenDates[i].start;
          Severity: Minor
          Found in lib/timeline/DateUtil.js - 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

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

          exports.toScreen = function (Core, time, width) {
            var conversion;
            if (Core.body.hiddenDates.length == 0) {
                conversion = Core.range.conversion(width);
                return (time.valueOf() - conversion.offset) * conversion.scale;
          Severity: Minor
          Found in lib/timeline/DateUtil.js - 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

                    switch (hiddenDates[i].repeat) {
                      case "daily": // case of time
                        if (startDate.day() != endDate.day()) {
                          offset = 1;
                        }
          Severity: Major
          Found in lib/timeline/DateUtil.js - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                      while (startDate < runUntil) {
                        body.hiddenDates.push({start: startDate.valueOf(), end: endDate.valueOf()});
                        switch (hiddenDates[i].repeat) {
                          case "daily":
                            startDate.add(1, 'days');
            Severity: Major
            Found in lib/timeline/DateUtil.js - About 45 mins to fix

              Function getAccumulatedHiddenDuration has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

              exports.getAccumulatedHiddenDuration = function(hiddenDates, range, requiredDuration) {
                var hiddenDuration = 0;
                var duration = 0;
                var previousPoint = range.start;
                //exports.printDates(hiddenDates)
              Severity: Minor
              Found in lib/timeline/DateUtil.js - About 35 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 too many return statements within this function.
              Open

                  return time;
              Severity: Major
              Found in lib/timeline/DateUtil.js - About 30 mins to fix

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

                exports.getHiddenDurationBefore = function(moment, hiddenDates, range, time) {
                  var timeOffset = 0;
                  time = moment(time).toDate().valueOf();
                
                  for (var i = 0; i < hiddenDates.length; i++) {
                Severity: Minor
                Found in lib/timeline/DateUtil.js - 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

                There are no issues that match your filters.

                Category
                Status