From 623247c9959c04abfbd648124e4425414f1efba9 Mon Sep 17 00:00:00 2001 From: Graham Lyon Date: Tue, 23 Nov 2010 22:01:26 +0000 Subject: [PATCH] Generalise timestamp code and default to using time.LocalTime --- client/connection.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/client/connection.go b/client/connection.go index 40f66e7..a70d371 100644 --- a/client/connection.go +++ b/client/connection.go @@ -37,6 +37,9 @@ type Conn struct { Debug bool + // Function which returns a *time.Time for use as a timestamp + Timestamp func() *time.Time + // Event handler mapping events map[string][]func(*Conn, *Line) @@ -63,6 +66,7 @@ type Line struct { // that you can add event handlers to it. See AddHandler() for details. func New(nick, user, name string) *Conn { conn := new(Conn) + conn.Timestamp = time.LocalTime conn.initialise() conn.Me = conn.NewNick(nick, user, name, "") conn.setupEvents() @@ -188,7 +192,7 @@ func (conn *Conn) send() { } conn.io.Flush() if conn.Debug { - fmt.Println(time.UTC().Format("[15:04:05]") + " -> " + line) + fmt.Println(conn.Timestamp().Format("[15:04:05]") + " -> " + line) } } } @@ -197,7 +201,7 @@ func (conn *Conn) send() { func (conn *Conn) recv() { for { s, err := conn.io.ReadString('\n') - t := time.UTC() + t := conn.Timestamp() if err != nil { conn.error("irc.recv(): %s", err.String()) conn.shutdown()