Delve: Add special formatting for time.Time

Created on 24 Oct 2017  路  9Comments  路  Source: go-delve/delve

Please answer the following before submitting your issue:

Note: Please include any substantial examples (debug session output,
stacktraces, etc) as linked gists.

  1. What version of Delve are you using (dlv version)?
    Delve Debugger
    Version: 1.0.0-rc.2
  2. What version of Go are you using? (go version)?
    go version go1.9 windows/amd64
  3. What operating system and processor architecture are you using?
    Windows10 64bit
  4. What did you do?
package main

import (
    "fmt"
    "time"
)
func main() {
    t:=time.Now()
    fmt.Println(t)
}

and run

dlv debug
b main.main
c
...
print t
  1. What did you expect to see?
    I want to get string like below formatted time text
    2017-10-23 11:03:00 ...
  2. What did you see instead?
time.Time {
        wall: 13723543243807126424,
        ext: 4158612300,
        loc: *time.Location {
                name: "",
                zone: []time.zone len: 0, cap: 0, nil,
                tx: []time.zoneTrans len: 0, cap: 0, nil,
                cacheStart: 0,
                cacheEnd: 0,
                cacheZone: *time.zone nil,},}

How to get formatted time text in dlv debug mode?

arecli kinenhancement

Most helpful comment

Closing, you can instead call methods on the time value to format via the call t.Format(...) or call t.String().

All 9 comments

time.Duration too. Is it possible to get this with breakpoints and print command?

@aarzilli I looked at your fork? Can you also print out time.Duration in a format that is better than the default (nanoseconds)?

I'd rather not:

  1. I think nanoseconds is an acceptable representation for time.Duration
  2. There's nowhere to save a different representation, the other types are structs and I can write the pretty print version in Variable.Value, this is a scalar value and Variable.Value is already used for its real value
  3. With the upcoming 1.10 release you will be able to evaluate "dt/time.Millisecond" to have the value of a duration in milliseconds.

Can you explain point 3 please?

Re Point1:

For 99.9% for programs, nanoseconds is not used for anything in practice. It's not trivial to convert from nanoseconds to minutes or hours in your head, yet for many human-facing applications, we work in minutes or hours.

For non-human facing applications, milliseconds or seconds is fine and it's easy to convert from nanoseconds to them.

Go's own string representation of time.Duration, recognising the facts above, print out durations in a format like 9h15m

Can you explain point 3 please?

If you have go 1.10 installed and dt is a variable of time.Duration the command print dt/time.Millisecond will print dt in milliseconds.

Right now I'm working on a configurable deadline-calculation package, so I'm looking forward to being able to make sense of the time.Time values I see when debugging. I think the pretty-print PR above would be sufficient for all use cases I've encountered so far.

For a given time.Time value t, is there a way to see or print t.Unix() or t.UnixNano() now?

Closing, you can instead call methods on the time value to format via the call t.Format(...) or call t.String().

Closing, you can instead call methods on the time value to format via the call t.Format(...) or call t.String().

you can not call these function when dealing with coredump file

If I would be interested in calling t.Format(...) or t.String() then why would I be using a debugger in first place?
I would rather go directly for fmt.Printf(...) instead!

Was this page helpful?
0 / 5 - 0 ratings