Bimba.git

ref: 5ec6b8b626f241c6a4b55f98f0f06c45d1d12e8c

converter/server/vendor/rybakit/msgpack/examples/datetime.php


 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
<?php

/*
 * This file is part of the rybakit/msgpack.php package.
 *
 * (c) Eugene Leonovich <gen.work@gmail.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

use App\MessagePack\DateTimeTransformer;
use MessagePack\BufferUnpacker;
use MessagePack\Packer;

require __DIR__.'/autoload.php';

$date = new DateTimeImmutable('2000-01-01');
$transformer = new DateTimeTransformer(2);

$packer = new Packer();
$packer->registerTransformer($transformer);
$packed = $packer->pack($date);

$unpacker = new BufferUnpacker($packed);
$unpacker->registerTransformer($transformer);

printf("Raw:      %s\n", $date->format('r'));
printf("Unpacked: %s\n", $unpacker->unpack()->format('r'));

/* OUTPUT
Raw:      Sat, 01 Jan 2000 00:00:00 +0000
Unpacked: Sat, 01 Jan 2000 00:00:00 +0000
*/