Sha256: b448bc248ce20ba4538766c83650c1a48718005a7fad71f6a945b0e34cb43752
Contents?: true
Size: 1.62 KB
Versions: 1
Compression:
Stored size: 1.62 KB
Contents
angular.module('EssayApp.filters') .filter('formattedHours', -> (hours, texts = null, options) -> return hours unless hours? options ||= { max_hours: 24 round_days: false } texts ||= { hours: zero: '' few: "{} #{I18n.t('new_order.label.few_h')}" one: "{} #{I18n.t('new_order.label.hour')}" many: "{} #{I18n.t('new_order.label.hours')}" days: zero: "" few: "{} #{I18n.t('new_order.label.few_d')}" one: "{} #{I18n.t('new_order.label.day')}" many: "{} #{I18n.t('new_order.label.days')}" } try hours = parseInt(hours) catch e return hours hours ||= 0 days = 0 if hours > options.max_hours || 24 days = Math.floor(hours / 24) hours -= days * 24 if options.round_days and hours > 0 days++ hours = null declOfNum = (number, titles) -> cases = [ 2 0 1 1 1 2 ] titles[if number % 100 > 4 && number % 100 < 20 then 2 else cases[if number % 10 < 5 then number % 10 else 5]] if days == 0 days_text = texts.days.zero else days_text = declOfNum(days, [texts.days.one, texts.days.few, texts.days.many]) days_text = days_text.replace('{}', days) if days_text if hours == 0 hours_text = texts.hours.zero else hours_text = declOfNum(hours, [texts.hours.one, texts.hours.few, texts.hours.many]) hours_text = hours_text.replace('{}', hours) if hours_text # console.log 'formattedHours', "#{days_text} #{hours_text}".trim return "#{days_text} #{hours_text}".trim() )
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
translation_cms-0.1.5 | app/assets/javascripts/app/filters/formatted_hours.js.coffee |