Skip to main content

example/
main.rs

1use aion::*;
2use chrono::{TimeZone, Utc};
3
4fn main() {
5    // Easily represent a chrono::Duration
6    let two_days = 2.days();
7    println!("2 days: {:?}", two_days);
8    let attention_span = 1.seconds();
9    println!("Attention span: {:?}", attention_span);
10
11    // Add or subtract durations from the current time (UTC)
12    let two_hours_from_now = 2.hours().from_now();
13    println!("2 hours from now: {}", two_hours_from_now);
14    let last_week = 7.days().ago(); // or 1.weeks().ago()
15    println!("1 week ago: {}", last_week);
16
17    // More complex DateTimes can be represented using before() and after() methods
18    let christmas = Utc.ymd(2020, 12, 25).and_hms(0, 0, 0);
19    let two_weeks_before_christmas = 2.weeks().before(christmas);
20    println!("2 weeks before christmas: {}", two_weeks_before_christmas);
21    let boxing_day = 1.days().after(christmas);
22    println!("Boxing day: {}", boxing_day);
23}