Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Donald Haase
Cockatrice
Commits
0af70883
Commit
0af70883
authored
Nov 17, 2014
by
Mitchell Rosen
Browse files
0s-5m displayed as '<5m ago'
parent
d0969c10
Changes
1
Hide whitespace changes
Inline
Side-by-side
cockatrice/src/gamesmodel.cpp
View file @
0af70883
...
@@ -6,28 +6,24 @@
...
@@ -6,28 +6,24 @@
#include
<time.h>
#include
<time.h>
namespace
{
namespace
{
const
unsigned
SECS_PER_MIN
=
60
;
const
unsigned
SECS_PER_MIN
=
60
;
const
unsigned
SECS_PER_HALF_HOUR
=
60
*
30
;
const
unsigned
SECS_PER_HOUR
=
60
*
60
;
const
unsigned
SECS_PER_HOUR
=
60
*
60
;
const
unsigned
SECS_PER_90_MINS
=
60
*
90
;
/**
/**
* Pretty print an integer number of seconds ago. Accurate to only one unit,
* Pretty print an integer number of seconds ago. Accurate to only one unit,
* rounded
. As a special case, time between 60 and 90 minutes will display
* rounded
; <5 minutes and >5 hours are displayed as such. As a special case,
* both the hours and minutes.
*
time between 60 and 90 minutes will display
both the hours and minutes.
*
*
* For example...
* For example...
* 0-
59
seconds will return "
Xs
ago"
* 0-
300
seconds will return "
<5m
ago"
*
1
-59 minutes will return "Xm ago"
; 90 seconds will return "2m ago"
*
5
-59 minutes will return "Xm ago"
* 60-90 minutes will return "Xhr Ym ago"
* 60-90 minutes will return "Xhr Ym ago"
* 91-300 minutes will return "Xhr ago"; 91 minutes will return "2hr ago"
* 91-300 minutes will return "Xhr ago"
* 300+ minutes will return "5+ hr ago", because it seems unlikely that we
* 300+ minutes will return "5+ hr ago"
* care about an accurate timestamp of old games.
*/
*/
QString
prettyPrintSecsAgo
(
uint32_t
secs
)
{
QString
prettyPrintSecsAgo
(
uint32_t
secs
)
{
if
(
secs
<
SECS_PER_MIN
)
{
if
(
secs
<
SECS_PER_MIN
*
5
)
{
//: This will have a number prepended, like "10s ago"
return
QObject
::
tr
(
"<5m ago"
);
return
QString
::
number
(
secs
).
append
(
QObject
::
tr
(
"s ago"
));
}
}
if
(
secs
<
SECS_PER_HOUR
)
{
if
(
secs
<
SECS_PER_HOUR
)
{
uint32_t
mins
=
secs
/
SECS_PER_MIN
;
uint32_t
mins
=
secs
/
SECS_PER_MIN
;
...
@@ -44,7 +40,7 @@ namespace {
...
@@ -44,7 +40,7 @@ namespace {
// Between 1:29:30 and 1:29:59 will display "1hr 31m ago"
// Between 1:29:30 and 1:29:59 will display "1hr 31m ago"
//
//
// Personally, I prefer to keep the code cleaner, and allow these.
// Personally, I prefer to keep the code cleaner, and allow these.
if
(
secs
<
SECS_PER_
90_MINS
)
{
if
(
secs
<
SECS_PER_
MIN
*
90
)
{
uint32_t
mins
=
secs
/
SECS_PER_MIN
-
60
;
uint32_t
mins
=
secs
/
SECS_PER_MIN
-
60
;
if
(
secs
%
SECS_PER_MIN
>=
30
)
if
(
secs
%
SECS_PER_MIN
>=
30
)
mins
++
;
mins
++
;
...
@@ -55,7 +51,7 @@ namespace {
...
@@ -55,7 +51,7 @@ namespace {
}
}
if
(
secs
<
SECS_PER_HOUR
*
5
)
{
if
(
secs
<
SECS_PER_HOUR
*
5
)
{
uint32_t
hours
=
secs
/
SECS_PER_HOUR
;
uint32_t
hours
=
secs
/
SECS_PER_HOUR
;
if
(
secs
%
SECS_PER_HOUR
>=
SECS_PER_
HALF_HOUR
)
if
(
secs
%
SECS_PER_HOUR
>=
SECS_PER_
MIN
*
30
)
hours
++
;
hours
++
;
//: This will have a number prepended, like "2h ago"
//: This will have a number prepended, like "2h ago"
return
QString
::
number
(
hours
).
append
(
QObject
::
tr
(
"hr ago"
));
return
QString
::
number
(
hours
).
append
(
QObject
::
tr
(
"hr ago"
));
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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