Compare commits
No commits in common. "main" and "v0.0.1" have entirely different histories.
18
Cargo.lock
generated
18
Cargo.lock
generated
@ -84,9 +84,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.98"
|
||||
version = "1.0.97"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e16d2d3311acee920a9eb8d33b8cbc1787ce4a264e85f964c2404b969bdcd487"
|
||||
checksum = "dcfed56ad506cb2c684a14971b8861fdc3baaaae314b9e5f9bb532cbe3ba7a4f"
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
@ -171,9 +171,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "4.5.36"
|
||||
version = "4.5.32"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2df961d8c8a0d08aa9945718ccf584145eee3f3aa06cddbeac12933781102e04"
|
||||
checksum = "6088f3ae8c3608d19260cd7445411865a485688711b78b5be70d78cd96136f83"
|
||||
dependencies = [
|
||||
"clap_builder",
|
||||
"clap_derive",
|
||||
@ -181,9 +181,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "clap_builder"
|
||||
version = "4.5.36"
|
||||
version = "4.5.32"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "132dbda40fb6753878316a489d5a1242a8ef2f0d9e47ba01c951ea8aa7d013a5"
|
||||
checksum = "22a7ef7f676155edfb82daa97f99441f3ebf4a58d5e32f295a56259f1b6facc8"
|
||||
dependencies = [
|
||||
"anstream",
|
||||
"anstyle",
|
||||
@ -211,7 +211,7 @@ checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6"
|
||||
|
||||
[[package]]
|
||||
name = "clock"
|
||||
version = "0.0.1"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"chrono",
|
||||
@ -784,9 +784,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "tokio"
|
||||
version = "1.44.2"
|
||||
version = "1.44.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e6b88822cbe49de4185e3a4cbf8321dd487cf5fe0c5c65695fef6346371e9c48"
|
||||
checksum = "f382da615b842244d4b8738c82ed1275e6c5dd90c459a30941cd07080b06c91a"
|
||||
dependencies = [
|
||||
"backtrace",
|
||||
"bytes",
|
||||
|
@ -61,31 +61,28 @@ async fn main() -> anyhow::Result<()> {
|
||||
|
||||
match cli.command.expect("to have a command available") {
|
||||
Commands::List { limit, project } => {
|
||||
let mut timetable = timetable.clone();
|
||||
let days = &timetable
|
||||
.days
|
||||
.iter_mut()
|
||||
.map(|d| {
|
||||
.iter()
|
||||
.filter(|d| {
|
||||
if let Some(project) = &project {
|
||||
d.entry = d
|
||||
.entry
|
||||
.iter()
|
||||
.filter(|d| d.project.as_ref() == Some(project))
|
||||
.cloned()
|
||||
.collect::<Vec<_>>();
|
||||
d
|
||||
Some(project) == d.project.as_ref()
|
||||
} else {
|
||||
d
|
||||
true
|
||||
}
|
||||
})
|
||||
.filter(|d| !d.entry.is_empty())
|
||||
.collect::<Vec<_>>();
|
||||
let days = days.iter().rev().take(limit).collect::<Vec<_>>();
|
||||
|
||||
for day in days {
|
||||
println!(
|
||||
"{}{}\n{}\n",
|
||||
day.date.format("%Y-%m-%d"),
|
||||
"{}{}{}\n {}{}\n",
|
||||
day.clock_in.with_timezone(&Local {}).format("%Y-%m-%d"),
|
||||
if let Some(project) = &day.project {
|
||||
format!(" project: {}", project)
|
||||
} else {
|
||||
"".into()
|
||||
},
|
||||
if day.breaks.is_empty() {
|
||||
"".into()
|
||||
} else {
|
||||
@ -94,64 +91,28 @@ async fn main() -> anyhow::Result<()> {
|
||||
day.breaks.iter().fold(0, |acc, _| acc + 30)
|
||||
)
|
||||
},
|
||||
day.entry
|
||||
.iter()
|
||||
.map(|e| {
|
||||
format!(
|
||||
" - {} - {}{}",
|
||||
e.clock_in.with_timezone(&Local {}).format("%H:%M"),
|
||||
if let Some(clockout) = &e.clock_out {
|
||||
clockout
|
||||
.with_timezone(&Local {})
|
||||
.format("%H:%M")
|
||||
.to_string()
|
||||
} else if day.date == now.date_naive() {
|
||||
let working_hours = e.clock_in - now;
|
||||
format!(
|
||||
"unclosed, current hours: {}h{}m",
|
||||
working_hours.num_hours().abs(),
|
||||
working_hours.num_minutes().abs() % 60
|
||||
)
|
||||
} else {
|
||||
"unclosed".into()
|
||||
},
|
||||
if let Some(project) = &e.project {
|
||||
format!(": project: {}", project)
|
||||
} else {
|
||||
"".into()
|
||||
}
|
||||
)
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n"),
|
||||
day.clock_in.with_timezone(&Local {}).format("%H:%M"),
|
||||
if let Some(clockout) = &day.clock_out {
|
||||
format!(" - {}", clockout.with_timezone(&Local {}).format("%H:%M"))
|
||||
} else {
|
||||
" - unclosed".into()
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
Commands::In { project } => {
|
||||
match timetable.get_day(now) {
|
||||
Some(d) => {
|
||||
d.entry.push(ClockIn {
|
||||
clock_in: now,
|
||||
clock_out: None,
|
||||
project,
|
||||
});
|
||||
}
|
||||
None => timetable.days.push(Day {
|
||||
entry: vec![ClockIn {
|
||||
clock_in: now,
|
||||
clock_out: None,
|
||||
project,
|
||||
}],
|
||||
breaks: Vec::default(),
|
||||
date: now.date_naive(),
|
||||
}),
|
||||
};
|
||||
timetable.days.push(Day {
|
||||
clock_in: now,
|
||||
clock_out: None,
|
||||
breaks: Vec::default(),
|
||||
project,
|
||||
});
|
||||
}
|
||||
Commands::Out { project } => match timetable.get_day_entry(project, now) {
|
||||
Commands::Out { project } => match timetable.get_day(project, now) {
|
||||
Some(day) => day.clock_out = Some(now),
|
||||
None => todo!(),
|
||||
},
|
||||
Commands::Break { project } => match timetable.get_day(now) {
|
||||
Commands::Break { project } => match timetable.get_day(project, now) {
|
||||
Some(day) => day.breaks.push(Break {}),
|
||||
None => todo!(),
|
||||
},
|
||||
@ -159,7 +120,6 @@ async fn main() -> anyhow::Result<()> {
|
||||
let to_resolve = timetable
|
||||
.days
|
||||
.iter_mut()
|
||||
.flat_map(|d| &mut d.entry)
|
||||
.filter(|d| d.clock_out.is_none())
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
@ -244,18 +204,15 @@ fn parse_string_to_time(v: &str) -> anyhow::Result<chrono::NaiveTime> {
|
||||
})
|
||||
.context("failed to parse int to hour")
|
||||
}
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
struct ClockIn {
|
||||
clock_in: chrono::DateTime<chrono::Utc>,
|
||||
clock_out: Option<chrono::DateTime<chrono::Utc>>,
|
||||
project: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
struct Day {
|
||||
date: chrono::NaiveDate,
|
||||
entry: Vec<ClockIn>,
|
||||
clock_in: chrono::DateTime<chrono::Utc>,
|
||||
clock_out: Option<chrono::DateTime<chrono::Utc>>,
|
||||
|
||||
breaks: Vec<Break>,
|
||||
|
||||
project: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
|
||||
@ -267,21 +224,12 @@ struct TimeTable {
|
||||
}
|
||||
|
||||
impl TimeTable {
|
||||
pub fn get_day(&mut self, now: chrono::DateTime<chrono::Utc>) -> Option<&mut Day> {
|
||||
let item = self
|
||||
.days
|
||||
.iter_mut()
|
||||
.find(|d| d.date.format("%Y-%m-%d").to_string() == now.format("%Y-%m-%d").to_string());
|
||||
|
||||
item
|
||||
}
|
||||
|
||||
pub fn get_day_entry(
|
||||
pub fn get_day(
|
||||
&mut self,
|
||||
project: Option<String>,
|
||||
now: chrono::DateTime<chrono::Utc>,
|
||||
) -> Option<&mut ClockIn> {
|
||||
let item = self.days.iter_mut().flat_map(|d| &mut d.entry).find(|d| {
|
||||
) -> Option<&mut Day> {
|
||||
let item = self.days.iter_mut().find(|d| {
|
||||
if d.project != project {
|
||||
return false;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user