Oregami
Repositories/oxedyne/fe2o3

oxedyne/fe2o3/fe2o3_datime/src/tests/formatting_test.rs

3.1 KiB, 4 runs

created by r1870400018:8500, 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//! Formatting tests for calendar dates and clock times.
2//!
3//! [Written with AI entirely](https://need2know.ai/entirely-ai/code)\
4//! Anthropic Claude
5
6use crate::{
7 calendar::CalendarDate,
8 clock::ClockTime,
9 time::CalClockZone,
10 core::Time,
11};
12
13#[test]
14fn test_date_formatting_comprehensive() {
15 let zone = CalClockZone::utc();
16 let date = CalendarDate::new(2024, 6, 15, zone).unwrap(); // Saturday
17
18 // Year formatting
19 assert_eq!(date.format("y"), "4");
20 assert_eq!(date.format("yy"), "24");
21 assert_eq!(date.format("yyyy"), "2024");
22
23 // Month formatting
24 assert_eq!(date.format("M"), "6");
25 assert_eq!(date.format("MM"), "06");
26 assert_eq!(date.format("MMM"), "Jun");
27 assert_eq!(date.format("MMMM"), "June");
28
29 // Day formatting
30 assert_eq!(date.format("d"), "15");
31 assert_eq!(date.format("dd"), "15");
32 assert_eq!(date.format("ddd"), "Sat");
33 assert_eq!(date.format("dddd"), "Saturday");
34
35 // Combined formats
36 assert_eq!(date.format("yyyy-MM-dd"), "2024-06-15");
37 assert_eq!(date.format("dd/MM/yyyy"), "15/06/2024");
38 assert_eq!(date.format("MMM d, yyyy"), "Jun 15, 2024");
39 assert_eq!(date.format("dddd, MMMM d, yyyy"), "Saturday, June 15, 2024");
40}
41
42#[test]
43fn test_time_formatting_comprehensive() {
44 let zone = CalClockZone::utc();
45 let time = ClockTime::new(14, 30, 45, 123_456_789, zone.clone()).unwrap();
46
47 // 24-hour formatting
48 assert_eq!(time.format("H"), "14");
49 assert_eq!(time.format("HH"), "14");
50 assert_eq!(time.format("HH:mm"), "14:30");
51 assert_eq!(time.format("HH:mm:ss"), "14:30:45");
52
53 // 12-hour formatting
54 assert_eq!(time.format("h"), "2");
55 assert_eq!(time.format("hh"), "02");
56 assert_eq!(time.format("h:mm tt"), "2:30 PM");
57 assert_eq!(time.format("hh:mm:ss tt"), "02:30:45 PM");
58
59 // Fractional seconds
60 assert_eq!(time.format("HH:mm:ss.f"), "14:30:45.1");
61 assert_eq!(time.format("HH:mm:ss.fff"), "14:30:45.123");
62 assert_eq!(time.format("HH:mm:ss.ffffff"), "14:30:45.123456");
63
64 // Test zero suppression with F
65 let time_no_frac = ClockTime::new(14, 30, 45, 0, zone.clone()).unwrap();
66 assert_eq!(time_no_frac.format("HH:mm:ss.FFF"), "14:30:45.0");
67
68 // AM/PM tests
69 let morning = ClockTime::new(9, 15, 30, 0, zone.clone()).unwrap();
70 assert_eq!(morning.format("h:mm tt"), "9:15 AM");
71 assert_eq!(morning.format("h:mm t"), "9:15 A");
72
73 let midnight = ClockTime::new(0, 0, 0, 0, zone.clone()).unwrap();
74 assert_eq!(midnight.format("h:mm tt"), "12:00 AM");
75}
76
77#[test]
78fn test_today_returns_current_date() {
79 let zone = CalClockZone::utc();
80 let today = CalendarDate::today(zone).unwrap();
81
82 // Just verify it's not the dummy date (2024-01-01)
83 let dummy_date = CalendarDate::new(2024, 1, 1, CalClockZone::utc()).unwrap();
84
85 // The chance of today being exactly 2024-01-01 is extremely low
86 // (this test will fail only on Jan 1, 2024 - acceptable for verification)
87 assert_ne!(today, dummy_date, "today() should return actual current date, not dummy date");
88
89 println!("Today is: {}", today.format("dddd, MMMM d, yyyy"));
90}