'use strict'

var utils = require('../utils')

module.exports = intervals




/**
 * Set intervals
 *
 * Use two date arguments if you specify one interval.
 *
 * In other cases use array arguments: each one will represent different interval.
 *
 * @param {string|number|Date} [start] Start time
 * @param {string|number|Date} [end] End time
 * @param {...array} [intervals]
 * @returns {string[]}
 */
function intervals(start, end, intervals) {
  if (!Array.isArray(start)) {
    intervals = [utils.args(arguments, 0)]
  }
  else {
    intervals = utils.args(arguments, 0)
  }

  return intervals.map(function(interval) {
    return interval.map(function(arg) {
      if (!(arg instanceof Date)) {
        arg = new Date(arg)
      }

      return JSON.stringify(arg).replace(/"/g, '')
    }).join('/')
  })
}
@@ -10,16 +10,65 @@
 ct'%0A%0Avar
+ FieldError = require('../errors').FieldError%0A  ,
  utils =
@@ -88,16 +88,16 @@
 utils')%0A
-
 %0Amodule.
@@ -493,16 +493,127 @@
  %7B%0A  if 
+(arguments.length === 0) %7B%0A    throw new FieldError('At least one interval should be specified')%0A  %7D%0A  else if 
 (!Array.
@@ -826,64 +826,98 @@
     
-if (!(arg instanceof Date)) %7B%0A        arg = new Date(arg
+arg = utils.date(arg)%0A%0A      if (!arg) %7B%0A        throw new FieldError('Bad date specified'
 )%0A  

add validations