Move date-string conversion utils to util module
This commit is contained in:
parent
a71c9281ec
commit
533d97532b
3 changed files with 37 additions and 13 deletions
|
@ -28,6 +28,8 @@ use error::HabitError as HE;
|
||||||
use error::HabitErrorKind as HEK;
|
use error::HabitErrorKind as HEK;
|
||||||
use error::*;
|
use error::*;
|
||||||
use iter::HabitInstanceStoreIdIterator;
|
use iter::HabitInstanceStoreIdIterator;
|
||||||
|
use util::date_to_string;
|
||||||
|
use util::date_from_string;
|
||||||
|
|
||||||
use libimagstore::store::Store;
|
use libimagstore::store::Store;
|
||||||
use libimagstore::store::FileLockEntry;
|
use libimagstore::store::FileLockEntry;
|
||||||
|
@ -35,8 +37,6 @@ use libimagstore::store::Entry;
|
||||||
use libimagstore::iter::get::StoreIdGetIteratorExtension;
|
use libimagstore::iter::get::StoreIdGetIteratorExtension;
|
||||||
use libimagstore::storeid::IntoStoreId;
|
use libimagstore::storeid::IntoStoreId;
|
||||||
|
|
||||||
pub const NAIVE_DATE_STRING_FORMAT : &'static str = "%Y-%m-%d";
|
|
||||||
|
|
||||||
/// A HabitTemplate is a "template" of a habit. A user may define a habit "Eat vegetable".
|
/// A HabitTemplate is a "template" of a habit. A user may define a habit "Eat vegetable".
|
||||||
/// If the user ate a vegetable, she should create a HabitInstance from the Habit with the
|
/// If the user ate a vegetable, she should create a HabitInstance from the Habit with the
|
||||||
/// appropriate date (and optionally a comment) set.
|
/// appropriate date (and optionally a comment) set.
|
||||||
|
@ -133,9 +133,8 @@ pub mod builder {
|
||||||
use error::HabitError as HE;
|
use error::HabitError as HE;
|
||||||
use error::HabitErrorKind as HEK;
|
use error::HabitErrorKind as HEK;
|
||||||
use error::*;
|
use error::*;
|
||||||
|
use util::date_to_string;
|
||||||
use super::date_to_string;
|
use util::date_from_string;
|
||||||
use super::date_from_string;
|
|
||||||
|
|
||||||
pub struct HabitBuilder {
|
pub struct HabitBuilder {
|
||||||
name: Option<String>,
|
name: Option<String>,
|
||||||
|
@ -200,11 +199,3 @@ pub mod builder {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn date_to_string(ndt: &NaiveDate) -> String {
|
|
||||||
ndt.format(NAIVE_DATE_STRING_FORMAT).to_string()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn date_from_string(s: &str) -> Result<NaiveDate> {
|
|
||||||
NaiveDate::parse_from_str(s, NAIVE_DATE_STRING_FORMAT).map_err(From::from)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
@ -36,4 +36,5 @@ pub mod instance;
|
||||||
pub mod iter;
|
pub mod iter;
|
||||||
pub mod result;
|
pub mod result;
|
||||||
pub mod store;
|
pub mod store;
|
||||||
|
mod util;
|
||||||
|
|
||||||
|
|
32
lib/domain/libimaghabit/src/util.rs
Normal file
32
lib/domain/libimaghabit/src/util.rs
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
//
|
||||||
|
// imag - the personal information management suite for the commandline
|
||||||
|
// Copyright (C) 2015, 2016 Matthias Beyer <mail@beyermatthias.de> and contributors
|
||||||
|
//
|
||||||
|
// This library is free software; you can redistribute it and/or
|
||||||
|
// modify it under the terms of the GNU Lesser General Public
|
||||||
|
// License as published by the Free Software Foundation; version
|
||||||
|
// 2.1 of the License.
|
||||||
|
//
|
||||||
|
// This library is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
// Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public
|
||||||
|
// License along with this library; if not, write to the Free Software
|
||||||
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
//
|
||||||
|
|
||||||
|
use chrono::NaiveDate;
|
||||||
|
use error::Result;
|
||||||
|
|
||||||
|
pub const NAIVE_DATE_STRING_FORMAT : &'static str = "%Y-%m-%d";
|
||||||
|
|
||||||
|
pub fn date_to_string(ndt: &NaiveDate) -> String {
|
||||||
|
ndt.format(NAIVE_DATE_STRING_FORMAT).to_string()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn date_from_string(s: &str) -> Result<NaiveDate> {
|
||||||
|
NaiveDate::parse_from_str(s, NAIVE_DATE_STRING_FORMAT).map_err(From::from)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue