Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
10a5eb0a
Commit
10a5eb0a
authored
Jan 15, 2010
by
Rob Pike
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix +0000 time zones.
Fixes #527. R=rsc CC=golang-dev
https://golang.org/cl/186159
parent
da9bc7ae
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
4 deletions
+32
-4
src/pkg/time/format.go
src/pkg/time/format.go
+12
-4
src/pkg/time/time_test.go
src/pkg/time/time_test.go
+20
-0
No files found.
src/pkg/time/format.go
View file @
10a5eb0a
...
...
@@ -326,9 +326,9 @@ func Parse(alayout, avalue string) (*Time, os.Error) {
prevLayout
:=
layout
layout
=
layout
[
i
:
]
// Ugly time zone handling.
if
reference
==
"Z"
||
reference
==
"z"
{
if
reference
==
"Z"
{
// Special case for ISO8601 time zone: "Z" or "-0800"
if
reference
==
"Z"
&&
value
[
0
]
==
'Z'
{
if
value
[
0
]
==
'Z'
{
i
=
1
}
else
if
len
(
value
)
>=
5
{
i
=
5
...
...
@@ -338,11 +338,19 @@ func Parse(alayout, avalue string) (*Time, os.Error) {
}
else
{
c
=
value
[
0
]
if
charType
(
c
)
!=
pieceType
{
// could be a minus sign introducing a negative year
// Ugly management of signs. Reference and data might differ.
// 1. Could be a minus sign introducing a negative year.
if
c
==
'-'
&&
pieceType
!=
minus
{
value
=
value
[
1
:
]
sign
=
"-"
layout
=
prevLayout
// don't consume reference item
sign
=
"-"
continue
}
// 2. Could be a plus sign for a +0100 time zone, represented by -0700 in the standard.
if
c
==
'+'
&&
pieceType
==
minus
{
value
=
value
[
1
:
]
layout
=
prevLayout
[
1
:
]
// absorb sign in both value and layout
sign
=
"+"
continue
}
return
nil
,
&
ParseError
{
Layout
:
alayout
,
Value
:
avalue
,
Message
:
formatErr
+
alayout
}
...
...
src/pkg/time/time_test.go
View file @
10a5eb0a
...
...
@@ -186,6 +186,26 @@ func TestParse(t *testing.T) {
}
}
var
rubyTests
=
[]
ParseTest
{
ParseTest
{
"RubyDate"
,
RubyDate
,
"Thu Feb 04 21:00:57 -0800 2010"
,
true
,
true
,
1
},
// Ignore the time zone in the test. If it parses, it'll be OK.
ParseTest
{
"RubyDate"
,
RubyDate
,
"Thu Feb 04 21:00:57 -0000 2010"
,
false
,
true
,
1
},
ParseTest
{
"RubyDate"
,
RubyDate
,
"Thu Feb 04 21:00:57 +0000 2010"
,
false
,
true
,
1
},
ParseTest
{
"RubyDate"
,
RubyDate
,
"Thu Feb 04 21:00:57 +1130 2010"
,
false
,
true
,
1
},
}
// Problematic time zone format needs special tests.
func
TestRubyParse
(
t
*
testing
.
T
)
{
for
_
,
test
:=
range
rubyTests
{
time
,
err
:=
Parse
(
test
.
format
,
test
.
value
)
if
err
!=
nil
{
t
.
Errorf
(
"%s error: %v"
,
test
.
name
,
err
)
}
else
{
checkTime
(
time
,
&
test
,
t
)
}
}
}
func
checkTime
(
time
*
Time
,
test
*
ParseTest
,
t
*
testing
.
T
)
{
// The time should be Thu Feb 4 21:00:57 PST 2010
if
test
.
yearSign
*
time
.
Year
!=
2010
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment