'use strict';

angular.module('qusion.common.date', [])
    .factory('Date', [
        function() {
            var daysBetween = function (date1, date2) {
                if (!date1 || !date2)
                    return 0;

                //Get 1 day in milliseconds
                var oneday = 1000 * 60 * 60 * 24;

                // Convert both dates to milliseconds
                var date1ms = date1.getTime();
                var date2ms = date2.getTime();

                // Calculate the difference in milliseconds
                var differencems = date2ms - date1ms;

                // Convert back to days and return
                return Math.round(differencems / oneday);
            };

            return {
                daysBetween: daysBetween
            };
        }
    ]);