diff --git a/etcdserver/server.go b/etcdserver/server.go index 0b79fecd4..102bcd1ed 100644 --- a/etcdserver/server.go +++ b/etcdserver/server.go @@ -41,7 +41,6 @@ import ( "github.com/coreos/etcd/pkg/pbutil" "github.com/coreos/etcd/pkg/runtime" "github.com/coreos/etcd/pkg/schedule" - "github.com/coreos/etcd/pkg/timeutil" "github.com/coreos/etcd/pkg/types" "github.com/coreos/etcd/pkg/wait" "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 { return Response{Event: ev, err: err} } - expr := timeutil.UnixNanoToTime(r.Expiration) + 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 { case "POST": return f(s.store.Create(r.Path, r.Dir, r.Val, true, ttlOptions)) diff --git a/pkg/timeutil/timeutil.go b/pkg/timeutil/timeutil.go deleted file mode 100644 index a120d2783..000000000 --- a/pkg/timeutil/timeutil.go +++ /dev/null @@ -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 -} diff --git a/pkg/timeutil/timeutil_test.go b/pkg/timeutil/timeutil_test.go deleted file mode 100644 index 42a84131b..000000000 --- a/pkg/timeutil/timeutil_test.go +++ /dev/null @@ -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) - } - } -}