-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clean up the Task and TaskData APIs (#24)
Not much changes here, but cleanup includes - adding `__repr__` - always passing timestamps as `datetime` / `DateTime<Utc>` - Annotations are immutable - tests for everything
- Loading branch information
Showing
9 changed files
with
576 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,48 @@ | ||
use chrono::DateTime; | ||
use chrono::{DateTime, Utc}; | ||
use pyo3::prelude::*; | ||
use taskchampion::Annotation as TCAnnotation; | ||
#[pyclass] | ||
|
||
#[pyclass(frozen, eq)] | ||
#[derive(PartialEq, Eq)] | ||
/// An annotation for the task | ||
pub struct Annotation(pub(crate) TCAnnotation); | ||
pub struct Annotation(TCAnnotation); | ||
|
||
#[pymethods] | ||
impl Annotation { | ||
#[new] | ||
pub fn new() -> Self { | ||
Annotation(TCAnnotation { | ||
entry: DateTime::default(), | ||
description: String::new(), | ||
}) | ||
pub fn new(entry: DateTime<Utc>, description: String) -> Self { | ||
Annotation(TCAnnotation { entry, description }) | ||
} | ||
#[getter] | ||
pub fn entry(&self) -> String { | ||
self.0.entry.to_rfc3339() | ||
|
||
pub fn __repr__(&self) -> String { | ||
format!("{:?}", self.as_ref()) | ||
} | ||
|
||
#[setter] | ||
pub fn set_entry(&mut self, time: String) { | ||
self.0.entry = DateTime::parse_from_rfc3339(&time).unwrap().into() | ||
#[getter] | ||
pub fn entry(&self) -> DateTime<Utc> { | ||
self.0.entry | ||
} | ||
|
||
#[getter] | ||
pub fn description(&self) -> String { | ||
self.0.description.clone() | ||
} | ||
} | ||
|
||
impl AsRef<TCAnnotation> for Annotation { | ||
fn as_ref(&self) -> &TCAnnotation { | ||
&self.0 | ||
} | ||
} | ||
|
||
impl From<TCAnnotation> for Annotation { | ||
fn from(value: TCAnnotation) -> Self { | ||
Annotation(value) | ||
} | ||
} | ||
|
||
#[setter] | ||
pub fn set_description(&mut self, description: String) { | ||
self.0.description = description | ||
impl From<Annotation> for TCAnnotation { | ||
fn from(value: Annotation) -> Self { | ||
value.0 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.