Skip to content

Commit

Permalink
Merge pull request #6 from Northys/branch-support
Browse files Browse the repository at this point in the history
Added support for branches
  • Loading branch information
Mario Bašić committed Feb 1, 2016
2 parents f17342c + 11feae3 commit ddf1359
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 19 deletions.
42 changes: 25 additions & 17 deletions src/Traits/Reports.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ trait Reports {
* @param $startDate
* @param $endDate
* @param null $project
* @param null|string $branches
* @return int
*/
public function getHoursLoggedFor($startDate, $endDate, $project = null)
public function getHoursLoggedFor($startDate, $endDate, $project = null, $branches = null)
{
$response = $this->summaries($endDate, $startDate, $project);
$response = $this->summaries($endDate, $startDate, $project, $branches);

return $this->calculateHoursLogged($response);
}
Expand All @@ -24,38 +25,41 @@ public function getHoursLoggedFor($startDate, $endDate, $project = null)
*
* @param $period
* @param null $project
* @param null|string $branches
* @return int
*/
public function getHoursLoggedForLast($period, $project = null)
public function getHoursLoggedForLast($period, $project = null, $branches = null)
{
$todayDate = date('m/d/Y');
$endDate = date_format(date_sub(date_create($todayDate), date_interval_create_from_date_string($period)), 'm/d/Y');

return $this->getHoursLoggedFor($todayDate, $endDate, $project);
return $this->getHoursLoggedFor($todayDate, $endDate, $project, $branches);
}

/**
* Returns hours logged today.
* You can optionally specify a project.
*
* @param null $project
* @param null|string $branches
* @return int
*/
public function getHoursLoggedForToday($project = null)
public function getHoursLoggedForToday($project = null, $branches = null)
{
return $this->getHoursLoggedForLast('0 days', $project);
return $this->getHoursLoggedForLast('0 days', $project, $branches);
}

/**
* Returns hours logged yesterday.
* You can optionally specify a project.
*
* @param null $project
* @param null|string $branches
* @return int
*/
public function getHoursLoggedForYesterday($project = null)
public function getHoursLoggedForYesterday($project = null, $branches = null)
{
return $this->getHoursLoggedForLast('1 day', $project);
return $this->getHoursLoggedForLast('1 day', $project, $branches);
}

/**
Expand All @@ -65,53 +69,57 @@ public function getHoursLoggedForYesterday($project = null)
* _You can still use any method as long as it is under 7 days._
*
* @param null $project
* @param null|string $branches
* @return int
*/
public function getHoursLoggedForLast7Days($project = null)
public function getHoursLoggedForLast7Days($project = null, $branches = null)
{
return $this->getHoursLoggedForLast('7 days', $project);
return $this->getHoursLoggedForLast('7 days', $project, $branches);
}

/**
* Calculates hours logged for last 30 days in history.
* You can optionally specify a project.
*
* @param null $project
* @param null|string $branches
* @return int
*/
public function getHoursLoggedForLast30Days($project = null)
public function getHoursLoggedForLast30Days($project = null, $branches = null)
{
return $this->getHoursLoggedForLast('1 month', $project);
return $this->getHoursLoggedForLast('1 month', $project, $branches);
}

/**
* Calculates hours logged for this month.
* You can optionally specify a project.
*
* @param null $project
* @param null|string $branches
* @return int
*/
public function getHoursLoggedForThisMonth($project = null)
public function getHoursLoggedForThisMonth($project = null, $branches = null)
{
$endDate = date('m/01/Y');
$startDate = date('m/d/Y');

return $this->getHoursLoggedFor($startDate, $endDate, $project);
return $this->getHoursLoggedFor($startDate, $endDate, $project, $branches);
}

/**
* Calculates hours logged for last month.
* You can optionally specify a project.
*
* @param null $project
* @param null|string $branches
* @return int
*/
public function getHoursLoggedForLastMonth($project = null)
public function getHoursLoggedForLastMonth($project = null, $branches = null)
{
$endDate = date_format(date_sub(date_create(), date_interval_create_from_date_string('1 month')), 'm/01/Y');
$startDate = date_format(date_sub(date_create(), date_interval_create_from_date_string('1 month')), 'm/t/Y');

return $this->getHoursLoggedFor($startDate, $endDate, $project);
return $this->getHoursLoggedFor($startDate, $endDate, $project, $branches);
}

/**
Expand All @@ -132,4 +140,4 @@ protected function calculateHoursLogged($response)
return (int) floor($totalSeconds / 3600);
}

}
}
8 changes: 6 additions & 2 deletions src/WakaTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,19 @@ public function currentUser()
* @param $startDate
* @param $endDate
* @param null $project
* @param null|string $branches
* @return mixed
*/
public function summaries($startDate, $endDate, $project = null)
public function summaries($startDate, $endDate, $project = null, $branches = null)
{
if ($project !== null) {
$project = "&project={$project}";
}
if ($branches !== null) {
$branches = "&branches={$branches}";
}

return $this->makeRequest("users/current/summaries?start={$startDate}&end={$endDate}" . $project);
return $this->makeRequest("users/current/summaries?start={$startDate}&end={$endDate}" . $project . $branches);
}

/**
Expand Down

0 comments on commit ddf1359

Please sign in to comment.