When debugging a program that processes time.Time
values, I need to be able to print the values and make sense of them. In Delve, if I print a variable of type time.Time
it prints the internal structure of the object, and does not allow me to run time.Time
methods on the object.
How do I makes sense of this structure and translate it to my normal understanding of what would be printed by the Unix()
, UnixNano()
, or String()
functions.
For example:
$ dlv test
(dlv) b calendar.go:200
(dlv) p appt
time.Time {
wall: 0,
ext: 63673770600,
loc: *time.Location {
name: "Local",
zone: []time.zone len: 4, cap: 4, [
(*time.zone)(0xc0000a8100),
],
tx: []time.zoneTrans len: 235, cap: 235, [
(*time.zoneTrans)(0xc0000bb000),
...+171 more
],
cacheStart: 1520751600,
cacheEnd: 1541311200,
cacheZone: *(*time.zone)(0xc0000a8100),},}
Or in the case of a list of values:
(dlv) p dates
[]time.Time len: 2, cap: 2, [
{
wall: 0,
ext: 63673689600,
loc: *(*time.Location)(0xc00008e9c0),},
{
wall: 0,
ext: 63673776000,
loc: *(*time.Location)(0xc00008ea80),},
]
I found a github ticket to add pretty-printing of time.Time
values to Delve. Until that is approved and released, what can I do to make sense of these values and translate them to a more readable form?
As a workaround, I considered adding new variables of string type that I would update (as needed) with the output of .String()
or .Format(...)
. Is there a better alternative?
Debugging your ApplicationAdd a breakpoint at line 10 of our main.go file by running breakpoint main.go:10 (or b main.go:10 for short). Run continue (or c ) to run-to-breakpoint.
Ubuntu Manpage: dlv - Delve is a debugger for the Go programming language. 22.04 LTS.
If you use VS Code to run your Go code and have the official Go extension installed on the editor, you can debug your code by pressing F5 or Run and Debug on your computer.
It looks like the issue adding the functionality you're wanting has been closed.
Closing, you can instead call methods on the time value to format via the call t.Format(...) or call t.String().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With