if (typeof util === "undefined") {
    var util = {};
}

if (!util.date) {
    util.date = (function() {
        // public interface
        return {
            formatDateFromMilliseconds: function(value) {
                return formatDateFromMilliseconds(value);
            }
        };

        // private methods

        function formatDateFromMilliseconds(value) {
            if (!!value) {
                var tmp = parseFloat(value, 10);
                tmp = new Date(tmp);
                tmp = getDateAsString(tmp);
                return getDateFormatted(tmp);
            }
            return "";
        }

        function getDateAsString(date) {
            return date2db(date) + "_";
        }

        function date2db(date) {
            return date2dbN(date) + "";
        }

        function date2dbN(date) {
            return date.getDate() + ((date.getMonth() + 1) * 100) + (date.getFullYear() * 10000);
        }

        function getDateFormatted(date) {
            var dateFormatted = "" + user_.dateFormat;
            if (date.length >= 8) {
                dateFormatted = dateFormatted.replace("dd", date.substr(6, 2));
                dateFormatted = dateFormatted.replace("MM", date.substr(4, 2));
                dateFormatted = dateFormatted.replace("yyyy", date.substr(0, 4));
                dateFormatted = dateFormatted.replace("yy", date.substr(2, 2));
            } else {
                dateFormatted = "";
            }
            return dateFormatted;
        }
    })();
}
