Benjamin Sago 8 лет назад
Родитель
Сommit
f0eed9fde4
4 измененных файлов с 48 добавлено и 20 удалено
  1. 4 3
      src/options/view.rs
  2. 40 17
      src/output/time.rs
  3. 3 0
      xtests/dates_full_iso
  4. 1 0
      xtests/run.sh

+ 4 - 3
src/options/view.rs

@@ -240,13 +240,14 @@ impl TimeFormat {
 
 
     /// Determine how time should be formatted in timestamp columns.
     /// Determine how time should be formatted in timestamp columns.
     fn deduce(matches: &getopts::Matches) -> Result<TimeFormat, Misfire> {
     fn deduce(matches: &getopts::Matches) -> Result<TimeFormat, Misfire> {
-        pub use output::time::{DefaultFormat, LongISO};
-        const STYLES: &[&str] = &["default", "long-iso"];
+        pub use output::time::{DefaultFormat};
+        const STYLES: &[&str] = &["default", "long-iso", "full-iso"];
 
 
         if let Some(word) = matches.opt_str("time-style") {
         if let Some(word) = matches.opt_str("time-style") {
             match &*word {
             match &*word {
                 "default"   => Ok(TimeFormat::DefaultFormat(DefaultFormat::new())),
                 "default"   => Ok(TimeFormat::DefaultFormat(DefaultFormat::new())),
-                "long-iso"  => Ok(TimeFormat::LongISO(LongISO)),
+                "long-iso"  => Ok(TimeFormat::LongISO),
+                "full-iso"  => Ok(TimeFormat::FullISO),
                 otherwise   => Err(Misfire::bad_argument("time-style", otherwise, STYLES))
                 otherwise   => Err(Misfire::bad_argument("time-style", otherwise, STYLES))
             }
             }
         }
         }

+ 40 - 17
src/output/time.rs

@@ -7,21 +7,24 @@ use fs::fields::Time;
 
 
 pub enum TimeFormat {
 pub enum TimeFormat {
     DefaultFormat(DefaultFormat),
     DefaultFormat(DefaultFormat),
-    LongISO(LongISO),
+    LongISO,
+    FullISO,
 }
 }
 
 
 impl TimeFormat {
 impl TimeFormat {
     pub fn format_local(&self, time: Time) -> String {
     pub fn format_local(&self, time: Time) -> String {
         match *self {
         match *self {
             TimeFormat::DefaultFormat(ref fmt) => fmt.format_local(time),
             TimeFormat::DefaultFormat(ref fmt) => fmt.format_local(time),
-            TimeFormat::LongISO(ref iso)       => iso.format_local(time),
+            TimeFormat::LongISO                => long_local(time),
+            TimeFormat::FullISO                => full_local(time),
         }
         }
     }
     }
 
 
     pub fn format_zoned(&self, time: Time, zone: &TimeZone) -> String {
     pub fn format_zoned(&self, time: Time, zone: &TimeZone) -> String {
         match *self {
         match *self {
             TimeFormat::DefaultFormat(ref fmt) => fmt.format_zoned(time, zone),
             TimeFormat::DefaultFormat(ref fmt) => fmt.format_zoned(time, zone),
-            TimeFormat::LongISO(ref iso)       => iso.format_zoned(time, zone),
+            TimeFormat::LongISO                => long_zoned(time, zone),
+            TimeFormat::FullISO                => full_zoned(time, zone),
         }
         }
     }
     }
 }
 }
@@ -101,20 +104,40 @@ impl DefaultFormat {
 }
 }
 
 
 
 
-pub struct LongISO;
+#[allow(trivial_numeric_casts)]
+fn long_local(time: Time) -> String {
+    let date = LocalDateTime::at(time.seconds as i64);
+    format!("{:04}-{:02}-{:02} {:02}:{:02}",
+            date.year(), date.month() as usize, date.day(),
+            date.hour(), date.minute())
+}
 
 
-impl LongISO {
-    #[allow(trivial_numeric_casts)]
-    fn format_local(&self, time: Time) -> String {
-        let date = LocalDateTime::at(time.seconds as i64);
-        format!("{:04}-{:02}-{:02} {:02}:{:02}",
-                date.year(), date.month() as usize, date.day(), date.hour(), date.minute())
-    }
+#[allow(trivial_numeric_casts)]
+fn long_zoned(time: Time, zone: &TimeZone) -> String {
+    let date = zone.to_zoned(LocalDateTime::at(time.seconds as i64));
+    format!("{:04}-{:02}-{:02} {:02}:{:02}",
+            date.year(), date.month() as usize, date.day(),
+            date.hour(), date.minute())
+}
 
 
-    #[allow(trivial_numeric_casts)]
-    fn format_zoned(&self, time: Time, zone: &TimeZone) -> String {
-        let date = zone.to_zoned(LocalDateTime::at(time.seconds as i64));
-        format!("{:04}-{:02}-{:02} {:02}:{:02}",
-                date.year(), date.month() as usize, date.day(), date.hour(), date.minute())
-    }
+
+#[allow(trivial_numeric_casts)]
+fn full_local(time: Time) -> String {
+    let date = LocalDateTime::at(time.seconds as i64);
+    format!("{:04}-{:02}-{:02} {:02}:{:02}:{:02}.{:09}",
+            date.year(), date.month() as usize, date.day(),
+            date.hour(), date.minute(), date.second(), time.nanoseconds)
+}
+
+#[allow(trivial_numeric_casts)]
+fn full_zoned(time: Time, zone: &TimeZone) -> String {
+    use datetime::Offset;
+
+    let local = LocalDateTime::at(time.seconds as i64);
+    let date = zone.to_zoned(local);
+    let offset = Offset::of_seconds(zone.offset(local) as i32).expect("Offset out of range");
+    format!("{:04}-{:02}-{:02} {:02}:{:02}:{:02}.{:09} {:+03}{:02}",
+            date.year(), date.month() as usize, date.day(),
+            date.hour(), date.minute(), date.second(), time.nanoseconds,
+            offset.hours(), offset.minutes().abs())
 }
 }

+ 3 - 0
xtests/dates_full_iso

@@ -0,0 +1,3 @@
+.rw-rw-r-- 0 cassowary 2006-06-15 23:14:29.000000000 +0000 peach
+.rw-rw-r-- 0 cassowary 2003-03-03 00:00:00.000000000 +0000 pear
+.rw-rw-r-- 0 cassowary 2009-07-22 10:38:53.000000000 +0000 plum

+ 1 - 0
xtests/run.sh

@@ -111,6 +111,7 @@ $exa $testcases/file-names-exts/music.* -I "*.OGG|*.mp3" -1 2>&1 | diff -q - $re
 $exa $testcases/dates -lh --accessed --sort=accessed 2>&1 | diff -q - $results/dates_accessed  || exit 1
 $exa $testcases/dates -lh --accessed --sort=accessed 2>&1 | diff -q - $results/dates_accessed  || exit 1
 $exa $testcases/dates -lh            --sort=modified 2>&1 | diff -q - $results/dates_modified  || exit 1
 $exa $testcases/dates -lh            --sort=modified 2>&1 | diff -q - $results/dates_modified  || exit 1
 $exa $testcases/dates -l       --time-style=long-iso 2>&1 | diff -q - $results/dates_long_iso  || exit 1
 $exa $testcases/dates -l       --time-style=long-iso 2>&1 | diff -q - $results/dates_long_iso  || exit 1
+$exa $testcases/dates -l       --time-style=full-iso 2>&1 | diff -q - $results/dates_full_iso  || exit 1
 
 
 
 
 # Paths and directories
 # Paths and directories