github.com/fraugster/parquet-go@v0.12.0/int96_time_test.go (about)

     1  package goparquet
     2  
     3  import (
     4  	"testing"
     5  	"time"
     6  
     7  	"github.com/stretchr/testify/require"
     8  )
     9  
    10  func TestConvert(t *testing.T) {
    11  	// The round here is essential, since the time in parquet does not contains a monotonic clock reading
    12  	now := time.Now().Round(0)
    13  	arr := []time.Time{
    14  		now,
    15  		now.Add(time.Hour),
    16  		now.Add(-24 * time.Hour),
    17  		now.Add(-240 * time.Hour),
    18  		now.Add(-2400 * time.Hour),
    19  		now.Add(-24000 * time.Hour),
    20  	}
    21  
    22  	for i := range arr {
    23  		conv := TimeToInt96(arr[i])
    24  		t2 := Int96ToTime(conv)
    25  
    26  		require.Equal(t, arr[i], t2)
    27  	}
    28  
    29  	date := [12]byte{00, 0x60, 0xFD, 0x4B, 0x32, 0x29, 0x00, 0x00, 0x59, 0x68, 0x25, 0x00}
    30  	// the generated time is in the current timezone (depends on the machine)
    31  	ts := Int96ToTime(date)
    32  	expected := time.Date(2000, 1, 1, 12, 34, 56, 0, time.UTC)
    33  	require.Equal(t, expected, ts.UTC())
    34  }
    35  
    36  func TestTimeAfterUnixEpoch(t *testing.T) {
    37  	var (
    38  		t0, t1 time.Time
    39  	)
    40  
    41  	t1, _ = time.Parse(time.RFC3339, "1970-01-01T00:00:01Z")
    42  
    43  	require.False(t, IsAfterUnixEpoch(t0))
    44  	require.True(t, IsAfterUnixEpoch(t1))
    45  }