Skip to content

Commit 401619e

Browse files
Update main.rs
1 parent 6262c3c commit 401619e

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/main.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,35 @@ use time_duration_api::time_utils::{CustomDuration, Time};
22

33
fn main() {
44
// Example usage of Time struct
5-
let mut now = Time::now();
5+
let mut now = Time::now(); // Make `now` mutable
66
println!("Current Time: {}", now);
77
println!(
88
"Formatted Time: {}",
99
now.format("%Y-%m-%d %H:%M:%S").unwrap()
1010
);
1111

1212
println!("Timestamp: {}", now.timestamp().unwrap());
13+
14+
// Make `future_time` mutable
1315
let mut future_time = now.add_duration(&CustomDuration::from_secs(3600));
1416
println!(
1517
"Time after 1 hour: {}",
1618
future_time.format("%Y-%m-%d %H:%M:%S").unwrap()
1719
);
20+
21+
// Make `past_time` mutable
1822
let mut past_time = now.sub_duration(&CustomDuration::from_secs(3600));
1923
println!(
2024
"Time before 1 hour: {}",
2125
past_time.format("%Y-%m-%d %H:%M:%S").unwrap()
2226
);
27+
28+
// Make `now` mutable again for timezone conversion
2329
let ist_time = now.to_timezone("+05:30").unwrap();
2430
println!("Time in IST: {}", ist_time);
2531

26-
let time_from_str = Time::from_str("2023-10-27 12:00:00+05:30", "%Y-%m-%d %H:%M:%S%z").unwrap();
32+
// Make `time_from_str` mutable
33+
let mut time_from_str = Time::from_str("2023-10-27 12:00:00+05:30", "%Y-%m-%d %H:%M:%S%z").unwrap();
2734
println!("Time from string: {}", time_from_str);
2835

2936
// Example usage of CustomDuration struct

0 commit comments

Comments
 (0)