mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #4647 from heyitsanthony/nuke-timeutil
pkg/timeutil: remove
This commit is contained in:
commit
942ae63398
@ -41,7 +41,6 @@ import (
|
|||||||
"github.com/coreos/etcd/pkg/pbutil"
|
"github.com/coreos/etcd/pkg/pbutil"
|
||||||
"github.com/coreos/etcd/pkg/runtime"
|
"github.com/coreos/etcd/pkg/runtime"
|
||||||
"github.com/coreos/etcd/pkg/schedule"
|
"github.com/coreos/etcd/pkg/schedule"
|
||||||
"github.com/coreos/etcd/pkg/timeutil"
|
|
||||||
"github.com/coreos/etcd/pkg/types"
|
"github.com/coreos/etcd/pkg/types"
|
||||||
"github.com/coreos/etcd/pkg/wait"
|
"github.com/coreos/etcd/pkg/wait"
|
||||||
"github.com/coreos/etcd/raft"
|
"github.com/coreos/etcd/raft"
|
||||||
@ -1027,9 +1026,13 @@ func (s *EtcdServer) applyRequest(r pb.Request) Response {
|
|||||||
f := func(ev *store.Event, err error) Response {
|
f := func(ev *store.Event, err error) Response {
|
||||||
return Response{Event: ev, err: err}
|
return Response{Event: ev, err: err}
|
||||||
}
|
}
|
||||||
expr := timeutil.UnixNanoToTime(r.Expiration)
|
|
||||||
refresh, _ := pbutil.GetBool(r.Refresh)
|
refresh, _ := pbutil.GetBool(r.Refresh)
|
||||||
ttlOptions := store.TTLOptionSet{ExpireTime: expr, Refresh: refresh}
|
ttlOptions := store.TTLOptionSet{Refresh: refresh}
|
||||||
|
if r.Expiration != 0 {
|
||||||
|
ttlOptions.ExpireTime = time.Unix(0, r.Expiration)
|
||||||
|
}
|
||||||
|
|
||||||
switch r.Method {
|
switch r.Method {
|
||||||
case "POST":
|
case "POST":
|
||||||
return f(s.store.Create(r.Path, r.Dir, r.Val, true, ttlOptions))
|
return f(s.store.Create(r.Path, r.Dir, r.Val, true, ttlOptions))
|
||||||
|
@ -1,28 +0,0 @@
|
|||||||
// Copyright 2015 CoreOS, Inc.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
// Package timeutil provides time-related utility functions.
|
|
||||||
package timeutil
|
|
||||||
|
|
||||||
import "time"
|
|
||||||
|
|
||||||
// UnixNanoToTime returns the local time corresponding to the given Unix time in nanoseconds.
|
|
||||||
// If the given Unix time is zero, an uninitialized zero time is returned.
|
|
||||||
func UnixNanoToTime(ns int64) time.Time {
|
|
||||||
var t time.Time
|
|
||||||
if ns != 0 {
|
|
||||||
t = time.Unix(0, ns)
|
|
||||||
}
|
|
||||||
return t
|
|
||||||
}
|
|
@ -1,48 +0,0 @@
|
|||||||
// Copyright 2015 CoreOS, Inc.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package timeutil
|
|
||||||
|
|
||||||
import (
|
|
||||||
"reflect"
|
|
||||||
"testing"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestUnixNanoToTime(t *testing.T) {
|
|
||||||
tests := []struct {
|
|
||||||
ns int64
|
|
||||||
want time.Time
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
0,
|
|
||||||
time.Time{},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
60000,
|
|
||||||
time.Unix(0, 60000),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
-60000,
|
|
||||||
time.Unix(0, -60000),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
for i, tt := range tests {
|
|
||||||
got := UnixNanoToTime(tt.ns)
|
|
||||||
if !reflect.DeepEqual(got, tt.want) {
|
|
||||||
t.Errorf("#%d: time = %v, want %v", i, got, tt.want)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user