diff --git a/lib/Service/SubmissionService.php b/lib/Service/SubmissionService.php index afe1e315c..931e6d9c4 100644 --- a/lib/Service/SubmissionService.php +++ b/lib/Service/SubmissionService.php @@ -39,7 +39,6 @@ use OCP\Files\IRootFolder; use OCP\Files\NotPermittedException; use OCP\IConfig; -use OCP\IDateTimeFormatter; use OCP\IL10N; use OCP\IUser; use OCP\IUserManager; @@ -93,7 +92,6 @@ public function __construct(FormMapper $formMapper, AnswerMapper $answerMapper, IRootFolder $storage, IConfig $config, - IDateTimeFormatter $dateTimeFormatter, IL10N $l10n, LoggerInterface $logger, IUserManager $userManager, @@ -104,7 +102,6 @@ public function __construct(FormMapper $formMapper, $this->answerMapper = $answerMapper; $this->storage = $storage; $this->config = $config; - $this->dateTimeFormatter = $dateTimeFormatter; $this->l10n = $l10n; $this->logger = $logger; $this->userManager = $userManager; @@ -236,7 +233,7 @@ public function getSubmissionsCsv(string $hash): array { } // Date - $row[] = $this->dateTimeFormatter->formatDateTime($submission->getTimestamp(), 'full', 'full', new DateTimeZone($userTimezone), $this->l10n); + $row[] = date_format(date_timestamp_set(new DateTime(), $submission->getTimestamp())->setTimezone(new DateTimeZone($userTimezone)), 'c'); // Answers, make sure we keep the question order $answers = array_reduce($this->answerMapper->findBySubmission($submission->getId()), function (array $carry, Answer $answer) { diff --git a/tests/Integration/Api/ApiV2Test.php b/tests/Integration/Api/ApiV2Test.php index 560c2f034..69025374d 100644 --- a/tests/Integration/Api/ApiV2Test.php +++ b/tests/Integration/Api/ApiV2Test.php @@ -1204,9 +1204,9 @@ public function dataExportSubmissions() { 'exportSubmissions' => [ 'expected' => ' "User ID","User display name","Timestamp","First Question?","Second Question?" - "user1","User No. 1","Friday, January 2, 1970 at 10:17:36 AM GMT+0:00","This is a short answer.","Option 1" - "","Anonymous user","Thursday, January 1, 1970 at 3:25:45 AM GMT+0:00","This is another short answer.","Option 2" - "","Anonymous user","Thursday, January 1, 1970 at 12:20:34 AM GMT+0:00","",""' + "user1","User No. 1","1970-01-02T10:17:36+00:00","This is a short answer.","Option 1" + "","Anonymous user","1970-01-01T03:25:45+00:00","This is another short answer.","Option 2" + "","Anonymous user","1970-01-01T00:20:34+00:00","",""' ] ]; } diff --git a/tests/Unit/Service/SubmissionServiceTest.php b/tests/Unit/Service/SubmissionServiceTest.php index 838bd1e4d..e555e75ff 100644 --- a/tests/Unit/Service/SubmissionServiceTest.php +++ b/tests/Unit/Service/SubmissionServiceTest.php @@ -40,7 +40,6 @@ use OCP\Files\IRootFolder; use OCP\Files\NotFoundException; use OCP\IConfig; -use OCP\IDateTimeFormatter; use OCP\IL10N; use OCP\IUser; use OCP\IUserManager; @@ -74,9 +73,6 @@ class SubmissionServiceTest extends TestCase { /** @var IConfig|MockObject */ private $config; - /** @var IDateTimeFormatter|MockObject */ - private $dateTimeFormatter; - /** @var IL10N|MockObject */ private $l10n; @@ -94,7 +90,6 @@ public function setUp(): void { $this->answerMapper = $this->createMock(AnswerMapper::class); $this->storage = $this->createMock(IRootFolder::class); $this->config = $this->createMock(IConfig::class); - $this->dateTimeFormatter = $this->createMock(IDateTimeFormatter::class); $this->l10n = $this->createMock(IL10N::class); $this->logger = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock(); $this->userManager = $this->createMock(IUserManager::class); @@ -121,7 +116,6 @@ public function setUp(): void { $this->answerMapper, $this->storage, $this->config, - $this->dateTimeFormatter, $this->l10n, $this->logger, $this->userManager, @@ -285,6 +279,7 @@ public function dataGetSubmissionsCsv() { [ 'id' => 1, 'userId' => 'user1', + 'timestamp' => 123456789, 'answers' => [ ['questionId' => 1, 'text' => 'Q1A1'], ['questionId' => 2, 'text' => 'Q2A1'] @@ -293,6 +288,7 @@ public function dataGetSubmissionsCsv() { [ 'id' => 2, 'userId' => 'user2', + 'timestamp' => 123456789, 'answers' => [ ['questionId' => 1, 'text' => 'Q1A2'], ['questionId' => 2, 'text' => 'Q2A2'] @@ -302,8 +298,8 @@ public function dataGetSubmissionsCsv() { // Expected CSV-Result ' "User ID","User display name","Timestamp","Question 1","Question 2" - "user1","User 1","01.01.01, 01:01","Q1A1","Q2A1" - "user2","User 2","01.01.01, 01:01","Q1A2","Q2A2" + "user1","User 1","1973-11-29T22:33:09+01:00","Q1A1","Q2A1" + "user2","User 2","1973-11-29T22:33:09+01:00","Q1A2","Q2A2" ' ], 'checkbox-multi-answers' => [ @@ -316,6 +312,7 @@ public function dataGetSubmissionsCsv() { [ 'id' => 1, 'userId' => 'user1', + 'timestamp' => 123456789, 'answers' => [ ['questionId' => 1, 'text' => 'Q1A1'], ['questionId' => 1, 'text' => 'Q1A2'], @@ -326,7 +323,7 @@ public function dataGetSubmissionsCsv() { // Expected CSV-Result ' "User ID","User display name","Timestamp","Question 1" - "user1","User 1","01.01.01, 01:01","Q1A1; Q1A2; Q1A3" + "user1","User 1","1973-11-29T22:33:09+01:00","Q1A1; Q1A2; Q1A3" ' ], 'anonymous-user' => [ @@ -339,6 +336,7 @@ public function dataGetSubmissionsCsv() { [ 'id' => 1, 'userId' => 'anon-user-xyz', + 'timestamp' => 123456789, 'answers' => [ ['questionId' => 1, 'text' => 'Q1A1'], ] @@ -347,7 +345,7 @@ public function dataGetSubmissionsCsv() { // Expected CSV-Result ' "User ID","User display name","Timestamp","Question 1" - "","Anonymous user","01.01.01, 01:01","Q1A1" + "","Anonymous user","1973-11-29T22:33:09+01:00","Q1A1" ' ], 'questions-not-answered' => [ @@ -362,6 +360,7 @@ public function dataGetSubmissionsCsv() { [ 'id' => 1, 'userId' => 'user1', + 'timestamp' => 123456789, 'answers' => [ ['questionId' => 2, 'text' => 'Q2A1'] ] @@ -370,7 +369,7 @@ public function dataGetSubmissionsCsv() { // Expected CSV-Result ' "User ID","User display name","Timestamp","Question 1","Question 2","Question 3" - "user1","User 1","01.01.01, 01:01","","Q2A1","" + "user1","User 1","1973-11-29T22:33:09+01:00","","Q2A1","" ' ], /* No submissions, but request via api */ @@ -395,6 +394,7 @@ public function dataGetSubmissionsCsv() { [ 'id' => 1, 'userId' => 'anon-user-xyz', + 'timestamp' => 123456789, 'answers' => [ ['questionId' => 1, 'text' => 'Q1A1'], ] @@ -403,7 +403,7 @@ public function dataGetSubmissionsCsv() { // Expected CSV-Result ' "User ID","User display name","Timestamp" - "","Anonymous user","01.01.01, 01:01" + "","Anonymous user","1973-11-29T22:33:09+01:00" ' ], ]; @@ -438,6 +438,7 @@ private function setUpSimpleCsvTest(): string { [ 'id' => 1, 'userId' => 'user1', + 'timestamp' => 123456789, 'answers' => [ ['questionId' => 1, 'text' => 'Q1A1'] ] @@ -446,7 +447,7 @@ private function setUpSimpleCsvTest(): string { // Expected CSV-Result ' "User ID","User display name","Timestamp","Question 1" - "user1","User 1","01.01.01, 01:01","Q1A1" + "user1","User 1","1973-11-29T22:33:09+01:00","Q1A1" ' ); } @@ -510,11 +511,6 @@ private function setUpCsvTest(array $questions, array $submissions, string $csvT ['unknown', null] ])); - // Just using any timestamp here - $this->dateTimeFormatter->expects($this->any()) - ->method('formatDateTime') - ->willReturn('01.01.01, 01:01'); - $this->answerMapper->expects($this->any()) ->method('findBySubmission') // Return AnswerObjects for corresponding submission