Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions src/languages/english.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,85 @@ impl Language for English {
}
}
}

#[derive(Default)]
pub struct EnglishAbbreviated;

impl Language for EnglishAbbreviated {
fn too_low(&self) -> &'static str {
"now"
}

fn too_high(&self) -> &'static str {
"old"
}

fn ago(&self) -> &'static str {
""
}

fn get_word(&self, tu: TimeUnit, _: u64) -> &'static str {
use TimeUnit::*;
match tu {
Nanoseconds => "ns",
Microseconds => "μs",
Milliseconds => "ms",
Seconds => "s",
Minutes => "m",
Hours => "h",
Days => "d",
Weeks => "wk",
Months => "mo",
Years => "yr",
}
}

fn clone_boxed(&self) -> crate::BoxedLanguage {
todo!()
}

fn place_ago_before(&self) -> bool {
false
}

fn override_space_near_ago(&self) -> &str {
""
}

fn place_unit_before(&self, _: u64) -> bool {
false
}

fn between_chunks(&self) -> &str {
" "
}

fn between_value_and_word(&self) -> &str {
""
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_abbreviated() {
fn fmt(seconds: u64) -> String {
crate::Formatter::with_language(EnglishAbbreviated)
.convert(std::time::Duration::from_secs(seconds))
}

assert_eq!(fmt(0), "now");
assert_eq!(fmt(1), "1s");
assert_eq!(fmt(59), "59s");
assert_eq!(fmt(60), "1m");
assert_eq!(fmt(65), "1m");
assert_eq!(fmt(119), "1m");
assert_eq!(fmt(120), "2m");
assert_eq!(fmt(3599), "59m");
assert_eq!(fmt(3600), "1h");
assert_eq!(fmt(1000_000), "1wk");
assert_eq!(fmt(1000_000_000), "31yr");
}
}