# # Common utility functions. # $ = jQuery context = window context.JK ||= {}; class LessonUtils constructor: () -> @logger = context.JK.logger init: () => getTimeRemaining: (endtime) -> t = new Date(endtime).getTime() - new Date().getTime() originalT = t if t < 0 seconds = Math.ceil( (t/1000) % 60 ); minutes = Math.ceil( (t/1000/60) % 60 ); hours = Math.ceil( (t/(1000*60*60)) % 24 ); days = Math.ceil( t/(1000*60*60*24) ); else seconds = Math.floor( (t/1000) % 60 ); minutes = Math.floor( (t/1000/60) % 60 ); hours = Math.floor( (t/(1000*60*60)) % 24 ); days = Math.floor( t/(1000*60*60*24) ); return { 'total': originalT, 'days': days, 'hours': hours, 'minutes': minutes, 'seconds': seconds }; # global instance context.JK.LessonUtils = new LessonUtils()