Skip to content

Instantly share code, notes, and snippets.

@pichfl
Created March 3, 2014 14:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pichfl/9326116 to your computer and use it in GitHub Desktop.
Save pichfl/9326116 to your computer and use it in GitHub Desktop.
timetracking-ticker
'use strict';
// Get global namespace
var SP = window.SP || {};
(function($) {
var target = $('#working-time-count');
var appointmentStartTime = SP.APPOINTMENT_START_TIME;
if (appointmentStartTime && target) {
var startParts = appointmentStartTime.split(' ');
var start = new Date(startParts[0]);
var startTime = startParts[1].split(':');
var displayTime = function() {
var now = new Date().getTime();
var delta = new Date(now - start);
var hours = delta.getHours();
var min = delta.getMinutes();
var sec = delta.getSeconds();
var timeLeft = '';
if (hours) {
timeLeft += hours + 'h ';
}
timeLeft += min + 'min ' + sec + 's';
target.text(timeLeft);
};
start.setHours(startTime[0]);
start.setMinutes(startTime[1]);
start.setSeconds(startTime[3]);
setInterval(displayTime, 1000);
}
} (jQuery));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment