Completed
Push — master ( b895c6...fa6d7b )
by Rain
03:32
created

sl.js ➔ ... ➔ processRelativeTime   C

Complexity

Conditions 72
Paths 93

Size

Total Lines 70

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 72
c 1
b 0
f 0
nc 93
dl 0
loc 70
rs 5.3488
nop 4

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

Complexity

Complex classes like sl.js ➔ ... ➔ processRelativeTime often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
//! moment.js locale configuration
2
//! locale : Slovenian [sl]
3
//! author : Robert Sedovšek : https://github.com/sedovsek
4
5
;(function (global, factory) {
6
   typeof exports === 'object' && typeof module !== 'undefined'
7
       && typeof require === 'function' ? factory(require('../moment')) :
8
   typeof define === 'function' && define.amd ? define(['../moment'], factory) :
9
   factory(global.moment)
10
}(this, function (moment) { 'use strict';
11
12
13
    function processRelativeTime(number, withoutSuffix, key, isFuture) {
14
        var result = number + ' ';
15
        switch (key) {
1 ignored issue
show
Coding Style introduced by
As per coding-style, switch statements should have a default case.
Loading history...
16
            case 's':
17
                return withoutSuffix || isFuture ? 'nekaj sekund' : 'nekaj sekundami';
18
            case 'm':
19
                return withoutSuffix ? 'ena minuta' : 'eno minuto';
20
            case 'mm':
21
                if (number === 1) {
22
                    result += withoutSuffix ? 'minuta' : 'minuto';
23
                } else if (number === 2) {
24
                    result += withoutSuffix || isFuture ? 'minuti' : 'minutama';
25
                } else if (number < 5) {
26
                    result += withoutSuffix || isFuture ? 'minute' : 'minutami';
27
                } else {
28
                    result += withoutSuffix || isFuture ? 'minut' : 'minutami';
29
                }
30
                return result;
31
            case 'h':
32
                return withoutSuffix ? 'ena ura' : 'eno uro';
33
            case 'hh':
34
                if (number === 1) {
35
                    result += withoutSuffix ? 'ura' : 'uro';
36
                } else if (number === 2) {
37
                    result += withoutSuffix || isFuture ? 'uri' : 'urama';
38
                } else if (number < 5) {
39
                    result += withoutSuffix || isFuture ? 'ure' : 'urami';
40
                } else {
41
                    result += withoutSuffix || isFuture ? 'ur' : 'urami';
42
                }
43
                return result;
44
            case 'd':
45
                return withoutSuffix || isFuture ? 'en dan' : 'enim dnem';
46
            case 'dd':
47
                if (number === 1) {
48
                    result += withoutSuffix || isFuture ? 'dan' : 'dnem';
49
                } else if (number === 2) {
50
                    result += withoutSuffix || isFuture ? 'dni' : 'dnevoma';
51
                } else {
52
                    result += withoutSuffix || isFuture ? 'dni' : 'dnevi';
53
                }
54
                return result;
55
            case 'M':
56
                return withoutSuffix || isFuture ? 'en mesec' : 'enim mesecem';
57
            case 'MM':
58
                if (number === 1) {
59
                    result += withoutSuffix || isFuture ? 'mesec' : 'mesecem';
60
                } else if (number === 2) {
61
                    result += withoutSuffix || isFuture ? 'meseca' : 'mesecema';
62
                } else if (number < 5) {
63
                    result += withoutSuffix || isFuture ? 'mesece' : 'meseci';
64
                } else {
65
                    result += withoutSuffix || isFuture ? 'mesecev' : 'meseci';
66
                }
67
                return result;
68
            case 'y':
69
                return withoutSuffix || isFuture ? 'eno leto' : 'enim letom';
70
            case 'yy':
71
                if (number === 1) {
72
                    result += withoutSuffix || isFuture ? 'leto' : 'letom';
73
                } else if (number === 2) {
74
                    result += withoutSuffix || isFuture ? 'leti' : 'letoma';
75
                } else if (number < 5) {
76
                    result += withoutSuffix || isFuture ? 'leta' : 'leti';
77
                } else {
78
                    result += withoutSuffix || isFuture ? 'let' : 'leti';
79
                }
80
                return result;
81
        }
0 ignored issues
show
Comprehensibility introduced by
There is no default case in this switch, so nothing gets returned when all cases fail. You might want to consider adding a default or return undefined explicitly.
Loading history...
82
    }
83
84
    var sl = moment.defineLocale('sl', {
85
        months : 'januar_februar_marec_april_maj_junij_julij_avgust_september_oktober_november_december'.split('_'),
86
        monthsShort : 'jan._feb._mar._apr._maj._jun._jul._avg._sep._okt._nov._dec.'.split('_'),
87
        monthsParseExact: true,
88
        weekdays : 'nedelja_ponedeljek_torek_sreda_četrtek_petek_sobota'.split('_'),
89
        weekdaysShort : 'ned._pon._tor._sre._čet._pet._sob.'.split('_'),
90
        weekdaysMin : 'ne_po_to_sr_če_pe_so'.split('_'),
91
        weekdaysParseExact : true,
92
        longDateFormat : {
93
            LT : 'H:mm',
94
            LTS : 'H:mm:ss',
95
            L : 'DD. MM. YYYY',
96
            LL : 'D. MMMM YYYY',
97
            LLL : 'D. MMMM YYYY H:mm',
98
            LLLL : 'dddd, D. MMMM YYYY H:mm'
99
        },
100
        calendar : {
101
            sameDay  : '[danes ob] LT',
102
            nextDay  : '[jutri ob] LT',
103
104
            nextWeek : function () {
105
                switch (this.day()) {
1 ignored issue
show
Coding Style introduced by
As per coding-style, switch statements should have a default case.
Loading history...
106
                    case 0:
107
                        return '[v] [nedeljo] [ob] LT';
108
                    case 3:
109
                        return '[v] [sredo] [ob] LT';
110
                    case 6:
111
                        return '[v] [soboto] [ob] LT';
112
                    case 1:
113
                    case 2:
114
                    case 4:
115
                    case 5:
116
                        return '[v] dddd [ob] LT';
117
                }
0 ignored issues
show
Comprehensibility introduced by
There is no default case in this switch, so nothing gets returned when all cases fail. You might want to consider adding a default or return undefined explicitly.
Loading history...
118
            },
119
            lastDay  : '[včeraj ob] LT',
120
            lastWeek : function () {
121
                switch (this.day()) {
1 ignored issue
show
Coding Style introduced by
As per coding-style, switch statements should have a default case.
Loading history...
122
                    case 0:
123
                        return '[prejšnjo] [nedeljo] [ob] LT';
124
                    case 3:
125
                        return '[prejšnjo] [sredo] [ob] LT';
126
                    case 6:
127
                        return '[prejšnjo] [soboto] [ob] LT';
128
                    case 1:
129
                    case 2:
130
                    case 4:
131
                    case 5:
132
                        return '[prejšnji] dddd [ob] LT';
133
                }
0 ignored issues
show
Comprehensibility introduced by
There is no default case in this switch, so nothing gets returned when all cases fail. You might want to consider adding a default or return undefined explicitly.
Loading history...
134
            },
135
            sameElse : 'L'
136
        },
137
        relativeTime : {
138
            future : 'čez %s',
139
            past   : 'pred %s',
140
            s      : processRelativeTime,
141
            m      : processRelativeTime,
142
            mm     : processRelativeTime,
143
            h      : processRelativeTime,
144
            hh     : processRelativeTime,
145
            d      : processRelativeTime,
146
            dd     : processRelativeTime,
147
            M      : processRelativeTime,
148
            MM     : processRelativeTime,
149
            y      : processRelativeTime,
150
            yy     : processRelativeTime
151
        },
152
        ordinalParse: /\d{1,2}\./,
153
        ordinal : '%d.',
154
        week : {
155
            dow : 1, // Monday is the first day of the week.
156
            doy : 7  // The week that contains Jan 1st is the first week of the year.
157
        }
158
    });
159
160
    return sl;
161
162
}));