Last active
August 29, 2015 14:03
-
-
Save stefbowerman/f13c12628ca328fd7e4f to your computer and use it in GitHub Desktop.
Simple Coffeescript Clock
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
| class Clock | |
| constructor: (targetEl) -> | |
| @$targetEl = $(targetEl) | |
| @tickingInterval = null | |
| startTicking: -> | |
| @tick() | |
| @tickingInterval = setInterval( => | |
| @tick() | |
| , 1000) | |
| stopTicking: -> | |
| clearInterval(@tickingInterval) | |
| tick: -> | |
| d = new Date() | |
| hours = d.getHours() | |
| mins = d.getMinutes() | |
| mins = "0#{mins}" if mins < 10 | |
| timeSuffix = 'AM' | |
| if hours > 12 | |
| hours = hours - 12 | |
| timeSuffix = 'PM' | |
| @$targetEl.html "#{hours}:#{mins} #{timeSuffix}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment