Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Jérome Perrin
gitlab-ce
Commits
03b7df7b
Commit
03b7df7b
authored
Sep 05, 2017
by
Bryce Johnson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Lightly refactor prettyTime module.
parent
a3b74f1a
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
156 additions
and
255 deletions
+156
-255
app/assets/javascripts/lib/utils/pretty_time.js
app/assets/javascripts/lib/utils/pretty_time.js
+50
-57
app/assets/javascripts/sidebar/components/time_tracking/collapsed_state.js
...ripts/sidebar/components/time_tracking/collapsed_state.js
+2
-3
app/assets/javascripts/sidebar/components/time_tracking/comparison_pane.js
...ripts/sidebar/components/time_tracking/comparison_pane.js
+4
-13
spec/javascripts/pretty_time_spec.js
spec/javascripts/pretty_time_spec.js
+100
-182
No files found.
app/assets/javascripts/lib/utils/pretty_time.js
View file @
03b7df7b
import
_
from
'
underscore
'
;
import
_
from
'
underscore
'
;
(()
=>
{
/*
/*
* TODO: Make these methods more configurable (e.g. stringifyTime condensed or
* TODO: Make these methods more configurable (e.g. stringifyTime condensed or
* non-condensed, abbreviateTimelengths)
* non-condensed, abbreviateTimelengths)
* */
* */
/*
const
utils
=
window
.
gl
.
utils
=
gl
.
utils
||
{};
* Accepts seconds and returns a timeObject { weeks: #, days: #, hours: #, minutes: # }
const
prettyTime
=
utils
.
prettyTime
=
{
* Seconds can be negative or positive, zero or non-zero. Can be configured for any day
/*
* or week length.
* Accepts seconds and returns a timeObject { weeks: #, days: #, hours: #, minutes: # }
*/
* Seconds can be negative or positive, zero or non-zero. Can be configured for any day
* or week length.
export
function
parseSeconds
(
seconds
,
{
daysPerWeek
=
5
,
hoursPerDay
=
8
}
=
{})
{
*/
const
DAYS_PER_WEEK
=
daysPerWeek
;
parseSeconds
(
seconds
,
{
daysPerWeek
=
5
,
hoursPerDay
=
8
}
=
{})
{
const
HOURS_PER_DAY
=
hoursPerDay
;
const
DAYS_PER_WEEK
=
daysPerWeek
;
const
MINUTES_PER_HOUR
=
60
;
const
HOURS_PER_DAY
=
hoursPerDay
;
const
MINUTES_PER_WEEK
=
DAYS_PER_WEEK
*
HOURS_PER_DAY
*
MINUTES_PER_HOUR
;
const
MINUTES_PER_HOUR
=
60
;
const
MINUTES_PER_DAY
=
HOURS_PER_DAY
*
MINUTES_PER_HOUR
;
const
MINUTES_PER_WEEK
=
DAYS_PER_WEEK
*
HOURS_PER_DAY
*
MINUTES_PER_HOUR
;
const
MINUTES_PER_DAY
=
HOURS_PER_DAY
*
MINUTES_PER_HOUR
;
const
timePeriodConstraints
=
{
weeks
:
MINUTES_PER_WEEK
,
const
timePeriodConstraints
=
{
days
:
MINUTES_PER_DAY
,
weeks
:
MINUTES_PER_WEEK
,
hours
:
MINUTES_PER_HOUR
,
days
:
MINUTES_PER_DAY
,
minutes
:
1
,
hours
:
MINUTES_PER_HOUR
,
};
minutes
:
1
,
};
let
unorderedMinutes
=
prettyTime
.
secondsToMinutes
(
seconds
);
let
unorderedMinutes
=
Math
.
abs
(
seconds
/
MINUTES_PER_HOUR
);
return
_
.
mapObject
(
timePeriodConstraints
,
(
minutesPerPeriod
)
=>
{
return
_
.
mapObject
(
timePeriodConstraints
,
(
minutesPerPeriod
)
=>
{
const
periodCount
=
Math
.
floor
(
unorderedMinutes
/
minutesPerPeriod
);
const
periodCount
=
Math
.
floor
(
unorderedMinutes
/
minutesPerPeriod
);
unorderedMinutes
-=
(
periodCount
*
minutesPerPeriod
);
unorderedMinutes
-=
(
periodCount
*
minutesPerPeriod
);
return
periodCount
;
return
periodCount
;
});
});
},
}
/*
/*
* Accepts a timeObject
and returns a condensed string representation of it
* Accepts a timeObject (see parseSeconds)
and returns a condensed string representation of it
* (e.g. '1w 2d 3h 1m' or '1h 30m'). Zero value units are not included.
* (e.g. '1w 2d 3h 1m' or '1h 30m'). Zero value units are not included.
*/
*/
stringifyTime
(
timeObject
)
{
export
function
stringifyTime
(
timeObject
)
{
const
reducedTime
=
_
.
reduce
(
timeObject
,
(
memo
,
unitValue
,
unitName
)
=>
{
const
reducedTime
=
_
.
reduce
(
timeObject
,
(
memo
,
unitValue
,
unitName
)
=>
{
const
isNonZero
=
!!
unitValue
;
const
isNonZero
=
!!
unitValue
;
return
isNonZero
?
`
${
memo
}
${
unitValue
}${
unitName
.
charAt
(
0
)}
`
:
memo
;
return
isNonZero
?
`
${
memo
}
${
unitValue
}${
unitName
.
charAt
(
0
)}
`
:
memo
;
},
''
).
trim
();
},
''
).
trim
();
return
reducedTime
.
length
?
reducedTime
:
'
0m
'
;
return
reducedTime
.
length
?
reducedTime
:
'
0m
'
;
},
}
/*
/*
* Accepts a time string of any size (e.g. '1w 2d 3h 5m' or '1w 2d') and returns
* Accepts a time string of any size (e.g. '1w 2d 3h 5m' or '1w 2d') and returns
* the first non-zero unit/value pair.
* the first non-zero unit/value pair.
*/
*/
abbreviateTime
(
timeStr
)
{
export
function
abbreviateTime
(
timeStr
)
{
return
timeStr
.
split
(
'
'
)
return
timeStr
.
split
(
'
'
)
.
filter
(
unitStr
=>
unitStr
.
charAt
(
0
)
!==
'
0
'
)[
0
];
.
filter
(
unitStr
=>
unitStr
.
charAt
(
0
)
!==
'
0
'
)[
0
];
},
}
secondsToMinutes
(
seconds
)
{
return
Math
.
abs
(
seconds
/
60
);
},
};
})(
window
.
gl
||
(
window
.
gl
=
{}));
app/assets/javascripts/sidebar/components/time_tracking/collapsed_state.js
View file @
03b7df7b
import
stopwatchSvg
from
'
icons/_icon_stopwatch.svg
'
;
import
stopwatchSvg
from
'
icons/_icon_stopwatch.svg
'
;
import
{
abbreviateTime
}
from
'
../../../lib/utils/pretty_time
'
;
import
'
../../../lib/utils/pretty_time
'
;
export
default
{
export
default
{
name
:
'
time-tracking-collapsed-state
'
,
name
:
'
time-tracking-collapsed-state
'
,
...
@@ -79,7 +78,7 @@ export default {
...
@@ -79,7 +78,7 @@ export default {
},
},
methods
:
{
methods
:
{
abbreviateTime
(
timeStr
)
{
abbreviateTime
(
timeStr
)
{
return
gl
.
utils
.
prettyTime
.
abbreviateTime
(
timeStr
);
return
abbreviateTime
(
timeStr
);
},
},
},
},
template
:
`
template
:
`
...
...
app/assets/javascripts/sidebar/components/time_tracking/comparison_pane.js
View file @
03b7df7b
import
'
../../../lib/utils/pretty_time
'
;
import
{
parseSeconds
,
stringifyTime
}
from
'
../../../lib/utils/pretty_time
'
;
const
prettyTime
=
gl
.
utils
.
prettyTime
;
export
default
{
export
default
{
name
:
'
time-tracking-comparison-pane
'
,
name
:
'
time-tracking-comparison-pane
'
,
...
@@ -23,12 +21,12 @@ export default {
...
@@ -23,12 +21,12 @@ export default {
},
},
},
},
computed
:
{
computed
:
{
parsedRemaining
()
{
parsed
Time
Remaining
()
{
const
diffSeconds
=
this
.
timeEstimate
-
this
.
timeSpent
;
const
diffSeconds
=
this
.
timeEstimate
-
this
.
timeSpent
;
return
p
rettyTime
.
p
arseSeconds
(
diffSeconds
);
return
parseSeconds
(
diffSeconds
);
},
},
timeRemainingHumanReadable
()
{
timeRemainingHumanReadable
()
{
return
prettyTime
.
stringifyTime
(
this
.
parsed
Remaining
);
return
stringifyTime
(
this
.
parsedTime
Remaining
);
},
},
timeRemainingTooltip
()
{
timeRemainingTooltip
()
{
const
prefix
=
this
.
timeRemainingMinutes
<
0
?
'
Over by
'
:
'
Time remaining:
'
;
const
prefix
=
this
.
timeRemainingMinutes
<
0
?
'
Over by
'
:
'
Time remaining:
'
;
...
@@ -44,13 +42,6 @@ export default {
...
@@ -44,13 +42,6 @@ export default {
timeRemainingStatusClass
()
{
timeRemainingStatusClass
()
{
return
this
.
timeEstimate
>=
this
.
timeSpent
?
'
within_estimate
'
:
'
over_estimate
'
;
return
this
.
timeEstimate
>=
this
.
timeSpent
?
'
within_estimate
'
:
'
over_estimate
'
;
},
},
/* Parsed time values */
parsedEstimate
()
{
return
prettyTime
.
parseSeconds
(
this
.
timeEstimate
);
},
parsedSpent
()
{
return
prettyTime
.
parseSeconds
(
this
.
timeSpent
);
},
},
},
template
:
`
template
:
`
<div class="time-tracking-comparison-pane">
<div class="time-tracking-comparison-pane">
...
...
spec/javascripts/pretty_time_spec.js
View file @
03b7df7b
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment