Skip to content

Commit 4c92a46

Browse files
committed
added overall seconds/minutes/hours/days to time format
1 parent 5ea309a commit 4c92a46

File tree

2 files changed

+29
-18
lines changed

2 files changed

+29
-18
lines changed

readme.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ hoursPerDay: 8
117117
118118
# columns to include in the report
119119
# available columns: id, iid, title, project_id, description, labels, milestone,
120-
# assignee, author, closed, updated_at, created_at, state
120+
# assignee, author, closed, updated_at, created_at, state, estimate, time_spent
121121
columns:
122122
- iid
123123
- title
@@ -128,12 +128,16 @@ dateFormat: Y-m-d H:i:s
128128
129129
# time format
130130
# [%sign], [%days], [%hours], [%minutes], [%seconds]
131-
# -> prints out the raw data
131+
# -> prints out the raw data+
132132
# [%days>string], [%hours>string], [%minutes>string], [%seconds>string]
133-
# -> is a conditional and prints out the data and appends the given string if the data is greater than zero
133+
# -> is a conditional and prints out the data and appends the given string
134+
# if the data is greater than zero
134135
# [%Days], [%Hours], [%Minutes], ...
135136
# -> uppercase adds leading zeros.
136-
timeFormat: [%sign][%days>d ][%hours>h ][%minutes>m ][%seconds>s]
137+
# [%days_overall], [%hours_overall], [%minutes_overall], [%seconds_overall]
138+
# -> instead of printing out the second-/minute-/hour-/day-part of the time
139+
# this prints the complete time in seconds/minutes/hours/days
140+
timeFormat: "[%sign][%days>d ][%hours>h ][%minutes>m ][%seconds>s]"
137141
138142
# default output
139143
output: markdown

src/Time.php

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,11 @@ class Time implements ArrayAccess, Arrayable
1414
protected $seconds;
1515
protected $user;
1616
protected $date;
17+
1718
private $hoursPerDay;
19+
private $timeFormat;
1820

1921
const TIME_FORMAT = '[%sign][%days>d ][%hours>h ][%minutes>m ][%seconds>s]';
20-
/**
21-
* @var string
22-
*/
23-
private $timeFormat;
2422

2523
/**
2624
* Time constructor.
@@ -126,33 +124,42 @@ public function setHumanReadable($humanReadable)
126124
/**
127125
* Seconds to human readable string.
128126
*
129-
* @param int $seconds
127+
* @param int $inputSeconds
130128
* @param int $hoursPerDay
131129
* @param string $format
132130
*
133131
* @return string
134132
*/
135133
static public function humanReadable(
136-
$seconds,
134+
$inputSeconds,
137135
$hoursPerDay = 8,
138136
$format = self::TIME_FORMAT
139137
) {
140-
$sign = $seconds < 0 ? '-' : '';
141-
$seconds = abs($seconds);
138+
$sign = $inputSeconds < 0 ? '-' : '';
139+
$inputSeconds = abs($inputSeconds);
142140

143141
$secondsInAMinute = 60;
144142
$secondsInAnHour = 60 * $secondsInAMinute;
145143
$secondsInADay = $hoursPerDay * $secondsInAnHour;
146144

147-
$days = floor($seconds / $secondsInADay);
148-
$hourSeconds = $seconds % $secondsInADay;
149-
$hours = floor($hourSeconds / $secondsInAnHour);
150-
$minuteSeconds = $hourSeconds % $secondsInAnHour;
151-
$minutes = floor($minuteSeconds / $secondsInAMinute);
145+
$days = floor($inputSeconds / $secondsInADay);
146+
$days_overall = $inputSeconds / $secondsInADay;
147+
148+
$hourSeconds = $inputSeconds % $secondsInADay;
149+
$hours = floor($hourSeconds / $secondsInAnHour);
150+
$hours_overall = $inputSeconds / $secondsInAnHour;
151+
152+
$minuteSeconds = $hourSeconds % $secondsInAnHour;
153+
$minutes = floor($minuteSeconds / $secondsInAMinute);
154+
$minutes_overall = $inputSeconds / $secondsInAMinute;
155+
152156
$remainingSeconds = $minuteSeconds % $secondsInAMinute;
153157
$seconds = ceil($remainingSeconds);
158+
$seconds_overall = $inputSeconds;
159+
160+
$inserts = compact('sign', 'days', 'hours', 'minutes', 'seconds', 'days_overall', 'hours_overall',
161+
'minutes_overall', 'seconds_overall');
154162

155-
$inserts = compact('sign', 'days', 'hours', 'minutes', 'seconds');
156163
foreach ($inserts as $key => $insert) {
157164
if ($key == 'sign') {
158165
continue;

0 commit comments

Comments
 (0)