mirror of
https://gitee.com/rulego/streamsql.git
synced 2026-07-17 09:01:12 +00:00
test:增加测试用例
This commit is contained in:
+5
-1
@@ -6,6 +6,10 @@ import (
|
||||
|
||||
// AlignTimeToWindow aligns time to window start time
|
||||
func AlignTimeToWindow(t time.Time, size time.Duration) time.Time {
|
||||
// Handle zero time
|
||||
if t.IsZero() {
|
||||
return t
|
||||
}
|
||||
offset := t.UnixNano() % int64(size)
|
||||
return t.Add(time.Duration(-offset))
|
||||
}
|
||||
@@ -13,7 +17,7 @@ func AlignTimeToWindow(t time.Time, size time.Duration) time.Time {
|
||||
// AlignTime aligns time to specified time unit. When roundUp is true, rounds up; when false, rounds down
|
||||
func AlignTime(t time.Time, timeUnit time.Duration, roundUp bool) time.Time {
|
||||
trunc := t.Truncate(timeUnit)
|
||||
if !roundUp {
|
||||
if roundUp && !t.Equal(trunc) {
|
||||
return trunc.Add(timeUnit)
|
||||
}
|
||||
return trunc
|
||||
|
||||
Reference in New Issue
Block a user