Skip to content

Instantly share code, notes, and snippets.

@stefbowerman
Last active August 29, 2015 14:03
Show Gist options
  • Select an option

  • Save stefbowerman/f13c12628ca328fd7e4f to your computer and use it in GitHub Desktop.

Select an option

Save stefbowerman/f13c12628ca328fd7e4f to your computer and use it in GitHub Desktop.
Simple Coffeescript Clock
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