modifs.mineures sans commentaires
This commit is contained in:
parent
6bffe89904
commit
375351a0b4
|
@ -2,6 +2,9 @@
|
|||
namespace nur\sery\file\csv;
|
||||
|
||||
use IteratorAggregate;
|
||||
use nur\sery\php\func;
|
||||
use nur\sery\php\time\Date;
|
||||
use nur\sery\php\time\DateTime;
|
||||
|
||||
abstract class AbstractReader implements IReader {
|
||||
const SCHEMA = null;
|
||||
|
@ -42,4 +45,13 @@ abstract class AbstractReader implements IReader {
|
|||
$row = array_combine($this->headers, $row);
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function verifixCol(&$col): void {
|
||||
# conversion Date et DateTime
|
||||
if (DateTime::isa_datetime($col, true)) {
|
||||
$col = new DateTime($col);
|
||||
} elseif (DateTime::isa_date($col, true)) {
|
||||
$col = new Date($col);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,22 +2,14 @@
|
|||
namespace nur\sery\file\csv;
|
||||
|
||||
use nur\sery\file\FileReader;
|
||||
use nur\sery\php\time\Date;
|
||||
use nur\sery\php\time\DateTime;
|
||||
|
||||
class CsvReader extends AbstractReader {
|
||||
function getIterator() {
|
||||
$reader = new FileReader($this->input);
|
||||
while (($row = $reader->fgetcsv()) !== null) {
|
||||
foreach ($row as &$col) {
|
||||
# conversion Date et DateTime
|
||||
if (DateTime::isa_datetime($col, true)) {
|
||||
$col = new DateTime($col);
|
||||
} elseif (DateTime::isa_date($col, true)) {
|
||||
$col = new Date($col);
|
||||
}
|
||||
$this->verifixCol($col);
|
||||
}; unset($col);
|
||||
|
||||
if ($this->cook($row)) {
|
||||
yield $row;
|
||||
$this->idest++;
|
||||
|
|
|
@ -77,9 +77,9 @@ class SsReader extends AbstractReader {
|
|||
for ($ncol = 1; $ncol <= $nbCols; $ncol++) {
|
||||
if ($ws->cellExistsByColumnAndRow($ncol, $nrow)) {
|
||||
$cell = $ws->getCellByColumnAndRow($ncol, $nrow);
|
||||
$value = $cell->getValue();
|
||||
if ($value instanceof RichText) {
|
||||
$value = $value->getPlainText();
|
||||
$col = $cell->getValue();
|
||||
if ($col instanceof RichText) {
|
||||
$col = $col->getPlainText();
|
||||
} else {
|
||||
$dataType = $cell->getDataType();
|
||||
if ($dataType == DataType::TYPE_NUMERIC || $dataType == DataType::TYPE_FORMULA) {
|
||||
|
@ -101,18 +101,13 @@ class SsReader extends AbstractReader {
|
|||
}
|
||||
}
|
||||
}
|
||||
$value = $cell->getFormattedValue();
|
||||
# conversion Date et DateTime
|
||||
if (DateTime::isa_datetime($value, true)) {
|
||||
$value = new DateTime($value);
|
||||
} elseif (DateTime::isa_date($value, true)) {
|
||||
$value = new Date($value);
|
||||
}
|
||||
$col = $cell->getFormattedValue();
|
||||
$this->verifixCol($col);
|
||||
}
|
||||
} else {
|
||||
$value = null;
|
||||
$col = null;
|
||||
}
|
||||
$row[] = $value;
|
||||
$row[] = $col;
|
||||
}
|
||||
if ($this->cook($row)) {
|
||||
yield $row;
|
||||
|
|
|
@ -35,6 +35,7 @@ class DateTime extends \DateTime {
|
|||
const YMDHISZ_PATTERN = '/^((?:\d{2})?\d{2})(\d{2})(\d{2})[tT](\d{2})(\d{2})(\d{2})?([zZ])?$/';
|
||||
|
||||
static function isa($datetime): bool {
|
||||
if ($datetime === null) return false;
|
||||
if ($datetime instanceof DateTimeInterface) return true;
|
||||
if (!is_int($datetime) && !is_string($datetime)) return false;
|
||||
return preg_match(self::DMY_PATTERN, $datetime) ||
|
||||
|
@ -44,17 +45,19 @@ class DateTime extends \DateTime {
|
|||
}
|
||||
|
||||
static function isa_datetime($datetime, bool $frOnly=false): bool {
|
||||
if ($datetime === null) return false;
|
||||
if ($datetime instanceof DateTimeInterface) return true;
|
||||
if (!is_int($datetime) && !is_string($datetime)) return false;
|
||||
return preg_match(self::DMYHIS_PATTERN, $datetime) ||
|
||||
(!$frOnly && preg_match(self::YMDHISZ_PATTERN, $datetime));
|
||||
}
|
||||
|
||||
static function isa_date($datetime, bool $frOnly=false): bool {
|
||||
if ($datetime instanceof DateTimeInterface) return true;
|
||||
if (!is_int($datetime) && !is_string($datetime)) return false;
|
||||
return preg_match(self::DMY_PATTERN, $datetime) ||
|
||||
(!$frOnly && preg_match(self::YMD_PATTERN, $datetime));
|
||||
static function isa_date($date, bool $frOnly=false): bool {
|
||||
if ($date === null) return false;
|
||||
if ($date instanceof DateTimeInterface) return true;
|
||||
if (!is_int($date) && !is_string($date)) return false;
|
||||
return preg_match(self::DMY_PATTERN, $date) ||
|
||||
(!$frOnly && preg_match(self::YMD_PATTERN, $date));
|
||||
}
|
||||
|
||||
static function _YmdHMSZ_format(\DateTime $datetime): string {
|
||||
|
|
Loading…
Reference in New Issue