Skip to content

Commit 664f739

Browse files
committed
feat: option to set date format
1 parent 0023894 commit 664f739

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/SQLLoader.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ class SQLLoader
3939

4040
public array $beginData = [];
4141

42+
protected string $dateFormat = 'YYYY-MM-DD"T"HH24:MI:SS."000000Z"';
43+
4244
public function __construct(public array $options = [])
4345
{
4446
}
@@ -97,6 +99,15 @@ public function into(
9799
$columns = $this->defaultColumns;
98100
}
99101

102+
if (! $formatOptions) {
103+
$formatOptions = [
104+
"DATE FORMAT '".$this->dateFormat."'",
105+
"TIMESTAMP FORMAT '".$this->dateFormat."'",
106+
"TIMESTAMP WITH TIME ZONE '".$this->dateFormat."'",
107+
"TIMESTAMP WITH LOCAL TIME ZONE '".$this->dateFormat."'",
108+
];
109+
}
110+
100111
$this->tables[] = new TableDefinition($table, $columns, $terminatedBy, $enclosedBy, $trailing, $formatOptions, $when);
101112

102113
return $this;
@@ -382,4 +393,11 @@ public function withHeaders(): static
382393

383394
return $this;
384395
}
396+
397+
public function dateFormat(string $format): static
398+
{
399+
$this->dateFormat = $format;
400+
401+
return $this;
402+
}
385403
}

0 commit comments

Comments
 (0)