Skip to content

Commit

Permalink
feat: rename FileNameFormatStr to 2006-01-02-15-04 (#82)
Browse files Browse the repository at this point in the history
Co-authored-by: jeessy2 <jeessy2@users.noreply.github.com>
  • Loading branch information
jeessy2 and jeessy2 authored Oct 8, 2023
1 parent 8cfde6b commit 5088449
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions util/file_name_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import (
"time"
)

const FileNameFormatStr = "2006-01-02_15_04"
const FileNameFormatStr = "2006-01-02-15-04"

// FileNameBeforeDays 查找文件名中有多少在指定天数之前的
func FileNameBeforeDays(days int, fileNames []string) []string {
oldFiles := make([]string, 0)
// 2006-01-02_15_04
fileRegxp := regexp.MustCompile(`([\d]{4})-([\d]{2})-([\d]{2})_([\d]{2})_([\d]{2})`)
// 2006-01-02-15-04
fileRegxp := regexp.MustCompile(`([\d]{4})-([\d]{2})-([\d]{2})-([\d]{2})-([\d]{2})`)
subDuration, _ := time.ParseDuration("-" + strconv.Itoa(days*24) + "h")
before := time.Now().Add(subDuration)
for i := 0; i < len(fileNames); i++ {
Expand Down
4 changes: 2 additions & 2 deletions util/file_name_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ func TestFileNameUtil(t *testing.T) {
const days = 10
beforeTomorrow, _ := time.ParseDuration("-" + strconv.Itoa((days+1)*24) + "h")
fileNames := []string{
"a2020-10-10_11_12b.sql",
"测试2021-10-10_11_12测试.sql",
"a2020-10-10-11-12b.sql",
"测试2021-10-10-11-12测试.sql",
time.Now().Add(beforeTomorrow).Format(FileNameFormatStr) + ".sql",
}
if len(fileNames) != len(FileNameBeforeDays(10, fileNames)) {
Expand Down

0 comments on commit 5088449

Please sign in to comment.