github.com/tilt-dev/tilt@v0.33.15-0.20240515162809-0a22ed45d8a0/web/src/time.tsx (about)

     1  import moment from "moment"
     2  
     3  export const zeroTime = "0001-01-01T00:00:00Z"
     4  
     5  export function isZeroTime(time: string) {
     6    return !time || time === zeroTime
     7  }
     8  
     9  // Duplicated internal/hud/format.go
    10  export function formatBuildDuration(d: moment.Duration): string {
    11    let hours = Math.floor(d.asHours())
    12    if (hours > 0) {
    13      return `${hours}h`
    14    }
    15  
    16    let minutes = Math.floor(d.asMinutes())
    17    if (minutes > 0) {
    18      return `${minutes}m`
    19    }
    20  
    21    let seconds = d.asSeconds()
    22    if (seconds >= 9.95) {
    23      return `${Math.round(seconds)}s`
    24    }
    25  
    26    return `${seconds.toFixed(1)}s`
    27  }
    28  
    29  export function timeDiff(start: string, end: string): moment.Duration {
    30    let t1 = moment(start || zeroTime)
    31    let t2 = moment(end || zeroTime)
    32    return moment.duration(t2.diff(t1))
    33  }