-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from keboola/update-CF-3202/proper-date-conver…
…sion-before-1970 UPDATE/CF-3202 - Proper date conversion before 1970
- Loading branch information
Showing
16 changed files
with
150 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MongoExtractor; | ||
|
||
interface DataNormalizer | ||
{ | ||
/** | ||
* @param array<string, mixed> $data | ||
*/ | ||
public function normalize(array &$data): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MongoExtractor; | ||
|
||
use DateTimeImmutable; | ||
use DateTimeInterface; | ||
use MongoDB\BSON\UTCDateTime; | ||
|
||
final class DateNormalizer implements DataNormalizer | ||
{ | ||
/** | ||
* @param array<string, mixed> $mapping | ||
*/ | ||
public function __construct( | ||
private array $mapping = [], | ||
) { | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function normalize(array &$data): void | ||
{ | ||
foreach ($data as &$item) { | ||
foreach ($this->mapping as $path => $mapping) { | ||
if (!isset($mapping['type']) || $mapping['type'] !== 'date') { | ||
continue; | ||
} | ||
|
||
$keys = explode('.', $path); | ||
$current = &$item; | ||
|
||
foreach ($keys as $key) { | ||
if (property_exists($current, $key)) { | ||
$current = &$current->{$key}; | ||
} | ||
} | ||
|
||
if (is_string($current)) { | ||
$current = (new DateTimeImmutable($current))->format(DateTimeInterface::ATOM); | ||
|
||
return; | ||
} | ||
|
||
if (property_exists($current, '$numberLong')) { | ||
$current = (new UTCDateTime((int) $current->{'$numberLong'})) | ||
->toDateTime()->format(DateTimeInterface::ATOM); | ||
|
||
return; | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[ | ||
{ | ||
"_id": { | ||
"$oid": "675042b13a59410a6c6c44b6" | ||
}, | ||
"birthDate": {"$date": "1907-03-31T03:01:56Z"} | ||
}, | ||
{ | ||
"_id": { | ||
"$oid": "6750431c3a59410a6c6c44b7" | ||
}, | ||
"birthDate": {"$date": "2024-03-04T11:11:11Z"} | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Connected to mongodb://mongodb:27017/test | ||
Exporting "export-all" | ||
Done "export-all", parsed 2 records in total |
Empty file.
Empty file.
2 changes: 2 additions & 0 deletions
2
tests/functional/export-date-values/expected/data/out/tables/export-all.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
"675042b13a59410a6c6c44b6","-1980449884" | ||
"6750431c3a59410a6c6c44b7","1709550671" |
1 change: 1 addition & 0 deletions
1
tests/functional/export-date-values/expected/data/out/tables/export-all.csv.manifest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"incremental":false,"columns":["id","timeColumn"],"column_metadata":{"id":[{"key":"KBC.datatype.nullable","value":true},{"key":"KBC.datatype.basetype","value":"string"}],"timeColumn":[{"key":"KBC.datatype.nullable","value":true},{"key":"KBC.datatype.basetype","value":"string"}]}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use MongoExtractor\FunctionalTests\DatadirTest; | ||
use MongoExtractor\Tests\Traits\ImportDatasetTrait; | ||
|
||
return static function (DatadirTest $test): void { | ||
(new class { use ImportDatasetTrait; | ||
|
||
})::importDatatasetNoAuthDb('restaurants', 'dataset-date.json'); | ||
}; |
27 changes: 27 additions & 0 deletions
27
tests/functional/export-date-values/source/data/config.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"parameters": { | ||
"db": { | ||
"host": "mongodb", | ||
"port": 27017, | ||
"database": "test" | ||
}, | ||
"collection": "restaurants", | ||
"tableName": "export-all", | ||
"mapping": { | ||
"_id.$oid": { | ||
"type": "column", | ||
"mapping": { | ||
"destination": "id" | ||
} | ||
}, | ||
"birthDate.$date": { | ||
"type": "date", | ||
"mapping": { | ||
"destination": "timeColumn" | ||
} | ||
} | ||
}, | ||
"mode": "mapping", | ||
"sort": "{_id: 1}" | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
tests/functional/test-connection-action-fail-wrong-host/expected-stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
No suitable servers found (`serverSelectionTryOnce` set): [Failed to resolve 'locahost'] | ||
No suitable servers found (`serverSelectionTryOnce` set): [Failed to resolve 'locahost']. Topology type: Single |