1
0
mirror of https://github.com/rclone/rclone.git synced 2025-12-15 15:53:41 +00:00

lsf: add --time-format flag

Before this change, lsf's time format was hard-coded to "2006-01-02 15:04:05",
regardless of the Fs's precision. After this change, a new optional
--time-format flag is added to allow customizing the format (the default is
unchanged).

Examples:
	rclone lsf remote:path --format pt --time-format 'Jan 2, 2006 at 3:04pm (MST)'
	rclone lsf remote:path --format pt --time-format '2006-01-02 15:04:05.000000000'
	rclone lsf remote:path --format pt --time-format '2006-01-02T15:04:05.999999999Z07:00'
	rclone lsf remote:path --format pt --time-format RFC3339
	rclone lsf remote:path --format pt --time-format DateOnly
	rclone lsf remote:path --format pt --time-format max

--time-format max will automatically truncate '2006-01-02 15:04:05.000000000'
to the maximum precision supported by the remote.
This commit is contained in:
nielash
2023-12-07 19:29:55 -05:00
parent b06935a12e
commit 66929416d4
4 changed files with 183 additions and 15 deletions

View File

@@ -1916,9 +1916,54 @@ func (l *ListFormat) SetOutput(output []func(entry *ListJSONItem) string) {
}
// AddModTime adds file's Mod Time to output
func (l *ListFormat) AddModTime() {
func (l *ListFormat) AddModTime(timeFormat string) {
switch timeFormat {
case "":
timeFormat = "2006-01-02 15:04:05"
case "Layout":
timeFormat = time.Layout
case "ANSIC":
timeFormat = time.ANSIC
case "UnixDate":
timeFormat = time.UnixDate
case "RubyDate":
timeFormat = time.RubyDate
case "RFC822":
timeFormat = time.RFC822
case "RFC822Z":
timeFormat = time.RFC822Z
case "RFC850":
timeFormat = time.RFC850
case "RFC1123":
timeFormat = time.RFC1123
case "RFC1123Z":
timeFormat = time.RFC1123Z
case "RFC3339":
timeFormat = time.RFC3339
case "RFC3339Nano":
timeFormat = time.RFC3339Nano
case "Kitchen":
timeFormat = time.Kitchen
case "Stamp":
timeFormat = time.Stamp
case "StampMilli":
timeFormat = time.StampMilli
case "StampMicro":
timeFormat = time.StampMicro
case "StampNano":
timeFormat = time.StampNano
case "DateTime":
// timeFormat = time.DateTime // missing in go1.19
timeFormat = "2006-01-02 15:04:05"
case "DateOnly":
// timeFormat = time.DateOnly // missing in go1.19
timeFormat = "2006-01-02"
case "TimeOnly":
// timeFormat = time.TimeOnly // missing in go1.19
timeFormat = "15:04:05"
}
l.AppendOutput(func(entry *ListJSONItem) string {
return entry.ModTime.When.Local().Format("2006-01-02 15:04:05")
return entry.ModTime.When.Local().Format(timeFormat)
})
}
@@ -2030,6 +2075,31 @@ func (l *ListFormat) Format(entry *ListJSONItem) (result string) {
return result
}
// FormatForLSFPrecision Returns a time format for the given precision
func FormatForLSFPrecision(precision time.Duration) string {
switch {
case precision <= time.Nanosecond:
return "2006-01-02 15:04:05.000000000"
case precision <= 10*time.Nanosecond:
return "2006-01-02 15:04:05.00000000"
case precision <= 100*time.Nanosecond:
return "2006-01-02 15:04:05.0000000"
case precision <= time.Microsecond:
return "2006-01-02 15:04:05.000000"
case precision <= 10*time.Microsecond:
return "2006-01-02 15:04:05.00000"
case precision <= 100*time.Microsecond:
return "2006-01-02 15:04:05.0000"
case precision <= time.Millisecond:
return "2006-01-02 15:04:05.000"
case precision <= 10*time.Millisecond:
return "2006-01-02 15:04:05.00"
case precision <= 100*time.Millisecond:
return "2006-01-02 15:04:05.0"
}
return "2006-01-02 15:04:05"
}
// DirMove renames srcRemote to dstRemote
//
// It does this by loading the directory tree into memory (using ListR