convert timestamp from episode action request to format also mysql can process

This commit is contained in:
thrillfall 2021-07-22 23:44:45 +02:00
parent 228be0b0b8
commit ad3b9c107d
2 changed files with 28 additions and 1 deletions

View File

@ -61,7 +61,7 @@ class EpisodeActionController extends Controller {
$episodeActionEntity->setPosition($episodeAction->getPosition());
$episodeActionEntity->setStarted($episodeAction->getStarted());
$episodeActionEntity->setTotal($episodeAction->getTotal());
$episodeActionEntity->setTimestamp($episodeAction->getTimestamp());
$episodeActionEntity->setTimestamp($this->convertTimestampToDbDateTimeString($episodeAction->getTimestamp()));
$episodeActionEntity->setUserId($this->userId);
try {
@ -101,4 +101,15 @@ class EpisodeActionController extends Controller {
? (new \DateTime)->setTimestamp($since)
: (new \DateTime('-1 week'));
}
/**
* @param string $episodeAction
*
* @return string
*/
private function convertTimestampToDbDateTimeString(string $timestamp)
{
return \DateTime::createFromFormat('D F d H:i:s T Y', $timestamp)
->format("Y-m-d\TH:i:s");
}
}

View File

@ -0,0 +1,16 @@
<?php
declare(strict_types=1);
namespace OCA\GPodderSync\Tests\Unit\Core\EpisodeAction;
use Test\TestCase;
class EpisodeActionRequestTimestampConversionTest extends TestCase
{
public function testTimestampConversion()
{
$episodeActionTimestamp = "Tue May 18 23:45:11 GMT+02:00 2021";
$datetime = \DateTime::createFromFormat('D F d H:i:s T Y', $episodeActionTimestamp);
$this->assertEquals("2021-05-18T23:45:11", $datetime->format("Y-m-d\TH:i:s"));
}
}