1 line
2.1 KiB
JavaScript
Executable File
1 line
2.1 KiB
JavaScript
Executable File
"use strict";window.App.Utils.Date=function(){function format(dateValue){var dateFormatType=1<arguments.length&&arguments[1]!==void 0?arguments[1]:"YMD",timeFormatType=2<arguments.length&&arguments[2]!==void 0?arguments[2]:"regular",withHours=!!(3<arguments.length&&arguments[3]!==void 0)&&arguments[3],dateMoment=moment(dateValue);if(!dateMoment.isValid())throw new Error("Invalid date value provided: ".concat(dateValue));var dateFormat;switch(dateFormatType){case"DMY":dateFormat="DD/MM/YYYY";break;case"MDY":dateFormat="MM/DD/YYYY";break;case"YMD":dateFormat="YYYY/MM/DD";break;default:throw new Error("Invalid date format type provided: ".concat(dateFormatType))}var timeFormat;switch(timeFormatType){case"regular":timeFormat="h:mm a";break;case"military":timeFormat="HH:mm";break;default:throw new Error("Invalid time format type provided: ".concat(timeFormatType))}var format=withHours?"".concat(dateFormat," ").concat(timeFormat):dateFormat;return dateMoment.format(format)}function getWeekdayName(weekDayId){var result;switch(weekDayId){case 0:result="sunday";break;case 1:result="monday";break;case 2:result="tuesday";break;case 3:result="wednesday";break;case 4:result="thursday";break;case 5:result="friday";break;case 6:result="saturday";break;default:throw new Error("Invalid weekday Id provided: ".concat(weekDayId))}return result}return{format:format,getWeekdayId:function(weekDayName){var result;switch(weekDayName.toLowerCase()){case"sunday":case"sun":result=0;break;case"monday":case"mon":result=1;break;case"tuesday":case"tue":result=2;break;case"wednesday":case"wed":result=3;break;case"thursday":case"thu":result=4;break;case"friday":case"fri":result=5;break;case"saturday":case"sat":result=6;break;default:throw new Error("Invalid weekday name provided: ".concat(weekDayName))}return result},sortWeekDictionary:function(weekDictionary,startDayId){for(var weekdayName,sortedWeekDictionary={},i=startDayId;i<startDayId+7;i++)weekdayName=getWeekdayName(i%7),sortedWeekDictionary[weekdayName]=weekDictionary[weekdayName];return sortedWeekDictionary},getWeekdayName:getWeekdayName}}(); |