it("should convert any random date",function(){

        var dates_to_check =[
            new Date(1,1,1601),
            new Date(14,7,1789),
            new Date(14,4,1929),
            new Date(14,4,1968),
            new Date(14,4,1972),
            new Date(14,4,2172)
        ];
        for(var i=0;i<100;i++) {
            dates_to_check.push(ec.randomDateTime());
        }
        var date,check_date, check_date_bn;
        var bs = new BinaryStream();
        for(var i=0;i<dates_to_check.length;i++) {
            date = dates_to_check[i];
            var hl  = date_time.bn_dateToHundredNanoSecondFrom1601(date);
            var hl_bn = bn_dateToHundredNanoSecondFrom1601_big_number(date);

            check_date    = date_time.bn_hundredNanoSecondFrom1601ToDate(hl[0],hl[1]);
            check_date_bn = bn_hundredNanoSecondFrom1601ToDate_big_number(hl[0],hl[1]);

            check_date.toString().should.eql(date.toString());

            ec.isValidUInt32(hl[0]).should.eql(true);
            ec.isValidUInt32(hl[1]).should.eql(true);
            ec.encodeDateTime(date,bs);
            bs.rewind();
        }
    });
Exemplo n.º 2
0
function isValidScalarVariant(dataType, value) {

    switch (dataType) {
        case DataType.NodeId:
            return ec.isValidNodeId(value);
        case DataType.String:
            return typeof value === "string" || util.isNullOrUndefined(value);
        case DataType.Int64:
            return ec.isValidInt64(value);
        case DataType.UInt64:
            return ec.isValidUInt64(value);
        case DataType.UInt32:
            return ec.isValidUInt32(value);
        case DataType.Int32:
            return ec.isValidInt32(value);
        case DataType.UInt16:
            return ec.isValidUInt16(value);
        case DataType.Int16:
            return ec.isValidInt16(value);
        case DataType.Byte:
            return ec.isValidUInt8(value);
        case DataType.SByte:
            return ec.isValidInt8(value);
        default:
            return true;
    }
}
Exemplo n.º 3
0
function isValidScalarVariant(dataType, value) {

    assert(value === null || DataType.Int64 === dataType || DataType.ByteString === dataType || DataType.UInt64 === dataType || !(value instanceof Array));
    assert(value === null || !(value instanceof Int32Array));
    assert(value === null || !(value instanceof Uint32Array));
    switch (dataType) {
        case DataType.NodeId:
            return ec.isValidNodeId(value);
        case DataType.String:
            return typeof value === "string" || utils.isNullOrUndefined(value);
        case DataType.Int64:
            return ec.isValidInt64(value);
        case DataType.UInt64:
            return ec.isValidUInt64(value);
        case DataType.UInt32:
            return ec.isValidUInt32(value);
        case DataType.Int32:
            return ec.isValidInt32(value);
        case DataType.UInt16:
            return ec.isValidUInt16(value);
        case DataType.Int16:
            return ec.isValidInt16(value);
        case DataType.Byte:
            return ec.isValidUInt8(value);
        case DataType.SByte:
            return ec.isValidInt8(value);
        default:
            return true;
    }
}