Skip to content

Commit

Permalink
Merge pull request #5 from eventum/weekly-report-arguments
Browse files Browse the repository at this point in the history
implement date arguments for weekly-report
  • Loading branch information
glensc authored Sep 17, 2017
2 parents f31f494 + a4bc41e commit 2be186d
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 22 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file.

## [0.0.3]

- implement date arguments for weekly-report #5

[0.0.3]: https://github.com/eventum/cli/compare/0.0.2...master

Expand Down
2 changes: 1 addition & 1 deletion src/Command/AddTimeEntryCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

/**
* @return int
* @throws InvalidArgumentException
* @return int
*/
private function getCategory($issue_id)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Command/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ protected function getClient()
*
* @param string $url
* @throws InvalidArgumentException
* @return array
* @throws RuntimeException
* @return array
*/
private function askAuthentication($url, $retry = 3)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Command/SelfUpdateManifestCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
*
* @param string $pharFile
* @param $pharFile
* @return string
* @throws RuntimeException
* @return string
*/
private function getPharFileVersion($pharFile)
{
Expand Down
46 changes: 27 additions & 19 deletions src/Command/WeeklyReportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,32 +52,18 @@ protected function configure()
->setHelp(
<<<EOT
<info>%command.full_name% [<week>] [--separate-closed]</info>
<info>%command.full_name% [<start>] [<end>] [--separate-closed]</info>
<info>%command.full_name% [<start_date>] [<end_date>] [--separate-closed]</info>
Fetches the weekly report. Week is specified as an integer with 0 representing
the current week, -1 the previous week and so on. If the week is omitted it
defaults to the current week. Alternately, a date range can be set. Dates
should be in the format 'YYYY-MM-DD'.
Shows the weekly report.
Dates should be in the format 'YYYY-MM-DD'.
EOT
);
}

protected function execute(InputInterface $input, OutputInterface $output)
{
$start = (string)$input->getArgument('start');
$end = (string)$input->getArgument('end');
$options = array(
'separate_closed' => $input->getOption('separate-closed'),
);

// take current week
$start = new DateTime('Last Monday');
$end = new DateTime('Next Monday');
// TODO: handle parameters and week option

$prj_id = $this->getProjectId();
$data = $this->getClient()->getWeeklyReportData($prj_id, $start, $end, $options);
$data = $this->getWeeklyReportData();

$group_name = isset($data['group_name']) ? "[{$data['group_name']}]" : '';
$output->writeln(
Expand Down Expand Up @@ -123,4 +109,26 @@ protected function execute(InputInterface $input, OutputInterface $output)

$output->writeln("Total Time Spent: {$data['total_time']}");
}

private function getWeeklyReportData()
{
list($start, $end) = $this->getDateRange();
$prj_id = $this->getProjectId();
$options = array(
'separate_closed' => $this->input->getOption('separate-closed'),
);

return $this->getClient()->getWeeklyReportData($prj_id, $start, $end, $options);
}

private function getDateRange()
{
$start = $this->input->getArgument('start') ?: 'Last Monday';
$end = $this->input->getArgument('end') ?: 'Next Monday';

return array(
new DateTime($start),
new DateTime($end),
);
}
}

0 comments on commit 2be186d

Please sign in to comment.