       scope.position = date.toDate()
 
 
-    ###
-      Helper method that split the steps by week
-    ###
+    #
+    # Compute a boolean value that indicate if
+    # switching to the next view would put the
+    # cursor on a date after maxDate.
+    #
+    # Returns true if maxDate is not defined.
+    #
+    canNextView = ->
+      if not scope.maxDate?
+        return true
+      else
+        return moment(scope.selected).add(steps[scope.view].next).isBefore(scope.maxDate)
+
+    #
+    # Compute a boolean value that indicate if
+    # switching to the previous view would put the
+    # cursor on a date before minDate.
+    #
+    # Returns true if minDate is not defined.
+    #
+    canPreviousView = ->
+      if not scope.minDate?
+        return true
+      else
+        return moment(scope.selected).add(steps[scope.view].previous).isAfter(scope.minDate)
+
+    #
+    #  Helper method that split the steps by week
+    #
     splitByWeeks = (steps = []) ->
+      return if not scope.steps?
+
       lastWeek = null
       stepsByWeek = []
       for step in steps

      -steps[scope.view].line

    scope.keyPress = ($event) ->

      selected = moment(scope.selected)

      switch $event.keyCode

          stepsByWeek.push []
          lastWeek = week
        stepsByWeek[stepsByWeek.length - 1].push step

      return stepsByWeek

    scope.$watch('minDate + maxDate + steps.length', ->
      return if not scope.steps?
      for step in scope.steps
        stepDate = moment(step.value)
        afterMinimum = if scope.minDate? then stepDate.isAfter(scope.minDate, scope.view) else true
        beforeMaximum = if scope.maxDate? then stepDate.isBefore(scope.maxDate, scope.view) else true
        step.selectable = afterMinimum and beforeMaximum
    )

    scope.$watch('activeBefore + activeAfter + steps.length', ->
      return if not scope.steps?
      for step in scope.steps
        stepDate = moment(step.value)
        if not scope.activeBefore? and not scope.activeAfter?
          step.active = false
        else
          isBefore = if scope.activeBefore? then stepDate.isBefore(scope.activeBefore, scope.view) or stepDate.isSame(scope.activeBefore, scope.view) else true
          isAfter = if scope.activeAfter? then stepDate.isAfter(scope.activeAfter, scope.view) or stepDate.isSame(scope.activeAfter, scope.view) else true
          step.active = isBefore and isAfter
    )

    scope.$watch('selected + steps.length', ->
      return if not scope.steps?

      for step in scope.steps
        step.selected = moment(step.value).isSame(scope.selected, scope.view)

      scope.$canNext = canNextView()
      scope.$canPrevious = canPreviousView()
    )

    scope.$watch('position + view', ->
      # Position only.
      step = steps[scope.view]
      stepDate = step.first(moment(scope.position))
      period = step.step
      amount = step.amount

      # TODO: Fix this!
      lowerDate = moment(scope.position).startOf(scope.view)
      upperDate = moment(scope.position).add(1, scope.view)
      console.log "#{ lowerDate.format() } -> #{ lowerDate.format() } (#{  scope.view })"

      scope.steps = for i in [0..amount] by 1
        stepDate.add(period)
        {
        past: moment(stepDate).isBefore(lowerDate)
        future: moment(stepDate).isAfter(upperDate)
        formatted: moment(stepDate).format(step.format)
        value: moment(stepDate).toDate()
        }
      scope.byWeeks = splitByWeeks(scope.steps) if scope.view == 'day'
      return
    )


    #
    # Return the next view value.
