"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.EndUserDateCoder = void 0;
class EndUserDateCoder {
    constructor() {
        this.vendor = 'JSC IIT';
        this.classVersion = 1;
        this.className = 'EndUserDateCoder';
        this.dateDelimeter = '.';
        this.timeDelimeter = ':';
        this.dateTimeDelimeter = ' ';
        this.format = 'dd.MM.yyyy HH:mm:ss';
    }
    encode(date) {
        var dd = date.getDate();
        var MM = date.getMonth() + 1;
        var yyyy = date.getFullYear();
        var HH = date.getHours();
        var mm = date.getMinutes();
        var ss = date.getSeconds();
        return dd + this.dateDelimeter + MM + this.dateDelimeter + yyyy +
            this.dateTimeDelimeter +
            HH + this.timeDelimeter + mm + this.timeDelimeter + ss;
    }
    decode(dateStr) {
        try {
            var arr = dateStr.split(this.dateTimeDelimeter);
            var dateArr = arr[0].split(this.dateDelimeter);
            var timeArr = arr[1].split(this.timeDelimeter);
            var dd = parseInt(dateArr[0]);
            var MM = parseInt(dateArr[1]) - 1;
            var yyyy = parseInt(dateArr[2]);
            if (dd < 0 || dd > 31 ||
                MM < 0 || MM > 12 || yyyy < 0) {
                return null;
            }
            var HH = parseInt(timeArr[0]);
            var mm = parseInt(timeArr[1]);
            var ss = parseInt(timeArr[2]);
            if (HH < 0 || HH > 23 ||
                mm < 0 || mm > 59 ||
                ss < 0 || ss > 59) {
                return null;
            }
            var date = new Date();
            date.setDate(dd);
            date.setMonth(MM);
            date.setFullYear(yyyy);
            date.setHours(HH);
            date.setMinutes(mm);
            date.setSeconds(ss);
            return date;
        }
        catch (e) {
            return null;
        }
    }
}
exports.EndUserDateCoder = EndUserDateCoder;
