@PlasticineHelpers = {} PlasticineHelpers.parseValue = (value, format) -> switch format when 'date' then new Date(value) else value PlasticineHelpers.setLocale = () -> d3.timeFormatDefaultLocale( "decimal": ",", "thousands": " ", "grouping": [3], "currency": ["$", ""], "dateTime": "%a %b %e %X %Y", "date": "%d-%m-%Y", "time": "%H:%M:%S", "periods": ["AM", "PM"], "days": ["Dimanche", "Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi"], "shortDays": ["Dim", "Lun", "Mar", "Mer", "Jeu", "Ven", "Sam"], "months": ["Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre"], "shortMonths": ["Jan", "Fev", "Mar", "Avr", "Mai", "Jun", "Jul", "Aou", "Sep", "Oct", "Nov", "Dec"] ) PlasticineHelpers.toPrice = (amount) -> if amount is 0 price = "0" else price = String(amount)[0..-3] price = "0" if price is "" price = switch price.length when 4 then [price.slice(0, 1), ' ', price.slice(1)].join('') when 5 then [price.slice(0, 2), ' ', price.slice(2)].join('') when 6 then [price.slice(0, 3), ' ', price.slice(3)].join('') when 7 then [price.slice(0, 1), ' ', price.slice(1, 4), ' ', price.slice(4)].join('') when 8 then [price.slice(0, 2), ' ', price.slice(2, 5), ' ', price.slice(4)].join('') else price # Show decimals #price += ',' + String(amount).slice(-2) price += ' $' PlasticineHelpers.toQuarter = (strDate, quarterStartMonth) -> date = new Date(strDate + 'T12:00:00') month = date.getMonth() + 1 monthEquiv = (month + (13 - quarterStartMonth)) % 12 value = switch when monthEquiv <= 3 then 'Q1' when monthEquiv <= 6 then 'Q2' when monthEquiv <= 9 then 'Q3' else 'Q4' year = Number(date.getFullYear()) if (value is "Q1" and quarterStartMonth >= 10) or ((value is "Q1" or value is "Q2") and quarterStartMonth >= 7 and quarterStartMonth < 10) year += 1 value += " #{year}" value PlasticineHelpers.toYear = (strDate, quarterStartMonth) -> date = new Date(strDate + 'T12:00:00') year = Number(date.getFullYear()) if quarterStartMonth >= 7 and (date.getMonth() + 1) >= 7 year += 1 year