/**
 * Created by fran lopez on 26/01/16.
 */

    /**
     * AngularJS filter. Filters in AngularJS are used to filter
     * information from models in the different views.
     *
     * There is a few situations, when a DOM attribute must be
     * formatted following patterns.
     *
     * In this case, a book's publication date must be formatted to
     * be more understandable for the application users.
     */

    angular.module('books').filter('filterToFormatPublicationDate',
        [function () {
                return function (publicationDate) {
                    var publicationDateInStringFormat = String('');

                    publicationDate = new Date(publicationDate);

                    if (publicationDate.getDate() < 10)
                        publicationDateInStringFormat += '0' + publicationDate.getDate() + '/';
                    else
                        publicationDateInStringFormat   += publicationDate.getDate() + '/';

                    if ((publicationDate.getMonth() + 1) < 10)
                        publicationDateInStringFormat += '0' + (publicationDate.getMonth() + 1) + '/';
                    else
                        publicationDateInStringFormat += (publicationDate.getMonth() + 1) + '/';

                    publicationDateInStringFormat += publicationDate.getFullYear();

                    return publicationDateInStringFormat;
                };
            }
        ]
    );