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

time: use operator overloading for >= and <= (#8009)

This commit is contained in:
Swastik Baranwal 2021-01-11 01:35:05 +05:30 committed by GitHub
parent 2a75a30be5
commit 8f4238e76a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 12 deletions

View File

@ -24,9 +24,9 @@ pub fn (t1 Time) < (t2 Time) bool {
return false
}
// le returns true if provided time is less or equal to time
// operator `<=` returns true if provided time is less or equal to time
[inline]
pub fn (t1 Time) le(t2 Time) bool {
pub fn (t1 Time) <= (t2 Time) bool {
return t1 < t2 || t1 == t2
}
@ -39,9 +39,9 @@ pub fn (t1 Time) > (t2 Time) bool {
return false
}
// ge returns true if provided time is greater or equal to time
// operator `>=` returns true if provided time is greater or equal to time
[inline]
pub fn (t1 Time) ge(t2 Time) bool {
pub fn (t1 Time) >= (t2 Time) bool {
return t1 > t2 || t1 == t2
}

View File

@ -221,8 +221,8 @@ fn test_time1_should_be_greater_or_equal_to_time2_when_gt() {
second: 4
microsecond: 0
})
assert t1.ge(t2)
assert t3.ge(t4)
assert t1 >= t2
assert t3 >= t4
}
fn test_time1_should_be_greater_or_equal_to_time2_when_eq() {
@ -264,8 +264,8 @@ fn test_time1_should_be_greater_or_equal_to_time2_when_eq() {
second: 3
microsecond: 0
})
assert t1.ge(t2)
assert t3.ge(t4)
assert t1 >= t2
assert t3 >= t4
}
fn test_time1_should_be_less_or_equal_to_time2_when_lt() {
@ -307,8 +307,8 @@ fn test_time1_should_be_less_or_equal_to_time2_when_lt() {
second: 4
microsecond: 0
})
assert t1.le(t2)
assert t3.le(t4)
assert t1 <= t2
assert t3 <= t4
}
fn test_time1_should_be_less_or_equal_to_time2_when_eq() {
@ -350,8 +350,8 @@ fn test_time1_should_be_less_or_equal_to_time2_when_eq() {
second: 3
microsecond: 0
})
assert t1.le(t2)
assert t3.le(t4)
assert t1 <= t2
assert t3 <= t4
}
fn test_time2_copied_from_time1_should_be_equal() {