github.com/gitbundle/modules@v0.0.0-20231025071548-85b91c5c3b01/util/sec_to_time_test.go (about)

     1  // Copyright 2023 The GitBundle Inc. All rights reserved.
     2  // Copyright 2017 The Gitea Authors. All rights reserved.
     3  // Use of this source code is governed by a MIT-style
     4  // license that can be found in the LICENSE file.
     5  
     6  package util
     7  
     8  import (
     9  	"testing"
    10  
    11  	"github.com/stretchr/testify/assert"
    12  )
    13  
    14  func TestSecToTime(t *testing.T) {
    15  	second := int64(1)
    16  	minute := 60 * second
    17  	hour := 60 * minute
    18  	day := 24 * hour
    19  	year := 365 * day
    20  
    21  	assert.Equal(t, "1 minute 6 seconds", SecToTime(minute+6*second))
    22  	assert.Equal(t, "1 hour", SecToTime(hour))
    23  	assert.Equal(t, "1 hour", SecToTime(hour+second))
    24  	assert.Equal(t, "14 hours 33 minutes", SecToTime(14*hour+33*minute+30*second))
    25  	assert.Equal(t, "6 days 12 hours", SecToTime(6*day+12*hour+30*minute+18*second))
    26  	assert.Equal(t, "2 weeks 4 days", SecToTime((2*7+4)*day+2*hour+16*minute+58*second))
    27  	assert.Equal(t, "4 weeks", SecToTime(4*7*day))
    28  	assert.Equal(t, "4 weeks 1 day", SecToTime((4*7+1)*day))
    29  	assert.Equal(t, "1 month 2 weeks", SecToTime((6*7+3)*day+13*hour+38*minute+45*second))
    30  	assert.Equal(t, "11 months", SecToTime(year-25*day))
    31  	assert.Equal(t, "1 year 5 months", SecToTime(year+163*day+10*hour+11*minute+5*second))
    32  }