Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace createFromDate() with create() #15

Merged
merged 1 commit into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Requests.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ public static function save($visits, $actions)

public static function getActions($year, $month)
{
$start = Carbon::createFromDate($year, $month)->startOfMonth();
$start = Carbon::create($year, $month)->startOfMonth();
$end = $start->copy()->addMonth();
$res = DB::table('kpis_actions')->whereBetween('date', [$start, $end])->sum('value');

return $res;
}
public static function getVisits($year, $month)
{
$start = Carbon::createFromDate($year, $month)->startOfMonth();
$start = Carbon::create($year, $month)->startOfMonth();
$end = $start->copy()->addMonth();
$res = DB::table('kpis_visits')->whereBetween('date', [$start, $end])->sum('value');

Expand Down
4 changes: 2 additions & 2 deletions src/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ class User
{
public static function getUser($year, $month)
{
$first = Carbon::createFromDate($year, $month)->startOfMonth();
$last = $first->copy()->addMonth();
$first = Carbon::create($year, $month)->startOfMonth();
$last = $first->copy()->endOfMonth();

return DB::table('kpis_users')
->whereBetween('date', [$first, $last])
Expand Down
12 changes: 12 additions & 0 deletions tests/RequestsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ public function testGetActions()
$this->assertEquals(10, $count);
}

public function testGetActionsOverflow()
{
Carbon::setTestNow(Carbon::parse('2024-07-31T05:45:23Z'));
$this->testGetActions();
}

public function testGetVisits()
{
$date = Carbon::now()
Expand All @@ -69,4 +75,10 @@ public function testGetVisits()

$this->assertEquals(10, $count);
}

public function testGetVisitsOverflow()
{
Carbon::setTestNow(Carbon::parse('2024-07-31T05:45:23Z'));
$this->testGetVisits();
}
}
6 changes: 6 additions & 0 deletions tests/UserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ public function testGetUser()
$this->assertEquals(20, $count);
}

public function testGetUserOverflow()
{
Carbon::setTestNow(Carbon::parse('2024-07-31T05:45:23Z'));
$this->testGetUser();
}

public function testGetUniqueUser(){
$date = Carbon::now()
->settings(['monthOverflow' => false])
Expand Down