fix carbon 3 diffIn*

This commit is contained in:
xiaomlove
2025-01-19 23:41:50 +08:00
parent 943e960921
commit 9de6fb42a9
12 changed files with 20 additions and 21 deletions

View File

@@ -37,7 +37,7 @@ class AttendanceRepository extends BaseRepository
//already attended today, do nothing
$isUpdated = 0;
} else {
$diffDays = $today->diffInDays($added);
$diffDays = $today->diffInDays($added, true);
if ($diffDays == 1) {
//yesterday do it, it's continuous
$continuousDays = $this->getContinuousDays($attendance, Carbon::yesterday());
@@ -292,7 +292,7 @@ class AttendanceRepository extends BaseRepository
}
$date = Carbon::parse($dateStr);
$now = Carbon::now();
if ($date->gte($now) || $now->diffInDays($date) > Attendance::MAX_RETROACTIVE_DAYS) {
if ($date->gte($now) || $now->diffInDays($date, true) > Attendance::MAX_RETROACTIVE_DAYS) {
throw new \LogicException(nexus_trans('attendance.target_date_can_no_be_retroactive', ['date' => $date->format('Y-m-d')]));
}
return NexusDB::transaction(function () use ($user, $attendance, $date) {

View File

@@ -225,7 +225,7 @@ class ClaimRepository extends BaseRepository
$uploadedCaseWhen[] = sprintf('when %s then %s', $row->id, $row->snatch->uploaded);
} else {
$targetStartOfMonth = $row->created_at->startOfMonth();
if ($startOfThisMonth->diffInMonths($targetStartOfMonth) > 1) {
if ($startOfThisMonth->diffInMonths($targetStartOfMonth, true) > 1) {
do_log("[UNREACHED_REMOVE], uid: $uid, torrent: " . $row->torrent_id);
$unReachedIdArr[] = $row->id;
$unReachedTorrentIdArr[] = $row->torrent_id;

View File

@@ -328,7 +328,7 @@ class ExamRepository extends BaseRepository
$filter = Exam::FILTER_USER_REGISTER_DAYS_RANGE;
$filterValues = $filters[$filter] ?? [];
$value = $user->added->diffInDays(now());
$value = $user->added->diffInDays(now(), true);
$begin = $filterValues[0] ?? null;
$end = $filterValues[1] ?? null;
if ($begin !== null && $value < $begin) {

View File

@@ -300,7 +300,7 @@ class ToolRepository extends BaseRepository
$start = Carbon::now();
try {
$remoteFilesystem->writeStream(basename($filename), $localFilesystem->readStream($filename));
$speed = !(float)$start->diffInSeconds() ? 0 :filesize($filename) / (float)$start->diffInSeconds();
$speed = !(float)abs($start->diffInSeconds()) ? 0 :filesize($filename) / (float)abs($start->diffInSeconds());
$log = 'Elapsed time: '.$start->diffForHumans(null, true);
$log .= ', Speed: '. number_format($speed/1024,2) . ' KB/s';
do_log($log);

View File

@@ -262,7 +262,7 @@ class TorrentRepository extends BaseRepository
public function getPeerUploadSpeed($peer): string
{
$diff = $peer->uploaded - $peer->uploadoffset;
$seconds = max(1, $peer->started->diffInSeconds($peer->last_action));
$seconds = max(1, $peer->started->diffInSeconds($peer->last_action, true));
return mksize($diff / $seconds) . '/s';
}
@@ -270,9 +270,9 @@ class TorrentRepository extends BaseRepository
{
$diff = $peer->downloaded - $peer->downloadoffset;
if ($peer->isSeeder()) {
$seconds = max(1, $peer->started->diffInSeconds($peer->finishedat));
$seconds = max(1, $peer->started->diffInSeconds($peer->finishedat, true));
} else {
$seconds = max(1, $peer->started->diffInSeconds($peer->last_action));
$seconds = max(1, $peer->started->diffInSeconds($peer->last_action, true));
}
return mksize($diff / $seconds) . '/s';
}
@@ -550,7 +550,7 @@ class TorrentRepository extends BaseRepository
$hasBeenDownloaded = Snatch::query()->where('torrentid', $torrent->id)->exists();
$log = "Torrent: {$torrent->id} is in promotion, hasBeenDownloaded: $hasBeenDownloaded";
if (!$hasBeenDownloaded) {
$diffInSeconds = $torrent->promotion_until->diffInSeconds($torrent->added);
$diffInSeconds = $torrent->promotion_until->diffInSeconds($torrent->added, true);
$log .= ", addSeconds: $diffInSeconds";
$torrentUpdate['promotion_until'] = $torrent->promotion_until->addSeconds($diffInSeconds);
}

View File

@@ -432,7 +432,7 @@ class UserRepository extends BaseRepository
$changeLog = $user->usernameChangeLogs()->orderBy('id', 'desc')->first();
if ($changeLog) {
$miniDays = Setting::get('system.change_username_min_interval_in_days', 365);
if ($changeLog->created_at->diffInDays() <= $miniDays) {
if (abs($changeLog->created_at->diffInDays()) <= $miniDays) {
$msg = nexus_trans('user.change_username_lte_min_interval', ['last_change_time' => $changeLog->created_at, 'interval' => $miniDays]);
throw new \RuntimeException($msg);
}