all files / core/security/digital-signature/x509/ x509-time.js

23.53% Statements 8/34
0% Branches 0/18
40% Functions 2/5
23.53% Lines 8/34
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48                                                                                
define(["require", "exports"], function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var _PdfX509Time = (function () {
        function _PdfX509Time(time) {
            this._time = time;
        }
        _PdfX509Time.prototype._getUniversalTime = function () {
            if (this._time._getTagNumber() === 23) {
                var val = this._time._getValue();
                if (typeof val === 'string') {
                    return val.trim();
                }
                if (val instanceof Uint8Array) {
                    var charCodes = [];
                    for (var i = 0; i < val.length; i++) {
                        charCodes.push(val[i]);
                    }
                    return String.fromCharCode.apply(null, charCodes).trim();
                }
            }
            return undefined;
        };
        _PdfX509Time.prototype._toDate = function () {
            var str = this._getUniversalTime();
            if (str) {
                var m = str.match(/^(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})Z$/);
                if (!m) {
                    m = str.match(/^(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})Z$/);
                }
                if (m) {
                    var year = parseInt(m[1], 10);
                    year += (year < 50) ? 2000 : 1900;
                    var month = parseInt(m[2], 10) - 1;
                    var day = parseInt(m[3], 10);
                    var hour = parseInt(m[4], 10);
                    var minute = parseInt(m[5], 10);
                    var second = m.length > 6 && typeof m[6] !== 'undefined' ? parseInt(m[6], 10) : 0;
                    return new Date(Date.UTC(year, month, day, hour, minute, second));
                }
            }
            return undefined;
        };
        return _PdfX509Time;
    }());
    exports._PdfX509Time = _PdfX509Time;
});