mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-12 04:48:29 +08:00
更新第十章timezones.go练习题答案 (#722)
* 根据map章节的教程,改写String方法 * format the source code * update to make it more friendly to new learners. * Update according to comments
This commit is contained in:
@@ -15,16 +15,15 @@ const (
|
|||||||
CST TZ = -6 * HOUR
|
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",
|
EST: "Eastern Standard time",
|
||||||
CST: "Central Standard time"}
|
CST: "Central Standard time"}
|
||||||
|
|
||||||
func (tz TZ) String() string { // Method on TZ (not ptr)
|
func (tz TZ) String() string { // Method on TZ (not ptr)
|
||||||
for name, zone := range timeZones {
|
if zone, ok := timeZones[tz]; ok {
|
||||||
if tz == name {
|
|
||||||
return zone
|
return zone
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user