-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
12 hour time bug #41
Comments
Hi @milesich, I came across this issue and thought I would do some research and attempt to fix it. My findings: Unicode Locale Data Markup Language (LDML) defines the following patterns for hour formats:
when looking at the CLDR json specifications for date time formatting, I found the hourFormat field definition for the en locale:
You can see this is defined using the HH pattern which would indicate it should adhere to the 00 format for 12 AM. Further Notes This does differ from what the standard go time package does if you were to format a time using the time.Kitchen format where it would be represented using the hh format. package main
import (
"fmt"
"time"
"github.com/go-playground/locales/en"
)
func main() {
datetime := time.Date(2016, 02, 03, 0, 0, 1, 0, time.Local)
l := en.New()
fmt.Printf("Local (en) Short Time : %v \n", l.FmtTimeShort(datetime))
fmt.Printf("Kitchen Format Time : %v \n", datetime.Format(time.Kitchen))
} Output:
Outcome: I see the current implementation working as expected defined by the CLDR specification. But before closing out, I’d be keen to check in with @deankarn and confirm this is expected and the issue is not a bug. If not, I’m more than happy to pick this up and implement a fix. I will likely implement something similar to how the go time.Format() function handles this case, inside the en/en.go#L503 h := t.Hour() % 12
if h == 0 {
h = 12
} |
@rokane You were looking at hour format for timezone part. eg. +13:00. The spec for time format for en locale is using 12h format:
|
@milesich thanks for the prompt response! Great, I was looking at the wrong file. I see now, that makes sense. I can take a look into this and see if I can get a fix working. |
@milesich I had a go at fixing this, if you can take a look and let me know what you think, that would be great |
@rokane you should not be fixing individual locales because those files are generated from the spec. The generator needs fixing. https://github.com/go-playground/locales/blob/master/cmd/generate_resources.go |
That code should print
12:00 am
but instead it prints0:00 am
.12 hour time does not have 0 hours.
The text was updated successfully, but these errors were encountered: