UNPKG

ng-jalali-date-time

Version:

Jalali date / month / range picker for Angular with Material Design support

1,416 lines 88 kB
(function (global, factory) {
    typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/common'), require('@angular/forms'), require('jalali-date-time'), require('@angular/material/button'), require('@angular/material/divider'), require('@angular/material/input'), require('@angular/animations')) :
    typeof define === 'function' && define.amd ? define('ng-jalali-date-time', ['exports', '@angular/core', '@angular/common', '@angular/forms', 'jalali-date-time', '@angular/material/button', '@angular/material/divider', '@angular/material/input', '@angular/animations'], factory) :
    (global = global || self, factory(global['ng-jalali-date-time'] = {}, global.ng.core, global.ng.common, global.ng.forms, global['jalali-date-time'], global.ng.material.button, global.ng.material.divider, global.ng.material.input, global.ng.animations));
}(this, (function (exports, core, common, forms, jalaliDateTime, button, divider, input, animations) { 'use strict';

    /*! *****************************************************************************
    Copyright (c) Microsoft Corporation.

    Permission to use, copy, modify, and/or distribute this software for any
    purpose with or without fee is hereby granted.

    THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
    REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
    AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
    INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
    LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
    OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
    PERFORMANCE OF THIS SOFTWARE.
    ***************************************************************************** */
    /* global Reflect, Promise */
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b)
                if (b.hasOwnProperty(p))
                    d[p] = b[p]; };
        return extendStatics(d, b);
    };
    function __extends(d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    }
    var __assign = function () {
        __assign = Object.assign || function __assign(t) {
            for (var s, i = 1, n = arguments.length; i < n; i++) {
                s = arguments[i];
                for (var p in s)
                    if (Object.prototype.hasOwnProperty.call(s, p))
                        t[p] = s[p];
            }
            return t;
        };
        return __assign.apply(this, arguments);
    };
    function __rest(s, e) {
        var t = {};
        for (var p in s)
            if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
                t[p] = s[p];
        if (s != null && typeof Object.getOwnPropertySymbols === "function")
            for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
                if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                    t[p[i]] = s[p[i]];
            }
        return t;
    }
    function __decorate(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;
    }
    function __param(paramIndex, decorator) {
        return function (target, key) { decorator(target, key, paramIndex); };
    }
    function __metadata(metadataKey, metadataValue) {
        if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
            return Reflect.metadata(metadataKey, metadataValue);
    }
    function __awaiter(thisArg, _arguments, P, generator) {
        function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
        return new (P || (P = Promise))(function (resolve, reject) {
            function fulfilled(value) { try {
                step(generator.next(value));
            }
            catch (e) {
                reject(e);
            } }
            function rejected(value) { try {
                step(generator["throw"](value));
            }
            catch (e) {
                reject(e);
            } }
            function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
            step((generator = generator.apply(thisArg, _arguments || [])).next());
        });
    }
    function __generator(thisArg, body) {
        var _ = { label: 0, sent: function () { if (t[0] & 1)
                throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
        return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g;
        function verb(n) { return function (v) { return step([n, v]); }; }
        function step(op) {
            if (f)
                throw new TypeError("Generator is already executing.");
            while (_)
                try {
                    if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
                        return t;
                    if (y = 0, t)
                        op = [op[0] & 2, t.value];
                    switch (op[0]) {
                        case 0:
                        case 1:
                            t = op;
                            break;
                        case 4:
                            _.label++;
                            return { value: op[1], done: false };
                        case 5:
                            _.label++;
                            y = op[1];
                            op = [0];
                            continue;
                        case 7:
                            op = _.ops.pop();
                            _.trys.pop();
                            continue;
                        default:
                            if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
                                _ = 0;
                                continue;
                            }
                            if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
                                _.label = op[1];
                                break;
                            }
                            if (op[0] === 6 && _.label < t[1]) {
                                _.label = t[1];
                                t = op;
                                break;
                            }
                            if (t && _.label < t[2]) {
                                _.label = t[2];
                                _.ops.push(op);
                                break;
                            }
                            if (t[2])
                                _.ops.pop();
                            _.trys.pop();
                            continue;
                    }
                    op = body.call(thisArg, _);
                }
                catch (e) {
                    op = [6, e];
                    y = 0;
                }
                finally {
                    f = t = 0;
                }
            if (op[0] & 5)
                throw op[1];
            return { value: op[0] ? op[1] : void 0, done: true };
        }
    }
    var __createBinding = Object.create ? (function (o, m, k, k2) {
        if (k2 === undefined)
            k2 = k;
        Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } });
    }) : (function (o, m, k, k2) {
        if (k2 === undefined)
            k2 = k;
        o[k2] = m[k];
    });
    function __exportStar(m, exports) {
        for (var p in m)
            if (p !== "default" && !exports.hasOwnProperty(p))
                __createBinding(exports, m, p);
    }
    function __values(o) {
        var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
        if (m)
            return m.call(o);
        if (o && typeof o.length === "number")
            return {
                next: function () {
                    if (o && i >= o.length)
                        o = void 0;
                    return { value: o && o[i++], done: !o };
                }
            };
        throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
    }
    function __read(o, n) {
        var m = typeof Symbol === "function" && o[Symbol.iterator];
        if (!m)
            return o;
        var i = m.call(o), r, ar = [], e;
        try {
            while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
                ar.push(r.value);
        }
        catch (error) {
            e = { error: error };
        }
        finally {
            try {
                if (r && !r.done && (m = i["return"]))
                    m.call(i);
            }
            finally {
                if (e)
                    throw e.error;
            }
        }
        return ar;
    }
    function __spread() {
        for (var ar = [], i = 0; i < arguments.length; i++)
            ar = ar.concat(__read(arguments[i]));
        return ar;
    }
    function __spreadArrays() {
        for (var s = 0, i = 0, il = arguments.length; i < il; i++)
            s += arguments[i].length;
        for (var r = Array(s), k = 0, i = 0; i < il; i++)
            for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
                r[k] = a[j];
        return r;
    }
    ;
    function __await(v) {
        return this instanceof __await ? (this.v = v, this) : new __await(v);
    }
    function __asyncGenerator(thisArg, _arguments, generator) {
        if (!Symbol.asyncIterator)
            throw new TypeError("Symbol.asyncIterator is not defined.");
        var g = generator.apply(thisArg, _arguments || []), i, q = [];
        return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
        function verb(n) { if (g[n])
            i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
        function resume(n, v) { try {
            step(g[n](v));
        }
        catch (e) {
            settle(q[0][3], e);
        } }
        function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
        function fulfill(value) { resume("next", value); }
        function reject(value) { resume("throw", value); }
        function settle(f, v) { if (f(v), q.shift(), q.length)
            resume(q[0][0], q[0][1]); }
    }
    function __asyncDelegator(o) {
        var i, p;
        return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
        function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
    }
    function __asyncValues(o) {
        if (!Symbol.asyncIterator)
            throw new TypeError("Symbol.asyncIterator is not defined.");
        var m = o[Symbol.asyncIterator], i;
        return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
        function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
        function settle(resolve, reject, d, v) { Promise.resolve(v).then(function (v) { resolve({ value: v, done: d }); }, reject); }
    }
    function __makeTemplateObject(cooked, raw) {
        if (Object.defineProperty) {
            Object.defineProperty(cooked, "raw", { value: raw });
        }
        else {
            cooked.raw = raw;
        }
        return cooked;
    }
    ;
    var __setModuleDefault = Object.create ? (function (o, v) {
        Object.defineProperty(o, "default", { enumerable: true, value: v });
    }) : function (o, v) {
        o["default"] = v;
    };
    function __importStar(mod) {
        if (mod && mod.__esModule)
            return mod;
        var result = {};
        if (mod != null)
            for (var k in mod)
                if (Object.hasOwnProperty.call(mod, k))
                    __createBinding(result, mod, k);
        __setModuleDefault(result, mod);
        return result;
    }
    function __importDefault(mod) {
        return (mod && mod.__esModule) ? mod : { default: mod };
    }
    function __classPrivateFieldGet(receiver, privateMap) {
        if (!privateMap.has(receiver)) {
            throw new TypeError("attempted to get private field on non-instance");
        }
        return privateMap.get(receiver);
    }
    function __classPrivateFieldSet(receiver, privateMap, value) {
        if (!privateMap.has(receiver)) {
            throw new TypeError("attempted to set private field on non-instance");
        }
        privateMap.set(receiver, value);
        return value;
    }

    var JalaliLocale = /** @class */ (function () {
        function JalaliLocale() {
            this.required = 'مشخص کردن مقدار الزامی است';
            this.notSpecified = 'مشخص نشده است';
            this.date = 'تاریخ';
            this.month = 'ماه';
            this.range = 'دوره زمانی';
            this.rangeTo = 'تا';
            this.rangeCustom = 'سفارشی';
            this.rangeCustomConfirm = 'انتخاب';
            this.rangeCurrentWeek = 'هفته جاری';
            this.rangeCurrentMonth = 'ماه جاری';
            this.rangeLast7Days = '۷ روز گذشته';
            this.rangeLast30Days = '۳۰ روز گذشته';
            this.rangeNext7Days = '۷ روز آینده';
            this.rangeNext30Days = '۳۰ روز آینده';
            this.monthNames = [
                'فروردین',
                'اردیبهشت',
                'خرداد',
                'تیر',
                'مرداد',
                'شهریور',
                'مهر',
                'آبان',
                'آذر',
                'دی',
                'بهمن',
                'اسفند'
            ];
            this.dayNames = ['ش', 'ی', 'د', 'س', 'چ', 'پ', 'ج'];
        }
        return JalaliLocale;
    }());

    var NgJalaliDateTimeService = /** @class */ (function () {
        function NgJalaliDateTimeService() {
            this.jalali = jalaliDateTime.JalaliDateTime({
                timezone: 'Asia/Tehran',
                locale: 'en',
                dateFormat: 'Y-M-D',
                timeFormat: 'H:I:S',
                titleFormat: 'W، d N Y',
                fullTextFormat: 'W، d N Y H:I:S',
            });
            this.jalaliLocale = new JalaliLocale();
        }
        NgJalaliDateTimeService.prototype.checkDate = function (date) {
            if (typeof date !== 'string' || date.length !== 10)
                return '';
            if (!date.match(/([0-9]{4}-[0-9]{2}-[0-9]{2})/))
                return '';
            var _a = __read(date.split('-'), 3), year = _a[0], month = _a[1], day = _a[2];
            if (Number(year) < 1000 || Number(year) > 4000)
                return '';
            if (Number(month) < 1 || Number(month) > 12)
                return '';
            if (Number(day) < 1 || Number(day) > 31)
                return '';
            return date;
        };
        NgJalaliDateTimeService.prototype.checkTime = function (time) {
            if (typeof time !== 'string' || time.length !== 8)
                return '';
            if (!time.match(/([0-9]{2}:[0-9]{2}:[0-9]{2})/))
                return '';
            var _a = __read(time.split('-'), 3), hour = _a[0], minute = _a[1], second = _a[2];
            if (Number(hour) < 0 || Number(hour) > 23)
                return '';
            if (Number(minute) < 0 || Number(minute) > 59)
                return '';
            if (Number(second) < 0 || Number(second) > 59)
                return '';
            return time;
        };
        NgJalaliDateTimeService.prototype.checkMonth = function (date) {
            if (typeof date !== 'string' || date.length !== 7)
                return '';
            if (!date.match(/([0-9]{4}-[0-9]{2})/))
                return '';
            var _a = __read(date.split('-'), 2), year = _a[0], month = _a[1];
            if (Number(year) < 1000 || Number(year) > 4000)
                return '';
            if (Number(month) < 1 || Number(month) > 12)
                return '';
            return date;
        };
        NgJalaliDateTimeService.prototype.checkAppearance = function (appearance) {
            return ['legacy', 'standard', 'fill', 'outline'].includes(appearance) ? appearance : 'legacy';
        };
        NgJalaliDateTimeService.prototype.setFontCSS = function (css, font) {
            return Object.assign(Object.assign({}, css), { fontFamily: font });
        };
        NgJalaliDateTimeService.prototype.checkCSS = function (css) {
            if (!css)
                css = {};
            css.font = css.font ? css.font : "Roboto, 'Helvetica Neue', sans-serif";
            css.field = css.field ? css.field : {};
            css.input = this.setFontCSS(css.input ? css.input : {}, css.font);
            css.reset = css.reset ? css.reset : {};
            css.box = css.box ? css.box : {};
            css.arrow = css.arrow ? css.arrow : {};
            css.header = this.setFontCSS(css.header ? css.header : {}, css.font);
            css.item = this.setFontCSS(css.item ? css.item : {}, css.font);
            css.selected = css.selected ? css.selected : {};
            css.selected = Object.assign(Object.assign({}, css.item), css.selected);
            css.current = css.current ? css.current : {};
            css.current = Object.assign(Object.assign({}, css.item), css.current);
            if (!css.date)
                css.date = {};
            css.date.name = this.setFontCSS(css.date.name ? css.date.name : {}, css.font);
            css.date.time = this.setFontCSS(css.date.time ? css.date.time : {}, css.font);
            if (!css.month)
                css.month = {};
            if (!css.range)
                css.range = {};
            css.range.tool = this.setFontCSS(css.range.tool ? css.range.tool : {}, css.font);
            css.range.custom = css.range.custom ? css.range.custom : {};
            css.range.custom = Object.assign(Object.assign({}, css.range.tool), css.range.custom);
            css.range.confirm = css.range.confirm ? css.range.confirm : {};
            css.range.confirm = Object.assign(Object.assign(Object.assign({}, css.range.tool), css.range.custom), css.range.confirm);
            css.range.name = this.setFontCSS(css.range.name ? css.range.name : {}, css.font);
            css.range.date = this.setFontCSS(css.range.date ? css.range.date : {}, css.font);
            return css;
        };
        NgJalaliDateTimeService.prototype.jalaliToGregorian = function (jalali, time) {
            var gregorian = this.jalali.gregorian(jalali).date;
            return new Date(gregorian + 'T' + (this.checkTime(time) ? time : '12:00:00'));
        };
        NgJalaliDateTimeService.prototype.getCalendar = function (month) {
            var now = this.jalaliToGregorian(month + '-01');
            var title = this.jalali.toFullText(now, { format: 'N Y' });
            var begin = now;
            while (begin.getDay() !== 6)
                begin = new Date(begin.getTime() - 24 * 3600 * 1000);
            var weeks = [];
            var days = [];
            var date = this.jalali.toDate(begin);
            while (date.substr(0, 7) <= month || days.length % 7 !== 0) {
                days.push({
                    date: date,
                    month: date.substr(0, 7),
                    day: Number(date.substr(8)),
                });
                if (days.length === 7) {
                    weeks.push({ days: days });
                    days = [];
                }
                begin = new Date(begin.getTime() + 24 * 3600 * 1000);
                date = this.jalali.toDate(begin);
            }
            return { month: month, title: title, weeks: weeks };
        };
        NgJalaliDateTimeService.prototype.getDayInMonth = function (month) {
            var _a = __read(month.split('-'), 2), Y = _a[0], M = _a[1];
            if (Number(M) < 7)
                return 31;
            if (Number(M) < 12)
                return 30;
            var date = this.jalaliToGregorian(month + '-30');
            var check = this.jalali.toString(date, { format: 'Y-M-D' }).substr(0, 7);
            return check === month ? 30 : 29;
        };
        /*
         * DATETIME
         */
        NgJalaliDateTimeService.prototype.getDateTimeValue = function (jalali, time) {
            var gregorian = jalali ? this.jalali.gregorian(jalali).date : '';
            var date = gregorian ? new Date(gregorian + 'T' + (time ? time : '12:00:00')) : null;
            var timestamp = gregorian ? Math.floor(date.getTime() / 1000) : null;
            time = time ? time : '00:00:00';
            return {
                jalali: jalali,
                gregorian: gregorian,
                date: date,
                time: time,
                timestamp: timestamp,
            };
        };
        NgJalaliDateTimeService.prototype.getDateTimeTitle = function (value, time) {
            if (!value.jalali)
                return '';
            return time ? this.jalali.toFullText(value.date) : this.jalali.toTitle(value.date);
        };
        /*
         * MONTH
         */
        NgJalaliDateTimeService.prototype.getMonthValue = function (month) {
            var days = 0;
            var gregorian = { first: '', last: '' };
            if (month) {
                days = this.getDayInMonth(month);
                gregorian.first = this.jalali.gregorian(month + '-01').date;
                gregorian.last = this.jalali.gregorian(month + '-' + days.toString()).date;
            }
            return {
                month: month,
                days: days,
                gregorian: gregorian,
            };
        };
        NgJalaliDateTimeService.prototype.getMonthTitle = function (value) {
            if (!value.month)
                return '';
            var date = this.jalaliToGregorian(value.month + '-01');
            return this.jalali.toTitle(date, { format: 'N Y' });
        };
        /*
         * RANGE
         */
        NgJalaliDateTimeService.prototype.getRangeValue = function (from, to) {
            var days = 0;
            var hours = 0;
            var minutes = 0;
            var seconds = 0;
            var gregorian = { from: '', to: '' };
            if (from && to) {
                gregorian.from = this.jalali.gregorian(from).date;
                gregorian.to = this.jalali.gregorian(to).date;
                var fTimestamp = Math.floor(new Date(gregorian.from + 'T12:00:00').getTime() / 1000);
                var tTimestamp = Math.floor(new Date(gregorian.to + 'T12:00:00').getTime() / 1000);
                days = Math.floor(Math.abs((tTimestamp - fTimestamp) / (24 * 3600))) + 1;
                hours = days * 24;
                minutes = hours * 60;
                seconds = minutes * 60;
            }
            return {
                range: from && to ? from + '|' + to : '',
                from: from,
                to: to,
                days: days,
                hours: hours,
                minutes: minutes,
                seconds: seconds,
                gregorian: gregorian,
            };
        };
        NgJalaliDateTimeService.prototype.getRangeTitle = function (value) {
            if (!value.from || !value.to)
                return '';
            var fDate = this.jalaliToGregorian(value.from);
            var tDate = this.jalaliToGregorian(value.to);
            var _a = __read(value.from.split('-'), 3), fY = _a[0], fM = _a[1], fD = _a[2];
            var _b = __read(value.to.split('-'), 3), tY = _b[0], tM = _b[1], tD = _b[2];
            var from = '';
            if (fY === tY && fM === tM) {
                from = this.jalali.toTitle(fDate, { format: 'd' });
            }
            else if (fY === tY) {
                from = this.jalali.toTitle(fDate, { format: 'd N' });
            }
            else {
                from = this.jalali.toTitle(fDate, { format: 'd N Y' });
            }
            return from + ' ' + this.jalaliLocale.rangeTo + ' ' + this.jalali.toTitle(tDate, { format: 'd N Y' });
        };
        return NgJalaliDateTimeService;
    }());
    NgJalaliDateTimeService.decorators = [
        { type: core.Injectable }
    ];
    NgJalaliDateTimeService.ctorParameters = function () { return []; };

    var MaterialModule = /** @class */ (function () {
        function MaterialModule() {
        }
        return MaterialModule;
    }());
    MaterialModule.decorators = [
        { type: core.NgModule, args: [{
                    exports: [input.MatInputModule, button.MatButtonModule, divider.MatDividerModule],
                },] }
    ];

    var NgJalaliDateTimeComponent = /** @class */ (function () {
        function NgJalaliDateTimeComponent(service) {
            this.service = service;
            this.show = false;
            this.random = Date.now().toString();
            this.month = '';
            this.today = '';
            this.reset = false;
            this.jalaliLocale = new JalaliLocale();
            this.week = this.jalaliLocale.dayNames;
            this.changed = new core.EventEmitter();
        }
        NgJalaliDateTimeComponent.prototype.ngOnInit = function () {
            this.month = this.value.jalali ? this.value.jalali.substr(0, 7) : this.service.jalali.now({ format: 'Y-M' });
            this.calendar = this.service.getCalendar(this.month);
            this.today = this.service.jalali.now({ format: 'Y-M-D' });
            var validators = [];
            if (this.config.required)
                validators.push(this.validate.bind(this));
            this.form.addControl(this.name, new forms.FormControl(this.value));
            this.form.addControl(this.name + '-title', new forms.FormControl('', validators));
            this.setTitle();
        };
        NgJalaliDateTimeComponent.prototype.validate = function () {
            return this.value.jalali ? null : { required: true };
        };
        NgJalaliDateTimeComponent.prototype.showCalendar = function (show) {
            var input = document.querySelector('#input' + this.random);
            input.blur();
            if (this.reset) {
                this.reset = false;
                show = false;
            }
            this.show = show;
            if (this.show) {
                this.form.get(this.name + '-title').markAsUntouched();
                if (!this.value.jalali)
                    this.value.time = '00:00:00';
                this.month = this.value.jalali
                    ? this.value.jalali.substr(0, 7)
                    : this.service.jalali.now({ format: 'Y-M' });
                this.calendar = this.service.getCalendar(this.month);
            }
            else
                this.form.get(this.name + '-title').markAsTouched();
        };
        NgJalaliDateTimeComponent.prototype.changeMonth = function (change) {
            var _a = __read(this.month.split('-'), 2), Y = _a[0], M = _a[1];
            var year = Number(Y);
            var month = Number(M) + change;
            while (month > 12) {
                month -= 12;
                year++;
            }
            while (month < 1) {
                month += 12;
                year--;
            }
            this.month = year.toString() + '-' + (month < 10 ? '0' : '') + month.toString();
            this.calendar = this.service.getCalendar(this.month);
        };
        NgJalaliDateTimeComponent.prototype.setTitle = function () {
            this.form.get(this.name).setValue(this.value);
            var title = this.service.getDateTimeTitle(this.value, this.config.time);
            this.form.get(this.name + '-title').setValue(title);
        };
        NgJalaliDateTimeComponent.prototype.setDate = function (jalali) {
            this.value = this.service.getDateTimeValue(jalali, this.value.time);
            this.setTitle();
            this.showCalendar(false);
            this.changed.emit(this.value.jalali ? this.value : null);
            this.form.get(this.name + '-title').updateValueAndValidity();
        };
        NgJalaliDateTimeComponent.prototype.getTime = function (type) {
            if (!this.value.time)
                return 0;
            var value = 0;
            switch (type) {
                case 'H':
                    value = Number(this.value.time.substr(0, 2));
                    break;
                case 'I':
                    value = Number(this.value.time.substr(3, 2));
                    break;
                case 'S':
                    value = Number(this.value.time.substr(6, 2));
                    break;
            }
            return isNaN(value) ? 0 : value;
        };
        NgJalaliDateTimeComponent.prototype.setTime = function () {
            var hour = document.querySelector('#hour' + this.random);
            var minute = document.querySelector('#minute' + this.random);
            var second = document.querySelector('#second' + this.random);
            var H = Math.floor(Number(hour.value));
            H = isNaN(H) || H < 0 || H > 23 ? 0 : H;
            hour.value = H.toString();
            var I = Math.floor(Number(minute.value));
            I = isNaN(I) || I < 0 || I > 59 ? 0 : I;
            minute.value = I.toString();
            var S = Math.floor(Number(second.value));
            S = isNaN(S) || S < 0 || S > 59 ? 0 : S;
            second.value = this.config.second ? S.toString() : '00';
            var time = (H < 10 ? '0' : '') +
                H.toString() +
                ':' +
                ((I < 10 ? '0' : '') + I.toString()) +
                ':' +
                ((S < 10 ? '0' : '') + S.toString());
            this.value = this.service.getDateTimeValue(this.value.jalali, time);
            this.setTitle();
            this.changed.emit(this.value.jalali ? this.value : null);
            this.form.get(this.name + '-title').updateValueAndValidity();
        };
        return NgJalaliDateTimeComponent;
    }());
    NgJalaliDateTimeComponent.decorators = [
        { type: core.Component, args: [{
                    template: "<div class=\"ng-jalali-back\" *ngIf=\"show\" (click)=\"showCalendar(false)\"></div>\n\n<div [formGroup]=\"form\" [ngStyle]=\"{ display: 'none' }\">\n    <input type=\"text\" [formControlName]=\"name\" />\n</div>\n\n<content class=\"ng-jalali\" dir=\"rtl\">\n    <mat-form-field [ngStyle]=\"css.field\" class=\"ng-jalali\" [formGroup]=\"form\" [appearance]=\"appearance\">\n        <mat-label [ngStyle]=\"{ fontFamily: css.font }\">{{ label }}</mat-label>\n        <input\n            matInput\n            id=\"input{{ random }}\"\n            type=\"text\"\n            [formControlName]=\"name + '-title'\"\n            (focus)=\"showCalendar(true)\"\n            [ngStyle]=\"css.input\"\n            class=\"ng-jalali\"\n        />\n        <span *ngIf=\"config.reset && value.jalali !== ''\" matSuffix (click)=\"setDate(''); reset = true\">\n            <button mat-button type=\"button\" [ngStyle]=\"css.reset\" class=\"ng-jalali-reset\">x</button>\n        </span>\n        <mat-error [ngStyle]=\"{ fontFamily: css.font }\" *ngIf=\"form.get(name + '-title').hasError('required')\">\n            {{ config.error }}\n        </mat-error>\n    </mat-form-field>\n\n    <div class=\"ng-jalali-calendar\" [ngStyle]=\"css.box\" [@calendar] *ngIf=\"show\">\n        <div class=\"ng-jalali-header\">\n            <div>\n                <button\n                    mat-icon-button\n                    type=\"button\"\n                    [ngStyle]=\"css.arrow\"\n                    (click)=\"changeMonth(-12)\"\n                    [disabled]=\"month.substr(0, 4) === '1000'\"\n                >\n                    &lt;&lt;\n                </button>\n            </div>\n            <div>\n                <button\n                    mat-icon-button\n                    type=\"button\"\n                    [ngStyle]=\"css.arrow\"\n                    (click)=\"changeMonth(-1)\"\n                    [disabled]=\"month === '1000-01'\"\n                >\n                    &lt;\n                </button>\n            </div>\n            <div class=\"ng-jalali-title\" [ngStyle]=\"css.header\">{{ calendar.title }}</div>\n            <div>\n                <button mat-icon-button type=\"button\" [ngStyle]=\"css.arrow\" (click)=\"changeMonth(1)\">&gt;</button>\n            </div>\n            <div>\n                <button mat-icon-button type=\"button\" [ngStyle]=\"css.arrow\" (click)=\"changeMonth(12)\">&gt;&gt;</button>\n            </div>\n        </div>\n        <div class=\"ng-jalali-date-time-header\">\n            <div [ngStyle]=\"css.date.name\" *ngFor=\"let day of week\">{{ day }}</div>\n        </div>\n        <div *ngFor=\"let week of calendar.weeks\" class=\"ng-jalali-date-time-week\">\n            <div *ngFor=\"let day of week.days\" class=\"ng-jalali-date-time-day\">\n                <button\n                    mat-icon-button\n                    type=\"button\"\n                    [disabled]=\"\n                        day.month !== month ||\n                        (config.min && day.date < config.min) ||\n                        (config.max && day.date > config.max)\n                    \"\n                    [ngClass]=\"{\n                        'ng-jalali-selected': day.date === value.jalali,\n                        'ng-jalali-current': day.date === today\n                    }\"\n                    [ngStyle]=\"day.date === today ? css.current : day.date === value.jalali ? css.selected : css.item\"\n                    (click)=\"setDate(day.date)\"\n                >\n                    {{ day.day }}\n                </button>\n            </div>\n        </div>\n        <ng-container *ngIf=\"config.time\">\n            <mat-divider></mat-divider>\n            <div class=\"ng-jalali-date-time-time\">\n                <input\n                    type=\"number\"\n                    min=\"0\"\n                    max=\"23\"\n                    step=\"1\"\n                    [value]=\"getTime('H')\"\n                    [ngStyle]=\"css.date.time\"\n                    id=\"hour{{ random }}\"\n                    (blur)=\"setTime()\"\n                />\n                <div>:</div>\n                <input\n                    type=\"number\"\n                    min=\"0\"\n                    max=\"59\"\n                    step=\"1\"\n                    [value]=\"getTime('I')\"\n                    [ngStyle]=\"css.date.time\"\n                    id=\"minute{{ random }}\"\n                    (blur)=\"setTime()\"\n                />\n                <div>:</div>\n                <input\n                    type=\"number\"\n                    min=\"0\"\n                    max=\"59\"\n                    step=\"1\"\n                    [disabled]=\"!config.second\"\n                    [value]=\"config.second ? getTime('S') : '00'\"\n                    [ngStyle]=\"css.date.time\"\n                    id=\"second{{ random }}\"\n                    (blur)=\"setTime()\"\n                /></div\n        ></ng-container>\n    </div>\n</content>\n",
                    animations: [
                        animations.trigger('calendar', [
                            animations.state('init', animations.style({ opacity: 1, transform: 'translateY(0) scaleY(1)' })),
                            animations.transition('void => *', [animations.style({ opacity: 0, transform: 'translateY(-45%) scaleY(0)' }), animations.animate(100)]),
                            animations.transition('* => void', animations.animate(100, animations.style({ opacity: 0, transform: 'translateY(-45%) scaleY(0)' })))
                        ])
                    ],
                    styles: ["div.ng-jalali-date-time-header{display:flex}div.ng-jalali-date-time-header div{background-color:#ddd;flex:1;padding:1rem .2rem;text-align:center}div.ng-jalali-date-time-week{display:flex}div.ng-jalali-date-time-day{flex:1;padding:.2rem;text-align:center}div.ng-jalali-date-time-time{align-items:center;direction:ltr;display:flex;margin:.5rem}div.ng-jalali-date-time-time div{text-align:center;width:2rem}div.ng-jalali-date-time-time input{background-color:#eee;border:0;direction:rtl;flex:1;outline:none;padding:.5rem;text-align:center}", "div.ng-jalali-back{background-color:transparent;bottom:0;left:0;position:fixed;right:0;top:0;z-index:999}content.ng-jalali{display:block;position:relative}mat-form-field.ng-jalali{direction:rtl;margin:0;text-align:right;width:100%}input.ng-jalali{cursor:default;text-align:right}button.ng-jalali-reset{color:#555;line-height:30px;min-width:auto;padding:0 .5rem}div.ng-jalali-calendar{background-color:#fff;box-shadow:0 2px 4px -1px rgba(0,0,0,.2),0 4px 5px 0 rgba(0,0,0,.14),0 1px 10px 0 rgba(0,0,0,.12);direction:rtl;position:absolute;right:0;top:45px;z-index:1000}div.ng-jalali-header{align-items:center;display:flex}div.ng-jalali-header div{flex:1;padding:.5rem .2rem;text-align:center}div.ng-jalali-header div.ng-jalali-title{flex:3}button.ng-jalali-selected{background-color:#eee;border:1px solid #999}button.ng-jalali-current{color:#009}"]
                },] }
    ];
    NgJalaliDateTimeComponent.ctorParameters = function () { return [
        { type: NgJalaliDateTimeService }
    ]; };
    NgJalaliDateTimeComponent.propDecorators = {
        changed: [{ type: core.Output }]
    };

    var NgJalaliDateTimeDirective = /** @class */ (function () {
        function NgJalaliDateTimeDirective(resolver, container, service) {
            this.resolver = resolver;
            this.container = container;
            this.service = service;
            this.jalaliLocale = new JalaliLocale();
            this.changed = new core.EventEmitter();
        }
        NgJalaliDateTimeDirective.prototype.ngOnInit = function () {
            if (!this.form)
                this.form = new forms.FormGroup({});
            if (!this.name)
                this.name = 'jalali-date-time-' + Date.now().toString();
            this.appearance = this.service.checkAppearance(this.appearance);
            if (!this.config)
                this.config = {};
            this.config.required = this.config.required ? true : false;
            this.config.min = this.service.checkDate(this.config.min) ? this.config.min : null;
            this.config.max = this.service.checkDate(this.config.max) ? this.config.max : null;
            this.config.reset = this.config.reset === false ? false : true;
            this.config.error = this.config.error ? this.config.error : this.jalaliLocale.required;
            this.config.time = this.config.time ? true : false;
            this.config.second = this.config.second ? true : false;
            this.css = this.service.checkCSS(this.css);
            this.date = this.service.checkDate(this.date);
            this.time = this.config.time ? this.service.checkTime(this.time) : '';
            this.label = this.label ? this.label : this.jalaliLocale.date;
            var factory = this.resolver.resolveComponentFactory(NgJalaliDateTimeComponent);
            this.component = this.container.createComponent(factory);
            this.component.instance.form = this.form;
            this.component.instance.name = this.name;
            this.component.instance.appearance = this.appearance;
            this.component.instance.config = this.config;
            this.component.instance.css = this.css;
            this.component.instance.value = this.service.getDateTimeValue(this.date, this.time);
            this.component.instance.label = this.label;
            this.component.instance.changed = this.changed;
        };
        return NgJalaliDateTimeDirective;
    }());
    NgJalaliDateTimeDirective.decorators = [
        { type: core.Directive, args: [{ selector: '[jalali-date-time]' },] }
    ];
    NgJalaliDateTimeDirective.ctorParameters = function () { return [
        { type: core.ComponentFactoryResolver },
        { type: core.ViewContainerRef },
        { type: NgJalaliDateTimeService }
    ]; };
    NgJalaliDateTimeDirective.propDecorators = {
        form: [{ type: core.Input }],
        name: [{ type: core.Input }],
        appearance: [{ type: core.Input }],
        config: [{ type: core.Input }],
        css: [{ type: core.Input }],
        date: [{ type: core.Input }],
        time: [{ type: core.Input }],
        label: [{ type: core.Input }],
        changed: [{ type: core.Output }]
    };

    var NgJalaliMonthComponent = /** @class */ (function () {
        function NgJalaliMonthComponent(service) {
            this.service = service;
            this.show = false;
            this.random = Date.now().toString();
            this.month = '';
            this.year = '';
            this.current = '';
            this.reset = false;
            this.jalaliLocale = new JalaliLocale();
            this.calendar = [
                [
                    { month: '01', title: this.jalaliLocale.monthNames[0] },
                    { month: '02', title: this.jalaliLocale.monthNames[1] },
                    { month: '03', title: this.jalaliLocale.monthNames[2] }
                ],
                [
                    { month: '04', title: this.jalaliLocale.monthNames[3] },
                    { month: '05', title: this.jalaliLocale.monthNames[4] },
                    { month: '06', title: this.jalaliLocale.monthNames[5] }
                ],
                [
                    { month: '07', title: this.jalaliLocale.monthNames[6] },
                    { month: '08', title: this.jalaliLocale.monthNames[7] },
                    { month: '09', title: this.jalaliLocale.monthNames[8] }
                ],
                [
                    { month: '10', title: this.jalaliLocale.monthNames[9] },
                    { month: '11', title: this.jalaliLocale.monthNames[10] },
                    { month: '12', title: this.jalaliLocale.monthNames[11] }
                ]
            ];
            this.changed = new core.EventEmitter();
        }
        NgJalaliMonthComponent.prototype.ngOnInit = function () {
            this.year = this.value.month ? this.value.month.substr(0, 4) : this.service.jalali.now({ format: 'Y' });
            this.current = this.service.jalali.now({ format: 'Y-M' });
            var validators = [];
            if (this.config.required)
                validators.push(this.validate.bind(this));
            this.form.addControl(this.name, new forms.FormControl(this.value));
            this.form.addControl(this.name + '-title', new forms.FormControl('', validators));
            this.setTitle();
        };
        NgJalaliMonthComponent.prototype.validate = function () {
            return this.value.month ? null : { required: true };
        };
        NgJalaliMonthComponent.prototype.showCalendar = function (show) {
            var input = document.querySelector('#input' + this.random);
            input.blur();
            if (this.reset) {
                this.reset = false;
                show = false;
            }
            this.show = show;
            if (this.show) {
                this.form.get(this.name + '-title').markAsUntouched();
                this.year = this.value.month ? this.value.month.substr(0, 4) : this.service.jalali.now({ format: 'Y' });
            }
            else
                this.form.get(this.name + '-title').markAsTouched();
        };
        NgJalaliMonthComponent.prototype.changeYear = function (change) {
            var year = Number(this.year) + change;
            this.year = year < 1000 ? '1000' : year.toString();
        };
        NgJalaliMonthComponent.prototype.setTitle = function () {
            this.form.get(this.name).setValue(this.value);
            var title = this.service.getMonthTitle(this.value);
            this.form.get(this.name + '-title').setValue(title);
        };
        NgJalaliMonthComponent.prototype.setMonth = function (month) {
            this.value = this.service.getMonthValue(month ? this.year + '-' + month : '');
            this.setTitle();
            this.showCalendar(false);
            this.changed.emit(this.value.month ? this.value : null);
            this.form.get(this.name + '-title').updateValueAndValidity();
        };
        return NgJalaliMonthComponent;
    }());
    NgJalaliMonthComponent.decorators = [
        { type: core.Component, args: [{
                    template: "<div class=\"ng-jalali-back\" *ngIf=\"show\" (click)=\"showCalendar(false)\"></div>\n\n<div [formGroup]=\"form\" [ngStyle]=\"{ display: 'none' }\">\n    <input type=\"text\" [formControlName]=\"name\" />\n</div>\n\n<content class=\"ng-jalali\" dir=\"rtl\">\n    <mat-form-field [ngStyle]=\"css.field\" class=\"ng-jalali\" [formGroup]=\"form\" [appearance]=\"appearance\">\n        <mat-label [ngStyle]=\"{ fontFamily: css.font }\">{{ label }}</mat-label>\n        <input\n            matInput\n            id=\"input{{ random }}\"\n            type=\"text\"\n            [formControlName]=\"name + '-title'\"\n            (focus)=\"showCalendar(true)\"\n            [ngStyle]=\"css.input\"\n            class=\"ng-jalali\"\n        />\n        <span *ngIf=\"config.reset && value.month !== ''\" matSuffix (click)=\"setMonth(''); reset = true\">\n            <button mat-button type=\"button\" [ngStyle]=\"css.reset\" class=\"ng-jalali-reset\">x</button>\n        </span>\n        <mat-error [ngStyle]=\"{ fontFamily: css.font }\" *ngIf=\"form.get(name + '-title').hasError('required')\">\n            {{ config.error }}\n        </mat-error>\n    </mat-form-field>\n\n    <div class=\"ng-jalali-calendar\" [ngStyle]=\"css.box\" [@calendar] *ngIf=\"show\">\n        <div class=\"ng-jalali-header\">\n            <div>\n                <button\n                    mat-icon-button\n                    type=\"button\"\n                    [ngStyle]=\"css.arrow\"\n                    (click)=\"changeYear(-10)\"\n                    [disabled]=\"year <= '1010'\"\n                >\n                    &lt;&lt;\n                </button>\n            </div>\n            <div>\n                <button\n                    mat-icon-button\n                    type=\"button\"\n                    [ngStyle]=\"css.arrow\"\n                    (click)=\"changeYear(-1)\"\n                    [disabled]=\"year === '1000'\"\n                >\n                    &lt;\n                </button>\n            </div>\n            <div class=\"ng-jalali-title\" [ngStyle]=\"css.header\">{{ year }}</div>\n            <div>\n                <button mat-icon-button type=\"button\" [ngStyle]=\"css.arrow\" (click)=\"changeYear(1)\">&gt;</button>\n            </div>\n            <div>\n                <button mat-icon-button type=\"button\" [ngStyle]=\"css.arrow\" (click)=\"changeYear(10)\">&gt;&gt;</button>\n            </div>\n        </div>\n        <mat-divider></mat-divider>\n        <div *ngFor=\"let season of calendar\" class=\"ng-jalali-month-season\">\n            <ng-container *ngFor=\"let month of season\">\n                <button\n                    mat-button\n                    type=\"button\"\n                    [disabled]=\"\n                        (config.min && year + '-' + month.month < config.min) ||\n                        (config.max && year + '-' + month.month > config.max)\n                    \"\n                    [ngClass]=\"{\n                        'ng-jalali-selected': year + '-' + month.month === value.month,\n                        'ng-jalali-current': year + '-' + month.month === current\n                    }\"\n                    [ngStyle]=\"\n                        year + '-' + month.month === current\n                            ? css.current\n                            : year + '-' + month.month === value.month\n                            ? css.selected\n                            : css.item\n                    \"\n                    (click)=\"setMonth(month.month)\"\n                >\n                    {{ month.title }}\n                </button>\n            </ng-container>\n        </div>\n    </div>\n</content>\n",
                    animations: [
                        animations.trigger('calendar', [
                            animations.state('init', animations.style({ opacity: 1, transform: 'translateY(0) scaleY(1)' })),
                            animations.transition('void => *', [animations.style({ opacity: 0, transform: 'translateY(-45%) scaleY(0)' }), animations.animate(100)]),
                            animations.transition('* => void', animations.animate(100, animations.style({ opacity: 0, transform: 'translateY(-45%) scaleY(0)' })))
                        ])
                    ],
                    styles: ["div.ng-jalali-month-season{display:flex}div.ng-jalali-month-season button{flex:1;padding:.5rem 2rem}", "div.ng-jalali-back{background-color:transparent;bottom:0;left:0;position:fixed;right:0;top:0;z-index:999}content.ng-jalali{display:block;position:relative}mat-form-field.ng-jalali{direction:rtl;margin:0;text-align:right;width:100%}input.ng-jalali{cursor:default;text-align:right}button.ng-jalali-reset{color:#555;line-height:30px;min-width:auto;padding:0 .5rem}div.ng-jalali-calendar{background-color:#fff;box-shadow:0 2px 4px -1px rgba(0,0,0,.2),0 4px 5px 0 rgba(0,0,0,.14),0 1px 10px 0 rgba(0,0,0,.12);direction:rtl;position:absolute;right:0;top:45px;z-index:1000}div.ng-jalali-header{align-items:center;display:flex}div.ng-jalali-header div{flex:1;padding:.5rem .2rem;text-align:center}div.ng-jalali-header div.ng-jalali-title{flex:3}button.ng-jalali-selected{background-color:#eee;border:1px solid #999}button.ng-jalali-current{color:#009}"]
                },] }
    ];
    NgJalaliMonthComponent.ctorParameters = function () { return [
        { type: NgJalaliDateTimeService }
    ]; };
    NgJalaliMonthComponent.propDecorators = {
        changed: [{ type: core.Output }]
    };

    var NgJalaliMonthDirective = /** @class */ (function () {
        function NgJalaliMonthDirective(resolver, container, service) {
            this.resolver = resolver;
            this.container = container;
            this.service = service;
            this.jalaliLocale = new JalaliLocale();
            this.changed = new core.EventEmitter();
        }
        NgJalaliMonthDirective.prototype.ngOnInit = function () {
            if (!this.form)
                this.form = new forms.FormGroup({});
            if (!this.name)
                this.name = 'jalali-month-' + Date.now().toString();
            this.appearance = this.service.checkAppearance(this.appearance);
            if (!this.config)
                this.config = {};
            this.config.required = this.config.required ? true : false;
            this.config.min = this.service.checkMonth(this.config.min) ? this.config.min : null;
            this.config.max = this.service.checkMonth(this.config.max) ? this.config.max : null;
            this.config.reset = this.config.reset === false ? false : true;
            this.config.error = this.config.error ? this.config.error : this.jalaliLocale.required;
            this.css = this.service.checkCSS(this.css);
            this.month = this.service.checkMonth(this.month);
            this.label = this.label ? this.label : this.jalaliLocale.month;
            var factory = this.resolver.resolveComponentFactory(NgJalaliMonthComponent);
            this.component = this.container.createComponent(factory);
            this.component.instance.form = this.form;
            this.component.instance.name = this.name;
            this.component.instance.appearance = this.appearance;
            this.component.instance.config = this.config;
            this.component.instance.css = this.css;
            this.component.instance.value = this.service.getMonthValue(this.month);
            this.component.instance.label = this.label;
            this.component.instance.changed = this.changed;
        };
        return NgJalaliMonthDirective;
    }());
    NgJalaliMonthDirective.decorators = [
        { type: core.Directive, args: [{ selector: '[jalali-month]' },] }
    ];
    NgJalaliMonthDirective.ctorParameters = function () { return [
        { type: core.ComponentFactoryResolver },
        { type: core.ViewContainerRef },
        { type: NgJalaliDateTimeService }
    ]; };
    NgJalaliMonthDirective.propDecorators = {
        form: [{ type: core.Input }],
        name: [{ type: core.Input }],
        appearance: [{ type: core.Input }],
        config: [{ type: core.Input }],
        css: [{ type: core.Input }],
        month: [{ type: core.Input }],
        label: [{ type: core.Input }],
        changed: [{ type: core.Output }]
    };

    var NgJalaliRangeComponent = /** @class */ (function () {
        function NgJalaliRangeComponent(service) {
            this.service = service;
            this.show = false;
            this.random = Date.now().toString();
            this.today = '';
            this.reset = false;
            this.jalaliLocale = new JalaliLocale();
            this.week = this.jalaliLocale.dayNames;
            this.changed = new core.EventEmitter();
        }
        NgJalaliRangeComponent.prototype.ngOnInit = function () {
            this.custom = { from: this.value.range ? this.value.from : '', to: this.value.range ? this.value.to : '' };
            this.setCustomTitle();
            this.fMonth = this.value.range ? this.value.from.substr(0, 7) : this.service.jalali.now({ format: 'Y-M' });
            this.fCalendar = this.service.getCalendar(this.fMonth);
            this.tMonth = this.value.range ? this.value.to.substr(0, 7) : this.service.jalali.now({ format: 'Y-M' });
            this.tCalendar = this.service.getCalendar(this.tMonth);
            this.today = this.service.jalali.now({ format: 'Y-M-D' });
            var validators = [];
            if (this.config.required)
                validators.push(this.validate.bind(this));
            this.form.addControl(this.name, new forms.FormControl(this.value));
            this.form.addControl(this.name + '-title', new forms.FormControl('', validators));
            this.setTitle();
        };
        NgJalaliRangeComponent.prototype.validate = function () {
            return this.value.range ? null : { required: true };
        };
        NgJalaliRangeComponent.prototype.showCalendar = function (show) {
            var input = document.querySelector('#input' + this.random);
            input.blur();
            if (this.reset) {
                this.reset = false;
                show = false;
            }
            this.show = show;
            if (this.show) {
                this.setCustomTitle();
                this.form.get(this.name + '-title').markAsUntouched();
                if (this.value.range) {
                    this.fMonth = this.value.from.substr(0, 7);
                    this.fCalendar = this.service.getCalendar(this.fMonth);
                    this.tMonth = this.value.to.substr(0, 7);
                    this.tCalendar = this.service.getCalendar(this.tMonth);
                }
                else {
                    this.fMonth = this.service.jalali.now({ format: 'Y-M' });
                    this.fCalendar = this.service.getCalendar(this.fMonth);
                    this.tMonth = this.service.jalali.now({ format: 'Y-M' });
                    this.tCalendar = this.service.getCalendar(this.tMonth);
                    this.setCustomDate('', '');
                }
            }
            else
                this.form.get(this.name + '-title').markAsTouched();
        };
        NgJalaliRangeComponent.prototype.changeMonth = function (type, change) {
            var _a, _b;
            var Y = '';
            var M = '';
            switch (type) {
                case 'from':
                    _a = __read(this.fMonth.split('-'), 2), Y = _a[0], M = _a[1];
                    break;
                case 'to':
                    _b = __read(this.tMonth.split('-'), 2), Y = _b[0], M = _b[1];
                    break;
            }
            var year = Number(Y);
            var month = Number(M) + change;
            while (month > 12) {
                month -= 12;
                year++;
            }
            while (month < 1) {
                month += 12;
                year--;
            }
            switch (type) {
                case 'from':
                    this.fMonth = year.toString() + '-' + (month < 10 ? '0' : '') + month.toString();
                    this.fCalendar = this.service.getCalendar(this.fMonth);
                    break;
                case 'to':
                    this.tMonth = year.toString() + '-' + (month < 10 ? '0' : '') + month.toString();
                    this.tCalendar = this.service.getCalendar(this.tMonth);
                    break;
            }
        };
        NgJalaliRangeComponent.prototype.setTitle = function () {
            this.form.get(this.name).setValue(this.value);
            var title = this.service.getRangeTitle(this.value);
            this.form.get(this.name + '-title').setValue(title);
        };
        NgJalaliRangeComponent.prototype.setCustomTitle = function () {
            this.fTitle = this.custom.from
                ? this.service.jalali.toTitle(this.service.jalaliToGregorian(this.custom.from))
                : this.jalaliLocale.notSpecified;
            this.tTitle = this.custom.to
                ? this.service.jalali.toTitle(this.service.jalaliToGregorian(this.custom.to))
                : this.jalaliLocale.notSpecified;
        };
        NgJalaliRangeComponent.prototype.setCustomDate = function (from, to) {
            if (from && to && from >= to)
                return;
            this.custom.from = from;
            this.custom.to = to;
            this.setCustomTitle();
        };
        NgJalaliRangeComponent.prototype.setRange = function (type) {
            var format = { format: 'Y-M-D' };
            var from = '';
            var to = '';
            var date = null;
            switch (type) {
                case 'current-week':
                    date = this.service.jalaliToGregorian(this.today);
                    while (date.getDay() !== 6) {
                        date = new Date(date.getTime() - 24 * 3600 * 1000);
                    }
                    from = this.service.jalali.toString(date, format);
                    to = this.service.jalali.toString(new Date(date.getTime() + 6 * 24 * 3600 * 1000), format);
                    break;
                case 'current-month':
                    date = this.service.jalaliToGregorian(this.today.substr(0, 8) + '01');
                    var days = this.service.getDayInMonth(this.today.substr(0, 7));
                    from = this.service.jalali.toString(date, format);
                    to = this.service.jalali.toString(new Date(date.getTime() + (days - 1) * 24 * 3600 * 1000), format);
                    break;
                case 'last-7days':
                    date = this.service.jalaliToGregorian(this.today);
                    from = this.service.jalali.toString(new Date(date.getTime() - 6 * 24 * 3600 * 1000), format);
                    to = this.service.jalali.toString(date, format);
                    break;
                case 'last-30days':
                    date = this.service.jalaliToGregorian(this.today);
                    from = this.service.jalali.toString(new Date(date.getTime() - 29 * 24 * 3600 * 1000), format);
                    to = this.service.jalali.toString(date, format);
                    break;
                case 'next-7days':
                    date = this.service.jalaliToGregorian(this.today);
                    from = this.service.jalali.toString(date, format);
                    to = this.service.jalali.toString(new Date(date.getTime() + 6 * 24 * 3600 * 1000), format);
                    break;
                case 'next-30days':
                    date = this.service.jalaliToGregorian(this.today);
                    from = this.service.jalali.toString(date, format);
                    to = this.service.jalali.toString(new Date(date.getTime() + 29 * 24 * 3600 * 1000), format);
                    break;
                case 'custom':
                    from = this.custom.from;
                    to = this.custom.to;
                    break;
                case 'reset':
                default:
                    break;
            }
            this.custom = { from: from, to: to };
            this.value = this.service.getRangeValue(from, to);
            this.setTitle();
            this.showCalendar(false);
            this.changed.emit(this.value.range ? this.value : null);
            this.form.get(this.name + '-title').updateValueAndValidity();
        };
        return NgJalaliRangeComponent;
    }());
    NgJalaliRangeComponent.decorators = [
        { type: core.Component, args: [{
                    template: "<div class=\"ng-jalali-back\" *ngIf=\"show\" (click)=\"showCalendar(false)\"></div>\n\n<div [formGroup]=\"form\" [ngStyle]=\"{ display: 'none' }\">\n    <input type=\"text\" [formControlName]=\"name\" />\n</div>\n\n<content class=\"ng-jalali\" dir=\"rtl\">\n    <mat-form-field [ngStyle]=\"css.field\" class=\"ng-jalali\" [formGroup]=\"form\" [appearance]=\"appearance\">\n        <mat-label [ngStyle]=\"{ fontFamily: css.font }\">{{ label }}</mat-label>\n        <input\n            matInput\n            id=\"input{{ random }}\"\n            type=\"text\"\n            [formControlName]=\"name + '-title'\"\n            (focus)=\"showCalendar(true)\"\n            [ngStyle]=\"css.input\"\n            class=\"ng-jalali\"\n        />\n        <span *ngIf=\"config.reset && value.range !== ''\" matSuffix (click)=\"setRange('reset'); reset = true\">\n            <button mat-button type=\"button\" [ngStyle]=\"css.reset\" class=\"ng-jalali-reset\">x</button>\n        </span>\n        <mat-error [ngStyle]=\"{ fontFamily: css.font }\" *ngIf=\"form.get(name + '-title').hasError('required')\">\n            {{ config.error }}\n        </mat-error>\n    </mat-form-field>\n\n    <div class=\"ng-jalali-calendar\" [ngStyle]=\"css.box\" [@calendar] *ngIf=\"show\">\n        <div class=\"ng-jalali-range-tools\">\n            <button\n                mat-button\n                type=\"button\"\n                [ngStyle]=\"custom.from === '' || custom.to === '' ? css.range.custom : css.range.confirm\"\n                [disabled]=\"custom.from === '' || custom.to === ''\"\n                (click)=\"setRange('custom')\"\n                class=\"ng-jalali-range-custom\"\n            >\n                {{\n                    custom.from === '' || custom.to === '' ? jalaliLocale.rangeCustom : jalaliLocale.rangeCustomConfirm\n                }}\n            </button>\n            <button mat-button type=\"button\" [ngStyle]=\"css.range.tool\" (click)=\"setRange('current-week')\">\n                {{ jalaliLocale.rangeCurrentWeek }}\n            </button>\n            <button mat-button type=\"button\" [ngStyle]=\"css.range.tool\" (click)=\"setRange('current-month')\">\n                {{ jalaliLocale.rangeCurrentMonth }}\n            </button>\n            <button mat-button type=\"button\" [ngStyle]=\"css.range.tool\" (click)=\"setRange('last-7days')\">\n                {{ jalaliLocale.rangeLast7Days }}\n            </button>\n            <button mat-button type=\"button\" [ngStyle]=\"css.range.tool\" (click)=\"setRange('last-30days')\">\n                {{ jalaliLocale.rangeLast30Days }}\n            </button>\n            <button mat-button type=\"button\" [ngStyle]=\"css.range.tool\" (click)=\"setRange('next-7days')\">\n                {{ jalaliLocale.rangeNext7Days }}\n            </button>\n            <button mat-button type=\"button\" [ngStyle]=\"css.range.tool\" (click)=\"setRange('next-30days')\">\n                {{ jalaliLocale.rangeNext30Days }}\n            </button>\n        </div>\n        <div class=\"ng-jalali-range-custom\">\n            <div class=\"ng-jalali-range-from\">\n                <div class=\"ng-jalali-header\">\n                    <div>\n                        <button\n                            mat-icon-button\n                            type=\"button\"\n                            [ngStyle]=\"css.arrow\"\n                            (click)=\"changeMonth('from', -12)\"\n                            [disabled]=\"fMonth.substr(0, 4) === '1000'\"\n                        >\n                            &lt;&lt;\n                        </button>\n                    </div>\n                    <div>\n                        <button\n                            mat-icon-button\n                            type=\"button\"\n                            [ngStyle]=\"css.arrow\"\n                            (click)=\"changeMonth('from', -1)\"\n                            [disabled]=\"fMonth === '1000-01'\"\n                        >\n                            &lt;\n                        </button>\n                    </div>\n                    <div class=\"ng-jalali-title\" [ngStyle]=\"css.header\">{{ fCalendar.title }}</div>\n                    <div>\n                        <button mat-icon-button type=\"button\" [ngStyle]=\"css.arrow\" (click)=\"changeMonth('from', 1)\">\n                            &gt;\n                        </button>\n                    </div>\n                    <div>\n                        <button mat-icon-button type=\"button\" [ngStyle]=\"css.arrow\" (click)=\"changeMonth('from', 12)\">\n                            &gt;&gt;\n                        </button>\n                    </div>\n                </div>\n                <div class=\"ng-jalali-range-header\">\n                    <div [ngStyle]=\"css.range.name\" *ngFor=\"let day of week\">{{ day }}</div>\n                </div>\n                <section>\n                    <div *ngFor=\"let week of fCalendar.weeks\" class=\"ng-jalali-range-week\">\n                        <div *ngFor=\"let day of week.days\" class=\"ng-jalali-range-day\">\n                            <button\n                                mat-icon-button\n                                type=\"button\"\n                                [disabled]=\"\n                                    day.month !== fMonth ||\n                                    (config.min && day.date < config.min) ||\n                                    (config.max && day.date > config.max) ||\n                                    (custom.to !== '' && day.date >= custom.to)\n                                \"\n                                [ngClass]=\"{\n                                    'ng-jalali-selected': day.date === custom.from,\n                                    'ng-jalali-current': day.date === today\n                                }\"\n                                [ngStyle]=\"\n                                    day.date === today\n                                        ? css.current\n                                        : day.date === custom.from\n                                        ? css.selected\n                                        : css.item\n                                \"\n                                (click)=\"setCustomDate(day.date, custom.to)\"\n                            >\n                                {{ day.day }}\n                            </button>\n                        </div>\n                    </div>\n                </section>\n                <div class=\"ng-jalali-range-custom-title\" [ngStyle]=\"css.range.date\">{{ fTitle }}</div>\n            </div>\n            <div class=\"ng-jalali-range-to\">\n                <div class=\"ng-jalali-header\">\n                    <div>\n                        <button\n                            mat-icon-button\n                            type=\"button\"\n                            [ngStyle]=\"css.arrow\"\n                            (click)=\"changeMonth('to', -12)\"\n                            [disabled]=\"tMonth.substr(0, 4) === '1000'\"\n                        >\n                            &lt;&lt;\n                        </button>\n                    </div>\n                    <div>\n                        <button\n                            mat-icon-button\n                            type=\"button\"\n                            [ngStyle]=\"css.arrow\"\n                            (click)=\"changeMonth('to', -1)\"\n                            [disabled]=\"tMonth === '1000-01'\"\n                        >\n                            &lt;\n                        </button>\n                    </div>\n                    <div class=\"ng-jalali-title\" [ngStyle]=\"css.header\">{{ tCalendar.title }}</div>\n                    <div>\n                        <button mat-icon-button type=\"button\" [ngStyle]=\"css.arrow\" (click)=\"changeMonth('to', 1)\">\n                            &gt;\n                        </button>\n                    </div>\n                    <div>\n                        <button mat-icon-button type=\"button\" [ngStyle]=\"css.arrow\" (click)=\"changeMonth('to', 12)\">\n                            &gt;&gt;\n                        </button>\n                    </div>\n                </div>\n                <div class=\"ng-jalali-range-header\">\n                    <div [ngStyle]=\"css.range.name\" *ngFor=\"let day of week\">{{ day }}</div>\n                </div>\n                <section>\n                    <div *ngFor=\"let week of tCalendar.weeks\" class=\"ng-jalali-range-week\">\n                        <div *ngFor=\"let day of week.days\" class=\"ng-jalali-range-day\">\n                            <button\n                                mat-icon-button\n                                type=\"button\"\n                                [disabled]=\"\n                                    day.month !== tMonth ||\n                                    (config.min && day.date < config.min) ||\n                                    (config.max && day.date > config.max) ||\n                                    (custom.from !== '' && day.date <= custom.from)\n                                \"\n                                [ngClass]=\"{\n                                    'ng-jalali-selected': day.date === custom.to,\n                                    'ng-jalali-current': day.date === today\n                                }\"\n                                [ngStyle]=\"\n                                    day.date === today ? css.current : day.date === custom.to ? css.selected : css.item\n                                \"\n                                (click)=\"setCustomDate(custom.from, day.date)\"\n                            >\n                                {{ day.day }}\n                            </button>\n                        </div>\n                    </div>\n                </section>\n                <div class=\"ng-jalali-range-custom-title\" [ngStyle]=\"css.range.date\">{{ tTitle }}</div>\n            </div>\n        </div>\n    </div>\n</content>\n",
                    animations: [
                        animations.trigger('calendar', [
                            animations.state('init', animations.style({ opacity: 1, transform: 'translateY(0) scaleY(1)' })),
                            animations.transition('void => *', [animations.style({ opacity: 0, transform: 'translateY(-45%) scaleY(0)' }), animations.animate(100)]),
                            animations.transition('* => void', animations.animate(100, animations.style({ opacity: 0, transform: 'translateY(-45%) scaleY(0)' })))
                        ])
                    ],
                    styles: ["div.ng-jalali-range-tools{display:flex}div.ng-jalali-range-tools button{background-color:#fafafa;border-bottom:1px solid #ccc;border-radius:0;border-right:1px solid #ccc;flex:1;min-width:auto;padding:.5rem 0;text-align:center;white-space:normal}div.ng-jalali-range-tools button.ng-jalali-range-custom{background-color:#fff;border-width:0}div.ng-jalali-range-custom{display:flex;flex-direction:row}div.ng-jalali-range-from{flex:1;margin:0 0 0 .5rem}div.ng-jalali-range-to{flex:1;margin:0 .5rem 0 0}@media only screen and (max-width:800px){div.ng-jalali-range-custom{flex-direction:column}div.ng-jalali-range-from{flex:1;margin:0 0 .5rem}div.ng-jalali-range-to{flex:1;margin:.5rem 0 0}}div.ng-jalali-range-from,div.ng-jalali-range-to{display:flex;flex-direction:column}div.ng-jalali-range-from section,div.ng-jalali-range-to section{flex:1}div.ng-jalali-range-header{align-items:center;display:flex}div.ng-jalali-range-header div{background-color:#ddd;flex:1;padding:1rem .2rem;text-align:center}div.ng-jalali-range-week{display:flex}div.ng-jalali-range-day{flex:1;padding:.2rem;text-align:center}div.ng-jalali-range-custom-title{border-top:1px solid #ccc;font-size:14px;padding:1rem;text-align:center}@media only screen and (max-width:800px){div.ng-jalali-range-custom-title{border-bottom:1px solid #ccc;border-top-width:0}}", "div.ng-jalali-back{background-color:transparent;bottom:0;left:0;position:fixed;right:0;top:0;z-index:999}content.ng-jalali{display:block;position:relative}mat-form-field.ng-jalali{direction:rtl;margin:0;text-align:right;width:100%}input.ng-jalali{cursor:default;text-align:right}button.ng-jalali-reset{color:#555;line-height:30px;min-width:auto;padding:0 .5rem}div.ng-jalali-calendar{background-color:#fff;box-shadow:0 2px 4px -1px rgba(0,0,0,.2),0 4px 5px 0 rgba(0,0,0,.14),0 1px 10px 0 rgba(0,0,0,.12);direction:rtl;position:absolute;right:0;top:45px;z-index:1000}div.ng-jalali-header{align-items:center;display:flex}div.ng-jalali-header div{flex:1;padding:.5rem .2rem;text-align:center}div.ng-jalali-header div.ng-jalali-title{flex:3}button.ng-jalali-selected{background-color:#eee;border:1px solid #999}button.ng-jalali-current{color:#009}"]
                },] }
    ];
    NgJalaliRangeComponent.ctorParameters = function () { return [
        { type: NgJalaliDateTimeService }
    ]; };
    NgJalaliRangeComponent.propDecorators = {
        changed: [{ type: core.Output }]
    };

    var NgJalaliRangeDirective = /** @class */ (function () {
        function NgJalaliRangeDirective(resolver, container, service) {
            this.resolver = resolver;
            this.container = container;
            this.service = service;
            this.jalaliLocale = new JalaliLocale();
            this.changed = new core.EventEmitter();
        }
        NgJalaliRangeDirective.prototype.ngOnInit = function () {
            if (!this.form)
                this.form = new forms.FormGroup({});
            if (!this.name)
                this.name = 'jalali-range-' + Date.now().toString();
            this.appearance = this.service.checkAppearance(this.appearance);
            if (!this.config)
                this.config = {};
            this.config.required = this.config.required ? true : false;
            this.config.min = this.service.checkDate(this.config.min) ? this.config.min : null;
            this.config.max = this.service.checkDate(this.config.max) ? this.config.max : null;
            this.config.reset = this.config.reset === false ? false : true;
            this.config.error = this.config.error ? this.config.error : this.jalaliLocale.required;
            this.css = this.service.checkCSS(this.css);
            this.from = this.service.checkDate(this.from);
            this.to = this.service.checkDate(this.to);
            this.label = this.label ? this.label : this.jalaliLocale.range;
            var factory = this.resolver.resolveComponentFactory(NgJalaliRangeComponent);
            this.component = this.container.createComponent(factory);
            this.component.instance.form = this.form;
            this.component.instance.name = this.name;
            this.component.instance.appearance = this.appearance;
            this.component.instance.config = this.config;
            this.component.instance.css = this.css;
            this.component.instance.value = this.service.getRangeValue(this.from, this.to);
            this.component.instance.label = this.label;
            this.component.instance.changed = this.changed;
        };
        return NgJalaliRangeDirective;
    }());
    NgJalaliRangeDirective.decorators = [
        { type: core.Directive, args: [{ selector: '[jalali-range]' },] }
    ];
    NgJalaliRangeDirective.ctorParameters = function () { return [
        { type: core.ComponentFactoryResolver },
        { type: core.ViewContainerRef },
        { type: NgJalaliDateTimeService }
    ]; };
    NgJalaliRangeDirective.propDecorators = {
        form: [{ type: core.Input }],
        name: [{ type: core.Input }],
        appearance: [{ type: core.Input }],
        config: [{ type: core.Input }],
        css: [{ type: core.Input }],
        from: [{ type: core.Input }],
        to: [{ type: core.Input }],
        label: [{ type: core.Input }],
        changed: [{ type: core.Output }]
    };

    var NgJalaliDatePipe = /** @class */ (function () {
        function NgJalaliDatePipe(service) {
            this.service = service;
        }
        NgJalaliDatePipe.prototype.transform = function (value) {
            var split = value.split(' ');
            var dateValue = split[0];
            var timeValue = split[1] && this.service.checkTime(split[1]) ? split[1] : '00:00:00';
            if (!this.service.checkDate(dateValue))
                return '';
            var date = this.service.jalaliToGregorian(dateValue, timeValue);
            return date.toString();
        };
        return NgJalaliDatePipe;
    }());
    NgJalaliDatePipe.decorators = [
        { type: core.Pipe, args: [{ name: 'jalaliDate' },] }
    ];
    NgJalaliDatePipe.ctorParameters = function () { return [
        { type: NgJalaliDateTimeService }
    ]; };

    var NgJalaliTimestampPipe = /** @class */ (function () {
        function NgJalaliTimestampPipe(service) {
            this.service = service;
        }
        NgJalaliTimestampPipe.prototype.transform = function (value) {
            var split = value.split(' ');
            var dateValue = split[0];
            var timeValue = split[1] && this.service.checkTime(split[1]) ? split[1] : '00:00:00';
            if (!this.service.checkDate(dateValue))
                return '';
            var date = this.service.jalaliToGregorian(dateValue, timeValue);
            return Math.floor(date.getTime() / 1000).toString();
        };
        return NgJalaliTimestampPipe;
    }());
    NgJalaliTimestampPipe.decorators = [
        { type: core.Pipe, args: [{ name: 'jalaliTimestamp' },] }
    ];
    NgJalaliTimestampPipe.ctorParameters = function () { return [
        { type: NgJalaliDateTimeService }
    ]; };

    var NgJalaliTitlePipe = /** @class */ (function () {
        function NgJalaliTitlePipe(service) {
            this.service = service;
        }
        NgJalaliTitlePipe.prototype.transform = function (value, format) {
            var date;
            switch (typeof value) {
                case 'number':
                    date = new Date(value * 1000);
                    break;
                case 'string':
                    if (!this.service.checkDate(value))
                        return '';
                    date = this.service.jalaliToGregorian(value);
                    break;
            }
            format = format ? format : 'W، D N Y';
            return this.service.jalali.toTitle(date, { format: format });
        };
        return NgJalaliTitlePipe;
    }());
    NgJalaliTitlePipe.decorators = [
        { type: core.Pipe, args: [{ name: 'jalaliTitle' },] }
    ];
    NgJalaliTitlePipe.ctorParameters = function () { return [
        { type: NgJalaliDateTimeService }
    ]; };

    var NgJalaliFullPipe = /** @class */ (function () {
        function NgJalaliFullPipe(service) {
            this.service = service;
        }
        NgJalaliFullPipe.prototype.transform = function (value, format) {
            var date;
            switch (typeof value) {
                case 'number':
                    date = new Date(value * 1000);
                    break;
                case 'string':
                    var data = value.split(' ');
                    var dateValue = data[0];
                    var timeValue = data[1] ? data[1] : '00:00:00';
                    if (!this.service.checkDate(dateValue))
                        return '';
                    date = this.service.jalaliToGregorian(dateValue, timeValue);
                    break;
            }
            format = format ? format : 'W، D N Y H:I:S';
            return this.service.jalali.toFullText(date, { format: format });
        };
        return NgJalaliFullPipe;
    }());
    NgJalaliFullPipe.decorators = [
        { type: core.Pipe, args: [{ name: 'jalaliFull' },] }
    ];
    NgJalaliFullPipe.ctorParameters = function () { return [
        { type: NgJalaliDateTimeService }
    ]; };

    var NgJalaliMonthPipe = /** @class */ (function () {
        function NgJalaliMonthPipe(service) {
            this.service = service;
        }
        NgJalaliMonthPipe.prototype.transform = function (value) {
            if (!this.service.checkMonth(value))
                return '';
            var date = this.service.jalaliToGregorian(value + '-01');
            return this.service.jalali.toTitle(date, { format: 'N Y' });
        };
        return NgJalaliMonthPipe;
    }());
    NgJalaliMonthPipe.decorators = [
        { type: core.Pipe, args: [{ name: 'jalaliMonth' },] }
    ];
    NgJalaliMonthPipe.ctorParameters = function () { return [
        { type: NgJalaliDateTimeService }
    ]; };

    var NgJalaliRangePipe = /** @class */ (function () {
        function NgJalaliRangePipe(service) {
            this.service = service;
        }
        NgJalaliRangePipe.prototype.transform = function (value) {
            var data = value.split('|');
            var from = data[0];
            var to = data[1] ? data[1] : '';
            if (!this.service.checkDate(from) || !this.service.checkDate(to))
                return '';
            return this.service.getRangeTitle(this.service.getRangeValue(from, to));
        };
        return NgJalaliRangePipe;
    }());
    NgJalaliRangePipe.decorators = [
        { type: core.Pipe, args: [{ name: 'jalaliRange' },] }
    ];
    NgJalaliRangePipe.ctorParameters = function () { return [
        { type: NgJalaliDateTimeService }
    ]; };

    var NgJalaliDaysPipe = /** @class */ (function () {
        function NgJalaliDaysPipe(service) {
            this.service = service;
        }
        NgJalaliDaysPipe.prototype.transform = function (value) {
            var split = value.split('|');
            var dateValue1 = split[0];
            var dateValue2 = split[1] && this.service.checkDate(split[1]) ? split[1] : '';
            if (!this.service.checkDate(dateValue1))
                return '';
            var time = this.service.jalali.now({ format: 'H:I:S' });
            var date1 = this.service.jalaliToGregorian(dateValue1, time);
            var date2 = dateValue2 ? this.service.jalaliToGregorian(dateValue2, time) : new Date();
            var second = Math.abs(Math.floor(date1.getTime() / 1000) - Math.floor(date2.getTime() / 1000));
            return (Math.floor(second / (24 * 3600)) + 1).toString();
        };
        return NgJalaliDaysPipe;
    }());
    NgJalaliDaysPipe.decorators = [
        { type: core.Pipe, args: [{ name: 'jalaliDays' },] }
    ];
    NgJalaliDaysPipe.ctorParameters = function () { return [
        { type: NgJalaliDateTimeService }
    ]; };

    var NgJalaliDateTimeModule = /** @class */ (function () {
        function NgJalaliDateTimeModule() {
        }
        return NgJalaliDateTimeModule;
    }());
    NgJalaliDateTimeModule.decorators = [
        { type: core.NgModule, args: [{
                    declarations: [
                        NgJalaliDateTimeComponent,
                        NgJalaliDateTimeDirective,
                        NgJalaliMonthComponent,
                        NgJalaliMonthDirective,
                        NgJalaliRangeComponent,
                        NgJalaliRangeDirective,
                        NgJalaliDatePipe,
                        NgJalaliTimestampPipe,
                        NgJalaliTitlePipe,
                        NgJalaliFullPipe,
                        NgJalaliMonthPipe,
                        NgJalaliRangePipe,
                        NgJalaliDaysPipe
                    ],
                    providers: [NgJalaliDateTimeService],
                    imports: [common.CommonModule, forms.ReactiveFormsModule, MaterialModule],
                    exports: [
                        NgJalaliDateTimeDirective,
                        NgJalaliMonthDirective,
                        NgJalaliRangeDirective,
                        NgJalaliDatePipe,
                        NgJalaliTimestampPipe,
                        NgJalaliTitlePipe,
                        NgJalaliFullPipe,
                        NgJalaliMonthPipe,
                        NgJalaliRangePipe,
                        NgJalaliDaysPipe
                    ],
                    entryComponents: [NgJalaliDateTimeComponent, NgJalaliMonthComponent, NgJalaliRangeComponent]
                },] }
    ];

    /*
     * Public API Surface of ng-jalali-date-time
     */

    /**
     * Generated bundle index. Do not edit.
     */

    exports.NgJalaliDateTimeModule = NgJalaliDateTimeModule;
    exports.ɵa = NgJalaliDateTimeComponent;
    exports.ɵb = NgJalaliDateTimeService;
    exports.ɵc = NgJalaliDateTimeDirective;
    exports.ɵd = NgJalaliMonthComponent;
    exports.ɵe = NgJalaliMonthDirective;
    exports.ɵf = NgJalaliRangeComponent;
    exports.ɵg = NgJalaliRangeDirective;
    exports.ɵh = NgJalaliDatePipe;
    exports.ɵi = NgJalaliTimestampPipe;
    exports.ɵj = NgJalaliTitlePipe;
    exports.ɵk = NgJalaliFullPipe;
    exports.ɵl = NgJalaliMonthPipe;
    exports.ɵm = NgJalaliRangePipe;
    exports.ɵn = NgJalaliDaysPipe;
    exports.ɵo = MaterialModule;

    Object.defineProperty(exports, '__esModule', { value: true });

})));
//# sourceMappingURL=ng-jalali-date-time.umd.js.map