Convert a date to a 3 byte KNX data array
198416
def date_to_knx(dateval):
    """"""

    if (dateval.year < 1990) or (dateval.year > 2089):
        raise KNXException("Year has to be between 1990 and 2089")

    if dateval.year < 2000:
        year = dateval.year - 1900
    else:
        year = dateval.year - 2000

    return([dateval.day, dateval.month, year])
266095
function prepareData(items, with_timestamps, with_ns) {
    var data = {
        request: 'sender data',
        data: items
    };

    if (with_timestamps) {
        var ts = Date.now() / 1000;
        data.clock = ts | 0;

        if (with_ns) {
            data.ns = (ts % 1) * 1000 * 1000000 | 0;
        }
    }

    var payload = new Buffer(JSON.stringify(data), 'utf8'),
        header  = new Buffer(5 + 4); // ZBXD\1 + packed payload.length

    header.write('ZBXD\x01');
    header.writeInt32LE(payload.length, 5);
    return Buffer.concat([header, new Buffer('\x00\x00\x00\x00'), payload]);
}
424186
def deserialize_date(attr):
        
        if isinstance(attr, ET.Element):
            attr = attr.text
        if re.search(r"[^\W\d_]", attr, re.I + re.U):
            raise DeserializationError("Date must have only digits and -. Received: %s" % attr)
        # This must NOT use defaultmonth/defaultday. Using None ensure this raises an exception.
        return isodate.parse_date(attr, defaultmonth=None, defaultday=None)
1203908
def date_cast(date):
    '''
    
    '''
    if date is None:
        return datetime.datetime.now()
    elif isinstance(date, datetime.datetime):
        return date

    # fuzzy date
    try:
        if isinstance(date, six.string_types):
            try:
                if HAS_TIMELIB:
                    # py3: yes, timelib.strtodatetime wants bytes, not str :/
                    return timelib.strtodatetime(
                        salt.utils.stringutils.to_bytes(date))
            except ValueError:
                pass

            # not parsed yet, obviously a timestamp?
            if date.isdigit():
                date = int(date)
            else:
                date = float(date)

        return datetime.datetime.fromtimestamp(date)
    except Exception:
        if HAS_TIMELIB:
            raise ValueError('Unable to parse {0}'.format(date))

        raise RuntimeError(
                'Unable to parse {0}. Consider installing timelib'.format(date))
113323
@Override
    public int encode ( byte[] dst, int dstIndex ) {
        int start = dstIndex;
        SMBUtil.writeTime(this.createTime, dst, dstIndex);
        dstIndex += 8;
        SMBUtil.writeTime(this.lastAccessTime, dst, dstIndex);
        dstIndex += 8;
        SMBUtil.writeTime(this.lastWriteTime, dst, dstIndex);
        dstIndex += 8;
        SMBUtil.writeTime(this.changeTime, dst, dstIndex);
        dstIndex += 8;
        SMBUtil.writeInt4(this.attributes, dst, dstIndex);
        dstIndex += 4;
        dstIndex += 4;
        return dstIndex - start;
    }
538985
def knx2_to_float(knxdata):
    """"""
    if len(knxdata) != 2:
        raise KNXException("Can only convert a 2 Byte object to float")

    data = knxdata[0] * 256 + knxdata[1]
    sign = data >> 15
    exponent = (data >> 11) & 0x0f
    mantisse = float(data & 0x7ff)
    if sign == 1:
        mantisse = -2048 + mantisse

    return mantisse * pow(2, exponent) / 100
210589
function (bytes) {
    var out = [], i, tmp=0;
    for (i=0; i<bytes.length; i++) {
      tmp = tmp << 8 | bytes[i];
      if ((i&3) === 3) {
        out.push(tmp);
        tmp = 0;
      }
    }
    if (i&3) {
      out.push(sjcl.bitArray.partial(8*(i&3), tmp));
    }
    return out;
  }
577578
function stringToByteArray(str) {
	const byteArray = [];
	for (let i = 0; i < str.length; i++) {
		if (str.charCodeAt(i) <= 0x7F) {
			byteArray.push(str.charCodeAt(i));
		} else {
			const h = encodeURIComponent(str.charAt(i)).substr(1).split('%');
			for (let j = 0; j < h.length; j++) {
				byteArray.push(parseInt(h[j], 16));
			}
		}
	}

	return byteArray;
}
701099
function md5ToHexEncodedArray(input) {
  var i;
  var x;
  var output = [];
  var length32 = input.length * 32;
  var hexTab = '0123456789abcdef';
  var hex;

  for (i = 0; i < length32; i += 8) {
    x = (input[i >> 5] >>> (i % 32)) & 0xFF;

    hex = parseInt(hexTab.charAt((x >>> 4) & 0x0F) + hexTab.charAt(x & 0x0F), 16);

    output.push(hex);
  }
  return output;
}
1351825
public byte[] serialize(Calendar date)
   {
      final String calendarString =
         CALENDAR_FIELDS_SEPARATOR + date.isLenient() + CALENDAR_FIELDS_DELIMITER + date.getFirstDayOfWeek()
            + CALENDAR_FIELDS_DELIMITER + date.getMinimalDaysInFirstWeek() + CALENDAR_FIELDS_DELIMITER
            + date.getTimeZone().getID();

      return (format(date) + calendarString).getBytes();
   }
396433
function deserialize (rawData) {
  return JSON.parse(rawData, function (k, v) {
    if (k === '$$date') { return new Date(v); }
    if (typeof v === 'string' || typeof v === 'number' || typeof v === 'boolean' || v === null) { return v; }
    if (v && v.$$date) { return v.$$date; }
    if (v && v.$$regex) { return deserializeRegex(v.$$regex) }

    return v;
  });
}
155328
function convertData2Hexd (data) {
  if (!isHexString(data)) {
    var hex = ''
    for (var i = 0; i < data.length; i++) {
      hex += data.charCodeAt(i).toString(16)
    }
    return '0x' + hex
  }
  return data
}
718181
function getDate(node) {
    var text = getText(node);
    if (!text) {
        return undefined;
    }
    if (text.indexOf(':') > 0) {
        return new Date(text);
    }
    var bytes = new DataView(ByteUtils.arrayToBuffer(ByteUtils.base64ToBytes(text)));
    var secondsFrom00 = new Int64(bytes.getUint32(0, true), bytes.getUint32(4, true)).value;
    var diff = (secondsFrom00 - EpochSeconds) * 1000;
    return new Date(diff);
}
114168
static private void encodeBytes(byte previous, byte current, int byteIndex, StringBuilder output) {
        int chunk;
        int offset = byteIndex % 5;
        switch (offset) {
            case 0:
                chunk = ((current & 0xF8) >>> 3);
                output.append(lookupTable.charAt(chunk));
                break;
            case 1:
                chunk = (((previous & 0x07) << 2) | ((current & 0xC0) >>> 6));
                output.append(lookupTable.charAt(chunk));
                chunk = ((current & 0x3E) >>> 1);
                output.append(lookupTable.charAt(chunk));
                break;
            case 2:
                chunk = (((previous & 0x01) << 4) | ((current & 0xF0) >>> 4));
                output.append(lookupTable.charAt(chunk));
                break;
            case 3:
                chunk = (((previous & 0x0F) << 1) | ((current & 0x80) >>> 7));
                output.append(lookupTable.charAt(chunk));
                chunk = ((current & 0x7C) >>> 2);
                output.append(lookupTable.charAt(chunk));
                break;
            case 4:
                chunk = (((previous & 0x03) << 3) | ((current & 0xE0) >>> 5));
                output.append(lookupTable.charAt(chunk));
                chunk = (current & 0x1F);
                output.append(lookupTable.charAt(chunk));
                break;
        }
    }
737465
function toAmzUtcString(date) {
  var pieces = new Date(date).toUTCString().match(/^(.+), (.+) (.+) (.+) (.+) GMT$/)
  return [pieces[1], pieces[3], pieces[2], pieces[5], 'UTC', pieces[4]].join(' ')
}
341409
@Override
    public byte[] encodeAsBytes(long time, int sequence) {
        byte[] buffer = new byte[16];
        buffer[0] = (byte) (time >>> 56);
        buffer[1] = (byte) (time >>> 48);
        buffer[2] = (byte) (time >>> 40);
        buffer[3] = (byte) (time >>> 32);
        buffer[4] = (byte) (time >>> 24);
        buffer[5] = (byte) (time >>> 16);
        buffer[6] = (byte) (time >>> 8);
        buffer[7] = (byte) (time);

        long rest = shiftedMachineId | (0x0000FFFF & sequence);
        buffer[8] = (byte) (rest >>> 56);
        buffer[9] = (byte) (rest >>> 48);
        buffer[10] = (byte) (rest >>> 40);
        buffer[11] = (byte) (rest >>> 32);
        buffer[12] = (byte) (rest >>> 24);
        buffer[13] = (byte) (rest >>> 16);
        buffer[14] = (byte) (rest >>> 8);
        buffer[15] = (byte) (rest);

        return buffer;
    }
1163045
private JSONValue datesToJsonArray(Collection<Date> dates) {

        if (null != dates) {
            JSONArray result = new JSONArray();
            for (Date d : dates) {
                result.set(result.size(), dateToJson(d));
            }
            return result;
        }
        return null;
    }