Skip to content

Commit e453219

Browse files
Use string|float for database decimals
This reverts part of 761f323 since Doctrine stores decimals as strings to not loose precision. When we upgrade to PHP 8.4, we can use a differnt type to store them as `BCMath\Number` objects instead, which seems to be the better way to do this.
1 parent 1e706f0 commit e453219

22 files changed

+110
-110
lines changed

webapp/src/Controller/API/JudgehostController.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -644,8 +644,8 @@ public function addJudgingRunAction(
644644
}
645645

646646
$runResult = $request->request->get('runresult');
647-
$startTime = (float)$request->request->get('start_time');
648-
$endTime = (float)$request->request->get('end_time');
647+
$startTime = $request->request->get('start_time');
648+
$endTime = $request->request->get('end_time');
649649
$runTime = $request->request->get('runtime');
650650
$outputRun = $request->request->get('output_run');
651651
$outputDiff = $request->request->get('output_diff');
@@ -926,8 +926,8 @@ private function addSingleJudgingRun(
926926
string $hostname,
927927
string $runResult,
928928
string $runTime,
929-
float $startTime,
930-
float $endTime,
929+
string $startTime,
930+
string $endTime,
931931
string $outputSystem,
932932
string $outputError,
933933
string $outputDiff,

webapp/src/Entity/AuditLog.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class AuditLog
2929
scale: 9,
3030
options: ['comment' => 'Timestamp of the logentry', 'unsigned' => true]
3131
)]
32-
private float $logtime;
32+
private string|float $logtime;
3333

3434
#[ORM\Column(
3535
nullable: true,
@@ -70,13 +70,13 @@ public function getLogid(): ?int
7070
return $this->logid;
7171
}
7272

73-
public function setLogtime(float $logtime): AuditLog
73+
public function setLogtime(string|float $logtime): AuditLog
7474
{
7575
$this->logtime = $logtime;
7676
return $this;
7777
}
7878

79-
public function getLogtime(): float
79+
public function getLogtime(): string|float
8080
{
8181
return $this->logtime;
8282
}

webapp/src/Entity/Clarification.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class Clarification extends BaseApiEntity implements
6161
options: ['comment' => 'Time sent', 'unsigned' => true]
6262
)]
6363
#[Serializer\Exclude]
64-
private float $submittime;
64+
private string|float $submittime;
6565

6666
#[ORM\Column(nullable: true, options: ['comment' => 'Name of jury member who answered this'])]
6767
#[Serializer\Exclude]
@@ -145,13 +145,13 @@ public function getExternalid(): ?string
145145
return $this->externalid;
146146
}
147147

148-
public function setSubmittime(float $submittime): Clarification
148+
public function setSubmittime(string|float $submittime): Clarification
149149
{
150150
$this->submittime = $submittime;
151151
return $this;
152152
}
153153

154-
public function getSubmittime(): float
154+
public function getSubmittime(): string|float
155155
{
156156
return $this->submittime;
157157
}

webapp/src/Entity/Contest.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class Contest extends BaseApiEntity implements
8383
options: ['comment' => 'Time contest becomes visible in team/public views', 'unsigned' => true]
8484
)]
8585
#[Serializer\Exclude]
86-
private ?float $activatetime;
86+
private string|float|null $activatetime;
8787

8888
#[ORM\Column(
8989
type: 'decimal',
@@ -92,7 +92,7 @@ class Contest extends BaseApiEntity implements
9292
options: ['comment' => 'Time contest starts, submissions accepted', 'unsigned' => true]
9393
)]
9494
#[Serializer\Exclude]
95-
private ?float $starttime = null;
95+
private string|float|null $starttime = null;
9696

9797
#[ORM\Column(options: [
9898
'comment' => 'If disabled, starttime is not used, e.g. to delay contest start',
@@ -109,7 +109,7 @@ class Contest extends BaseApiEntity implements
109109
options: ['comment' => 'Time scoreboard is frozen', 'unsigned' => true]
110110
)]
111111
#[Serializer\Exclude]
112-
private ?float $freezetime = null;
112+
private string|float|null $freezetime = null;
113113

114114
#[ORM\Column(
115115
type: 'decimal',
@@ -118,7 +118,7 @@ class Contest extends BaseApiEntity implements
118118
options: ['comment' => 'Time after which no more submissions are accepted', 'unsigned' => true]
119119
)]
120120
#[Serializer\Exclude]
121-
private ?float $endtime;
121+
private string|float|null $endtime;
122122

123123
#[ORM\Column(
124124
type: 'decimal',
@@ -128,7 +128,7 @@ class Contest extends BaseApiEntity implements
128128
options: ['comment' => 'Unfreeze a frozen scoreboard at this time', 'unsigned' => true]
129129
)]
130130
#[Serializer\Exclude]
131-
private ?float $unfreezetime = null;
131+
private string|float|null $unfreezetime = null;
132132

133133
#[ORM\Column(
134134
type: 'decimal',
@@ -138,7 +138,7 @@ class Contest extends BaseApiEntity implements
138138
options: ['comment' => 'Time when contest was finalized, null if not yet', 'unsigned' => true]
139139
)]
140140
#[Serializer\Exclude]
141-
private ?float $finalizetime = null;
141+
private string|float|null $finalizetime = null;
142142

143143
#[ORM\Column(
144144
type: 'text',
@@ -213,7 +213,7 @@ public function getScoreboardTypeString(): string
213213
options: ['comment' => 'Time contest becomes invisible in team/public views', 'unsigned' => true]
214214
)]
215215
#[Serializer\Exclude]
216-
private ?float $deactivatetime = null;
216+
private string|float|null $deactivatetime = null;
217217

218218
#[ORM\Column(
219219
length: 64,
@@ -513,7 +513,7 @@ public function getActivatetime(): ?float
513513
return $this->activatetime === null ? null : (float)$this->activatetime;
514514
}
515515

516-
public function setStarttime(float $starttime): Contest
516+
public function setStarttime(string|float $starttime): Contest
517517
{
518518
$this->starttime = $starttime;
519519
return $this;
@@ -581,7 +581,7 @@ public function getFinalizetime(): ?float
581581
return $this->finalizetime === null ? null : (float)$this->finalizetime;
582582
}
583583

584-
public function setFinalizetime(?float $finalizetimeString): Contest
584+
public function setFinalizetime(string|float|null $finalizetimeString): Contest
585585
{
586586
$this->finalizetime = $finalizetimeString;
587587
return $this;
@@ -699,31 +699,31 @@ public function getDeactivatetimeString(): ?string
699699
return $this->deactivatetimeString;
700700
}
701701

702-
public function setActivatetime(float $activatetime): Contest
702+
public function setActivatetime(string|float|null $activatetime): Contest
703703
{
704704
$this->activatetime = $activatetime;
705705
return $this;
706706
}
707707

708-
public function setFreezetime(float $freezetime): Contest
708+
public function setFreezetime(string|float $freezetime): Contest
709709
{
710710
$this->freezetime = $freezetime;
711711
return $this;
712712
}
713713

714-
public function setEndtime(float $endtime): Contest
714+
public function setEndtime(string|float $endtime): Contest
715715
{
716716
$this->endtime = $endtime;
717717
return $this;
718718
}
719719

720-
public function setUnfreezetime(float $unfreezetime): Contest
720+
public function setUnfreezetime(string|float $unfreezetime): Contest
721721
{
722722
$this->unfreezetime = $unfreezetime;
723723
return $this;
724724
}
725725

726-
public function setDeactivatetime(float $deactivatetime): Contest
726+
public function setDeactivatetime(string|float $deactivatetime): Contest
727727
{
728728
$this->deactivatetime = $deactivatetime;
729729
return $this;
@@ -1042,7 +1042,7 @@ public function isActive(): bool
10421042
($this->deactivatetime == null || $this->deactivatetime > time());
10431043
}
10441044

1045-
public function getAbsoluteTime(?string $time_string): float|int|null
1045+
public function getAbsoluteTime(?string $time_string): string|float|int|null
10461046
{
10471047
if ($time_string === null) {
10481048
return null;
@@ -1073,7 +1073,7 @@ public function getAbsoluteTime(?string $time_string): float|int|null
10731073
} catch (Exception) {
10741074
return null;
10751075
}
1076-
return (float)$date->format('U.v');
1076+
return $date->format('U.v');
10771077
}
10781078
}
10791079

webapp/src/Entity/Event.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class Event
2929
scale: 9,
3030
options: ['comment' => 'When the event occurred', 'unsigned' => true]
3131
)]
32-
private float $eventtime;
32+
private string|float $eventtime;
3333

3434
#[ORM\Column(length: 32, options: ['comment' => 'API endpoint associated to this entry'])]
3535
private string $endpointtype;
@@ -64,13 +64,13 @@ public function getEventid(): int
6464
return $this->eventid;
6565
}
6666

67-
public function setEventtime(float $eventtime): Event
67+
public function setEventtime(string|float $eventtime): Event
6868
{
6969
$this->eventtime = $eventtime;
7070
return $this;
7171
}
7272

73-
public function getEventtime(): float
73+
public function getEventtime(): string|float
7474
{
7575
return $this->eventtime;
7676
}

webapp/src/Entity/ExternalContestSource.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class ExternalContestSource
4747
nullable: true,
4848
options: ['comment' => 'Time of last poll by event feed reader', 'unsigned' => true]
4949
)]
50-
private ?float $lastPollTime = null;
50+
private string|float|null $lastPollTime = null;
5151

5252
#[ORM\Column(
5353
type: 'smallint',
@@ -139,12 +139,12 @@ public function setLastEventId(?string $lastEventId): ExternalContestSource
139139
return $this;
140140
}
141141

142-
public function getLastPollTime(): float|null
142+
public function getLastPollTime(): string|float|null
143143
{
144144
return $this->lastPollTime;
145145
}
146146

147-
public function setLastPollTime(?float $lastPollTime): ExternalContestSource
147+
public function setLastPollTime(string|float|null $lastPollTime): ExternalContestSource
148148
{
149149
$this->lastPollTime = $lastPollTime;
150150
return $this;

webapp/src/Entity/ExternalJudgement.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class ExternalJudgement
6868
scale: 9,
6969
options: ['comment' => 'Time judging started', 'unsigned' => true]
7070
)]
71-
private float $starttime;
71+
private string|float $starttime;
7272

7373
#[ORM\Column(
7474
type: 'decimal',
@@ -77,7 +77,7 @@ class ExternalJudgement
7777
nullable: true,
7878
options: ['comment' => 'Time judging ended, null = still busy', 'unsigned' => true]
7979
)]
80-
private ?float $endtime = null;
80+
private string|float|null $endtime = null;
8181

8282
#[ORM\Column(
8383
options: ['comment' => 'Old external judgement is marked as invalid when receiving a new one', 'default' => 1]
@@ -163,24 +163,24 @@ public function getVerifyComment(): ?string
163163
return $this->verify_comment;
164164
}
165165

166-
public function setStarttime(float $starttime): ExternalJudgement
166+
public function setStarttime(string|float $starttime): ExternalJudgement
167167
{
168168
$this->starttime = $starttime;
169169
return $this;
170170
}
171171

172-
public function getStarttime(): float
172+
public function getStarttime(): string|float
173173
{
174174
return $this->starttime;
175175
}
176176

177-
public function setEndtime(?float $endtime): ExternalJudgement
177+
public function setEndtime(string|float|null $endtime): ExternalJudgement
178178
{
179179
$this->endtime = $endtime;
180180
return $this;
181181
}
182182

183-
public function getEndtime(): float|null
183+
public function getEndtime(): string|float|null
184184
{
185185
return $this->endtime;
186186
}

webapp/src/Entity/ExternalRun.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class ExternalRun
4545
scale: 9,
4646
options: ['comment' => 'Time run ended', 'unsigned' => true]
4747
)]
48-
private float $endtime;
48+
private string|float $endtime;
4949

5050
#[ORM\Column(options: ['comment' => 'Running time on this testcase'])]
5151
private float $runtime;
@@ -89,13 +89,13 @@ public function getResult(): string
8989
return $this->result;
9090
}
9191

92-
public function setEndtime(float $endtime): ExternalRun
92+
public function setEndtime(string|float $endtime): ExternalRun
9393
{
9494
$this->endtime = $endtime;
9595
return $this;
9696
}
9797

98-
public function getEndtime(): float
98+
public function getEndtime(): string|float
9999
{
100100
return $this->endtime;
101101
}

webapp/src/Entity/InternalError.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class InternalError
4343
scale: 9,
4444
options: ['comment' => 'Timestamp of the internal error', 'unsigned' => true]
4545
)]
46-
private float $time;
46+
private string|float $time;
4747

4848
/**
4949
* @var array{kind: string, hostname?: string, execid?: string, probid: string, langid: string}
@@ -118,13 +118,13 @@ public function getJudgehostlog(): string
118118
return $this->judgehostlog;
119119
}
120120

121-
public function setTime(float $time): InternalError
121+
public function setTime(string|float $time): InternalError
122122
{
123123
$this->time = $time;
124124
return $this;
125125
}
126126

127-
public function getTime(): float
127+
public function getTime(): string|float
128128
{
129129
return $this->time;
130130
}

webapp/src/Entity/JudgeTask.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public function getSubmitid(): ?int
152152
options: ['comment' => 'Time the judgetask was started', 'unsigned' => true]
153153
)]
154154
#[Serializer\Exclude]
155-
private ?float $starttime = null;
155+
private string|float|null $starttime = null;
156156

157157
/**
158158
* @var Collection<int, JudgingRun>
@@ -341,13 +341,13 @@ public function getValid(): bool
341341
return $this->valid;
342342
}
343343

344-
public function setStarttime(?float $starttime): JudgeTask
344+
public function setStarttime(string|float|null $starttime): JudgeTask
345345
{
346346
$this->starttime = $starttime;
347347
return $this;
348348
}
349349

350-
public function getStarttime(): float|null
350+
public function getStarttime(): string|float|null
351351
{
352352
return $this->starttime;
353353
}

0 commit comments

Comments
 (0)