[librsvg: 2/3] Remove obsolete workarounds for datetime parsing



commit a3f604972833777d48c27480603a7780ac58bb48
Author: Sven Neumann <sven svenfoo org>
Date:   Mon Feb 17 15:27:29 2020 +0100

    Remove obsolete workarounds for datetime parsing
    
    Datetime parsing has been fixed in the latest lopdf release, so
    these workarounds aren't needed any longer.

 tests/src/cmdline/predicates.rs | 38 ++++----------------------------------
 1 file changed, 4 insertions(+), 34 deletions(-)
---
diff --git a/tests/src/cmdline/predicates.rs b/tests/src/cmdline/predicates.rs
index 3162e74d..065d5a2c 100644
--- a/tests/src/cmdline/predicates.rs
+++ b/tests/src/cmdline/predicates.rs
@@ -5,7 +5,7 @@ extern crate predicates;
 
 pub mod file {
 
-    use chrono::{DateTime, FixedOffset, Utc};
+    use chrono::{DateTime, Utc};
 
     use predicates::boolean::AndPredicate;
     use predicates::prelude::*;
@@ -118,40 +118,10 @@ pub mod file {
                 doc.get_object(id)?.as_dict()?.get(key)
             }
 
-            if let Ok(obj) = get_from_trailer(self, b"CreationDate") {
-                // Now this should actually be as simple as returning obj.as_datetime().
-                // However there are bugs that need to be worked around here:
-                //
-                // First of all cairo inadvertently truncates the timezone offset,
-                // see https://gitlab.freedesktop.org/cairo/cairo/issues/392
-                //
-                // On top of that the lopdf::Object::as_datetime() method has issues
-                // and can not be used, see https://github.com/J-F-Liu/lopdf/issues/88
-                //
-                // So here's our implentation instead.
-
-                fn as_datetime(str: &str) -> Option<DateTime<FixedOffset>> {
-                    if str.ends_with("0000") {
-                        DateTime::parse_from_str(str, "%Y%m%d%H%M%S%z").ok()
-                    } else {
-                        let str = String::from(str) + "00";
-                        as_datetime(&str)
-                    }
-                }
-
-                if let lopdf::Object::String(ref bytes, _) = obj {
-                    if let Ok(str) = String::from_utf8(
-                        bytes
-                            .iter()
-                            .filter(|b| ![b'D', b':', b'\''].contains(b))
-                            .cloned()
-                            .collect(),
-                    ) {
-                        return as_datetime(&str).map(|date| date.with_timezone(&Utc));
-                    }
-                }
+            match get_from_trailer(self, b"CreationDate") {
+                Ok(obj) => obj.as_datetime().map(|date| date.with_timezone(&Utc)),
+                Err(_) => None,
             }
-            None
         }
 
         fn get_num_pages(self: &Self) -> usize {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]