pkg/epoch: fix Y2038 on 32-bit hosts
`strconv.Itoa(int(tm.Unix()))` rounds the time to 32-bit int on 32-bit hosts Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
This commit is contained in:
parent
8348a8cecb
commit
4807571352
@ -73,7 +73,7 @@ func ParseSourceDateEpoch(sourceDateEpoch string) (*time.Time, error) {
|
|||||||
|
|
||||||
// SetSourceDateEpoch sets the SOURCE_DATE_EPOCH env var.
|
// SetSourceDateEpoch sets the SOURCE_DATE_EPOCH env var.
|
||||||
func SetSourceDateEpoch(tm time.Time) {
|
func SetSourceDateEpoch(tm time.Time) {
|
||||||
_ = os.Setenv(SourceDateEpochEnv, strconv.Itoa(int(tm.Unix())))
|
_ = os.Setenv(SourceDateEpochEnv, fmt.Sprintf("%d", tm.Unix()))
|
||||||
}
|
}
|
||||||
|
|
||||||
// UnsetSourceDateEpoch unsets the SOURCE_DATE_EPOCH env var.
|
// UnsetSourceDateEpoch unsets the SOURCE_DATE_EPOCH env var.
|
||||||
|
@ -17,9 +17,9 @@
|
|||||||
package epoch
|
package epoch
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -85,7 +85,7 @@ func TestSourceDateEpoch(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.True(t, vp.Equal(sourceDateEpoch.UTC()))
|
require.True(t, vp.Equal(sourceDateEpoch.UTC()))
|
||||||
|
|
||||||
vp, err = ParseSourceDateEpoch(strconv.Itoa(int(sourceDateEpoch.Unix())))
|
vp, err = ParseSourceDateEpoch(fmt.Sprintf("%d", sourceDateEpoch.Unix()))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.True(t, vp.Equal(sourceDateEpoch))
|
require.True(t, vp.Equal(sourceDateEpoch))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user