-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
views.py: Add last generated timestamp
This adds a UTC last generated timestamp to the view as well as how long ago it was updated. Closes #7
- Loading branch information
Showing
5 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,3 +84,4 @@ | |
|
||
STATIC_URL = '/static/' | ||
STATIC_ROOT = '_site/' | ||
STATICFILES_DIRS = ['static/'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
function generateTimeString(timestamp) { | ||
var sec = ((new Date()).getTime() / 1000) - parseInt(timestamp); | ||
var min = sec / 60; | ||
var hour = min / 60; | ||
var day = hour / 24; | ||
|
||
var timeString = ''; | ||
if (day >= 1) { | ||
timeString = Math.round(day) + ' days ago'; | ||
} else if (hour >= 1) { | ||
timeString = Math.round(hour) + ' hours ago'; | ||
} else if (min >= 1) { | ||
timeString = Math.round(min) + ' minutes ago'; | ||
} else { | ||
timeString = Math.round(sec) + ' seconds ago'; | ||
} | ||
|
||
return timeString; | ||
} | ||
|
||
function updateTimeAgo(time, ago) { | ||
ago.innerHTML = generateTimeString(time.getAttribute('data-time')); | ||
} | ||
|
||
function loadTimeElements() { | ||
var time = document.getElementById('time'); | ||
var ago = document.getElementById('ago'); | ||
|
||
updateTimeAgo(time, ago); | ||
} |