mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-10-12 02:16:39 +00:00
CLI file timestamps reject offsets and discard milliseconds (#20491)
Fixes #20486 ## Summary Try RFC3339/RFC3339Nano and preserve the millisecond remainder when converting epoch milliseconds.
This commit is contained in:
@@ -760,6 +760,8 @@ func parseTime(v interface{}) time.Time {
|
||||
formats := []string{
|
||||
"2006-01-02 15:04:05",
|
||||
"2006-01-02T15:04:05",
|
||||
time.RFC3339Nano,
|
||||
time.RFC3339,
|
||||
"2006-01-02T15:04:05Z",
|
||||
"2006-01-02",
|
||||
}
|
||||
@@ -774,9 +776,10 @@ func parseTime(v interface{}) time.Time {
|
||||
return time.Time{}
|
||||
}
|
||||
|
||||
// Convert milliseconds to seconds if timestamp is in milliseconds (13 digits)
|
||||
// Convert milliseconds to seconds if timestamp is in milliseconds (13 digits),
|
||||
// preserving the sub-second remainder.
|
||||
if ts > 1e12 {
|
||||
ts = ts / 1000
|
||||
return time.Unix(ts/1000, (ts%1000)*int64(time.Millisecond))
|
||||
}
|
||||
|
||||
return time.Unix(ts, 0)
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package filesystem
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestParseTimeRFC3339WithOffset(t *testing.T) {
|
||||
got := parseTime("2026-09-30T15:04:05+05:30")
|
||||
if got.IsZero() {
|
||||
t.Fatal("RFC3339 timestamp with zone offset must parse, got zero time")
|
||||
}
|
||||
want, _ := time.Parse(time.RFC3339, "2026-09-30T15:04:05+05:30")
|
||||
if !got.Equal(want) {
|
||||
t.Fatalf("got %v, want %v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseTimeMillisecondsRemainder(t *testing.T) {
|
||||
var record map[string]interface{}
|
||||
if err := json.Unmarshal([]byte(`{"created_at":1727700000123}`), &record); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, input := range []interface{}{int64(1727700000123), record["created_at"]} {
|
||||
got := parseTime(input)
|
||||
if got.UnixMilli() != 1727700000123 {
|
||||
t.Fatalf("millisecond remainder lost for %T: got %d", input, got.UnixMilli())
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user