Skip to content

Commit

Permalink
move formatUnixNanoTime into a utility function
Browse files Browse the repository at this point in the history
  • Loading branch information
camerondavison committed Aug 9, 2016
1 parent a66c568 commit 0b7acd5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 15 deletions.
10 changes: 2 additions & 8 deletions command/alloc_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func (c *AllocStatusCommand) outputTaskStatus(state *api.TaskState) {

size := len(state.Events)
for i, event := range state.Events {
formatedTime := c.formatUnixNanoTime(event.Time)
formatedTime := formatUnixNanoTime(event.Time)

// Build up the description based on the event type.
var desc string
Expand Down Expand Up @@ -400,7 +400,7 @@ func (c *AllocStatusCommand) shortTaskStatus(alloc *api.Allocation) {
if l != 0 {
last := state.Events[l-1]
lastEvent = last.Type
lastTime = c.formatUnixNanoTime(last.Time)
lastTime = formatUnixNanoTime(last.Time)
}

tasks = append(tasks, fmt.Sprintf("%s|%s|%s|%s",
Expand Down Expand Up @@ -430,9 +430,3 @@ func (c *AllocStatusCommand) sortedTaskStateIterator(m map[string]*api.TaskState
close(output)
return output
}

// formatUnixNanoTime is a helper for formating time for output.
func (c *AllocStatusCommand) formatUnixNanoTime(nano int64) string {
t := time.Unix(0, nano)
return formatTime(t)
}
6 changes: 6 additions & 0 deletions command/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ func formatTime(t time.Time) string {
return t.Format("01/02/06 15:04:05 MST")
}

// formatUnixNanoTime is a helper for formatting time for output.
func formatUnixNanoTime(nano int64) string {
t := time.Unix(0, nano)
return formatTime(t)
}

// formatTimeDifference takes two times and determines their duration difference
// truncating to a passed unit.
// E.g. formatTimeDifference(first=1m22s33ms, second=1m28s55ms, time.Second) -> 6s
Expand Down
8 changes: 1 addition & 7 deletions command/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ func (c *StatusCommand) outputJobInfo(client *api.Client, job *api.Job) error {
alloc.TaskGroup,
alloc.DesiredStatus,
alloc.ClientStatus,
c.formatUnixNanoTime(alloc.CreateTime))
formatUnixNanoTime(alloc.CreateTime))
}

c.Ui.Output(formatList(allocs))
Expand Down Expand Up @@ -347,12 +347,6 @@ func (c *StatusCommand) outputFailedPlacements(failedEval *api.Evaluation) {
}
}

// formatUnixNanoTime is a helper for formatting time for output.
func (c *StatusCommand) formatUnixNanoTime(nano int64) string {
t := time.Unix(0, nano)
return formatTime(t)
}

// convertApiJob is used to take a *api.Job and convert it to an *struct.Job.
// This function is just a hammer and probably needs to be revisited.
func convertApiJob(in *api.Job) (*structs.Job, error) {
Expand Down

0 comments on commit 0b7acd5

Please sign in to comment.