Skip to content
This repository was archived by the owner on Mar 30, 2024. It is now read-only.

Commit a0b9fab

Browse files
committed
Implement #41
1 parent 2c3830d commit a0b9fab

File tree

2 files changed

+107
-26
lines changed

2 files changed

+107
-26
lines changed

core/Stats.php

Lines changed: 106 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,49 +18,130 @@ public function __construct(CLIParser $parser, CLIOutput $output) {
1818
}
1919

2020
private function parseCommands(array $commands) : void {
21-
$this->output->print(
22-
array('Statistics',
23-
array(
24-
'Use commands ' .
25-
CLIOutput::colorString( 'day', CLIOutput::BLUE ) . ', ' .
26-
CLIOutput::colorString( 'week', CLIOutput::BLUE ) . ', '.
27-
CLIOutput::colorString( 'month', CLIOutput::BLUE ) . ', '.
28-
CLIOutput::colorString( 'range', CLIOutput::BLUE ) . ', '.
29-
CLIOutput::colorString( 'all', CLIOutput::BLUE ) . ' or '.
30-
CLIOutput::colorString( 'today', CLIOutput::BLUE ) . ' (=default).',
31-
'Optional add '.CLIOutput::colorString('-cats Hobby,Home', CLIOutput::BLUE) .
32-
', ' . CLIOutput::colorString('-names TTT,Website', CLIOutput::BLUE),
33-
'and/or ' . CLIOutput::colorString('-devices Laptop,Desktop', CLIOutput::BLUE).
34-
' to filter for',
35-
'categories, names and devices (if synced across devices).',
36-
'Also '.CLIOutput::colorString('-localOnly', CLIOutput::BLUE) .
37-
' can be added to ignore external devices from syncs.',
38-
)
39-
));
21+
$this->showHelp(in_array( '-h', $commands) || in_array( '--help', $commands));
22+
if(in_array('--help', $commands)){
23+
return;
24+
}
25+
4026
switch( $commands[0] ) {
41-
case "day":
42-
$this->backUntil(time() - 86400, array_slice($commands, 1));
43-
break;
4427
case "week":
45-
$this->backUntil(time() - 604800, array_slice($commands, 1));
28+
case "cWeek":
29+
$this->backUntil(strtotime("last Monday"), array_slice($commands, 1));
4630
break;
4731
case "month":
48-
$this->backUntil(time() - 2628000, array_slice($commands, 1));
32+
case "cMonth":
33+
$this->backUntil(strtotime(date("Y-m")."-01"), array_slice($commands, 1));
34+
break;
35+
case "year":
36+
case "cYear":
37+
$this->backUntil(strtotime(date("Y")."-01-01"), array_slice($commands, 1));
4938
break;
39+
40+
case "lWeek":
41+
$this->backUntil(time() - 7*24*60*60, array_slice($commands, 1));
42+
break;
43+
case "lMonth":
44+
$this->backUntil(time() - 30*24*60*60, array_slice($commands, 1));
45+
break;
46+
case "lYear":
47+
$this->backUntil(time() - 365*24*60*60, array_slice($commands, 1));
48+
break;
49+
5050
case "all":
5151
$this->backUntil(0, array_slice($commands, 1));
5252
break;
5353
case "range":
5454
$this->rangeStats(array_slice($commands, 1));
5555
break;
56-
case "today":
56+
57+
case "day":
58+
case "lDay":
59+
$this->backUntil(time() - 24*60*60, array_slice($commands, 1));
60+
break;
61+
case "cDay":
62+
case "today": // => also default
5763
$commands = array_slice($commands, 1);
5864
default:
5965
$this->todayview = true;
6066
$this->backUntil(strtotime("today"), $commands);
6167
}
6268
}
6369

70+
private function showHelp(bool $full = false) : void {
71+
$info = array('Statistics',
72+
array(
73+
'Use commands ' .
74+
CLIOutput::colorString( 'week', CLIOutput::BLUE ) . ', ' .
75+
CLIOutput::colorString( 'month', CLIOutput::BLUE ) . ', ' .
76+
CLIOutput::colorString( 'range', CLIOutput::BLUE ) . ' or ' .
77+
CLIOutput::colorString( 'today', CLIOutput::BLUE ) . ' (=default).',
78+
'Optionally add, e.g., '.CLIOutput::colorString('-cats Hobby,Home', CLIOutput::BLUE) . ', to filter for categories.'
79+
),
80+
);
81+
82+
if($full) {
83+
$info[] = array(
84+
'Select time range:',
85+
array(
86+
'Current day, week, month or year:',
87+
array(
88+
CLIOutput::colorString('cDay', CLIOutput::BLUE) . ' or ' .
89+
CLIOutput::colorString('today', CLIOutput::BLUE) . ' => since last midnight',
90+
CLIOutput::colorString('cWeek', CLIOutput::BLUE) . ' or ' .
91+
CLIOutput::colorString('week', CLIOutput::BLUE) . ' => since last Monday',
92+
CLIOutput::colorString('cMonth', CLIOutput::BLUE) . ' or ' .
93+
CLIOutput::colorString('month', CLIOutput::BLUE) . ' => since beginning of current month',
94+
CLIOutput::colorString('cYear', CLIOutput::BLUE) . ' or ' .
95+
CLIOutput::colorString('year', CLIOutput::BLUE) . ' => since last first of January'
96+
),
97+
'Last day, week, month or year:',
98+
array(
99+
CLIOutput::colorString('lDay', CLIOutput::BLUE) . ' or ' .
100+
CLIOutput::colorString('day', CLIOutput::BLUE) . ' => last 24 hours',
101+
CLIOutput::colorString('lWeek', CLIOutput::BLUE) . ' => last 7 days',
102+
CLIOutput::colorString('lMonth', CLIOutput::BLUE) . ' => last 30 days',
103+
CLIOutput::colorString('lYear', CLIOutput::BLUE) . ' => last 365 days'
104+
),
105+
'Special ranges:',
106+
array(
107+
CLIOutput::colorString('all', CLIOutput::BLUE) . ' => all time (may load some minutes)',
108+
CLIOutput::colorString('range', CLIOutput::BLUE) . ' => range between dates ' .
109+
'(add one or two dates, e.g., ' . CLIOutput::colorString('2015-01-01 2015-01-31', CLIOutput::BLUE) . ')'
110+
)
111+
),
112+
'Optional arguments:',
113+
array(
114+
'Filter for categories, names and/or devices (if synced across devices) by adding',
115+
array(
116+
CLIOutput::colorString('-cats Hobby,Home', CLIOutput::BLUE),
117+
CLIOutput::colorString('-names TTT,Website', CLIOutput::BLUE),
118+
CLIOutput::colorString('-devices Laptop,Desktop', CLIOutput::BLUE)
119+
)
120+
),
121+
array(
122+
'Also '.CLIOutput::colorString('-localOnly', CLIOutput::BLUE) .
123+
' can be added to ignore external devices added via sync.',
124+
),
125+
'Examples:',
126+
array(
127+
CLIOutput::colorString( 'ttt s week -localOnly', CLIOutput::BLUE ),
128+
CLIOutput::colorString( 'ttt s cMonth -cats Hobby', CLIOutput::BLUE ),
129+
CLIOutput::colorString( 'ttt s range 2021-02-03 2021-03-02', CLIOutput::BLUE ),
130+
CLIOutput::colorString( 'ttt s all', CLIOutput::BLUE )
131+
)
132+
);
133+
}
134+
else {
135+
$info[] = array(
136+
'Add ' .
137+
CLIOutput::colorString( '-h', CLIOutput::BLUE ) .' or ' .
138+
CLIOutput::colorString( '--help', CLIOutput::BLUE ) .
139+
' to get more information.'
140+
);
141+
}
142+
$this->output->print($info);
143+
}
144+
64145
private function rangeStats(array $commands) {
65146
$cmd = array_values(array_filter(array_slice($commands, 0, 2), function ($d) {
66147
return preg_match( StatsData::DATE_PREG, $d) === 1;

core/Utilities.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55
class Utilities {
66

7-
const VERSION = 'v1.1.3';
7+
const VERSION = 'v1.1.4';
88

99
const DEFAULT_LINE_LENGTH = 125;
1010

0 commit comments

Comments
 (0)