NaturalCycles/js-lib

View on GitHub
src/datetime/localTime.ts

Summary

Maintainability
D
2 days
Test Coverage
B
89%

LocalTime has 60 functions (exceeds 50 allowed). Consider refactoring.
Open

export class LocalTime {
  private constructor(private $date: Date) {}

  /**
   * Parses input String into LocalDate.
Severity: Major
Found in src/datetime/localTime.ts - About 3 hrs to fix

    Function endOf has a Cognitive Complexity of 18 (exceeds 8 allowed). Consider refactoring.
    Open

      endOf(unit: LocalTimeUnit, mutate = false): LocalTime {
        if (unit === 'second') return this
        const d = mutate ? this.$date : new Date(this.$date)
        d.setSeconds(59, 0)
    
    
    Severity: Minor
    Found in src/datetime/localTime.ts - 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 startOf has a Cognitive Complexity of 15 (exceeds 8 allowed). Consider refactoring.
    Open

      startOf(unit: LocalTimeUnit, mutate = false): LocalTime {
        if (unit === 'second') return this
        const d = mutate ? this.$date : new Date(this.$date)
        d.setSeconds(0, 0)
    
    
    Severity: Minor
    Found in src/datetime/localTime.ts - 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 setComponents has a Cognitive Complexity of 10 (exceeds 8 allowed). Consider refactoring.
    Open

      setComponents(c: Partial<LocalTimeComponents>, mutate = false): LocalTime {
        const d = mutate ? this.$date : new Date(this.$date)
    
        // Year, month and day set all-at-once, to avoid 30/31 (and 28/29) mishap
        if (c.day || c.month !== undefined || c.year !== undefined) {
    Severity: Minor
    Found in src/datetime/localTime.ts - 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

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

      isBetween(min: LocalTimeInput, max: LocalTimeInput, 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/localTime.ts and 1 other location - About 4 hrs to fix
    src/datetime/localDate.ts on lines 207..214

    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: LocalTimeInput[]): LocalTime {
        _assert(items.length, 'LocalTime.earliest called on empty array')
    
        return items
          .map(i => LocalTime.of(i))
    Severity: Major
    Found in src/datetime/localTime.ts and 3 other locations - About 1 hr to fix
    src/datetime/localDate.ts on lines 126..132
    src/datetime/localDate.ts on lines 138..144
    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: LocalTimeInput[]): LocalTime {
        _assert(items.length, 'LocalTime.latest called on empty array')
    
        return items
          .map(i => LocalTime.of(i))
    Severity: Major
    Found in src/datetime/localTime.ts and 3 other locations - About 1 hr to fix
    src/datetime/localDate.ts on lines 126..132
    src/datetime/localDate.ts on lines 138..144
    src/datetime/localTime.ts on lines 403..409

    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

      isSameOrOlderThan(n: number, unit: LocalTimeUnit, now?: LocalTimeInput): boolean {
        return this.isSameOrBefore(LocalTime.of(now ?? new Date()).plus(-n, unit))
      }
    Severity: Major
    Found in src/datetime/localTime.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/localDate.ts on lines 252..254
    src/datetime/localTime.ts on lines 463..465
    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: LocalTimeUnit, now?: LocalTimeInput): boolean {
        return this.isBefore(LocalTime.of(now ?? new Date()).plus(-n, unit))
      }
    Severity: Major
    Found in src/datetime/localTime.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/localDate.ts on lines 252..254
    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

      isYoungerThan(n: number, unit: LocalTimeUnit, now?: LocalTimeInput): boolean {
        return this.isAfter(LocalTime.of(now ?? new Date()).plus(-n, unit))
      }
    Severity: Major
    Found in src/datetime/localTime.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/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 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: LocalTimeUnit, now?: LocalTimeInput): boolean {
        return this.isSameOrAfter(LocalTime.of(now ?? new Date()).plus(-n, unit))
      }
    Severity: Major
    Found in src/datetime/localTime.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/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

    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 4 locations. Consider refactoring.
    Open

      isBefore(d: LocalTimeInput, inclusive = false): boolean {
        const r = this.cmp(d)
        return r === -1 || (r === 0 && inclusive)
      }
    Severity: Major
    Found in src/datetime/localTime.ts and 3 other locations - About 30 mins to fix
    src/datetime/dateInterval.ts on lines 42..45
    src/datetime/localDate.ts on lines 189..192
    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