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

➔ moment.defineLocale(ꞌruꞌ).calendar.nextWeek   C

Complexity

Conditions 10
Paths 6

Size

Total Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 10
c 0
b 0
f 0
nc 6
dl 0
loc 22
rs 6.1368
nop 1

How to fix   Complexity   

Complexity

Complex classes like ru.js ➔ ... ➔ moment.defineLocale(ꞌruꞌ).calendar.nextWeek 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 : Russian [ru]
3
//! author : Viktorminator : https://github.com/Viktorminator
4
//! Author : Menelion Elensúle : https://github.com/Oire
5
//! author : Коренберг Марк : https://github.com/socketpair
6
7
;(function (global, factory) {
8
   typeof exports === 'object' && typeof module !== 'undefined'
9
       && typeof require === 'function' ? factory(require('../moment')) :
10
   typeof define === 'function' && define.amd ? define(['../moment'], factory) :
11
   factory(global.moment)
12
}(this, function (moment) { 'use strict';
13
14
15
    function plural(word, num) {
16
        var forms = word.split('_');
17
        return num % 10 === 1 && num % 100 !== 11 ? forms[0] : (num % 10 >= 2 && num % 10 <= 4 && (num % 100 < 10 || num % 100 >= 20) ? forms[1] : forms[2]);
18
    }
19
    function relativeTimeWithPlural(number, withoutSuffix, key) {
20
        var format = {
21
            'mm': withoutSuffix ? 'минута_минуты_минут' : 'минуту_минуты_минут',
22
            'hh': 'час_часа_часов',
23
            'dd': 'день_дня_дней',
24
            'MM': 'месяц_месяца_месяцев',
25
            'yy': 'год_года_лет'
26
        };
27
        if (key === 'm') {
28
            return withoutSuffix ? 'минута' : 'минуту';
29
        }
30
        else {
31
            return number + ' ' + plural(format[key], +number);
32
        }
33
    }
34
    var monthsParse = [/^янв/i, /^фев/i, /^мар/i, /^апр/i, /^ма[йя]/i, /^июн/i, /^июл/i, /^авг/i, /^сен/i, /^окт/i, /^ноя/i, /^дек/i];
35
36
    // http://new.gramota.ru/spravka/rules/139-prop : § 103
37
    // Сокращения месяцев: http://new.gramota.ru/spravka/buro/search-answer?s=242637
38
    // CLDR data:          http://www.unicode.org/cldr/charts/28/summary/ru.html#1753
39
    var ru = moment.defineLocale('ru', {
40
        months : {
41
            format: 'января_февраля_марта_апреля_мая_июня_июля_августа_сентября_октября_ноября_декабря'.split('_'),
42
            standalone: 'январь_февраль_март_апрель_май_июнь_июль_август_сентябрь_октябрь_ноябрь_декабрь'.split('_')
43
        },
44
        monthsShort : {
45
            // по CLDR именно "июл." и "июн.", но какой смысл менять букву на точку ?
46
            format: 'янв._февр._мар._апр._мая_июня_июля_авг._сент._окт._нояб._дек.'.split('_'),
47
            standalone: 'янв._февр._март_апр._май_июнь_июль_авг._сент._окт._нояб._дек.'.split('_')
48
        },
49
        weekdays : {
50
            standalone: 'воскресенье_понедельник_вторник_среда_четверг_пятница_суббота'.split('_'),
51
            format: 'воскресенье_понедельник_вторник_среду_четверг_пятницу_субботу'.split('_'),
52
            isFormat: /\[ ?[Вв] ?(?:прошлую|следующую|эту)? ?\] ?dddd/
53
        },
54
        weekdaysShort : 'вс_пн_вт_ср_чт_пт_сб'.split('_'),
55
        weekdaysMin : 'вс_пн_вт_ср_чт_пт_сб'.split('_'),
56
        monthsParse : monthsParse,
57
        longMonthsParse : monthsParse,
58
        shortMonthsParse : monthsParse,
59
60
        // полные названия с падежами, по три буквы, для некоторых, по 4 буквы, сокращения с точкой и без точки
61
        monthsRegex: /^(январ[ья]|янв\.?|феврал[ья]|февр?\.?|марта?|мар\.?|апрел[ья]|апр\.?|ма[йя]|июн[ья]|июн\.?|июл[ья]|июл\.?|августа?|авг\.?|сентябр[ья]|сент?\.?|октябр[ья]|окт\.?|ноябр[ья]|нояб?\.?|декабр[ья]|дек\.?)/i,
62
63
        // копия предыдущего
64
        monthsShortRegex: /^(январ[ья]|янв\.?|феврал[ья]|февр?\.?|марта?|мар\.?|апрел[ья]|апр\.?|ма[йя]|июн[ья]|июн\.?|июл[ья]|июл\.?|августа?|авг\.?|сентябр[ья]|сент?\.?|октябр[ья]|окт\.?|ноябр[ья]|нояб?\.?|декабр[ья]|дек\.?)/i,
65
66
        // полные названия с падежами
67
        monthsStrictRegex: /^(январ[яь]|феврал[яь]|марта?|апрел[яь]|ма[яй]|июн[яь]|июл[яь]|августа?|сентябр[яь]|октябр[яь]|ноябр[яь]|декабр[яь])/i,
68
69
        // Выражение, которое соотвествует только сокращённым формам
70
        monthsShortStrictRegex: /^(янв\.|февр?\.|мар[т.]|апр\.|ма[яй]|июн[ья.]|июл[ья.]|авг\.|сент?\.|окт\.|нояб?\.|дек\.)/i,
71
        longDateFormat : {
72
            LT : 'HH:mm',
73
            LTS : 'HH:mm:ss',
74
            L : 'DD.MM.YYYY',
75
            LL : 'D MMMM YYYY г.',
76
            LLL : 'D MMMM YYYY г., HH:mm',
77
            LLLL : 'dddd, D MMMM YYYY г., HH:mm'
78
        },
79
        calendar : {
80
            sameDay: '[Сегодня в] LT',
81
            nextDay: '[Завтра в] LT',
82
            lastDay: '[Вчера в] LT',
83
            nextWeek: function (now) {
84
                if (now.week() !== this.week()) {
85
                    switch (this.day()) {
1 ignored issue
show
Coding Style introduced by
As per coding-style, switch statements should have a default case.
Loading history...
86
                        case 0:
87
                            return '[В следующее] dddd [в] LT';
88
                        case 1:
89
                        case 2:
90
                        case 4:
91
                            return '[В следующий] dddd [в] LT';
92
                        case 3:
93
                        case 5:
94
                        case 6:
95
                            return '[В следующую] dddd [в] LT';
96
                    }
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...
97
                } else {
98
                    if (this.day() === 2) {
99
                        return '[Во] dddd [в] LT';
100
                    } else {
101
                        return '[В] dddd [в] LT';
102
                    }
103
                }
104
            },
105
            lastWeek: function (now) {
106
                if (now.week() !== this.week()) {
107
                    switch (this.day()) {
1 ignored issue
show
Coding Style introduced by
As per coding-style, switch statements should have a default case.
Loading history...
108
                        case 0:
109
                            return '[В прошлое] dddd [в] LT';
110
                        case 1:
111
                        case 2:
112
                        case 4:
113
                            return '[В прошлый] dddd [в] LT';
114
                        case 3:
115
                        case 5:
116
                        case 6:
117
                            return '[В прошлую] dddd [в] LT';
118
                    }
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...
119
                } else {
120
                    if (this.day() === 2) {
121
                        return '[Во] dddd [в] LT';
122
                    } else {
123
                        return '[В] dddd [в] LT';
124
                    }
125
                }
126
            },
127
            sameElse: 'L'
128
        },
129
        relativeTime : {
130
            future : 'через %s',
131
            past : '%s назад',
132
            s : 'несколько секунд',
133
            m : relativeTimeWithPlural,
134
            mm : relativeTimeWithPlural,
135
            h : 'час',
136
            hh : relativeTimeWithPlural,
137
            d : 'день',
138
            dd : relativeTimeWithPlural,
139
            M : 'месяц',
140
            MM : relativeTimeWithPlural,
141
            y : 'год',
142
            yy : relativeTimeWithPlural
143
        },
144
        meridiemParse: /ночи|утра|дня|вечера/i,
145
        isPM : function (input) {
146
            return /^(дня|вечера)$/.test(input);
147
        },
148
        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...
149
            if (hour < 4) {
150
                return 'ночи';
151
            } else if (hour < 12) {
152
                return 'утра';
153
            } else if (hour < 17) {
154
                return 'дня';
155
            } else {
156
                return 'вечера';
157
            }
158
        },
159
        ordinalParse: /\d{1,2}-(й|го|я)/,
160
        ordinal: function (number, period) {
161
            switch (period) {
162
                case 'M':
163
                case 'd':
164
                case 'DDD':
165
                    return number + '-й';
166
                case 'D':
167
                    return number + '-го';
168
                case 'w':
169
                case 'W':
170
                    return number + '-я';
171
                default:
172
                    return number;
173
            }
174
        },
175
        week : {
176
            dow : 1, // Monday is the first day of the week.
177
            doy : 7  // The week that contains Jan 1st is the first week of the year.
178
        }
179
    });
180
181
    return ru;
182
183
}));