use simple_datetime_rs::{Date, DateTime, Time};
fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("Advanced Features Demo");
println!("======================");
println!("Data Normalization:");
let invalid_date = Date::new(2020, 49, 32);
let normalized = invalid_date.normalize();
println!("Invalid date {} normalized to {}", invalid_date, normalized);
let invalid_time = Time::new(25, 70, 80);
let normalized_time = invalid_time.normalize();
println!(
"Invalid time {} normalized to {}",
invalid_time, normalized_time
);
println!("\nMS-DOS Format Support:");
let dos_date = Date::from_ms_dos_date(0x354b);
let dos_time = Time::from_ms_dos_time(0x7d1c);
println!("MS-DOS date 0x354b = {}", dos_date);
println!("MS-DOS time 0x7d1c = {}", dos_time);
println!("\nMicrosecond Precision:");
let precise_time = Time::new_with_microseconds(14, 30, 45, 123456);
println!("Time with microseconds: {}", precise_time);
println!("Microseconds: {}", precise_time.to_microseconds());
println!("Milliseconds: {}", precise_time.to_milliseconds());
println!("\nBusiness Logic Helpers:");
let date = Date::new(2023, 6, 15);
println!("Date: {}", date);
println!("Is weekend: {}", date.is_weekend());
println!("Is weekday: {}", date.is_week_day());
println!("Is Monday: {}", date.is_monday());
println!("Is Friday: {}", date.is_friday());
println!("\nLeap Year Utilities:");
let leap_date = Date::new(2024, 2, 29);
let non_leap_date = Date::new(2023, 2, 28);
println!("2024 is leap year: {}", leap_date.leap_year());
println!("2023 is leap year: {}", non_leap_date.leap_year());
println!(
"Next leap year after 2023: {}",
non_leap_date.next_leap_year()
);
println!(
"Recent leap year before 2023: {}",
non_leap_date.recent_leap_year()
);
println!("\nQuarter and Year Day:");
println!("Quarter of {}: {}", date, date.quarter());
println!("Day of year: {}", date.year_day());
println!("Days remaining in year: {}", date.days_to_next_year());
println!("\nMonth Boundary Operations:");
let last_day = Date::new(2023, 6, 30);
let first_day = Date::new(2023, 6, 1);
println!(
"Is {} last day of month: {}",
last_day,
last_day.is_month_last_day()
);
println!(
"Is {} first day of month: {}",
first_day,
first_day.day == 1
);
println!("Last day of June 2023: {}", first_day.month_last_day());
println!("\nTimezone Handling:");
let mut dt = DateTime::new(date, Time::new(14, 30, 45), 0);
println!("Original DateTime: {}", dt);
dt.set_shift(120);
println!("With UTC+2 offset: {}", dt);
println!("GMT time: {}", dt.to_seconds_from_unix_epoch_gmt());
println!("\nString Formatting:");
let time = Time::new(14, 30, 45);
println!("Full time: {}", time);
println!("HH:MM format: {}", time.to_hh_mm_string());
let datetime = DateTime::new(date, time, 0);
println!("ISO 8601: {}", datetime.to_iso_8061());
println!("\nCross-Platform Time Access:");
let now = DateTime::now();
let today = Date::today();
println!("Current time: {}", now);
println!("Today's date: {}", today);
Ok(())
}