diff --git a/Cargo.toml b/Cargo.toml index 6518831..f6b7fdc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,10 +5,13 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[features] +gui = ["gtk", "adw", "gio"] + [dependencies] -adw = { version = "0.4", package = "libadwaita", features = ["v1_2"] } -gio = "0.18.3" -gtk = { version = "0.6", package = "gtk4" } +adw = { version = "0.4", package = "libadwaita", features = ["v1_2"], optional = true } +gio = { version = "0.18.3", optional = true } +gtk = { version = "0.6", package = "gtk4", optional = true } icu = { version = "1.4.0", features = ["experimental"] } icu_provider = "1.4.0" icu_locid = "1.4.0" diff --git a/src/bin/cli-app.rs b/src/bin/cli-app.rs new file mode 100644 index 0000000..2b73732 --- /dev/null +++ b/src/bin/cli-app.rs @@ -0,0 +1,96 @@ +use chrono::{Datelike, Local, Timelike}; +use icu::{ + calendar::{ + types::{IsoHour, IsoMinute, IsoSecond, NanoSecond, Time}, + Date, DateTime, + }, + datetime::{ + options::length::{self, Bag}, + DateTimeFormatter, + }, +}; +use icu_locid::Locale; +use icu_provider::DataLocale; +use libc::{self, LC_MESSAGES, LC_TIME}; + +fn main() { + let now = chrono::Utc::now(); + let now: icu::calendar::DateTime = icu::calendar::DateTime::new( + Date::try_new_gregorian_date(now.year() as i32, now.month() as u8, now.day() as u8) + .unwrap(), + Time::new( + IsoHour::try_from(now.hour() as u8).unwrap(), + IsoMinute::try_from(now.minute() as u8).unwrap(), + IsoSecond::try_from(now.second() as u8).unwrap(), + NanoSecond::try_from(0 as u32).unwrap(), + ), + ); + + let locales = ["en-US", "eo", "de-DE", "fr-FR", "es-ES", "zh-CN", "ja-JA"]; + let styles: Vec<(String, Locale, Bag)> = locales + .into_iter() + .map(|locale| { + let lc = locale.parse::().unwrap(); + vec![ + ( + format!("{}, full date", locale), + lc.clone(), + length::Bag::from_date_style(length::Date::Full).into(), + ), + ( + format!("{}, long date", locale), + lc.clone(), + length::Bag::from_date_style(length::Date::Long).into(), + ), + ( + format!("{}, medium date", locale), + lc.clone(), + length::Bag::from_date_style(length::Date::Medium).into(), + ), + ( + format!("{}, short date", locale), + lc.clone(), + length::Bag::from_date_style(length::Date::Short).into(), + ), + ( + format!("{}, full time", locale), + lc.clone(), + length::Bag::from_time_style(length::Time::Full).into(), + ), + ( + format!("{}, long time", locale), + lc.clone(), + length::Bag::from_time_style(length::Time::Long).into(), + ), + ( + format!("{}, medium time", locale), + lc.clone(), + length::Bag::from_time_style(length::Time::Medium).into(), + ), + ( + format!("{}, short time", locale), + lc.clone(), + length::Bag::from_time_style(length::Time::Short).into(), + ), + ] + }) + .flatten() + .collect(); + + for (descriptor, locale, bag) in styles { + let formatter = DateTimeFormatter::try_new(&DataLocale::from(locale), bag.into()); + + match formatter { + Ok(formatter) => println!( + "[{:20}] {}", + descriptor, + &formatter.format_to_string(&now.to_any()).unwrap() + ), + Err(formatter_err) => println!( + "[{:20}] {}", + &descriptor, + &format!("unhandled formatter: {:?}", formatter_err), + ), + } + } +} diff --git a/src/bin/gtk.rs b/src/bin/gui-app.rs similarity index 100% rename from src/bin/gtk.rs rename to src/bin/gui-app.rs