import moment from 'moment'

export default class DatesUtils {
  private $moment: typeof moment;

  constructor (momentInstance: any) {
    this.$moment = momentInstance
  }

  /**
   * Formate la ou les dates au format donné
   *
   * @param dates
   * @param format
   */
  formattedDate (dates: any, format: string): string {
    const dFormat: Array<string> = []
    if (Array.isArray(dates)) {
      for (const date of dates) {
        dFormat.push(this.$moment(date).format(format))
      }
    } else {
      dFormat.push(this.$moment(dates as string).format(format))
    }
    return dFormat.join(' - ')
  }

  /**
   * Trie les dates par ordre chronologique
   * @param dates
   */
  sortDate (dates: Array<string>): Array<string> {
    return dates.sort()
  }
}
