Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
2
22fa00199
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Summer2022
22fa00199
Commits
9bbc3e67
Unverified
Commit
9bbc3e67
authored
2 years ago
by
broccoliSpicy
Committed by
GitHub
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
fix issue#2450 (#2452)
parent
6fadbce0
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
pkg/container/types/temestamp_test.go
+48
-0
48 additions, 0 deletions
pkg/container/types/temestamp_test.go
pkg/container/types/timestamp.go
+3
-4
3 additions, 4 deletions
pkg/container/types/timestamp.go
with
51 additions
and
4 deletions
pkg/container/types/temestamp_test.go
+
48
−
0
View file @
9bbc3e67
...
...
@@ -19,6 +19,54 @@ import (
"testing"
)
func
TestTimestamp_String
(
t
*
testing
.
T
)
{
a
,
err
:=
ParseTimestamp
(
"2012-01-01 11:11:11"
,
6
)
require
.
NoError
(
t
,
err
)
resultStr
:=
a
.
String
()
require
.
Equal
(
t
,
"2012-01-01 11:11:11.000000"
,
resultStr
)
a
,
err
=
ParseTimestamp
(
"20120101111111"
,
6
)
require
.
NoError
(
t
,
err
)
resultStr
=
a
.
String
()
require
.
Equal
(
t
,
"2012-01-01 11:11:11.000000"
,
resultStr
)
resultStr1
:=
a
.
String
()
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
"2012-01-01 11:11:11.000000"
,
resultStr1
)
resultStr2
:=
a
.
String
()
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
"2012-01-01 11:11:11.000000"
,
resultStr2
)
a
,
err
=
ParseTimestamp
(
"2012-01-01 11:11:11.123"
,
6
)
resultStr3
:=
a
.
String
()
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
"2012-01-01 11:11:11.123000"
,
resultStr3
)
a
,
err
=
ParseTimestamp
(
"20120101111111.123"
,
6
)
resultStr3
=
a
.
String
()
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
"2012-01-01 11:11:11.123000"
,
resultStr3
)
resultStr4
:=
a
.
String2
(
3
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
"2012-01-01 11:11:11.123"
,
resultStr4
)
resultStr5
:=
a
.
String2
(
6
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
"2012-01-01 11:11:11.123000"
,
resultStr5
)
a
,
err
=
ParseTimestamp
(
"2012-01-01 11:11:11.123456"
,
3
)
resultStr6
:=
a
.
String2
(
0
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
"2012-01-01 11:11:11"
,
resultStr6
)
resultStr7
:=
a
.
String2
(
3
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
"2012-01-01 11:11:11.123"
,
resultStr7
)
resultStr8
:=
a
.
String2
(
6
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
"2012-01-01 11:11:11.123000"
,
resultStr8
)
}
func
TestTimestamp_String2
(
t
*
testing
.
T
)
{
a
,
err
:=
ParseTimestamp
(
"2012-01-01 11:11:11"
,
6
)
require
.
NoError
(
t
,
err
)
...
...
This diff is collapsed.
Click to expand it.
pkg/container/types/timestamp.go
+
3
−
4
View file @
9bbc3e67
...
...
@@ -42,7 +42,7 @@ import (
const
microSecondsDigits
=
6
func
(
ts
Timestamp
)
String
()
string
{
dt
:=
Datetime
(
int64
(
ts
)
+
localTZ
)
dt
:=
Datetime
(
int64
(
ts
)
+
localTZ
<<
20
)
y
,
m
,
d
,
_
:=
dt
.
ToDate
()
.
Calendar
(
true
)
hour
,
minute
,
sec
:=
dt
.
Clock
()
msec
:=
int64
(
ts
)
&
0xfffff
// the lower 20 bits of timestamp stores the microseconds value
...
...
@@ -51,7 +51,7 @@ func (ts Timestamp) String() string {
// String2 stringify timestamp, including its fractional seconds precision part(fsp)
func
(
ts
Timestamp
)
String2
(
precision
int32
)
string
{
dt
:=
Datetime
(
int64
(
ts
))
dt
:=
Datetime
(
int64
(
ts
)
+
localTZ
<<
20
)
y
,
m
,
d
,
_
:=
dt
.
ToDate
()
.
Calendar
(
true
)
hour
,
minute
,
sec
:=
dt
.
Clock
()
if
precision
>
0
{
...
...
@@ -122,7 +122,6 @@ func ParseTimestamp(s string, precision int32) (Timestamp, error) {
for
i
:=
0
;
i
<
padZeros
;
i
++
{
msecStr
=
msecStr
+
string
(
'0'
)
}
fmt
.
Println
(
"len(s) > 19, msecStr is"
,
msecStr
)
m
,
err
:=
strconv
.
ParseUint
(
msecStr
,
10
,
32
)
if
err
!=
nil
{
return
-
1
,
errIncorrectDatetimeValue
...
...
@@ -177,7 +176,7 @@ func TimestampToDatetime(xs []Timestamp, rs []Datetime) ([]Datetime, error) {
return
rs
,
nil
}
// FromClock
2
gets the utc time value in Timestamp
// FromClock
UTC
gets the utc time value in Timestamp
func
FromClockUTC
(
year
int32
,
month
,
day
,
hour
,
min
,
sec
uint8
,
msec
uint32
)
Timestamp
{
days
:=
FromCalendar
(
year
,
month
,
day
)
secs
:=
int64
(
days
)
*
secsPerDay
+
int64
(
hour
)
*
secsPerHour
+
int64
(
min
)
*
secsPerMinute
+
int64
(
sec
)
-
localTZ
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment