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

mr.js ➔ ... ➔ relativeTimeMr   D

Complexity

Conditions 24
Paths 24

Size

Total Lines 35

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 24
c 1
b 0
f 0
nc 24
dl 0
loc 35
rs 4.76
nop 4

How to fix   Complexity   

Complexity

Complex classes like mr.js ➔ ... ➔ relativeTimeMr 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 : Marathi [mr]
3
//! author : Harshad Kale : https://github.com/kalehv
4
//! author : Vivek Athalye : https://github.com/vnathalye
5
6
;(function (global, factory) {
7
   typeof exports === 'object' && typeof module !== 'undefined'
8
       && typeof require === 'function' ? factory(require('../moment')) :
9
   typeof define === 'function' && define.amd ? define(['../moment'], factory) :
10
   factory(global.moment)
11
}(this, function (moment) { 'use strict';
12
13
14
    var symbolMap = {
15
        '1': '१',
16
        '2': '२',
17
        '3': '३',
18
        '4': '४',
19
        '5': '५',
20
        '6': '६',
21
        '7': '७',
22
        '8': '८',
23
        '9': '९',
24
        '0': '०'
25
    },
26
    numberMap = {
27
        '१': '1',
28
        '२': '2',
29
        '३': '3',
30
        '४': '4',
31
        '५': '5',
32
        '६': '6',
33
        '७': '7',
34
        '८': '8',
35
        '९': '9',
36
        '०': '0'
37
    };
38
39
    function relativeTimeMr(number, withoutSuffix, string, isFuture)
0 ignored issues
show
Unused Code introduced by
The parameter isFuture is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
40
    {
41
        var output = '';
42
        if (withoutSuffix) {
43
            switch (string) {
1 ignored issue
show
Coding Style introduced by
As per coding-style, switch statements should have a default case.
Loading history...
44
                case 's': output = 'काही सेकंद'; break;
45
                case 'm': output = 'एक मिनिट'; break;
46
                case 'mm': output = '%d मिनिटे'; break;
47
                case 'h': output = 'एक तास'; break;
48
                case 'hh': output = '%d तास'; break;
49
                case 'd': output = 'एक दिवस'; break;
50
                case 'dd': output = '%d दिवस'; break;
51
                case 'M': output = 'एक महिना'; break;
52
                case 'MM': output = '%d महिने'; break;
53
                case 'y': output = 'एक वर्ष'; break;
54
                case 'yy': output = '%d वर्षे'; break;
55
            }
56
        }
57
        else {
58
            switch (string) {
1 ignored issue
show
Coding Style introduced by
As per coding-style, switch statements should have a default case.
Loading history...
59
                case 's': output = 'काही सेकंदां'; break;
60
                case 'm': output = 'एका मिनिटा'; break;
61
                case 'mm': output = '%d मिनिटां'; break;
62
                case 'h': output = 'एका तासा'; break;
63
                case 'hh': output = '%d तासां'; break;
64
                case 'd': output = 'एका दिवसा'; break;
65
                case 'dd': output = '%d दिवसां'; break;
66
                case 'M': output = 'एका महिन्या'; break;
67
                case 'MM': output = '%d महिन्यां'; break;
68
                case 'y': output = 'एका वर्षा'; break;
69
                case 'yy': output = '%d वर्षां'; break;
70
            }
71
        }
72
        return output.replace(/%d/i, number);
73
    }
74
75
    var mr = moment.defineLocale('mr', {
76
        months : 'जानेवारी_फेब्रुवारी_मार्च_एप्रिल_मे_जून_जुलै_ऑगस्ट_सप्टेंबर_ऑक्टोबर_नोव्हेंबर_डिसेंबर'.split('_'),
77
        monthsShort: 'जाने._फेब्रु._मार्च._एप्रि._मे._जून._जुलै._ऑग._सप्टें._ऑक्टो._नोव्हें._डिसें.'.split('_'),
78
        monthsParseExact : true,
79
        weekdays : 'रविवार_सोमवार_मंगळवार_बुधवार_गुरूवार_शुक्रवार_शनिवार'.split('_'),
80
        weekdaysShort : 'रवि_सोम_मंगळ_बुध_गुरू_शुक्र_शनि'.split('_'),
81
        weekdaysMin : 'र_सो_मं_बु_गु_शु_श'.split('_'),
82
        longDateFormat : {
83
            LT : 'A h:mm वाजता',
84
            LTS : 'A h:mm:ss वाजता',
85
            L : 'DD/MM/YYYY',
86
            LL : 'D MMMM YYYY',
87
            LLL : 'D MMMM YYYY, A h:mm वाजता',
88
            LLLL : 'dddd, D MMMM YYYY, A h:mm वाजता'
89
        },
90
        calendar : {
91
            sameDay : '[आज] LT',
92
            nextDay : '[उद्या] LT',
93
            nextWeek : 'dddd, LT',
94
            lastDay : '[काल] LT',
95
            lastWeek: '[मागील] dddd, LT',
96
            sameElse : 'L'
97
        },
98
        relativeTime : {
99
            future: '%sमध्ये',
100
            past: '%sपूर्वी',
101
            s: relativeTimeMr,
102
            m: relativeTimeMr,
103
            mm: relativeTimeMr,
104
            h: relativeTimeMr,
105
            hh: relativeTimeMr,
106
            d: relativeTimeMr,
107
            dd: relativeTimeMr,
108
            M: relativeTimeMr,
109
            MM: relativeTimeMr,
110
            y: relativeTimeMr,
111
            yy: relativeTimeMr
112
        },
113
        preparse: function (string) {
114
            return string.replace(/[१२३४५६७८९०]/g, function (match) {
115
                return numberMap[match];
116
            });
117
        },
118
        postformat: function (string) {
119
            return string.replace(/\d/g, function (match) {
120
                return symbolMap[match];
121
            });
122
        },
123
        meridiemParse: /रात्री|सकाळी|दुपारी|सायंकाळी/,
124
        meridiemHour : function (hour, meridiem) {
125
            if (hour === 12) {
126
                hour = 0;
127
            }
128
            if (meridiem === 'रात्री') {
129
                return hour < 4 ? hour : hour + 12;
130
            } else if (meridiem === 'सकाळी') {
131
                return hour;
132
            } else if (meridiem === 'दुपारी') {
133
                return hour >= 10 ? hour : hour + 12;
134
            } else if (meridiem === 'सायंकाळी') {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if meridiem === "सायंकाळी" is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
135
                return hour + 12;
136
            }
137
        },
138
        meridiem: function (hour, minute, isLower) {
0 ignored issues
show
Unused Code introduced by
The parameter minute is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter isLower is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
139
            if (hour < 4) {
140
                return 'रात्री';
141
            } else if (hour < 10) {
142
                return 'सकाळी';
143
            } else if (hour < 17) {
144
                return 'दुपारी';
145
            } else if (hour < 20) {
146
                return 'सायंकाळी';
147
            } else {
148
                return 'रात्री';
149
            }
150
        },
151
        week : {
152
            dow : 0, // Sunday is the first day of the week.
153
            doy : 6  // The week that contains Jan 1st is the first week of the year.
154
        }
155
    });
156
157
    return mr;
158
159
}));