Created
January 31, 2019 04:58
-
-
Save corypina/475bcd43b711f996d825b287b907483f to your computer and use it in GitHub Desktop.
Show local time and date for backups in Flywheel (converted from UTC)
This file contains hidden or 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
// ==UserScript== | |
// @name Flywheel Backups to Local Date | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description Convert UTC dates to local Time | |
// @author Cory Piña | |
// @match https://app.getflywheel.com/*/backups | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
var times = document.querySelectorAll('.--backup-description'); | |
var i; | |
for (i = 0; i < times.length; i++) { | |
var datetime = times[i].querySelectorAll('h4 time')[0].getAttribute("datetime"); | |
var stamp = new Date(datetime); | |
// Get date | |
var date = formatDate(stamp); | |
// Get time | |
var time = formatAMPM(stamp); | |
// Change HTML | |
times[i].querySelector('h4 time').innerHTML = date; | |
times[i].querySelector('p time').innerHTML = time; | |
} | |
function formatAMPM(date) { | |
var hours = date.getHours(); | |
var minutes = date.getMinutes(); | |
var ampm = hours >= 12 ? 'pm' : 'am'; | |
hours = hours % 12; | |
hours = hours ? hours : 12; // the hour '0' should be '12' | |
minutes = minutes < 10 ? '0'+minutes : minutes; | |
var strTime = hours + ':' + minutes + ' ' + ampm; | |
return strTime; | |
} | |
function formatDate(date) { | |
const monthNames = ["January", "February", "March", "April", "May", "June", | |
"July", "August", "September", "October", "November", "December"]; | |
var m = date.getMonth(); | |
var d = date.getDate(); | |
var y = date.getFullYear(); | |
var strDate = monthNames[m] + " " + d + ", " + y; | |
return strDate; | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment