mirror of
https://github.com/JeroenED/libpairtwo.git
synced 2024-11-25 15:57:41 +01:00
Reading out date fields
This commit is contained in:
parent
38e67a4261
commit
ac908ea814
@ -76,17 +76,30 @@ class Swar4 implements ReaderInterface
|
|||||||
{
|
{
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
case 'String':
|
case 'String':
|
||||||
|
case 'Date':
|
||||||
$length = $this->readData('Int', $handle);
|
$length = $this->readData('Int', $handle);
|
||||||
|
echo $length . ' ';
|
||||||
|
if ($length == 0) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
$data = fread($handle, $length);
|
$data = fread($handle, $length);
|
||||||
|
if ($type == 'String') {
|
||||||
if ($data == '') {
|
if ($data == '') {
|
||||||
return (is_null($default)) ? '' : $default;
|
return (is_null($default)) ? '' : $default;
|
||||||
}
|
}
|
||||||
|
echo $data . PHP_EOL;
|
||||||
return iconv('windows-1252', 'utf-8', $data);
|
return iconv('windows-1252', 'utf-8', $data);
|
||||||
|
} elseif ($type == 'Date') {
|
||||||
|
echo $data . 'date' . PHP_EOL;
|
||||||
|
if ($data == '') {
|
||||||
|
return (is_null($default)) ? $this->convertStringToDate('01/01/1900') : $default;
|
||||||
|
}
|
||||||
|
return $this->convertStringToDate($data);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 'Hex':
|
case 'Hex':
|
||||||
case 'Int':
|
case 'Int':
|
||||||
case 'Bool':
|
case 'Bool':
|
||||||
case 'Date':
|
|
||||||
$data = fread($handle, 4);
|
$data = fread($handle, 4);
|
||||||
$hex = implode(unpack("H*", $data));
|
$hex = implode(unpack("H*", $data));
|
||||||
$hex = array_reverse(str_split($hex, 2));
|
$hex = array_reverse(str_split($hex, 2));
|
||||||
@ -111,11 +124,6 @@ class Swar4 implements ReaderInterface
|
|||||||
return (is_null($default)) ? 0 : $default;
|
return (is_null($default)) ? 0 : $default;
|
||||||
}
|
}
|
||||||
return hexdec($hex);
|
return hexdec($hex);
|
||||||
} elseif ($type == 'Date') {
|
|
||||||
if ($hex == '00') {
|
|
||||||
return (is_null($default)) ? $this->convertUIntToTimestamp(0) : $default;
|
|
||||||
}
|
|
||||||
return $this->convertUIntToTimestamp(hexdec($hex));
|
|
||||||
} elseif ($type == 'Bool') {
|
} elseif ($type == 'Bool') {
|
||||||
return ($hex == "01") ? true : false;
|
return ($hex == "01") ? true : false;
|
||||||
}
|
}
|
||||||
@ -145,7 +153,7 @@ class Swar4 implements ReaderInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns binary data that was read out the pairtwo file but was not needed immediately
|
* Returns binary data that was read out the swar file but was not needed immediately
|
||||||
*
|
*
|
||||||
* @param string $Key
|
* @param string $Key
|
||||||
* @return bool|DateTime|int|string
|
* @return bool|DateTime|int|string
|
||||||
@ -156,15 +164,21 @@ class Swar4 implements ReaderInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets binary data that is read out the pairtwo file but is not needed immediately
|
* Sets binary data that is read out the swar file but is not needed immediately
|
||||||
*
|
*
|
||||||
* @param string $Key
|
* @param string $Key
|
||||||
* @param bool|int|DateTime|string $Value
|
* @param bool|int|DateTime|string $Value
|
||||||
* @return Pairtwo6
|
* @return Pairtwo6
|
||||||
*/
|
*/
|
||||||
public function setBinaryData(string $Key, $Value): Pairtwo6
|
public function setBinaryData(string $Key, $Value): Swar4
|
||||||
{
|
{
|
||||||
$this->BinaryData[$Key] = $Value;
|
$this->BinaryData[$Key] = $Value;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function convertStringToDate(string $string): \DateTime
|
||||||
|
{
|
||||||
|
echo $string;
|
||||||
|
return DateTime::createFromFormat('d/m/Y', $string);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user