const dataProcessing = {
  isValidUrl(url) {
    if (url) return /^(ftp|http|https):\/\/[^ "]+\.+[^ "]+$/.test(url)
    else return true
  },

  formatDatetime(date) {
    let d = new Date(date)
    let month = '' + (d.getMonth() + 1)
    let day = '' + d.getDate()
    let year = d.getFullYear()

    if (month.length < 2) month = '0' + month
    if (day.length < 2) day = '0' + day

    let formattedDate = [day, month, year].join('/')

    let hour = d.getHours()
    let minutes = d.getMinutes()

    let formattedTime = [hour, minutes].join(':')

    let formattedDatetime = [formattedDate, formattedTime].join(' ')

    return formattedDatetime
  },
}

export default dataProcessing
