mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
time: add is_leap_year(year int)
This commit is contained in:
parent
d9753ee2c6
commit
b3e5c89ba9
@ -319,3 +319,8 @@ pub fn sleep_ms(n int) {
|
|||||||
C.usleep(n * 1000)
|
C.usleep(n * 1000)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Determine whether a year is a leap year.
|
||||||
|
pub fn is_leap_year(year int) bool {
|
||||||
|
return (year%4 == 0) && (year%100 != 0 || year%400 == 0)
|
||||||
|
}
|
17
vlib/time/time_test.v
Normal file
17
vlib/time/time_test.v
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import time
|
||||||
|
|
||||||
|
fn test_is_leap_year() {
|
||||||
|
assert time.is_leap_year(1700) == false
|
||||||
|
assert time.is_leap_year(1800) == false
|
||||||
|
assert time.is_leap_year(1900) == false
|
||||||
|
|
||||||
|
assert time.is_leap_year(1600) == true
|
||||||
|
assert time.is_leap_year(2000) == true
|
||||||
|
|
||||||
|
assert time.is_leap_year(2100) == false
|
||||||
|
assert time.is_leap_year(2200) == false
|
||||||
|
assert time.is_leap_year(2300) == false
|
||||||
|
|
||||||
|
assert time.is_leap_year(1996) == true
|
||||||
|
assert time.is_leap_year(1997) == false
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user