aboutsummaryrefslogtreecommitdiff
path: root/karlgui/src/helper.rs
diff options
context:
space:
mode:
authormetamuffin <yvchraiqi@protonmail.com>2022-08-17 08:38:33 +0200
committermetamuffin <yvchraiqi@protonmail.com>2022-08-17 08:38:33 +0200
commit5e6509163df53788799bb7aa97d07a90bf416eb7 (patch)
tree902f37c8ffcd7b94a60a230f51418c7b6fb84bc9 /karlgui/src/helper.rs
parentaca12bc6d0194364d9e36c455fbcd2390e00d8be (diff)
downloadkarlender-5e6509163df53788799bb7aa97d07a90bf416eb7.tar
karlender-5e6509163df53788799bb7aa97d07a90bf416eb7.tar.bz2
karlender-5e6509163df53788799bb7aa97d07a90bf416eb7.tar.zst
refactor
Diffstat (limited to 'karlgui/src/helper.rs')
-rw-r--r--karlgui/src/helper.rs63
1 files changed, 32 insertions, 31 deletions
diff --git a/karlgui/src/helper.rs b/karlgui/src/helper.rs
index 1ae29c8..eb4c981 100644
--- a/karlgui/src/helper.rs
+++ b/karlgui/src/helper.rs
@@ -4,40 +4,11 @@ use karlcommon::Property;
pub fn format_value(prop: Property, value: i64) -> String {
match prop {
Property::Year => format!("{value}"),
- Property::Monthofyear => format!(
- "{}",
- match value {
- 0 => "January",
- 1 => "February",
- 2 => "March",
- 3 => "April",
- 4 => "May",
- 5 => "June",
- 6 => "July",
- 7 => "August",
- 8 => "September",
- 9 => "October",
- 10 => "November",
- 11 => "December",
- _ => "(invalid)",
- }
- ),
+ Property::Monthofyear => format!("{}", month_to_str(value)),
Property::Weekofmonth => format!("{value}"),
Property::Dayofyear => format!("{value}"),
Property::Dayofmonth => format!("{value}"),
- Property::Dayofweek => format!(
- "{}",
- match value {
- 0 => "Monday",
- 1 => "Thuesday",
- 2 => "Wednesday",
- 3 => "Thursday",
- 4 => "Friday",
- 5 => "Saturday",
- 6 => "Sunday",
- _ => "(invalid)",
- }
- ),
+ Property::Dayofweek => format!("{}", weekday_to_str(value)),
Property::Hour => format!("{value}h"),
Property::Minute => format!("{value}min"),
Property::Second => format!("{value}s"),
@@ -91,3 +62,33 @@ pub fn edit_value(ui: &mut Ui, prop: Property, value: &mut i64) {
}
}
}
+
+pub fn weekday_to_str(value: i64) -> &'static str {
+ match value {
+ 0 => "Monday",
+ 1 => "Thuesday",
+ 2 => "Wednesday",
+ 3 => "Thursday",
+ 4 => "Friday",
+ 5 => "Saturday",
+ 6 => "Sunday",
+ _ => "(invalid)",
+ }
+}
+pub fn month_to_str(value: i64) -> &'static str {
+ match value {
+ 0 => "January",
+ 1 => "February",
+ 2 => "March",
+ 3 => "April",
+ 4 => "May",
+ 5 => "June",
+ 6 => "July",
+ 7 => "August",
+ 8 => "September",
+ 9 => "October",
+ 10 => "November",
+ 11 => "December",
+ _ => "(invalid)",
+ }
+}