NaturalCycles/js-lib

View on GitHub
src/datetime/localDate.ts

Summary

Maintainability
D
3 days
Test Coverage
A
90%

Function plus has a Cognitive Complexity of 27 (exceeds 8 allowed). Consider refactoring.
Open

  plus(num: number, unit: LocalDateUnit, mutate = false): LocalDate {
    let { $day, $month, $year } = this

    if (unit === 'week') {
      num *= 7
Severity: Minor
Found in src/datetime/localDate.ts - About 3 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

LocalDate has 54 functions (exceeds 50 allowed). Consider refactoring.
Open

export class LocalDate {
  private constructor(
    private $year: number,
    private $month: number,
    private $day: number,
Severity: Major
Found in src/datetime/localDate.ts - About 2 hrs to fix

    Function diff has a Cognitive Complexity of 22 (exceeds 8 allowed). Consider refactoring.
    Open

      diff(d: LocalDateInput, unit: LocalDateUnit): number {
        d = LocalDate.of(d)
    
        const sign = this.cmp(d)
        if (!sign) return 0
    Severity: Minor
    Found in src/datetime/localDate.ts - 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

    Consider simplifying this complex logical expression.
    Open

        if (
          !year ||
          !month ||
          month < 1 ||
          month > 12 ||
    Severity: Major
    Found in src/datetime/localDate.ts - About 1 hr to fix

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

        isBetween(min: LocalDateInput, max: LocalDateInput, incl: Inclusiveness = '[)'): boolean {
          let r = this.cmp(min)
          // eslint-disable-next-line @typescript-eslint/prefer-string-starts-ends-with
          if (r < 0 || (r === 0 && incl[0] === '(')) return false
          r = this.cmp(max)
      Severity: Major
      Found in src/datetime/localDate.ts and 1 other location - About 4 hrs to fix
      src/datetime/localTime.ts on lines 445..452

      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 138.

      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

      Similar blocks of code found in 4 locations. Consider refactoring.
      Open

        static earliest(items: LocalDateInput[]): LocalDate {
          _assert(items.length, 'LocalDate.earliest called on empty array')
      
          return items
            .map(i => LocalDate.of(i))
      Severity: Major
      Found in src/datetime/localDate.ts and 3 other locations - About 1 hr to fix
      src/datetime/localDate.ts on lines 138..144
      src/datetime/localTime.ts on lines 403..409
      src/datetime/localTime.ts on lines 415..421

      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 85.

      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

      Similar blocks of code found in 4 locations. Consider refactoring.
      Open

        static latest(items: LocalDateInput[]): LocalDate {
          _assert(items.length, 'LocalDate.latest called on empty array')
      
          return items
            .map(i => LocalDate.of(i))
      Severity: Major
      Found in src/datetime/localDate.ts and 3 other locations - About 1 hr to fix
      src/datetime/localDate.ts on lines 126..132
      src/datetime/localTime.ts on lines 403..409
      src/datetime/localTime.ts on lines 415..421

      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 85.

      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

      Similar blocks of code found in 8 locations. Consider refactoring.
      Open

        isYoungerThan(n: number, unit: LocalDateUnit, today?: LocalDateInput): boolean {
          return this.isAfter(LocalDate.of(today || new Date()).plus(-n, unit))
        }
      Severity: Major
      Found in src/datetime/localDate.ts and 7 other locations - About 1 hr to fix
      src/datetime/localDate.ts on lines 225..227
      src/datetime/localDate.ts on lines 232..234
      src/datetime/localDate.ts on lines 252..254
      src/datetime/localTime.ts on lines 463..465
      src/datetime/localTime.ts on lines 470..472
      src/datetime/localTime.ts on lines 483..485
      src/datetime/localTime.ts on lines 490..492

      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 72.

      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

      Similar blocks of code found in 8 locations. Consider refactoring.
      Open

        isSameOrOlderThan(n: number, unit: LocalDateUnit, today?: LocalDateInput): boolean {
          return this.isSameOrBefore(LocalDate.of(today || new Date()).plus(-n, unit))
        }
      Severity: Major
      Found in src/datetime/localDate.ts and 7 other locations - About 1 hr to fix
      src/datetime/localDate.ts on lines 225..227
      src/datetime/localDate.ts on lines 245..247
      src/datetime/localDate.ts on lines 252..254
      src/datetime/localTime.ts on lines 463..465
      src/datetime/localTime.ts on lines 470..472
      src/datetime/localTime.ts on lines 483..485
      src/datetime/localTime.ts on lines 490..492

      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 72.

      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

      Similar blocks of code found in 8 locations. Consider refactoring.
      Open

        isSameOrYoungerThan(n: number, unit: LocalDateUnit, today?: LocalDateInput): boolean {
          return this.isSameOrAfter(LocalDate.of(today || new Date()).plus(-n, unit))
        }
      Severity: Major
      Found in src/datetime/localDate.ts and 7 other locations - About 1 hr to fix
      src/datetime/localDate.ts on lines 225..227
      src/datetime/localDate.ts on lines 232..234
      src/datetime/localDate.ts on lines 245..247
      src/datetime/localTime.ts on lines 463..465
      src/datetime/localTime.ts on lines 470..472
      src/datetime/localTime.ts on lines 483..485
      src/datetime/localTime.ts on lines 490..492

      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 72.

      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

      Similar blocks of code found in 8 locations. Consider refactoring.
      Open

        isOlderThan(n: number, unit: LocalDateUnit, today?: LocalDateInput): boolean {
          return this.isBefore(LocalDate.of(today || new Date()).plus(-n, unit))
        }
      Severity: Major
      Found in src/datetime/localDate.ts and 7 other locations - About 1 hr to fix
      src/datetime/localDate.ts on lines 232..234
      src/datetime/localDate.ts on lines 245..247
      src/datetime/localDate.ts on lines 252..254
      src/datetime/localTime.ts on lines 463..465
      src/datetime/localTime.ts on lines 470..472
      src/datetime/localTime.ts on lines 483..485
      src/datetime/localTime.ts on lines 490..492

      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 72.

      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

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

        toString(): IsoDateString {
          return [
            String(this.$year).padStart(4, '0'),
            String(this.$month).padStart(2, '0'),
            String(this.$day).padStart(2, '0'),
      Severity: Major
      Found in src/datetime/localDate.ts and 1 other location - About 1 hr to fix
      src/datetime/localDate.ts on lines 499..505

      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 70.

      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

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

        toStringCompact(): string {
          return [
            String(this.$year).padStart(4, '0'),
            String(this.$month).padStart(2, '0'),
            String(this.$day).padStart(2, '0'),
      Severity: Major
      Found in src/datetime/localDate.ts and 1 other location - About 1 hr to fix
      src/datetime/localDate.ts on lines 491..497

      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 70.

      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

      Similar blocks of code found in 4 locations. Consider refactoring.
      Open

        isBefore(d: LocalDateInput, inclusive = false): boolean {
          const r = this.cmp(d)
          return r === -1 || (r === 0 && inclusive)
        }
      Severity: Major
      Found in src/datetime/localDate.ts and 3 other locations - About 30 mins to fix
      src/datetime/dateInterval.ts on lines 42..45
      src/datetime/localTime.ts on lines 427..430
      src/datetime/timeInterval.ts on lines 62..65

      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 60.

      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