Page MenuHomePhorge

D2464.1775207192.diff
No OneTemporary

Authored By
Unknown
Size
2 KB
Referenced Files
None
Subscribers
None

D2464.1775207192.diff

diff --git a/src/app/Http/Controllers/API/V4/WalletsController.php b/src/app/Http/Controllers/API/V4/WalletsController.php
--- a/src/app/Http/Controllers/API/V4/WalletsController.php
+++ b/src/app/Http/Controllers/API/V4/WalletsController.php
@@ -308,9 +308,18 @@
// We make sure both have the same time set.
$now = Carbon::now()->setTimeFrom($until);
+ $diffOptions = [
+ 'syntax' => Carbon::DIFF_ABSOLUTE,
+ 'parts' => 1,
+ ];
+
+ if ($now->diff($until)->days > 31) {
+ $diffOptions['parts'] = 2;
+ }
+
$params = [
'date' => $until->toDateString(),
- 'days' => $now->diffForHumans($until, Carbon::DIFF_ABSOLUTE),
+ 'days' => $now->diffForHumans($until, $diffOptions),
];
return \trans('app.wallet-notice-date', $params);
diff --git a/src/composer.json b/src/composer.json
--- a/src/composer.json
+++ b/src/composer.json
@@ -41,7 +41,7 @@
"kirschbaum-development/mail-intercept": "^0.2.4",
"laravel/dusk": "~5.11.0",
"mockery/mockery": "^1.0",
- "nunomaduro/larastan": "^0.6",
+ "nunomaduro/larastan": "^0.7",
"phpstan/phpstan": "^0.12",
"phpunit/phpunit": "^8"
},
diff --git a/src/tests/Feature/Controller/WalletsTest.php b/src/tests/Feature/Controller/WalletsTest.php
--- a/src/tests/Feature/Controller/WalletsTest.php
+++ b/src/tests/Feature/Controller/WalletsTest.php
@@ -68,11 +68,24 @@
$wallet->owner->created_at = Carbon::now()->subMonthsWithoutOverflow(1)->subDays(1);
$wallet->owner->save();
+ // test "1 month"
$wallet->balance = 999;
$notice = $method->invoke($controller, $wallet);
$this->assertRegExp('/\((1 month|4 weeks)\)/', $notice);
+ // test "2 months"
+ $wallet->balance = 999 * 2.6;
+ $notice = $method->invoke($controller, $wallet);
+
+ $this->assertRegExp('/\(2 months 2 weeks\)/', $notice);
+
+ // test "almost 2 years"
+ $wallet->balance = 999 * 23.5;
+ $notice = $method->invoke($controller, $wallet);
+
+ $this->assertRegExp('/\(1 year 11 months\)/', $notice);
+
// Old entitlements, 100% discount
$this->backdateEntitlements($wallet->entitlements, Carbon::now()->subDays(40));
$discount = \App\Discount::where('discount', 100)->first();

File Metadata

Mime Type
text/plain
Expires
Fri, Apr 3, 9:06 AM (4 d, 4 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18823393
Default Alt Text
D2464.1775207192.diff (2 KB)

Event Timeline