1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

time: fix losing of the .is_local value after adding duration (#18938)

This commit is contained in:
werkzeug 2023-07-22 06:01:11 +02:00 committed by GitHub
parent ba1c5def77
commit a3449098a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 0 deletions

View File

@ -116,6 +116,9 @@ pub fn (t Time) add(d Duration) Time {
microseconds := i64(t.unix) * 1_000_000 + t.microsecond + d.microseconds()
unix := microseconds / 1_000_000
micro := microseconds % 1_000_000
if t.is_local {
return unix2(unix, int(micro)).as_local()
}
return unix2(unix, int(micro))
}

View File

@ -187,10 +187,15 @@ fn test_add() {
assert t2.second == t1.second + d_seconds
assert t2.microsecond == t1.microsecond + d_microseconds
assert t2.unix == t1.unix + d_seconds
assert t2.is_local == t1.is_local
t3 := time_to_test.add(-duration)
assert t3.second == t1.second - d_seconds
assert t3.microsecond == t1.microsecond - d_microseconds
assert t3.unix == t1.unix - d_seconds
assert t3.is_local == t1.is_local
t4 := time_to_test.as_local()
t5 := t4.add(duration)
assert t5.is_local == t4.is_local
}
fn test_add_days() {