     d.setMilliseconds(0)
     return d.getTime()
 
+  last_month_no_later_than = (time) ->
+    d = new Date(time)
+    d.setDate(1)
+    d.setHours(0)
+    d.setMinutes(0)
+    d.setSeconds(0)
+    d.setMilliseconds(0)
+    return d.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 SimpleScale extends CompositeScale
    constructor: (intervals) ->
      super(intervals.map((interval) ->

      best_scale_ix = scale_ixs[argmin(errors)]
      best_scale = @scales[best_scale_ix]

      console.log("Selected #{best_scale.constructor.name}")

      return best_scale

