Don't reduce year of date to two digits

This commit is contained in:
Julian Kornberger 2018-01-04 13:25:44 +01:00
parent 352a1d8821
commit 5bde7e961e

View File

@ -2,6 +2,7 @@ package ftp
import ( import (
"errors" "errors"
"fmt"
"strconv" "strconv"
"strings" "strings"
"time" "time"
@ -224,8 +225,8 @@ func (e *Entry) setSize(str string) (err error) {
func (e *Entry) setTime(fields []string, now time.Time) (err error) { func (e *Entry) setTime(fields []string, now time.Time) (err error) {
if strings.Contains(fields[2], ":") { // contains time if strings.Contains(fields[2], ":") { // contains time
thisYear, _, _ := now.Date() thisYear, _, _ := now.Date()
timeStr := fields[1] + " " + fields[0] + " " + strconv.Itoa(thisYear)[2:4] + " " + fields[2] + " GMT" timeStr := fmt.Sprintf("%s %s %d %s GMT", fields[1], fields[0], thisYear, fields[2])
e.Time, err = time.Parse("_2 Jan 06 15:04 MST", timeStr) e.Time, err = time.Parse("_2 Jan 2006 15:04 MST", timeStr)
/* /*
On unix, `info ls` shows: On unix, `info ls` shows:
@ -247,8 +248,8 @@ func (e *Entry) setTime(fields []string, now time.Time) (err error) {
if len(fields[2]) != 4 { if len(fields[2]) != 4 {
return errors.New("Invalid year format in time string") return errors.New("Invalid year format in time string")
} }
timeStr := fields[1] + " " + fields[0] + " " + fields[2][2:4] + " 00:00 GMT" timeStr := fmt.Sprintf("%s %s %s 00:00 GMT", fields[1], fields[0], fields[2])
e.Time, err = time.Parse("_2 Jan 06 15:04 MST", timeStr) e.Time, err = time.Parse("_2 Jan 2006 15:04 MST", timeStr)
} }
return return
} }