Browse Source

pkg/timeutil: removal

Overkill of a package for three lines of code.
Anthony Romano 10 years ago
parent
commit
1d6ebdd35c
3 changed files with 6 additions and 79 deletions
  1. 6 3
      etcdserver/server.go
  2. 0 28
      pkg/timeutil/timeutil.go
  3. 0 48
      pkg/timeutil/timeutil_test.go

+ 6 - 3
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))

+ 0 - 28
pkg/timeutil/timeutil.go

@@ -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
-}

+ 0 - 48
pkg/timeutil/timeutil_test.go

@@ -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)
-		}
-	}
-}