mirror of https://github.com/helm/helm
Signed-off-by: Terry Howe <terrylhowe@gmail.com>pull/31293/head
parent
ff61915cda
commit
3e1dd9a5dc
@ -1 +1 @@
|
|||||||
{"name":"flummoxed-chickadee","info":{"first_deployed":"","last_deployed":"2016-01-16T00:00:00Z","deleted":"","status":"deployed"},"namespace":"default"}
|
{"name":"flummoxed-chickadee","info":{"last_deployed":"2016-01-16T00:00:00Z","status":"deployed"},"namespace":"default"}
|
||||||
|
@ -1 +1 @@
|
|||||||
{"name":"flummoxed-chickadee","info":{"first_deployed":"","last_deployed":"2016-01-16T00:00:00Z","deleted":"","status":"deployed","notes":"release notes"},"namespace":"default"}
|
{"name":"flummoxed-chickadee","info":{"last_deployed":"2016-01-16T00:00:00Z","status":"deployed","notes":"release notes"},"namespace":"default"}
|
||||||
|
@ -1,29 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright The Helm Authors.
|
|
||||||
|
|
||||||
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 ctime
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
func Created(fi os.FileInfo) time.Time {
|
|
||||||
return modified(fi)
|
|
||||||
}
|
|
||||||
|
|
||||||
func Modified(fi os.FileInfo) time.Time {
|
|
||||||
return modified(fi)
|
|
||||||
}
|
|
@ -1,30 +0,0 @@
|
|||||||
//go:build linux
|
|
||||||
|
|
||||||
/*
|
|
||||||
Copyright The Helm Authors.
|
|
||||||
|
|
||||||
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 ctime
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
"syscall"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
func modified(fi os.FileInfo) time.Time {
|
|
||||||
st := fi.Sys().(*syscall.Stat_t)
|
|
||||||
//nolint
|
|
||||||
return time.Unix(int64(st.Mtim.Sec), int64(st.Mtim.Nsec))
|
|
||||||
}
|
|
@ -1,27 +0,0 @@
|
|||||||
//go:build !linux
|
|
||||||
|
|
||||||
/*
|
|
||||||
Copyright The Helm Authors.
|
|
||||||
|
|
||||||
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 ctime
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
func modified(fi os.FileInfo) time.Time {
|
|
||||||
return fi.ModTime()
|
|
||||||
}
|
|
@ -1,92 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright The Helm Authors.
|
|
||||||
|
|
||||||
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 time contains a wrapper for time.Time in the standard library and
|
|
||||||
// associated methods. This package mainly exists to work around an issue in Go
|
|
||||||
// where the serializer doesn't omit an empty value for time:
|
|
||||||
// https://github.com/golang/go/issues/11939. As such, this can be removed if a
|
|
||||||
// proposal is ever accepted for Go
|
|
||||||
package time
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
// emptyString contains an empty JSON string value to be used as output
|
|
||||||
var emptyString = `""`
|
|
||||||
|
|
||||||
// Time is a convenience wrapper around stdlib time, but with different
|
|
||||||
// marshalling and unmarshalling for zero values
|
|
||||||
type Time struct {
|
|
||||||
time.Time
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now returns the current time. It is a convenience wrapper around time.Now()
|
|
||||||
func Now() Time {
|
|
||||||
return Time{time.Now()}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t Time) MarshalJSON() ([]byte, error) {
|
|
||||||
if t.IsZero() {
|
|
||||||
return []byte(emptyString), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return t.Time.MarshalJSON()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *Time) UnmarshalJSON(b []byte) error {
|
|
||||||
if bytes.Equal(b, []byte("null")) {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
// If it is empty, we don't have to set anything since time.Time is not a
|
|
||||||
// pointer and will be set to the zero value
|
|
||||||
if bytes.Equal([]byte(emptyString), b) {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return t.Time.UnmarshalJSON(b)
|
|
||||||
}
|
|
||||||
|
|
||||||
func Parse(layout, value string) (Time, error) {
|
|
||||||
t, err := time.Parse(layout, value)
|
|
||||||
return Time{Time: t}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func ParseInLocation(layout, value string, loc *time.Location) (Time, error) {
|
|
||||||
t, err := time.ParseInLocation(layout, value, loc)
|
|
||||||
return Time{Time: t}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func Date(year int, month time.Month, day, hour, minute, second, nanoSecond int, loc *time.Location) Time {
|
|
||||||
return Time{Time: time.Date(year, month, day, hour, minute, second, nanoSecond, loc)}
|
|
||||||
}
|
|
||||||
|
|
||||||
func Unix(sec int64, nsec int64) Time { return Time{Time: time.Unix(sec, nsec)} }
|
|
||||||
|
|
||||||
func (t Time) Add(d time.Duration) Time { return Time{Time: t.Time.Add(d)} }
|
|
||||||
func (t Time) AddDate(years int, months int, days int) Time {
|
|
||||||
return Time{Time: t.Time.AddDate(years, months, days)}
|
|
||||||
}
|
|
||||||
func (t Time) After(u Time) bool { return t.Time.After(u.Time) }
|
|
||||||
func (t Time) Before(u Time) bool { return t.Time.Before(u.Time) }
|
|
||||||
func (t Time) Equal(u Time) bool { return t.Time.Equal(u.Time) }
|
|
||||||
func (t Time) In(loc *time.Location) Time { return Time{Time: t.Time.In(loc)} }
|
|
||||||
func (t Time) Local() Time { return Time{Time: t.Time.Local()} }
|
|
||||||
func (t Time) Round(d time.Duration) Time { return Time{Time: t.Time.Round(d)} }
|
|
||||||
func (t Time) Sub(u Time) time.Duration { return t.Time.Sub(u.Time) }
|
|
||||||
func (t Time) Truncate(d time.Duration) Time { return Time{Time: t.Time.Truncate(d)} }
|
|
||||||
func (t Time) UTC() Time { return Time{Time: t.Time.UTC()} }
|
|
@ -1,153 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright The Helm Authors.
|
|
||||||
|
|
||||||
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 time
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"testing"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
timeParseString = `"1977-09-02T22:04:05Z"`
|
|
||||||
timeString = "1977-09-02 22:04:05 +0000 UTC"
|
|
||||||
)
|
|
||||||
|
|
||||||
func givenTime(t *testing.T) Time {
|
|
||||||
t.Helper()
|
|
||||||
result, err := Parse(time.RFC3339, "1977-09-02T22:04:05Z")
|
|
||||||
require.NoError(t, err)
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestDate(t *testing.T) {
|
|
||||||
testingTime := givenTime(t)
|
|
||||||
got := Date(1977, 9, 2, 22, 04, 05, 0, time.UTC)
|
|
||||||
assert.Equal(t, timeString, got.String())
|
|
||||||
assert.True(t, testingTime.Equal(got))
|
|
||||||
assert.True(t, got.Equal(testingTime))
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestNow(t *testing.T) {
|
|
||||||
testingTime := givenTime(t)
|
|
||||||
got := Now()
|
|
||||||
assert.True(t, testingTime.Before(got))
|
|
||||||
assert.True(t, got.After(testingTime))
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestTime_Add(t *testing.T) {
|
|
||||||
testingTime := givenTime(t)
|
|
||||||
got := testingTime.Add(time.Hour)
|
|
||||||
assert.Equal(t, timeString, testingTime.String())
|
|
||||||
assert.Equal(t, "1977-09-02 23:04:05 +0000 UTC", got.String())
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestTime_AddDate(t *testing.T) {
|
|
||||||
testingTime := givenTime(t)
|
|
||||||
got := testingTime.AddDate(1, 1, 1)
|
|
||||||
assert.Equal(t, "1978-10-03 22:04:05 +0000 UTC", got.String())
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestTime_In(t *testing.T) {
|
|
||||||
testingTime := givenTime(t)
|
|
||||||
edt, err := time.LoadLocation("America/New_York")
|
|
||||||
assert.NoError(t, err)
|
|
||||||
got := testingTime.In(edt)
|
|
||||||
assert.Equal(t, "America/New_York", got.Location().String())
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestTime_MarshalJSONNonZero(t *testing.T) {
|
|
||||||
testingTime := givenTime(t)
|
|
||||||
res, err := json.Marshal(testingTime)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.Equal(t, timeParseString, string(res))
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestTime_MarshalJSONZeroValue(t *testing.T) {
|
|
||||||
res, err := json.Marshal(Time{})
|
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.Equal(t, `""`, string(res))
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestTime_Round(t *testing.T) {
|
|
||||||
testingTime := givenTime(t)
|
|
||||||
got := testingTime.Round(time.Hour)
|
|
||||||
assert.Equal(t, timeString, testingTime.String())
|
|
||||||
assert.Equal(t, "1977-09-02 22:00:00 +0000 UTC", got.String())
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestTime_Sub(t *testing.T) {
|
|
||||||
testingTime := givenTime(t)
|
|
||||||
before, err := Parse(time.RFC3339, "1977-09-01T22:04:05Z")
|
|
||||||
require.NoError(t, err)
|
|
||||||
got := testingTime.Sub(before)
|
|
||||||
assert.Equal(t, "24h0m0s", got.String())
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestTime_Truncate(t *testing.T) {
|
|
||||||
testingTime := givenTime(t)
|
|
||||||
got := testingTime.Truncate(time.Hour)
|
|
||||||
assert.Equal(t, timeString, testingTime.String())
|
|
||||||
assert.Equal(t, "1977-09-02 22:00:00 +0000 UTC", got.String())
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestTime_UTC(t *testing.T) {
|
|
||||||
edtTime, err := Parse(time.RFC3339, "1977-09-03T05:04:05+07:00")
|
|
||||||
require.NoError(t, err)
|
|
||||||
got := edtTime.UTC()
|
|
||||||
assert.Equal(t, timeString, got.String())
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestTime_UnmarshalJSONNonZeroValue(t *testing.T) {
|
|
||||||
testingTime := givenTime(t)
|
|
||||||
var myTime Time
|
|
||||||
err := json.Unmarshal([]byte(timeParseString), &myTime)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.True(t, testingTime.Equal(myTime))
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestTime_UnmarshalJSONEmptyString(t *testing.T) {
|
|
||||||
var myTime Time
|
|
||||||
err := json.Unmarshal([]byte(emptyString), &myTime)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.True(t, myTime.IsZero())
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestTime_UnmarshalJSONNullString(t *testing.T) {
|
|
||||||
var myTime Time
|
|
||||||
err := json.Unmarshal([]byte("null"), &myTime)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.True(t, myTime.IsZero())
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestTime_UnmarshalJSONZeroValue(t *testing.T) {
|
|
||||||
// This test ensures that we can unmarshal any time value that was output
|
|
||||||
// with the current go default value of "0001-01-01T00:00:00Z"
|
|
||||||
var myTime Time
|
|
||||||
err := json.Unmarshal([]byte(`"0001-01-01T00:00:00Z"`), &myTime)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.True(t, myTime.IsZero())
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestUnix(t *testing.T) {
|
|
||||||
got := Unix(242085845, 0)
|
|
||||||
assert.Equal(t, int64(242085845), got.Unix())
|
|
||||||
assert.Equal(t, timeString, got.UTC().String())
|
|
||||||
}
|
|
Loading…
Reference in new issue