export const sleep = delay => new Promise((resolve) => setTimeout(resolve, delay)); export const isEmptyObject = obj => Object.keys(obj).length === 0; export const padZeros = str => (('00' + str).slice(-2)); export const setThemeColor = color => document.querySelector('meta[name="theme-color"]').setAttribute('content', color); export const queryBackgroundColor = (target, query) => window.getComputedStyle(target.querySelector(query)).getPropertyValue('background-color'); export class CustomDate extends Date { formatDate() { return `${this.getDate()}.${this.getMonth() + 1}.${this.getFullYear()}`; } formatISODate() { return `${this.getFullYear()}-${padZeros(this.getMonth()+1)}-${padZeros(this.getDate())}`; } formatISODateTime() { return `${this.formatISODate()}T${this.formatTime()}`; } formatTime() { return `${padZeros(this.getHours())}:${padZeros(this.getMinutes())}`; } setDate(value) { const splitValue = value.split('-'); if (splitValue.length !== 3) return false; this.setFullYear(splitValue[0], splitValue[1]-1, splitValue[2]); } setTime(value) { const splitValue = value.split(':'); if (splitValue.length !== 2) return false; this.setHours(splitValue[0], splitValue[1]); } setDateTime(value) { const splitValue = value.split('T'); if (splitValue.length !== 2) return false; this.setDate(splitValue[0]); this.setTime(splitValue[1]); } }