aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--base/src/context.rs6
-rw-r--r--cli/src/lib.rs18
-rw-r--r--formats/energymech/src/lib.rs20
-rw-r--r--formats/weechat/src/lib.rs25
4 files changed, 44 insertions, 25 deletions
diff --git a/base/src/context.rs b/base/src/context.rs
index c49ef23..79f0a6a 100644
--- a/base/src/context.rs
+++ b/base/src/context.rs
@@ -2,7 +2,8 @@ use chrono::naive::date::NaiveDate;
use chrono::offset::fixed::FixedOffset;
pub struct Context {
- pub timezone: FixedOffset,
+ pub timezone_in: FixedOffset,
+ pub timezone_out: FixedOffset,
pub override_date: Option<NaiveDate>,
pub channel: Option<String>,
}
@@ -10,7 +11,8 @@ pub struct Context {
impl Default for Context {
fn default() -> Context {
Context {
- timezone: FixedOffset::west(0),
+ timezone_in: FixedOffset::west(0),
+ timezone_out: FixedOffset::west(0),
override_date: None,
channel: None,
}
diff --git a/cli/src/lib.rs b/cli/src/lib.rs
index f4cc077..79953e4 100644
--- a/cli/src/lib.rs
+++ b/cli/src/lib.rs
@@ -64,11 +64,16 @@ pub fn main(cli: Cli) {
.author("Till Höppner <till@hoeppner.ws>")
.about("A converter and statistics utility for IRC log files")
.arg(Arg::with_name("time")
- .help("Timestamp offset, in seconds")
+ .help("Timestamp offset of input events, in seconds")
.global(true)
.takes_value(true)
- .long("timeoffset")
+ .long("time_in")
.short("t"))
+ .arg(Arg::with_name("time_out")
+ .help("Timestamp offset for output events, in seconds")
+ .global(true)
+ .takes_value(true)
+ .long("time_out"))
.arg(Arg::with_name("date")
.help("Override the date for this log, ISO 8601, YYYY-MM-DD")
.global(true)
@@ -390,9 +395,12 @@ impl<'a> Environment<'a> {
pub fn build_context(args: &ArgMatches) -> Context {
let mut context = Context {
- timezone: FixedOffset::west(args.value_of("time")
- .and_then(|s| s.parse::<i32>().ok())
- .unwrap_or(0)),
+ timezone_in: FixedOffset::east(args.value_of("time")
+ .and_then(|s| s.parse::<i32>().ok())
+ .unwrap_or(0)),
+ timezone_out: FixedOffset::east(args.value_of("time_out")
+ .and_then(|s| s.parse::<i32>().ok())
+ .unwrap_or(0)),
override_date: args.value_of("date").and_then(|d| NaiveDate::from_str(&d).ok()),
channel: args.value_of("channel").map(str::to_owned).clone(),
};
diff --git a/formats/energymech/src/lib.rs b/formats/energymech/src/lib.rs
index cf9f654..e0481e1 100644
--- a/formats/energymech/src/lib.rs
+++ b/formats/energymech/src/lib.rs
@@ -34,7 +34,7 @@ impl<'a> Iterator for Iter<'a> {
let m = time[4..6].parse::<u32>().unwrap();
let s = time[7..9].parse::<u32>().unwrap();
if let Some(date) = context.override_date {
- Time::Timestamp(context.timezone
+ Time::Timestamp(context.timezone_in
.from_local_date(&date)
.and_time(NaiveTime::from_hms(h, m, s))
.single()
@@ -236,35 +236,35 @@ impl Encode for Energymech {
&Event { ty: Type::Msg { ref from, ref content }, ref time, .. } => {
try!(writeln!(&mut output,
"[{}] <{}> {}",
- time.with_format(&context.timezone, TIME_FORMAT),
+ time.with_format(&context.timezone_out, TIME_FORMAT),
from,
content))
}
&Event { ty: Type::Notice { ref from, ref content }, ref time, .. } => {
try!(writeln!(&mut output,
"[{}] -{}- {}",
- time.with_format(&context.timezone, TIME_FORMAT),
+ time.with_format(&context.timezone_out, TIME_FORMAT),
from,
content))
}
&Event { ty: Type::Action { ref from, ref content }, ref time, .. } => {
try!(writeln!(&mut output,
"[{}] * {} {}",
- time.with_format(&context.timezone, TIME_FORMAT),
+ time.with_format(&context.timezone_out, TIME_FORMAT),
from,
content))
}
&Event { ty: Type::Nick { ref old_nick, ref new_nick }, ref time, .. } => {
try!(writeln!(&mut output,
"[{}] *** {} is now known as {}",
- time.with_format(&context.timezone, TIME_FORMAT),
+ time.with_format(&context.timezone_out, TIME_FORMAT),
old_nick,
new_nick))
}
&Event { ty: Type::Mode { ref nick, ref mode, ref masks }, ref time, .. } => {
try!(writeln!(&mut output,
"[{}] *** {} sets mode: {} {}",
- time.with_format(&context.timezone, TIME_FORMAT),
+ time.with_format(&context.timezone_out, TIME_FORMAT),
nick.as_ref().expect("Nickname not present, but required."),
mode,
masks))
@@ -272,14 +272,14 @@ impl Encode for Energymech {
&Event { ty: Type::Join { ref nick, ref mask }, ref time, .. } => {
try!(writeln!(&mut output,
"[{}] *** Joins: {} ({})",
- time.with_format(&context.timezone, TIME_FORMAT),
+ time.with_format(&context.timezone_out, TIME_FORMAT),
nick,
mask.as_ref().expect("Mask not present, but required.")))
}
&Event { ty: Type::Part { ref nick, ref mask, ref reason }, ref time, .. } => {
try!(writeln!(&mut output,
"[{}] *** Parts: {} ({}) ({})",
- time.with_format(&context.timezone, TIME_FORMAT),
+ time.with_format(&context.timezone_out, TIME_FORMAT),
nick,
mask.as_ref().expect("Mask not present, but required."),
reason.as_ref().unwrap_or(&Cow::Borrowed(""))))
@@ -287,7 +287,7 @@ impl Encode for Energymech {
&Event { ty: Type::Quit { ref nick, ref mask, ref reason }, ref time, .. } => {
try!(writeln!(&mut output,
"[{}] *** Quits: {} ({}) ({})",
- time.with_format(&context.timezone, TIME_FORMAT),
+ time.with_format(&context.timezone_out, TIME_FORMAT),
nick,
mask.as_ref().expect("Mask not present, but required."),
reason.as_ref().expect("Reason not present, but required.")))
@@ -295,7 +295,7 @@ impl Encode for Energymech {
&Event { ty: Type::TopicChange { ref nick, ref new_topic }, ref time, .. } => {
try!(writeln!(&mut output,
"[{}] *** {} changes topic to '{}'",
- time.with_format(&context.timezone, TIME_FORMAT),
+ time.with_format(&context.timezone_out, TIME_FORMAT),
nick.as_ref().expect("Nick not present, but required."),
new_topic))
}
diff --git a/formats/weechat/src/lib.rs b/formats/weechat/src/lib.rs
index 7d9eb3d..d347d5d 100644
--- a/formats/weechat/src/lib.rs
+++ b/formats/weechat/src/lib.rs
@@ -27,7 +27,9 @@ impl<'a> Iterator for Iter<'a> {
type Item = ilc_base::Result<Event<'a>>;
fn next(&mut self) -> Option<ilc_base::Result<Event<'a>>> {
fn parse_time(c: &Context, date: &str, time: &str) -> Time {
- Time::from_format(&c.timezone, &format!("{} {}", date, time), TIME_DATE_FORMAT)
+ Time::from_format(&c.timezone_in,
+ &format!("{} {}", date, time),
+ TIME_DATE_FORMAT)
}
loop {
@@ -181,29 +183,36 @@ impl Encode for Weechat {
&Event { ty: Type::Msg { ref from, ref content, .. }, ref time, .. } => {
try!(writeln!(&mut output,
"{}\t{}\t{}",
- time.with_format(&context.timezone, TIME_DATE_FORMAT),
+ time.with_format(&context.timezone_out, TIME_DATE_FORMAT),
from,
content))
}
&Event { ty: Type::Action { ref from, ref content, .. }, ref time, .. } => {
try!(writeln!(&mut output,
"{}\t *\t{} {}",
- time.with_format(&context.timezone, TIME_DATE_FORMAT),
+ time.with_format(&context.timezone_out, TIME_DATE_FORMAT),
from,
content))
}
&Event { ty: Type::Join { ref nick, ref mask, .. }, ref channel, ref time } => {
try!(writeln!(&mut output,
"{}\t-->\t{} ({}) has joined {}",
- time.with_format(&context.timezone, TIME_DATE_FORMAT),
+ time.with_format(&context.timezone_out, TIME_DATE_FORMAT),
nick,
mask.as_ref().expect("Hostmask not present, but required."),
channel.as_ref().expect("Channel not present, but required.")))
}
+ &Event { ty: Type::Nick { ref old_nick, ref new_nick, .. }, ref time, .. } => {
+ try!(writeln!(&mut output,
+ "{}\t--\t{} is now known as {}",
+ time.with_format(&context.timezone_out, TIME_DATE_FORMAT),
+ old_nick,
+ new_nick))
+ }
&Event { ty: Type::Part { ref nick, ref mask, ref reason }, ref channel, ref time } => {
try!(write!(&mut output,
"{}\t<--\t{} ({}) has left {}",
- time.with_format(&context.timezone, TIME_DATE_FORMAT),
+ time.with_format(&context.timezone_out, TIME_DATE_FORMAT),
nick,
mask.as_ref().expect("Hostmask not present, but required."),
channel.as_ref().expect("Channel not present, but required.")));
@@ -215,7 +224,7 @@ impl Encode for Weechat {
&Event { ty: Type::Quit { ref nick, ref mask, ref reason }, ref time, .. } => {
try!(write!(&mut output,
"{}\t<--\t{} ({}) has quit",
- time.with_format(&context.timezone, TIME_DATE_FORMAT),
+ time.with_format(&context.timezone_out, TIME_DATE_FORMAT),
nick,
mask.as_ref().expect("Hostmask not present, but required.")));
if reason.is_some() && reason.as_ref().unwrap().len() > 0 {
@@ -226,12 +235,12 @@ impl Encode for Weechat {
&Event { ty: Type::Disconnect, ref time, .. } => {
try!(writeln!(&mut output,
"{}\t--\tirc: disconnected from server",
- time.with_format(&context.timezone, TIME_DATE_FORMAT)))
+ time.with_format(&context.timezone_out, TIME_DATE_FORMAT)))
}
&Event { ty: Type::Notice { ref from, ref content }, ref time, .. } => {
try!(writeln!(&mut output,
"{}\t--\tNotice({}): {}",
- time.with_format(&context.timezone, TIME_DATE_FORMAT),
+ time.with_format(&context.timezone_out, TIME_DATE_FORMAT),
from,
content))
}