     d.setMilliseconds(0)
     return d.getTime()
 
+  last_year_no_later_than = (time) ->
+    d = new Date(time)
+    d.setMonth(0)
+    d.setDate(1)
+    d.setHours(0)
+    d.setMinutes(0)
+    d.setSeconds(0)
+    d.setMilliseconds(0)
+    return d.getTime()
+
+  copy_date = (date) ->
+    return new Date(date.getTime())
+
   add_days = (time, n_days) ->
     d = new Date(time)
     d.setDate(d.getDate() + n_days)

      console.log(ticks.map((time) -> new Date(time)))
      return ticks

  class DaysScale extends SingleIntervalScale
    constructor: (@days) ->
      @typical_interval = if @days.length > 1

      # FIXME Use a list comprehension?
      day_dates = _.flatten(month_dates.map((date) -> days_of_month(date)))

      all_ticks = _.invoke(day_dates, 'getTime')
      # FIXME Since the ticks are sorted, this could be done more efficiently.
      ticks_in_range = _.filter(all_ticks,
                                ((tick) -> data_low <= tick <= data_high))

      # FIXME Continue here:
      # Transition between 12-hour and 24-hour resolutions is not correct.
      # This is because the day resolutions are aligned with the local time
      # zone, and the resolutions below are aligned with GMT.

      return ticks_in_range

