Last active
May 7, 2023 17:35
-
-
Save ethanniser/2d230999c2319ef6667b20d9d8f2b015 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum Duration { | |
Ms(usize), | |
Sec(usize), | |
Min(usize), | |
Hour(usize), | |
Day(usize), | |
Week(usize), | |
Month(usize), | |
Year(usize), | |
} | |
impl Duration { | |
fn into_ms(self) -> usize { | |
match self { | |
Duration::Ms(x) => x, | |
Duration::Sec(x) => x * 1000, | |
Duration::Min(x) => x * 60 * 1000, | |
Duration::Hour(x) => x * 60 * 60 * 1000, | |
Duration::Day(x) => x * 24 * 60 * 60 * 1000, | |
Duration::Week(x) => x * 7 * 24 * 60 * 60 * 1000, | |
Duration::Month(x) => x * 30 * 24 * 60 * 60 * 1000, // Assuming an average month has 30 days | |
Duration::Year(x) => x * 365 * 24 * 60 * 60 * 1000, // Assuming a non-leap year | |
} | |
} | |
} | |
fn revalidate(duration: Duration) { | |
let time_in_ms = duration.into_ms(); | |
// Perform revalidation with the calculated time_in_ms | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment