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

@@ -102,12 +102,11 @@ class Test extends Command
*/
public function handle()
{
$whoami = executeCommand('whoami');
$user = get_current_user();
$uid = getmyuid();
$uid2 = posix_getuid();
$info = posix_getpwuid($uid2);
dd($whoami, $user, $uid, $uid2, $info);
$today = Carbon::today();
$yesterday = Carbon::yesterday();
$tomorrow = Carbon::tomorrow();
$diff = $tomorrow->diffInDays();
dd($today, $tomorrow, $diff);
}
}

View File

@@ -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.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('last_settle_at')->label(__('label.claim.last_settle_at'))->dateTime(),
Tables\Columns\TextColumn::make('seedTimeThisMonth')->label(__('label.claim.seed_time_this_month')),

View File

@@ -73,7 +73,7 @@ class HitAndRun extends NexusModel
return '---';
}
$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);
}

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);
}