aboutsummaryrefslogtreecommitdiff
path: root/mavigator-cockpit/src/main/scala/mavigator/dashboard/ui/instruments/Clock.scala
blob: 160fd2dc3bc21dd2905064f63777e3ae7eb1d92e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package mavigator.dashboard.ui.instruments

import org.scalajs.dom
import rx._
import scala.scalajs.js.Date
import scalatags.JsDom.all._

class Clock extends Instrument[Date] {
  
  def format(date: Date) = date.toLocaleTimeString()
  
  val value = Var(new Date)
  
  val element = span(format(value())).render
  
  protected def update(value: Date) = {
    element.innerHTML = format(value)
  }
  
  dom.setInterval(() => {value() = new Date}, 1000)
  ready()

}