aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/scala/spark/deploy/WebUI.scala
blob: ad1a1092b2ebd137cef52ba2355dea8c1e72eef5 (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
24
25
26
27
28
29
30
package spark.deploy

import java.text.SimpleDateFormat
import java.util.Date

/**
 * Utilities used throughout the web UI.
 */
private[spark] object WebUI {
  val DATE_FORMAT = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss")

  def formatDate(date: Date): String = DATE_FORMAT.format(date)

  def formatDate(timestamp: Long): String = DATE_FORMAT.format(new Date(timestamp))

  def formatDuration(milliseconds: Long): String = {
    val seconds = milliseconds.toDouble / 1000
    if (seconds < 60) {
      return "%.0f s".format(seconds)
    }
    val minutes = seconds / 60
    if (minutes < 10) {
      return "%.1f min".format(minutes)
    } else if (minutes < 60) {
      return "%.0f min".format(minutes)
    }
    val hours = minutes / 60
    return "%.1f h".format(hours)
  }
}