oxedyne/fe2o3/fe2o3_datime/tests/new_features.rs
7.9 KiB, 8 runs
created by r1870400018:6419, which is this file's identity for as long as the history lasts, whatever it is later renamed to
download · who wrote it · its history
| 1 | //! [Written with AI entirely](https://need2know.ai/entirely-ai/code)\ |
| 2 | //! Anthropic Claude |
| 3 | |
| 4 | use oxedyne_fe2o3_core::{ |
| 5 | prelude::*, |
| 6 | test::test_it, |
| 7 | }; |
| 8 | use oxedyne_fe2o3_datime::{ |
| 9 | calendar::{CalendarDate, CalendarSystem}, |
| 10 | time::{ |
| 11 | CalClock, |
| 12 | CalClockZone, |
| 13 | SystemTimezoneManager, |
| 14 | SystemTimezoneConfig, |
| 15 | SystemTimezoneExt, |
| 16 | LeapSecondCapability, |
| 17 | }, |
| 18 | }; |
| 19 | |
| 20 | pub fn test_new_features(filter: &str) -> Outcome<()> { |
| 21 | |
| 22 | res!(test_it(filter, &["calendar_systems", "all", "calendar", "gregorian", "julian"], || { |
| 23 | let zone = res!(CalClockZone::new("UTC")); |
| 24 | |
| 25 | // Test default Gregorian calendar |
| 26 | let gregorian_date = res!(CalendarDate::new(2024, 6, 15, zone.clone())); |
| 27 | assert!(gregorian_date.is_gregorian()); |
| 28 | assert!(!gregorian_date.is_julian()); |
| 29 | assert_eq!(gregorian_date.calendar_system(), &CalendarSystem::Gregorian); |
| 30 | |
| 31 | // Test explicit Gregorian calendar |
| 32 | let gregorian_explicit = res!(CalendarDate::new_with_system( |
| 33 | 2024, 6, 15, zone.clone(), CalendarSystem::Gregorian |
| 34 | )); |
| 35 | assert_eq!(gregorian_date, gregorian_explicit); |
| 36 | |
| 37 | // Test Julian calendar |
| 38 | let julian_date = res!(CalendarDate::new_with_system( |
| 39 | 2024, 6, 15, zone.clone(), CalendarSystem::Julian |
| 40 | )); |
| 41 | assert!(!julian_date.is_gregorian()); |
| 42 | assert!(julian_date.is_julian()); |
| 43 | assert_eq!(julian_date.calendar_system(), &CalendarSystem::Julian); |
| 44 | |
| 45 | // Test calendar conversion |
| 46 | let converted_to_julian = res!(gregorian_date.to_julian()); |
| 47 | assert!(converted_to_julian.is_julian()); |
| 48 | |
| 49 | let converted_to_gregorian = res!(julian_date.to_gregorian()); |
| 50 | assert!(converted_to_gregorian.is_gregorian()); |
| 51 | |
| 52 | Ok(()) |
| 53 | })); |
| 54 | |
| 55 | res!(test_it(filter, &["leap_year_differences", "all", "calendar", "leap"], || { |
| 56 | let zone = res!(CalClockZone::new("UTC")); |
| 57 | |
| 58 | // Test year 1900 - leap in Julian, not in Gregorian |
| 59 | let gregorian_1900 = res!(CalendarDate::new_with_system( |
| 60 | 1900, 2, 28, zone.clone(), CalendarSystem::Gregorian |
| 61 | )); |
| 62 | let julian_1900 = res!(CalendarDate::new_with_system( |
| 63 | 1900, 2, 29, zone.clone(), CalendarSystem::Julian |
| 64 | )); |
| 65 | |
| 66 | assert!(!gregorian_1900.is_leap_year()); |
| 67 | assert!(julian_1900.is_leap_year()); |
| 68 | |
| 69 | // Test year 2000 - leap in both |
| 70 | let gregorian_2000 = res!(CalendarDate::new_with_system( |
| 71 | 2000, 2, 29, zone.clone(), CalendarSystem::Gregorian |
| 72 | )); |
| 73 | let julian_2000 = res!(CalendarDate::new_with_system( |
| 74 | 2000, 2, 29, zone.clone(), CalendarSystem::Julian |
| 75 | )); |
| 76 | |
| 77 | assert!(gregorian_2000.is_leap_year()); |
| 78 | assert!(julian_2000.is_leap_year()); |
| 79 | |
| 80 | Ok(()) |
| 81 | })); |
| 82 | |
| 83 | res!(test_it(filter, &["system_timezone_config", "all", "timezone", "system"], || { |
| 84 | // Test default conservative configuration |
| 85 | let default_config = SystemTimezoneConfig::default(); |
| 86 | assert!(!default_config.use_system_data); |
| 87 | assert!(default_config.require_consent); |
| 88 | assert!(default_config.detect_conflicts); |
| 89 | assert!(!default_config.search_paths.is_empty()); |
| 90 | |
| 91 | // Test automatic configuration (Jiff-style) |
| 92 | let auto_config = SystemTimezoneConfig::automatic(); |
| 93 | assert!(auto_config.use_system_data); |
| 94 | assert!(!auto_config.require_consent); |
| 95 | assert!(auto_config.detect_conflicts); |
| 96 | |
| 97 | // Test with consent configuration |
| 98 | let consent_config = SystemTimezoneConfig::with_consent(); |
| 99 | assert!(consent_config.use_system_data); |
| 100 | assert!(consent_config.require_consent); |
| 101 | assert!(consent_config.detect_conflicts); |
| 102 | |
| 103 | Ok(()) |
| 104 | })); |
| 105 | |
| 106 | res!(test_it(filter, &["system_timezone_manager", "all", "timezone", "manager"], || { |
| 107 | let config = SystemTimezoneConfig::default(); |
| 108 | let manager = SystemTimezoneManager::new(config); |
| 109 | |
| 110 | // Test initial state |
| 111 | assert!(!manager.has_consent()); |
| 112 | |
| 113 | // Test cache stats |
| 114 | let stats = manager.cache_stats(); |
| 115 | assert_eq!(stats.cached_zones, 0); |
| 116 | |
| 117 | // Test system timezone list (should work even without consent for listing) |
| 118 | let _zones = res!(manager.list_system_timezones()); |
| 119 | |
| 120 | Ok(()) |
| 121 | })); |
| 122 | |
| 123 | res!(test_it(filter, &["embedded_vs_system_timezone", "all", "timezone", "embedded"], || { |
| 124 | // Test embedded-only timezone creation |
| 125 | let embedded_utc = res!(CalClockZone::new_embedded("UTC")); |
| 126 | assert_eq!(embedded_utc.id(), "UTC"); |
| 127 | |
| 128 | // Test system-or-embedded timezone creation (should fall back to embedded) |
| 129 | let system_utc = res!(CalClockZone::from_system_or_embedded("UTC")); |
| 130 | assert_eq!(system_utc.id(), "UTC"); |
| 131 | |
| 132 | // Test conflict detection (should return empty since we don't have system data) |
| 133 | let conflicts = res!(embedded_utc.detect_conflicts()); |
| 134 | assert!(conflicts.is_empty()); |
| 135 | |
| 136 | Ok(()) |
| 137 | })); |
| 138 | |
| 139 | res!(test_it(filter, &["leap_second_capability", "all", "timezone", "leap_seconds"], || { |
| 140 | // Test leap second capability assessment |
| 141 | assert!(!LeapSecondCapability::handles_leap_seconds()); |
| 142 | assert!(LeapSecondCapability::requires_separate_implementation()); |
| 143 | |
| 144 | let explanation = LeapSecondCapability::leap_second_explanation(); |
| 145 | assert!(explanation.contains("NOT handle leap seconds")); |
| 146 | assert!(explanation.contains("TAI-UTC")); |
| 147 | assert!(explanation.contains("separate")); |
| 148 | |
| 149 | Ok(()) |
| 150 | })); |
| 151 | |
| 152 | res!(test_it(filter, &["calendar_display", "all", "calendar", "display"], || { |
| 153 | let zone = res!(CalClockZone::new("UTC")); |
| 154 | |
| 155 | // Test Gregorian display (should not show calendar type) |
| 156 | let gregorian = res!(CalendarDate::new(2024, 6, 15, zone.clone())); |
| 157 | let gregorian_str = format!("{}", gregorian); |
| 158 | assert_eq!(gregorian_str, "2024-06-15"); |
| 159 | |
| 160 | // Test Julian display (should show calendar type) |
| 161 | let julian = res!(CalendarDate::new_with_system( |
| 162 | 2024, 6, 15, zone.clone(), CalendarSystem::Julian |
| 163 | )); |
| 164 | let julian_str = format!("{}", julian); |
| 165 | assert_eq!(julian_str, "2024-06-15 (Julian)"); |
| 166 | |
| 167 | Ok(()) |
| 168 | })); |
| 169 | |
| 170 | res!(test_it(filter, &["calendar_system_parsing", "all", "calendar", "parsing"], || { |
| 171 | // Test calendar system parsing from string |
| 172 | assert_eq!(res!(CalendarSystem::from_str("gregorian")), CalendarSystem::Gregorian); |
| 173 | assert_eq!(res!(CalendarSystem::from_str("GREGORIAN")), CalendarSystem::Gregorian); |
| 174 | assert_eq!(res!(CalendarSystem::from_str("greg")), CalendarSystem::Gregorian); |
| 175 | assert_eq!(res!(CalendarSystem::from_str("g")), CalendarSystem::Gregorian); |
| 176 | |
| 177 | assert_eq!(res!(CalendarSystem::from_str("julian")), CalendarSystem::Julian); |
| 178 | assert_eq!(res!(CalendarSystem::from_str("JULIAN")), CalendarSystem::Julian); |
| 179 | assert_eq!(res!(CalendarSystem::from_str("jul")), CalendarSystem::Julian); |
| 180 | assert_eq!(res!(CalendarSystem::from_str("j")), CalendarSystem::Julian); |
| 181 | |
| 182 | // Test invalid parsing |
| 183 | assert!(CalendarSystem::from_str("invalid").is_err()); |
| 184 | |
| 185 | Ok(()) |
| 186 | })); |
| 187 | |
| 188 | res!(test_it(filter, &["calendar_integration_with_calclock", "all", "calendar", "calclock"], || { |
| 189 | let zone = res!(CalClockZone::new("UTC")); |
| 190 | |
| 191 | // Test that CalClock still uses Gregorian calendar by default |
| 192 | let calclock = res!(CalClock::new(2024, 6, 15, 14, 30, 0, 0, zone.clone())); |
| 193 | assert!(calclock.date().is_gregorian()); |
| 194 | |
| 195 | // Test CalClock with Julian calendar date |
| 196 | let julian_date = res!(CalendarDate::new_with_system( |
| 197 | 2024, 6, 15, zone.clone(), CalendarSystem::Julian |
| 198 | )); |
| 199 | assert!(julian_date.is_julian()); |
| 200 | |
| 201 | Ok(()) |
| 202 | })); |
| 203 | |
| 204 | Ok(()) |
| 205 | } |