-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.js
49 lines (34 loc) · 1.29 KB
/
utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// This file contains some helper scripts for formatting data
// For multiplayer games, show the player count as '1-N'
function formatPlayers(playerCount) {
if (playerCount === 1)
return playerCount
return "1-" + playerCount;
}
// Show dates in Y-M-D format
function formatDate(date) {
return Qt.formatDate(date, "yyyy-MM-dd");
}
// Show last played time as text. Based on the code of the default Pegasus theme.
// Note to self: I should probably move this into the API.
function formatLastPlayed(lastPlayed) {
if (isNaN(lastPlayed))
return "never";
var now = new Date();
var elapsedHours = (now.getTime() - lastPlayed.getTime()) / 1000 / 60 / 60;
if (elapsedHours < 24 && now.getDate() === lastPlayed.getDate())
return "today";
var elapsedDays = Math.round(elapsedHours / 24);
if (elapsedDays <= 1)
return "yesterday";
return elapsedDays + " days ago"
}
// Display the play time (provided in seconds) with text.
// Based on the code of the default Pegasus theme.
// Note to self: I should probably move this into the API.
function formatPlayTime(playTime) {
var minutes = Math.ceil(playTime / 60)
if (minutes <= 90)
return Math.round(minutes) + " minutes";
return parseFloat((minutes / 60).toFixed(1)) + " hours"
}