mirror of
https://github.com/tickstep/aliyunpan.git
synced 2025-02-02 21:27:15 +08:00
format time string
This commit is contained in:
parent
971369e968
commit
267cf937be
@ -17,6 +17,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"github.com/tickstep/aliyunpan-api/aliyunpan/apierror"
|
"github.com/tickstep/aliyunpan-api/aliyunpan/apierror"
|
||||||
"github.com/tickstep/aliyunpan/cmder"
|
"github.com/tickstep/aliyunpan/cmder"
|
||||||
|
"github.com/tickstep/aliyunpan/internal/utils"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
@ -427,7 +428,7 @@ func RunUpload(localPaths []string, savePath string, opt *UploadOptions) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("\n")
|
fmt.Printf("\n")
|
||||||
fmt.Printf("上传结束, 时间: %s, 总大小: %s\n", statistic.Elapsed()/1e6*1e6, converter.ConvertFileSize(statistic.TotalSize()))
|
fmt.Printf("上传结束, 时间: %s, 总大小: %s\n", utils.ConvertTime(statistic.Elapsed()), converter.ConvertFileSize(statistic.TotalSize()))
|
||||||
|
|
||||||
// 输出上传失败的文件列表
|
// 输出上传失败的文件列表
|
||||||
for _, failed := range failedList {
|
for _, failed := range failedList {
|
||||||
|
@ -15,6 +15,7 @@ package panupload
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/tickstep/aliyunpan/internal/utils"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -285,7 +286,7 @@ func (utu *UploadTaskUnit) Run() (result *taskframework.TaskUnitRunResult) {
|
|||||||
} else {
|
} else {
|
||||||
msg = result.ResultMessage
|
msg = result.ResultMessage
|
||||||
}
|
}
|
||||||
fmt.Printf("%s [%s] 文件上传结果:%s 耗时 %.2fs\n", time.Now().Format("2006-01-02 15:04:06"), utu.taskInfo.Id(), msg, time.Now().Sub(timeStart).Seconds())
|
fmt.Printf("%s [%s] 文件上传结果:%s 耗时 %s\n", time.Now().Format("2006-01-02 15:04:06"), utu.taskInfo.Id(), msg, utils.ConvertTime(time.Now().Sub(timeStart)))
|
||||||
}()
|
}()
|
||||||
// 准备文件
|
// 准备文件
|
||||||
utu.prepareFile()
|
utu.prepareFile()
|
||||||
|
@ -16,12 +16,14 @@ package utils
|
|||||||
import (
|
import (
|
||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
"flag"
|
"flag"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http/cookiejar"
|
"net/http/cookiejar"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TrimPathPrefix 去除目录的前缀
|
// TrimPathPrefix 去除目录的前缀
|
||||||
@ -112,3 +114,26 @@ func parseInt(numStr string) int {
|
|||||||
}
|
}
|
||||||
return num
|
return num
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ConvertTime(t time.Duration) string {
|
||||||
|
seconds := int64(t.Seconds())
|
||||||
|
|
||||||
|
MT := int64(1 * 60)
|
||||||
|
HT := int64(1 * 60 * 60)
|
||||||
|
|
||||||
|
if seconds <= 0 {
|
||||||
|
return "0秒"
|
||||||
|
}
|
||||||
|
if seconds < MT {
|
||||||
|
return fmt.Sprintf("%d秒", seconds)
|
||||||
|
}
|
||||||
|
if seconds >= MT && seconds < HT {
|
||||||
|
return fmt.Sprintf("%d分%d秒", seconds / MT, seconds % MT)
|
||||||
|
}
|
||||||
|
if seconds >= HT {
|
||||||
|
h := seconds / HT
|
||||||
|
tmp := seconds % HT
|
||||||
|
return fmt.Sprintf("%d小时%d分%d秒", h, tmp / MT, tmp % MT)
|
||||||
|
}
|
||||||
|
return "0秒"
|
||||||
|
}
|
21
internal/utils/utils_test.go
Normal file
21
internal/utils/utils_test.go
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
package utils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestConvertTime(t *testing.T) {
|
||||||
|
seconds := time.Duration(50) * time.Second
|
||||||
|
fmt.Println(ConvertTime(seconds))
|
||||||
|
|
||||||
|
seconds = time.Duration(150) * time.Second
|
||||||
|
fmt.Println(ConvertTime(seconds))
|
||||||
|
|
||||||
|
seconds = time.Duration(3600) * time.Second
|
||||||
|
fmt.Println(ConvertTime(seconds))
|
||||||
|
|
||||||
|
seconds = time.Duration(1246852) * time.Second
|
||||||
|
fmt.Println(ConvertTime(seconds))
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user