import ngModule from '../module'; class WeekDays { constructor($translate) { this.$translate = $translate; this.days = [ { code: 'sun', name: 'Sunday' }, { code: 'mon', name: 'Monday' }, { code: 'tue', name: 'Tuesday' }, { code: 'wed', name: 'Wednesday' }, { code: 'thu', name: 'Thursday' }, { code: 'fri', name: 'Friday' }, { code: 'sat', name: 'Saturday' } ]; this.map = {}; for (let i = 0; i < this.days.length; i++) { let day = this.days[i]; day.index = i; day.char = day.name.substr(0, 1); day.abr = day.name.substr(0, 3); this.map[day.code] = day; } this.getLocales(); } getLocales() { for (let day of this.days) { let locale = this.$translate.instant(day.name); Object.assign(day, { locale, localeChar: locale.substr(0, 1), localeAbr: locale.substr(0, 3) }); } this.localeCodes = [ 'mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun' ]; this.locales = []; for (let code of this.localeCodes) this.locales.push(this.map[code]); } } WeekDays.$inject = ['$translate']; ngModule.service('vnWeekDays', WeekDays);