use tina::{ chrono::Timelike, tina::data::{ date_time::{DateTimeExt, LocalDate, LocalDateTime}, json::{FromJson, ToJson}, }, }; #[test] fn serde() { let now = LocalDateTime(LocalDateTime::now().with_nanosecond(0).expect("init date time failed")); let today = now.to_date(); // println!("now: {now:?}"); // println!("today: {today:?}"); // println!("============================"); let now_str = now.to_json_string(); let today_str = today.to_json_string(); // println!("now_str: {now_str}"); // println!("today_str: {today_str}"); // println!("============================"); let now2 = LocalDateTime::from_json_string(now_str.as_str()).unwrap_or_else(|err| panic!("{:?}", err)); let today2 = LocalDate::from_json_string(today_str.as_str()).unwrap_or_else(|err| panic!("{:?}", err)); // println!("now2: {now2:?}"); // println!("today2: {today2:?}"); // println!("============================"); assert_eq!(now2.0, now.0); assert_eq!(today2.0, today.0); let now_bson = tina::bson::to_bson(&now).unwrap_or_else(|err| panic!("{err:?}")); let today_bson = tina::bson::to_bson(&today).unwrap_or_else(|err| panic!("{err:?}")); // println!("now_bson: {now_bson:?}"); // println!("today_bson: {today_bson:?}"); // println!("============================"); assert!(now_bson.as_datetime().is_some()); assert!(today_bson.as_datetime().is_some()); let now3 = tina::bson::from_bson::(now_bson).unwrap_or_else(|err| panic!("{err:?}")); let today3 = tina::bson::from_bson::(today_bson).unwrap_or_else(|err| panic!("{err:?}")); // println!("now3: {now3:?}"); // println!("today3: {today3:?}"); // println!("============================"); assert_eq!(now3.0, now.0); assert_eq!(today3.0, today.0); let now_rbs = tina::rbs::to_value(now).unwrap_or_else(|err| panic!("{err:?}")); let today_rbs = tina::rbs::to_value(today).unwrap_or_else(|err| panic!("{err:?}")); // println!("now_rbs: {now_rbs:?}"); // println!("today_rbs: {today_rbs:?}"); // println!("============================"); assert!(now_rbs.is_i64()); assert!(today_rbs.is_i64()); let now4 = tina::rbs::from_value::(now_rbs).unwrap_or_else(|err| panic!("{err:?}")); let today4 = tina::rbs::from_value::(today_rbs).unwrap_or_else(|err| panic!("{err:?}")); // println!("now4: {now4:?}"); // println!("today4: {today4:?}"); // println!("============================"); assert_eq!(now4.0, now.0); assert_eq!(today4.0, today.0); }