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
+5 -6
View File
@@ -102,12 +102,11 @@ class Test extends Command
*/ */
public function handle() public function handle()
{ {
$whoami = executeCommand('whoami'); $today = Carbon::today();
$user = get_current_user(); $yesterday = Carbon::yesterday();
$uid = getmyuid(); $tomorrow = Carbon::tomorrow();
$uid2 = posix_getuid(); $diff = $tomorrow->diffInDays();
$info = posix_getpwuid($uid2); dd($today, $tomorrow, $diff);
dd($whoami, $user, $uid, $uid2, $info);
} }
} }
@@ -56,7 +56,7 @@ class ClaimResource extends Resource
, ,
Tables\Columns\TextColumn::make('torrent.name')->limit(40)->label(__('label.torrent.label'))->searchable(), Tables\Columns\TextColumn::make('torrent.name')->limit(40)->label(__('label.torrent.label'))->searchable(),
Tables\Columns\TextColumn::make('torrent.size')->label(__('label.torrent.size'))->formatStateUsing(fn (Model $record) => mksize($record->torrent->size)), Tables\Columns\TextColumn::make('torrent.size')->label(__('label.torrent.size'))->formatStateUsing(fn (Model $record) => mksize($record->torrent->size)),
Tables\Columns\TextColumn::make('torrent.added')->label(__('label.torrent.ttl'))->formatStateUsing(fn (Model $record) => mkprettytime($record->torrent->added->diffInSeconds())), Tables\Columns\TextColumn::make('torrent.added')->label(__('label.torrent.ttl'))->formatStateUsing(fn (Model $record) => mkprettytime(abs($record->torrent->added->diffInSeconds()))),
Tables\Columns\TextColumn::make('created_at')->label(__('label.created_at'))->dateTime(), Tables\Columns\TextColumn::make('created_at')->label(__('label.created_at'))->dateTime(),
Tables\Columns\TextColumn::make('last_settle_at')->label(__('label.claim.last_settle_at'))->dateTime(), Tables\Columns\TextColumn::make('last_settle_at')->label(__('label.claim.last_settle_at'))->dateTime(),
Tables\Columns\TextColumn::make('seedTimeThisMonth')->label(__('label.claim.seed_time_this_month')), Tables\Columns\TextColumn::make('seedTimeThisMonth')->label(__('label.claim.seed_time_this_month')),
+1 -1
View File
@@ -73,7 +73,7 @@ class HitAndRun extends NexusModel
return '---'; return '---';
} }
$inspectTime = HitAndRun::getConfig('inspect_time', $searchBoxId); $inspectTime = HitAndRun::getConfig('inspect_time', $searchBoxId);
$diffInSeconds = Carbon::now()->diffInSeconds($this->created_at->addHours(intval($inspectTime))); $diffInSeconds = Carbon::now()->diffInSeconds($this->created_at->addHours(intval($inspectTime)), true);
return mkprettytime($diffInSeconds); return mkprettytime($diffInSeconds);
} }
+2 -2
View File
@@ -37,7 +37,7 @@ class AttendanceRepository extends BaseRepository
//already attended today, do nothing //already attended today, do nothing
$isUpdated = 0; $isUpdated = 0;
} else { } else {
$diffDays = $today->diffInDays($added); $diffDays = $today->diffInDays($added, true);
if ($diffDays == 1) { if ($diffDays == 1) {
//yesterday do it, it's continuous //yesterday do it, it's continuous
$continuousDays = $this->getContinuousDays($attendance, Carbon::yesterday()); $continuousDays = $this->getContinuousDays($attendance, Carbon::yesterday());
@@ -292,7 +292,7 @@ class AttendanceRepository extends BaseRepository
} }
$date = Carbon::parse($dateStr); $date = Carbon::parse($dateStr);
$now = Carbon::now(); $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')])); 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) { return NexusDB::transaction(function () use ($user, $attendance, $date) {
+1 -1
View File
@@ -225,7 +225,7 @@ class ClaimRepository extends BaseRepository
$uploadedCaseWhen[] = sprintf('when %s then %s', $row->id, $row->snatch->uploaded); $uploadedCaseWhen[] = sprintf('when %s then %s', $row->id, $row->snatch->uploaded);
} else { } else {
$targetStartOfMonth = $row->created_at->startOfMonth(); $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); do_log("[UNREACHED_REMOVE], uid: $uid, torrent: " . $row->torrent_id);
$unReachedIdArr[] = $row->id; $unReachedIdArr[] = $row->id;
$unReachedTorrentIdArr[] = $row->torrent_id; $unReachedTorrentIdArr[] = $row->torrent_id;
+1 -1
View File
@@ -328,7 +328,7 @@ class ExamRepository extends BaseRepository
$filter = Exam::FILTER_USER_REGISTER_DAYS_RANGE; $filter = Exam::FILTER_USER_REGISTER_DAYS_RANGE;
$filterValues = $filters[$filter] ?? []; $filterValues = $filters[$filter] ?? [];
$value = $user->added->diffInDays(now()); $value = $user->added->diffInDays(now(), true);
$begin = $filterValues[0] ?? null; $begin = $filterValues[0] ?? null;
$end = $filterValues[1] ?? null; $end = $filterValues[1] ?? null;
if ($begin !== null && $value < $begin) { if ($begin !== null && $value < $begin) {
+1 -1
View File
@@ -300,7 +300,7 @@ class ToolRepository extends BaseRepository
$start = Carbon::now(); $start = Carbon::now();
try { try {
$remoteFilesystem->writeStream(basename($filename), $localFilesystem->readStream($filename)); $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 = 'Elapsed time: '.$start->diffForHumans(null, true);
$log .= ', Speed: '. number_format($speed/1024,2) . ' KB/s'; $log .= ', Speed: '. number_format($speed/1024,2) . ' KB/s';
do_log($log); do_log($log);
+4 -4
View File
@@ -262,7 +262,7 @@ class TorrentRepository extends BaseRepository
public function getPeerUploadSpeed($peer): string public function getPeerUploadSpeed($peer): string
{ {
$diff = $peer->uploaded - $peer->uploadoffset; $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'; return mksize($diff / $seconds) . '/s';
} }
@@ -270,9 +270,9 @@ class TorrentRepository extends BaseRepository
{ {
$diff = $peer->downloaded - $peer->downloadoffset; $diff = $peer->downloaded - $peer->downloadoffset;
if ($peer->isSeeder()) { if ($peer->isSeeder()) {
$seconds = max(1, $peer->started->diffInSeconds($peer->finishedat)); $seconds = max(1, $peer->started->diffInSeconds($peer->finishedat, true));
} else { } 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'; return mksize($diff / $seconds) . '/s';
} }
@@ -550,7 +550,7 @@ class TorrentRepository extends BaseRepository
$hasBeenDownloaded = Snatch::query()->where('torrentid', $torrent->id)->exists(); $hasBeenDownloaded = Snatch::query()->where('torrentid', $torrent->id)->exists();
$log = "Torrent: {$torrent->id} is in promotion, hasBeenDownloaded: $hasBeenDownloaded"; $log = "Torrent: {$torrent->id} is in promotion, hasBeenDownloaded: $hasBeenDownloaded";
if (!$hasBeenDownloaded) { if (!$hasBeenDownloaded) {
$diffInSeconds = $torrent->promotion_until->diffInSeconds($torrent->added); $diffInSeconds = $torrent->promotion_until->diffInSeconds($torrent->added, true);
$log .= ", addSeconds: $diffInSeconds"; $log .= ", addSeconds: $diffInSeconds";
$torrentUpdate['promotion_until'] = $torrent->promotion_until->addSeconds($diffInSeconds); $torrentUpdate['promotion_until'] = $torrent->promotion_until->addSeconds($diffInSeconds);
} }
+1 -1
View File
@@ -432,7 +432,7 @@ class UserRepository extends BaseRepository
$changeLog = $user->usernameChangeLogs()->orderBy('id', 'desc')->first(); $changeLog = $user->usernameChangeLogs()->orderBy('id', 'desc')->first();
if ($changeLog) { if ($changeLog) {
$miniDays = Setting::get('system.change_username_min_interval_in_days', 365); $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]); $msg = nexus_trans('user.change_username_lte_min_interval', ['last_change_time' => $changeLog->created_at, 'interval' => $miniDays]);
throw new \RuntimeException($msg); throw new \RuntimeException($msg);
} }
+1 -1
View File
@@ -68,7 +68,7 @@ foreach ($period as $value) {
if ($logValue->is_retroactive) { if ($logValue->is_retroactive) {
$events[] = array_merge($eventBase, ['title' => $lang_attendance['retroactive_event_text'], 'display' => 'list-item']); $events[] = array_merge($eventBase, ['title' => $lang_attendance['retroactive_event_text'], 'display' => 'list-item']);
} }
} elseif ($value->lte($today) && $value->diffInDays($today) <= \App\Models\Attendance::MAX_RETROACTIVE_DAYS) { } elseif ($value->lte($today) && $value->diffInDays($today, true) <= \App\Models\Attendance::MAX_RETROACTIVE_DAYS) {
$events[] = array_merge($eventBase, ['groupId' => 'to_do', 'display' => 'list-item']); $events[] = array_merge($eventBase, ['groupId' => 'to_do', 'display' => 'list-item']);
} }
} }
+1 -1
View File
@@ -73,7 +73,7 @@ foreach ($list as $row) {
<td class='rowfollow' align='left'><a href='userdetails.php?id=" . $row->uid . "'>" . $row->user->username . "</a></td> <td class='rowfollow' align='left'><a href='userdetails.php?id=" . $row->uid . "'>" . $row->user->username . "</a></td>
<td class='rowfollow' align='left'><a href='details.php?id=" . $row->torrent_id . "'>" . $row->torrent->name . "</a></td> <td class='rowfollow' align='left'><a href='details.php?id=" . $row->torrent_id . "'>" . $row->torrent->name . "</a></td>
<td class='rowfollow nowrap' align='center'>" . mksize($row->torrent->size) . "</td> <td class='rowfollow nowrap' align='center'>" . mksize($row->torrent->size) . "</td>
<td class='rowfollow nowrap' align='center'>" . mkprettytime($row->torrent->added->diffInSeconds($now)) . "</td> <td class='rowfollow nowrap' align='center'>" . mkprettytime($row->torrent->added->diffInSeconds($now, true)) . "</td>
<td class='rowfollow nowrap' align='center'>" . format_datetime($row->created_at) . "</td> <td class='rowfollow nowrap' align='center'>" . format_datetime($row->created_at) . "</td>
<td class='rowfollow nowrap' align='center'>" . format_datetime($row->last_settle_at) . "</td> <td class='rowfollow nowrap' align='center'>" . format_datetime($row->last_settle_at) . "</td>
<td class='rowfollow nowrap' align='center'>" . mkprettytime($row->snatch->seedtime - $row->seed_time_begin) . "</td> <td class='rowfollow nowrap' align='center'>" . mkprettytime($row->snatch->seedtime - $row->seed_time_begin) . "</td>
+1 -1
View File
@@ -30,7 +30,7 @@ $userRep = new \App\Repositories\UserRepository();
if ($user['added'] == "0000-00-00 00:00:00" || $user['added'] == null) { if ($user['added'] == "0000-00-00 00:00:00" || $user['added'] == null) {
$joindate = $lang_userdetails['text_not_available']; $joindate = $lang_userdetails['text_not_available'];
} else { } else {
$weeks = $userInfo->added->diffInWeeks() . nexus_trans('nexus.time_units.week'); $weeks = abs($userInfo->added->diffInWeeks()) . nexus_trans('nexus.time_units.week');
$joindate = $user['added']." (" . gettime($user["added"], true, false, true).", $weeks)"; $joindate = $user['added']." (" . gettime($user["added"], true, false, true).", $weeks)";
} }
$lastseen = $user["last_access"]; $lastseen = $user["last_access"];