From f462e39fa64b4d96c49075c495102f515cdc9394 Mon Sep 17 00:00:00 2001 From: SoniaChoo Date: Wed, 16 Oct 2019 05:59:06 +0900 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=AC=AC=E5=8D=81=E7=AB=A0ti?= =?UTF-8?q?mezones.go=E7=BB=83=E4=B9=A0=E9=A2=98=E7=AD=94=E6=A1=88=20(#722?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 根据map章节的教程,改写String方法 * format the source code * update to make it more friendly to new learners. * Update according to comments --- eBook/exercises/chapter_10/timezones.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/eBook/exercises/chapter_10/timezones.go b/eBook/exercises/chapter_10/timezones.go index 3088b74..52a1bcb 100755 --- a/eBook/exercises/chapter_10/timezones.go +++ b/eBook/exercises/chapter_10/timezones.go @@ -15,15 +15,14 @@ const ( CST TZ = -6 * HOUR ) -var timeZones = map[TZ]string{UTC: "Universal Greenwich time", +var timeZones = map[TZ]string{ + UTC: "Universal Greenwich time", EST: "Eastern Standard time", CST: "Central Standard time"} func (tz TZ) String() string { // Method on TZ (not ptr) - for name, zone := range timeZones { - if tz == name { - return zone - } + if zone, ok := timeZones[tz]; ok { + return zone } return "" }