Skip to content

Commit

Permalink
Fix Get DateTime Value From Visual FoxPro
Browse files Browse the repository at this point in the history
  • Loading branch information
nikolay committed Mar 15, 2020
1 parent 514dab8 commit 96122f8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"homepage": "http://blog.kgd.in",
"type": "library",
"license": "MIT",
"version": "1.0.6",
"version": "1.0.7",
"authors": [
{
"name": "Chizhov Nikolay",
Expand Down
8 changes: 6 additions & 2 deletions src/Records.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Records {
private $v_fox = false;
private $nullFlagColumns = [];
private $logicals = ['t', 'y', 'д'];
private $notTrimTypes = ["M", "P", "G", "I", "Y", "T", "0"];

public function __construct($data, $encode = "utf-8", $headers = null, $columns = null) {
if ($data instanceof Table) {
Expand Down Expand Up @@ -50,7 +51,7 @@ public function nextRecord() {
$record["deleted"] = (unpack("C", $data[0])[1] == 42);
$pos = 1;
foreach ($this->columns as $column) {
$sub_data = (in_array($column["type"], ["M", "P", "G", "I", "Y", "0"])) ? substr($data, $pos, $column["length"]) : trim(substr($data, $pos, $column["length"]));
$sub_data = (in_array($column["type"], $this->notTrimTypes)) ? substr($data, $pos, $column["length"]) : trim(substr($data, $pos, $column["length"]));
switch($column["type"]) {
case "F":
case "N":
Expand All @@ -64,7 +65,7 @@ public function nextRecord() {
$record[$column["name"]] = unpack("l", $sub_data)[1];
break;
case "T":
$record[$column["name"]] = (empty($sub_data)) ? null : $this->getDateTime($sub_data);
$record[$column["name"]] = $this->getDateTime($sub_data);
break;
case "D":
$record[$column["name"]] = empty($sub_data) ? null : $sub_data;
Expand Down Expand Up @@ -118,6 +119,9 @@ private function convertChar($data) {
}

private function getDateTime($data) {
if (empty(trim($data))) {
return null;
}
$dateData = unpack("L", substr($data, 0, 4))[1];
$timeData = unpack("L", substr($data, 4, 4))[1];
return gmdate("YmdHis", jdtounix($dateData) + intval($timeData / 1000));
Expand Down

0 comments on commit 96122f8

Please sign in to comment.