| Conditions | 1 |
| Paths | 1 |
| Total Lines | 87 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
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:
If many parameters/temporary variables are present:
| 1 | //! moment.js locale configuration |
||
| 11 | }(this, function (moment) { 'use strict'; |
||
| 12 | |||
| 13 | |||
| 14 | var units = { |
||
| 15 | 'm': 'minūtes_minūtēm_minūte_minūtes'.split('_'), |
||
| 16 | 'mm': 'minūtes_minūtēm_minūte_minūtes'.split('_'), |
||
| 17 | 'h': 'stundas_stundām_stunda_stundas'.split('_'), |
||
| 18 | 'hh': 'stundas_stundām_stunda_stundas'.split('_'), |
||
| 19 | 'd': 'dienas_dienām_diena_dienas'.split('_'), |
||
| 20 | 'dd': 'dienas_dienām_diena_dienas'.split('_'), |
||
| 21 | 'M': 'mēneša_mēnešiem_mēnesis_mēneši'.split('_'), |
||
| 22 | 'MM': 'mēneša_mēnešiem_mēnesis_mēneši'.split('_'), |
||
| 23 | 'y': 'gada_gadiem_gads_gadi'.split('_'), |
||
| 24 | 'yy': 'gada_gadiem_gads_gadi'.split('_') |
||
| 25 | }; |
||
| 26 | /** |
||
| 27 | * @param withoutSuffix boolean true = a length of time; false = before/after a period of time. |
||
| 28 | */ |
||
| 29 | function format(forms, number, withoutSuffix) { |
||
| 30 | if (withoutSuffix) { |
||
| 31 | // E.g. "21 minūte", "3 minūtes". |
||
| 32 | return number % 10 === 1 && number % 100 !== 11 ? forms[2] : forms[3]; |
||
| 33 | } else { |
||
| 34 | // E.g. "21 minūtes" as in "pēc 21 minūtes". |
||
| 35 | // E.g. "3 minūtēm" as in "pēc 3 minūtēm". |
||
| 36 | return number % 10 === 1 && number % 100 !== 11 ? forms[0] : forms[1]; |
||
| 37 | } |
||
| 38 | } |
||
| 39 | function relativeTimeWithPlural(number, withoutSuffix, key) { |
||
| 40 | return number + ' ' + format(units[key], number, withoutSuffix); |
||
| 41 | } |
||
| 42 | function relativeTimeWithSingular(number, withoutSuffix, key) { |
||
| 43 | return format(units[key], number, withoutSuffix); |
||
| 44 | } |
||
| 45 | function relativeSeconds(number, withoutSuffix) { |
||
| 46 | return withoutSuffix ? 'dažas sekundes' : 'dažām sekundēm'; |
||
| 47 | } |
||
| 48 | |||
| 49 | var lv = moment.defineLocale('lv', { |
||
| 50 | months : 'janvāris_februāris_marts_aprīlis_maijs_jūnijs_jūlijs_augusts_septembris_oktobris_novembris_decembris'.split('_'), |
||
| 51 | monthsShort : 'jan_feb_mar_apr_mai_jūn_jūl_aug_sep_okt_nov_dec'.split('_'), |
||
| 52 | weekdays : 'svētdiena_pirmdiena_otrdiena_trešdiena_ceturtdiena_piektdiena_sestdiena'.split('_'), |
||
| 53 | weekdaysShort : 'Sv_P_O_T_C_Pk_S'.split('_'), |
||
| 54 | weekdaysMin : 'Sv_P_O_T_C_Pk_S'.split('_'), |
||
| 55 | weekdaysParseExact : true, |
||
| 56 | longDateFormat : { |
||
| 57 | LT : 'HH:mm', |
||
| 58 | LTS : 'HH:mm:ss', |
||
| 59 | L : 'DD.MM.YYYY.', |
||
| 60 | LL : 'YYYY. [gada] D. MMMM', |
||
| 61 | LLL : 'YYYY. [gada] D. MMMM, HH:mm', |
||
| 62 | LLLL : 'YYYY. [gada] D. MMMM, dddd, HH:mm' |
||
| 63 | }, |
||
| 64 | calendar : { |
||
| 65 | sameDay : '[Šodien pulksten] LT', |
||
| 66 | nextDay : '[Rīt pulksten] LT', |
||
| 67 | nextWeek : 'dddd [pulksten] LT', |
||
| 68 | lastDay : '[Vakar pulksten] LT', |
||
| 69 | lastWeek : '[Pagājušā] dddd [pulksten] LT', |
||
| 70 | sameElse : 'L' |
||
| 71 | }, |
||
| 72 | relativeTime : { |
||
| 73 | future : 'pēc %s', |
||
| 74 | past : 'pirms %s', |
||
| 75 | s : relativeSeconds, |
||
| 76 | m : relativeTimeWithSingular, |
||
| 77 | mm : relativeTimeWithPlural, |
||
| 78 | h : relativeTimeWithSingular, |
||
| 79 | hh : relativeTimeWithPlural, |
||
| 80 | d : relativeTimeWithSingular, |
||
| 81 | dd : relativeTimeWithPlural, |
||
| 82 | M : relativeTimeWithSingular, |
||
| 83 | MM : relativeTimeWithPlural, |
||
| 84 | y : relativeTimeWithSingular, |
||
| 85 | yy : relativeTimeWithPlural |
||
| 86 | }, |
||
| 87 | ordinalParse: /\d{1,2}\./, |
||
| 88 | ordinal : '%d.', |
||
| 89 | week : { |
||
| 90 | dow : 1, // Monday is the first day of the week. |
||
| 91 | doy : 4 // The week that contains Jan 4th is the first week of the year. |
||
| 92 | } |
||
| 93 | }); |
||
| 94 | |||
| 95 | return lv; |
||
| 96 | |||
| 97 | })); |