UNPKG

@iabtechlabtcf/core

Version:

Ensures consistent encoding and decoding of TC Signals for the iab. Transparency and Consent Framework (TCF).

16 lines (15 loc) 520 B
import { IntEncoder, } from './IntEncoder.js'; import { DecodingError, } from '../../errors/index.js'; export class DateEncoder { static encode(value, numBits) { return IntEncoder.encode(Math.round(value.getTime() / 100), numBits); } static decode(value, numBits) { if (numBits !== value.length) { throw new DecodingError('invalid bit length'); } const date = new Date(); date.setTime(IntEncoder.decode(value, numBits) * 100); return date; } }