Skip to content

Commit 9de6fb4

Browse files
committed
fix carbon 3 diffIn*
1 parent 943e960 commit 9de6fb4

File tree

12 files changed

+20
-21
lines changed

12 files changed

+20
-21
lines changed

app/Console/Commands/Test.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,11 @@ public function __construct()
102102
*/
103103
public function handle()
104104
{
105-
$whoami = executeCommand('whoami');
106-
$user = get_current_user();
107-
$uid = getmyuid();
108-
$uid2 = posix_getuid();
109-
$info = posix_getpwuid($uid2);
110-
dd($whoami, $user, $uid, $uid2, $info);
105+
$today = Carbon::today();
106+
$yesterday = Carbon::yesterday();
107+
$tomorrow = Carbon::tomorrow();
108+
$diff = $tomorrow->diffInDays();
109+
dd($today, $tomorrow, $diff);
111110
}
112111

113112
}

app/Filament/Resources/User/ClaimResource.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public static function table(Table $table): Table
5656
,
5757
Tables\Columns\TextColumn::make('torrent.name')->limit(40)->label(__('label.torrent.label'))->searchable(),
5858
Tables\Columns\TextColumn::make('torrent.size')->label(__('label.torrent.size'))->formatStateUsing(fn (Model $record) => mksize($record->torrent->size)),
59-
Tables\Columns\TextColumn::make('torrent.added')->label(__('label.torrent.ttl'))->formatStateUsing(fn (Model $record) => mkprettytime($record->torrent->added->diffInSeconds())),
59+
Tables\Columns\TextColumn::make('torrent.added')->label(__('label.torrent.ttl'))->formatStateUsing(fn (Model $record) => mkprettytime(abs($record->torrent->added->diffInSeconds()))),
6060
Tables\Columns\TextColumn::make('created_at')->label(__('label.created_at'))->dateTime(),
6161
Tables\Columns\TextColumn::make('last_settle_at')->label(__('label.claim.last_settle_at'))->dateTime(),
6262
Tables\Columns\TextColumn::make('seedTimeThisMonth')->label(__('label.claim.seed_time_this_month')),

app/Models/HitAndRun.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ private function doGetInspectTimeLeft(): string
7373
return '---';
7474
}
7575
$inspectTime = HitAndRun::getConfig('inspect_time', $searchBoxId);
76-
$diffInSeconds = Carbon::now()->diffInSeconds($this->created_at->addHours(intval($inspectTime)));
76+
$diffInSeconds = Carbon::now()->diffInSeconds($this->created_at->addHours(intval($inspectTime)), true);
7777
return mkprettytime($diffInSeconds);
7878
}
7979

app/Repositories/AttendanceRepository.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function attend($uid)
3737
//already attended today, do nothing
3838
$isUpdated = 0;
3939
} else {
40-
$diffDays = $today->diffInDays($added);
40+
$diffDays = $today->diffInDays($added, true);
4141
if ($diffDays == 1) {
4242
//yesterday do it, it's continuous
4343
$continuousDays = $this->getContinuousDays($attendance, Carbon::yesterday());
@@ -292,7 +292,7 @@ public function retroactive($user, $dateStr)
292292
}
293293
$date = Carbon::parse($dateStr);
294294
$now = Carbon::now();
295-
if ($date->gte($now) || $now->diffInDays($date) > Attendance::MAX_RETROACTIVE_DAYS) {
295+
if ($date->gte($now) || $now->diffInDays($date, true) > Attendance::MAX_RETROACTIVE_DAYS) {
296296
throw new \LogicException(nexus_trans('attendance.target_date_can_no_be_retroactive', ['date' => $date->format('Y-m-d')]));
297297
}
298298
return NexusDB::transaction(function () use ($user, $attendance, $date) {

app/Repositories/ClaimRepository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ public function settleUser($uid, $force = false, $test = false): bool
225225
$uploadedCaseWhen[] = sprintf('when %s then %s', $row->id, $row->snatch->uploaded);
226226
} else {
227227
$targetStartOfMonth = $row->created_at->startOfMonth();
228-
if ($startOfThisMonth->diffInMonths($targetStartOfMonth) > 1) {
228+
if ($startOfThisMonth->diffInMonths($targetStartOfMonth, true) > 1) {
229229
do_log("[UNREACHED_REMOVE], uid: $uid, torrent: " . $row->torrent_id);
230230
$unReachedIdArr[] = $row->id;
231231
$unReachedTorrentIdArr[] = $row->torrent_id;

app/Repositories/ExamRepository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ private function isExamMatchUser(Exam $exam, $user): bool
328328

329329
$filter = Exam::FILTER_USER_REGISTER_DAYS_RANGE;
330330
$filterValues = $filters[$filter] ?? [];
331-
$value = $user->added->diffInDays(now());
331+
$value = $user->added->diffInDays(now(), true);
332332
$begin = $filterValues[0] ?? null;
333333
$end = $filterValues[1] ?? null;
334334
if ($begin !== null && $value < $begin) {

app/Repositories/ToolRepository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ private function doTransfer(\Illuminate\Filesystem\FilesystemAdapter $remoteFile
300300
$start = Carbon::now();
301301
try {
302302
$remoteFilesystem->writeStream(basename($filename), $localFilesystem->readStream($filename));
303-
$speed = !(float)$start->diffInSeconds() ? 0 :filesize($filename) / (float)$start->diffInSeconds();
303+
$speed = !(float)abs($start->diffInSeconds()) ? 0 :filesize($filename) / (float)abs($start->diffInSeconds());
304304
$log = 'Elapsed time: '.$start->diffForHumans(null, true);
305305
$log .= ', Speed: '. number_format($speed/1024,2) . ' KB/s';
306306
do_log($log);

app/Repositories/TorrentRepository.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,17 +262,17 @@ public function listPeers($torrentId)
262262
public function getPeerUploadSpeed($peer): string
263263
{
264264
$diff = $peer->uploaded - $peer->uploadoffset;
265-
$seconds = max(1, $peer->started->diffInSeconds($peer->last_action));
265+
$seconds = max(1, $peer->started->diffInSeconds($peer->last_action, true));
266266
return mksize($diff / $seconds) . '/s';
267267
}
268268

269269
public function getPeerDownloadSpeed($peer): string
270270
{
271271
$diff = $peer->downloaded - $peer->downloadoffset;
272272
if ($peer->isSeeder()) {
273-
$seconds = max(1, $peer->started->diffInSeconds($peer->finishedat));
273+
$seconds = max(1, $peer->started->diffInSeconds($peer->finishedat, true));
274274
} else {
275-
$seconds = max(1, $peer->started->diffInSeconds($peer->last_action));
275+
$seconds = max(1, $peer->started->diffInSeconds($peer->last_action, true));
276276
}
277277
return mksize($diff / $seconds) . '/s';
278278
}
@@ -550,7 +550,7 @@ public function approval($user, array $params): array
550550
$hasBeenDownloaded = Snatch::query()->where('torrentid', $torrent->id)->exists();
551551
$log = "Torrent: {$torrent->id} is in promotion, hasBeenDownloaded: $hasBeenDownloaded";
552552
if (!$hasBeenDownloaded) {
553-
$diffInSeconds = $torrent->promotion_until->diffInSeconds($torrent->added);
553+
$diffInSeconds = $torrent->promotion_until->diffInSeconds($torrent->added, true);
554554
$log .= ", addSeconds: $diffInSeconds";
555555
$torrentUpdate['promotion_until'] = $torrent->promotion_until->addSeconds($diffInSeconds);
556556
}

app/Repositories/UserRepository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ public function consumeBenefit($uid, array $params): bool
432432
$changeLog = $user->usernameChangeLogs()->orderBy('id', 'desc')->first();
433433
if ($changeLog) {
434434
$miniDays = Setting::get('system.change_username_min_interval_in_days', 365);
435-
if ($changeLog->created_at->diffInDays() <= $miniDays) {
435+
if (abs($changeLog->created_at->diffInDays()) <= $miniDays) {
436436
$msg = nexus_trans('user.change_username_lte_min_interval', ['last_change_time' => $changeLog->created_at, 'interval' => $miniDays]);
437437
throw new \RuntimeException($msg);
438438
}

public/attendance.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
if ($logValue->is_retroactive) {
6969
$events[] = array_merge($eventBase, ['title' => $lang_attendance['retroactive_event_text'], 'display' => 'list-item']);
7070
}
71-
} elseif ($value->lte($today) && $value->diffInDays($today) <= \App\Models\Attendance::MAX_RETROACTIVE_DAYS) {
71+
} elseif ($value->lte($today) && $value->diffInDays($today, true) <= \App\Models\Attendance::MAX_RETROACTIVE_DAYS) {
7272
$events[] = array_merge($eventBase, ['groupId' => 'to_do', 'display' => 'list-item']);
7373
}
7474
}

0 commit comments

Comments
 (0)