Giter VIP home page Giter VIP logo

Comments (11)

vapour1024 avatar vapour1024 commented on May 26, 2024 5

cmd/time.go中calculateTimeCmd的space=1的分支layout格式没有秒

from go-programming-tour-book-comments.

FarmerChillax avatar FarmerChillax commented on May 26, 2024 2

1.3.3.2 time calc 子命令 中,利用冒号:来做分隔符会更妥当,使用空格作为分隔符会造成bug

from go-programming-tour-book-comments.

Nanrdml avatar Nanrdml commented on May 26, 2024

我直接clone下来项目但是测试的时候总是会有异常,输出结果: 1970-01-01 08:05, 300,一直报的是这个

from go-programming-tour-book-comments.

IIeming avatar IIeming commented on May 26, 2024

space := strings.Count(calculateTime, " ")中把" "改成" "就可以了

from go-programming-tour-book-comments.

IIeming avatar IIeming commented on May 26, 2024

改成":"

from go-programming-tour-book-comments.

Nanrdml avatar Nanrdml commented on May 26, 2024

好的,我按照你说的将空格删掉了之后就成功了,谢谢!

from go-programming-tour-book-comments.

shaoyxu avatar shaoyxu commented on May 26, 2024

输出异常的真正原因是,space为1的时候,layout写错了。
作者写成了layout = "2006-01-02 15:04",正确写法应该是layout = "2006-01-02 15:04:05"

from go-programming-tour-book-comments.

bourne-3 avatar bourne-3 commented on May 26, 2024

您好 1.3.3.2 time calc 子命令 处好像有bug

if space == 0 {
layout = "2006-01-02"
}
if space == 1 {
layout = "2006-01-02 15:04"
}

命令行中 2029-09-04 12:02:33 输入的space为1,但是匹配到的layout是 2006-01-02 15:04,在秒数上是对应不上的,因此会出现得出的结果为:1970-01-01 08:05。 按照代码贴上去发现了这个问题

from go-programming-tour-book-comments.

zha-hengfeng avatar zha-hengfeng commented on May 26, 2024

space := strings.Count(calcTime, " ")
if space == 0 {
layout = "2006-01-02"
}
if space == 1 {
layout = "2006-01-02 15:04"
}
如果输入时候多输入了空格会发生不可预测的问题,判断冒号":"可能会更好一些

from go-programming-tour-book-comments.

tiandiyijian avatar tiandiyijian commented on May 26, 2024
			space := strings.Count(calculateTime, " ")
			if space == 0 {
				layout = "2006-01-02"
			} else if space == 1 {
				switch strings.Count(calculateTime, ":") {
				case 0:
					layout = "2006-01-02 15"
				case 1:
					layout = "2006-01-02 15:04"
				}
			}

from go-programming-tour-book-comments.

tiandiyijian avatar tiandiyijian commented on May 26, 2024

我觉得这样判断更合理,空格数量决定年月日后面有没有跟上时分秒,冒号数量决定时分秒这三个字段输入了几个:

space := strings.Count(calculateTime, " ")
if space == 0 {
	layout = "2006-01-02"
} else {
	switch strings.Count(calculateTime, ":") {
	case 0:
		layout = "2006-01-02 15"
	case 1:
		layout = "2006-01-02 15:04"
	}
}

from go-programming-tour-book-comments.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.