Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
perxis-go
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Package registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
perxis
perxis-go
Commits
5ea3241a
Commit
5ea3241a
authored
2 years ago
by
ko_oler
Browse files
Options
Downloads
Patches
Plain Diff
правки по ПР
parent
d8653efe
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
pkg/schema/field/timestamp.go
+4
-5
4 additions, 5 deletions
pkg/schema/field/timestamp.go
pkg/schema/field/timestamp_test.go
+5
-5
5 additions, 5 deletions
pkg/schema/field/timestamp_test.go
with
9 additions
and
10 deletions
pkg/schema/field/timestamp.go
+
4
−
5
View file @
5ea3241a
...
...
@@ -3,10 +3,10 @@ package field
import
(
"context"
"fmt"
"reflect"
"time"
)
var
zeroTime
=
time
.
Time
{}
var
timestampType
=
&
TimestampType
{}
type
TimestampParameters
struct
{}
...
...
@@ -31,13 +31,12 @@ func (TimestampType) IsEmpty(v interface{}) bool {
func
(
TimestampType
)
Decode
(
_
context
.
Context
,
_
*
Field
,
v
interface
{})
(
interface
{},
error
)
{
switch
i
:=
v
.
(
type
)
{
case
nil
:
return
0
,
nil
return
nil
,
nil
case
string
:
duration
,
err
:=
time
.
ParseDuration
(
i
)
if
err
==
nil
{
return
duration
.
Nanoseconds
(),
nil
}
zeroTime
:=
time
.
Time
{}
t
,
err
:=
time
.
Parse
(
time
.
TimeOnly
,
i
)
if
err
==
nil
{
...
...
@@ -68,14 +67,14 @@ func toTimestamp(i interface{}) (interface{}, error) {
case
uint32
:
return
int64
(
v
),
nil
default
:
return
0
,
fmt
.
Errorf
(
"unsupported value type:
\"
%
s
\"
"
,
reflect
.
ValueOf
(
v
)
.
Kind
()
)
return
0
,
fmt
.
Errorf
(
"unsupported value type:
\"
%
T
\"
"
,
v
)
}
}
func
(
TimestampType
)
Encode
(
_
context
.
Context
,
_
*
Field
,
v
interface
{})
(
interface
{},
error
)
{
switch
i
:=
v
.
(
type
)
{
case
nil
:
return
0
,
nil
return
nil
,
nil
default
:
return
toTimestamp
(
i
)
}
...
...
This diff is collapsed.
Click to expand it.
pkg/schema/field/timestamp_test.go
+
5
−
5
View file @
5ea3241a
...
...
@@ -29,10 +29,10 @@ func TestTimestamp_Decode(t *testing.T) {
{
"Correct"
,
Timestamp
(),
"00:00:00"
,
int64
(
0
),
false
,
""
},
// #8
{
"Correct"
,
Timestamp
(),
"00:00:01"
,
int64
(
1000000000
),
false
,
""
},
// #8
{
"Correct"
,
Timestamp
(),
uint64
(
2
),
int64
(
2
),
false
,
""
},
{
"Correct"
,
Timestamp
(),
nil
,
0
,
false
,
""
},
{
"Correct"
,
Timestamp
(),
nil
,
nil
,
false
,
""
},
{
"Wrong data"
,
Timestamp
(),
""
,
nil
,
true
,
"decode error: parsing time
\"\"
as
\"
15:04:05
\"
: cannot parse
\"\"
as
\"
15
\"
"
},
// #0
{
"Wrong data"
,
Timestamp
(),
[]
byte
(
""
),
nil
,
true
,
"decode error: unsupported value type:
\"
slice
\"
"
},
// #1
{
"Wrong data"
,
Timestamp
(),
[]
byte
(
""
),
nil
,
true
,
"decode error: unsupported value type:
\"
[]uint8
\"
"
},
// #1
{
"Wrong data"
,
Timestamp
(),
2.2
,
nil
,
true
,
"decode error: unsupported value type:
\"
float64
\"
"
},
// #2
{
"Wrong data"
,
Timestamp
(),
"13:10"
,
nil
,
true
,
"decode error: parsing time
\"
13:10
\"
as
\"
15:04:05
\"
: cannot parse
\"\"
as
\"
:
\"
"
},
// #3
{
"Wrong data"
,
Timestamp
(),
"24:00:00"
,
nil
,
true
,
"decode error: parsing time
\"
24:00:00
\"
: hour out of range"
},
// #4
...
...
@@ -66,7 +66,7 @@ func TestTimestamp_Encode(t *testing.T) {
{
"Correct"
,
Timestamp
(),
uint64
(
2
),
int64
(
2
),
false
,
""
},
// #2
{
"Wrong data"
,
Timestamp
(),
""
,
nil
,
true
,
"encode error: unsupported value type:
\"
string
\"
"
},
// #0
{
"Wrong data"
,
Timestamp
(),
[]
byte
(
""
),
nil
,
true
,
"encode error: unsupported value type:
\"
slice
\"
"
},
// #1
{
"Wrong data"
,
Timestamp
(),
[]
byte
(
""
),
nil
,
true
,
"encode error: unsupported value type:
\"
[]uint8
\"
"
},
// #1
{
"Wrong data"
,
Timestamp
(),
2.2
,
nil
,
true
,
"encode error: unsupported value type:
\"
float64
\"
"
},
// #2
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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