summaryrefslogtreecommitdiffstats
path: root/lib/etc
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2018-01-31 22:04:54 +0100
committerMatthias Beyer <mail@beyermatthias.de>2018-02-01 09:26:33 +0100
commit4d94791b1f74e20380f77de70d1c7d1209c070c7 (patch)
tree7ecc3618dfe361b3535319073fc80dbc7982e445 /lib/etc
parent20f9c99c8304f2a09d03897f77a973445cbaea18 (diff)
Move date <-> string conversion utility to libimagutil
Diffstat (limited to 'lib/etc')
-rw-r--r--lib/etc/libimagutil/Cargo.toml1
-rw-r--r--lib/etc/libimagutil/src/date.rs32
-rw-r--r--lib/etc/libimagutil/src/lib.rs2
3 files changed, 35 insertions, 0 deletions
diff --git a/lib/etc/libimagutil/Cargo.toml b/lib/etc/libimagutil/Cargo.toml
index a0d1a70d..dfd87d1a 100644
--- a/lib/etc/libimagutil/Cargo.toml
+++ b/lib/etc/libimagutil/Cargo.toml
@@ -32,4 +32,5 @@ lazy_static = "0.2"
log = "0.4.0"
regex = "0.2"
tempfile = "2.1"
+chrono = "0.4"
diff --git a/lib/etc/libimagutil/src/date.rs b/lib/etc/libimagutil/src/date.rs
new file mode 100644
index 00000000..dc9f9de0
--- /dev/null
+++ b/lib/etc/libimagutil/src/date.rs
@@ -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 chrono::format::ParseError;
+
+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: String) -> Result<NaiveDate, ParseError> {
+ NaiveDate::parse_from_str(&s, NAIVE_DATE_STRING_FORMAT)
+}
+
diff --git a/lib/etc/libimagutil/src/lib.rs b/lib/etc/libimagutil/src/lib.rs
index cdf1a015..e2ee8397 100644
--- a/lib/etc/libimagutil/src/lib.rs
+++ b/lib/etc/libimagutil/src/lib.rs
@@ -39,9 +39,11 @@ extern crate regex;
extern crate url;
extern crate boolinator;
extern crate tempfile;
+extern crate chrono;
#[macro_use] mod log_result;
pub mod cli_validators;
+pub mod date;
pub mod debug_result;
pub mod edit;
pub mod info_result;