var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import moment from 'moment';
import { noView } from 'aurelia-framework';
export var DateFormatValueConverter = (function () {
    function DateFormatValueConverter() {
    }
    DateFormatValueConverter.prototype.toView = function (value, format) {
        console.debug('toview ' + value);
        if (!value) {
            console.debug('toview return null');
            return null;
        }
        var m = moment(value);
        if (m.isValid()) {
            console.debug('toview return formatted date');
            return m.format(format);
        }
        if (!m.isValid()) {
            console.debug('toview not valid date return value');
            return value;
        }
        if (m.year() <= 1970) {
            console.debug('toview year <= 1970 return empty');
            return "";
        }
        console.debug('toview return value');
        return value;
    };
    DateFormatValueConverter.prototype.fromView = function (value) {
        var m = moment(value, 'DD/MM/YYYY', true);
        if (m.isValid()) {
            console.debug('input correctly parsed as date', m.toDate());
            return m.set("hour", 12).toDate();
        }
        console.debug('not a date', value);
        console.debug('return null');
        return null;
    };
    DateFormatValueConverter = __decorate([
        noView
    ], DateFormatValueConverter);
    return DateFormatValueConverter;
}());

//# sourceMappingURL=date-format-value-converter.js.map
