PresentationDate

by Mike McCaughan

HTML

<ul id="debug">
</ul>

JavaScript

'use strict';
            var PresentationDate = (function () {
                function PresentationDate() {
                    var args = [];
                    for (var _i = 0; _i < arguments.length; _i++) {
                        args[_i - 0] = arguments[_i];
                    }
                    // Builds a Date from any arguments passed in, or a new Date if none.
                    // Note that invalid arguments for this constructor will result in an invalid date, just the same as if
                    // passed to the Date constructor directly.
                    this.localDate = args.length ? new (Function.prototype.bind.apply(Date, [null].concat(args))) : new Date();
                }
                PresentationDate.prototype.isValid = function () {
                    return !isNaN(this.localDate.valueOf());
                };
                PresentationDate.prototype.toDate = function () {
                    // Returns a Date, which contains the date value of the current localDate, with no time component, in UTC,
                    // or if the current date is invalid, undefined.
                    // For example, if the current localDate is "Wed Sep 09 2015 16:35:41 GMT-0500 (Central Daylight Time)",
                    // this will return  "Tue Sep 08 2015 19:00:00 GMT-0500 (Central Daylight Time)", which translated to UTC is
                    // "2015-09-09T00:00:00.000Z".
                    if (!this.isValid()) {
                        return;
                    }
                    return new Date(Date.UTC(this.localDate.getFullYear(), this.localDate.getMonth(), this.localDate.getDate()));
                };
                PresentationDate.getNumberOfDaysInMonth = function (year, month) {
                    var lastDay = new Date(year, month + 1, 0);
                    return lastDay.getDate();
                };
                PresentationDate.prototype.numberOfDaysInMonth = function () {
                    return...