         @changeDates 'month'
 
     changeDates: (type) ->
-        value = moment().subtract(1, type).startOf(type) if type
+        value = moment().subtract(1, type) if type
         state =
             isActive    : !!type
-            startDate   : value?.format momentFormat
-            endDate     : value?.endOf(type).format momentFormat
+            startDate   : start = value?.startOf(type).format momentFormat
+            endDate     : end = value?.endOf(type).format momentFormat
 
         @setState state, @filterize
 


momentFormat     = 'DD/MM/YYYY'
datePickerFormat = '%d/%m/%Y'


module.exports = DateRangePicker = React.createClass
    displayName: 'DateRangePicker'



    filterize: ->
        getValue = (key) =>
            return unless (value = @state[key + 'Date'])
            moment(value, momentFormat)[key + 'Of']('day').toISOString()

        @props.onDateFilter getValue('start'), getValue('end')


    onReset: ->
