Compare commits
13 Commits
Author | SHA1 | Date | |
---|---|---|---|
c596f4afda | |||
4db436cdbc | |||
1485b653af | |||
f04c613bc4 | |||
e1f6477fac | |||
2ba53ca505 | |||
f739ba4a36 | |||
2afa9448b3 | |||
bc310d4b72 | |||
c63b325a76 | |||
2ad6401655 | |||
01e620cde4 | |||
fb7d4a028e |
51
Cargo.lock
generated
51
Cargo.lock
generated
@ -84,9 +84,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.97"
|
||||
version = "1.0.98"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dcfed56ad506cb2c684a14971b8861fdc3baaaae314b9e5f9bb532cbe3ba7a4f"
|
||||
checksum = "e16d2d3311acee920a9eb8d33b8cbc1787ce4a264e85f964c2404b969bdcd487"
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
@ -156,9 +156,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "chrono"
|
||||
version = "0.4.40"
|
||||
version = "0.4.41"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1a7964611d71df112cb1730f2ee67324fcf4d0fc6606acbbe9bfe06df124637c"
|
||||
checksum = "c469d952047f47f91b68d1cba3f10d63c11d73e4636f24f08daf0278abf01c4d"
|
||||
dependencies = [
|
||||
"android-tzdata",
|
||||
"iana-time-zone",
|
||||
@ -171,9 +171,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "4.5.32"
|
||||
version = "4.5.41"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6088f3ae8c3608d19260cd7445411865a485688711b78b5be70d78cd96136f83"
|
||||
checksum = "be92d32e80243a54711e5d7ce823c35c41c9d929dc4ab58e1276f625841aadf9"
|
||||
dependencies = [
|
||||
"clap_builder",
|
||||
"clap_derive",
|
||||
@ -181,9 +181,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "clap_builder"
|
||||
version = "4.5.32"
|
||||
version = "4.5.41"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "22a7ef7f676155edfb82daa97f99441f3ebf4a58d5e32f295a56259f1b6facc8"
|
||||
checksum = "707eab41e9622f9139419d573eca0900137718000c517d47da73045f54331c3d"
|
||||
dependencies = [
|
||||
"anstream",
|
||||
"anstyle",
|
||||
@ -193,9 +193,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "clap_derive"
|
||||
version = "4.5.32"
|
||||
version = "4.5.41"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "09176aae279615badda0765c0c0b3f6ed53f4709118af73cf4655d85d1530cd7"
|
||||
checksum = "ef4f52386a59ca4c860f7393bcf8abd8dfd91ecccc0f774635ff68e92eeef491"
|
||||
dependencies = [
|
||||
"heck",
|
||||
"proc-macro2",
|
||||
@ -211,7 +211,7 @@ checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6"
|
||||
|
||||
[[package]]
|
||||
name = "clock"
|
||||
version = "0.1.0"
|
||||
version = "0.0.1"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"chrono",
|
||||
@ -392,6 +392,17 @@ dependencies = [
|
||||
"unicode-width",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "io-uring"
|
||||
version = "0.7.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b86e202f00093dcba4275d4636b93ef9dd75d025ae560d2521b45ea28ab49013"
|
||||
dependencies = [
|
||||
"bitflags 2.9.0",
|
||||
"cfg-if",
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "is_terminal_polyfill"
|
||||
version = "1.70.1"
|
||||
@ -719,6 +730,12 @@ dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "slab"
|
||||
version = "0.4.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "04dc19736151f35336d325007ac991178d504a119863a2fcb3758cdb5e52c50d"
|
||||
|
||||
[[package]]
|
||||
name = "smallvec"
|
||||
version = "1.14.0"
|
||||
@ -784,17 +801,19 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "tokio"
|
||||
version = "1.44.1"
|
||||
version = "1.46.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f382da615b842244d4b8738c82ed1275e6c5dd90c459a30941cd07080b06c91a"
|
||||
checksum = "0cc3a2344dafbe23a245241fe8b09735b521110d30fcefbbd5feb1797ca35d17"
|
||||
dependencies = [
|
||||
"backtrace",
|
||||
"bytes",
|
||||
"io-uring",
|
||||
"libc",
|
||||
"mio 1.0.3",
|
||||
"parking_lot",
|
||||
"pin-project-lite",
|
||||
"signal-hook-registry",
|
||||
"slab",
|
||||
"socket2",
|
||||
"tokio-macros",
|
||||
"windows-sys 0.52.0",
|
||||
@ -895,11 +914,13 @@ checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
|
||||
|
||||
[[package]]
|
||||
name = "uuid"
|
||||
version = "1.16.0"
|
||||
version = "1.17.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "458f7a779bf54acc9f347480ac654f68407d3aab21269a6e3c9f922acd9e2da9"
|
||||
checksum = "3cf4199d1e5d15ddd86a694e4d0dffa9c323ce759fea589f00fef9d81cc1931d"
|
||||
dependencies = [
|
||||
"getrandom 0.3.2",
|
||||
"js-sys",
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -61,28 +61,31 @@ 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()
|
||||
.filter(|d| {
|
||||
.iter_mut()
|
||||
.map(|d| {
|
||||
if let Some(project) = &project {
|
||||
Some(project) == d.project.as_ref()
|
||||
d.entry = d
|
||||
.entry
|
||||
.iter()
|
||||
.filter(|d| d.project.as_ref() == Some(project))
|
||||
.cloned()
|
||||
.collect::<Vec<_>>();
|
||||
d
|
||||
} else {
|
||||
true
|
||||
d
|
||||
}
|
||||
})
|
||||
.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.clock_in.with_timezone(&Local {}).format("%Y-%m-%d"),
|
||||
if let Some(project) = &day.project {
|
||||
format!(" project: {}", project)
|
||||
} else {
|
||||
"".into()
|
||||
},
|
||||
"{}{}\n{}\n",
|
||||
day.date.format("%Y-%m-%d"),
|
||||
if day.breaks.is_empty() {
|
||||
"".into()
|
||||
} else {
|
||||
@ -91,28 +94,64 @@ async fn main() -> anyhow::Result<()> {
|
||||
day.breaks.iter().fold(0, |acc, _| acc + 30)
|
||||
)
|
||||
},
|
||||
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()
|
||||
},
|
||||
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"),
|
||||
)
|
||||
}
|
||||
}
|
||||
Commands::In { project } => {
|
||||
timetable.days.push(Day {
|
||||
clock_in: now,
|
||||
clock_out: None,
|
||||
breaks: Vec::default(),
|
||||
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(),
|
||||
}),
|
||||
};
|
||||
}
|
||||
Commands::Out { project } => match timetable.get_day(project, now) {
|
||||
Commands::Out { project } => match timetable.get_day_entry(project, now) {
|
||||
Some(day) => day.clock_out = Some(now),
|
||||
None => todo!(),
|
||||
},
|
||||
Commands::Break { project } => match timetable.get_day(project, now) {
|
||||
Commands::Break { project } => match timetable.get_day(now) {
|
||||
Some(day) => day.breaks.push(Break {}),
|
||||
None => todo!(),
|
||||
},
|
||||
@ -120,6 +159,7 @@ 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<_>>();
|
||||
|
||||
@ -204,15 +244,18 @@ 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 {
|
||||
clock_in: chrono::DateTime<chrono::Utc>,
|
||||
clock_out: Option<chrono::DateTime<chrono::Utc>>,
|
||||
|
||||
date: chrono::NaiveDate,
|
||||
entry: Vec<ClockIn>,
|
||||
breaks: Vec<Break>,
|
||||
|
||||
project: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
|
||||
@ -224,12 +267,21 @@ struct TimeTable {
|
||||
}
|
||||
|
||||
impl TimeTable {
|
||||
pub fn get_day(
|
||||
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(
|
||||
&mut self,
|
||||
project: Option<String>,
|
||||
now: chrono::DateTime<chrono::Utc>,
|
||||
) -> Option<&mut Day> {
|
||||
let item = self.days.iter_mut().find(|d| {
|
||||
) -> Option<&mut ClockIn> {
|
||||
let item = self.days.iter_mut().flat_map(|d| &mut d.entry).find(|d| {
|
||||
if d.project != project {
|
||||
return false;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user