datesUtils.ts 773 B

1234567891011121314151617181920212223242526272829303132333435
  1. import moment from 'moment'
  2. export default class DatesUtils {
  3. private $moment: typeof moment;
  4. constructor (momentInstance: any) {
  5. this.$moment = momentInstance
  6. }
  7. /**
  8. * Formate la ou les dates au format donné
  9. *
  10. * @param dates
  11. * @param format
  12. */
  13. formattedDate (dates: any, format: string): string {
  14. const dFormat: Array<string> = []
  15. if (Array.isArray(dates)) {
  16. for (const date of dates) {
  17. dFormat.push(this.$moment(date).format(format))
  18. }
  19. } else {
  20. dFormat.push(this.$moment(dates as string).format(format))
  21. }
  22. return dFormat.join(' - ')
  23. }
  24. /**
  25. * Trie les dates par ordre chronologique
  26. * @param dates
  27. */
  28. sortDate (dates: Array<string>): Array<string> {
  29. return dates.sort()
  30. }
  31. }