Skip to content

Commit 155971b

Browse files
committed
Add time_out param, change timezone handling
1 parent 51c7e0c commit 155971b

File tree

4 files changed

+44
-25
lines changed

4 files changed

+44
-25
lines changed

base/src/context.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@ use chrono::naive::date::NaiveDate;
22
use chrono::offset::fixed::FixedOffset;
33

44
pub struct Context {
5-
pub timezone: FixedOffset,
5+
pub timezone_in: FixedOffset,
6+
pub timezone_out: FixedOffset,
67
pub override_date: Option<NaiveDate>,
78
pub channel: Option<String>,
89
}
910

1011
impl Default for Context {
1112
fn default() -> Context {
1213
Context {
13-
timezone: FixedOffset::west(0),
14+
timezone_in: FixedOffset::west(0),
15+
timezone_out: FixedOffset::west(0),
1416
override_date: None,
1517
channel: None,
1618
}

cli/src/lib.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,16 @@ pub fn main(cli: Cli) {
6464
.author("Till Höppner <till@hoeppner.ws>")
6565
.about("A converter and statistics utility for IRC log files")
6666
.arg(Arg::with_name("time")
67-
.help("Timestamp offset, in seconds")
67+
.help("Timestamp offset of input events, in seconds")
6868
.global(true)
6969
.takes_value(true)
70-
.long("timeoffset")
70+
.long("time_in")
7171
.short("t"))
72+
.arg(Arg::with_name("time_out")
73+
.help("Timestamp offset for output events, in seconds")
74+
.global(true)
75+
.takes_value(true)
76+
.long("time_out"))
7277
.arg(Arg::with_name("date")
7378
.help("Override the date for this log, ISO 8601, YYYY-MM-DD")
7479
.global(true)
@@ -390,9 +395,12 @@ impl<'a> Environment<'a> {
390395

391396
pub fn build_context(args: &ArgMatches) -> Context {
392397
let mut context = Context {
393-
timezone: FixedOffset::west(args.value_of("time")
394-
.and_then(|s| s.parse::<i32>().ok())
395-
.unwrap_or(0)),
398+
timezone_in: FixedOffset::east(args.value_of("time")
399+
.and_then(|s| s.parse::<i32>().ok())
400+
.unwrap_or(0)),
401+
timezone_out: FixedOffset::east(args.value_of("time_out")
402+
.and_then(|s| s.parse::<i32>().ok())
403+
.unwrap_or(0)),
396404
override_date: args.value_of("date").and_then(|d| NaiveDate::from_str(&d).ok()),
397405
channel: args.value_of("channel").map(str::to_owned).clone(),
398406
};

formats/energymech/src/lib.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl<'a> Iterator for Iter<'a> {
3434
let m = time[4..6].parse::<u32>().unwrap();
3535
let s = time[7..9].parse::<u32>().unwrap();
3636
if let Some(date) = context.override_date {
37-
Time::Timestamp(context.timezone
37+
Time::Timestamp(context.timezone_in
3838
.from_local_date(&date)
3939
.and_time(NaiveTime::from_hms(h, m, s))
4040
.single()
@@ -236,66 +236,66 @@ impl Encode for Energymech {
236236
&Event { ty: Type::Msg { ref from, ref content }, ref time, .. } => {
237237
try!(writeln!(&mut output,
238238
"[{}] <{}> {}",
239-
time.with_format(&context.timezone, TIME_FORMAT),
239+
time.with_format(&context.timezone_out, TIME_FORMAT),
240240
from,
241241
content))
242242
}
243243
&Event { ty: Type::Notice { ref from, ref content }, ref time, .. } => {
244244
try!(writeln!(&mut output,
245245
"[{}] -{}- {}",
246-
time.with_format(&context.timezone, TIME_FORMAT),
246+
time.with_format(&context.timezone_out, TIME_FORMAT),
247247
from,
248248
content))
249249
}
250250
&Event { ty: Type::Action { ref from, ref content }, ref time, .. } => {
251251
try!(writeln!(&mut output,
252252
"[{}] * {} {}",
253-
time.with_format(&context.timezone, TIME_FORMAT),
253+
time.with_format(&context.timezone_out, TIME_FORMAT),
254254
from,
255255
content))
256256
}
257257
&Event { ty: Type::Nick { ref old_nick, ref new_nick }, ref time, .. } => {
258258
try!(writeln!(&mut output,
259259
"[{}] *** {} is now known as {}",
260-
time.with_format(&context.timezone, TIME_FORMAT),
260+
time.with_format(&context.timezone_out, TIME_FORMAT),
261261
old_nick,
262262
new_nick))
263263
}
264264
&Event { ty: Type::Mode { ref nick, ref mode, ref masks }, ref time, .. } => {
265265
try!(writeln!(&mut output,
266266
"[{}] *** {} sets mode: {} {}",
267-
time.with_format(&context.timezone, TIME_FORMAT),
267+
time.with_format(&context.timezone_out, TIME_FORMAT),
268268
nick.as_ref().expect("Nickname not present, but required."),
269269
mode,
270270
masks))
271271
}
272272
&Event { ty: Type::Join { ref nick, ref mask }, ref time, .. } => {
273273
try!(writeln!(&mut output,
274274
"[{}] *** Joins: {} ({})",
275-
time.with_format(&context.timezone, TIME_FORMAT),
275+
time.with_format(&context.timezone_out, TIME_FORMAT),
276276
nick,
277277
mask.as_ref().expect("Mask not present, but required.")))
278278
}
279279
&Event { ty: Type::Part { ref nick, ref mask, ref reason }, ref time, .. } => {
280280
try!(writeln!(&mut output,
281281
"[{}] *** Parts: {} ({}) ({})",
282-
time.with_format(&context.timezone, TIME_FORMAT),
282+
time.with_format(&context.timezone_out, TIME_FORMAT),
283283
nick,
284284
mask.as_ref().expect("Mask not present, but required."),
285285
reason.as_ref().unwrap_or(&Cow::Borrowed(""))))
286286
}
287287
&Event { ty: Type::Quit { ref nick, ref mask, ref reason }, ref time, .. } => {
288288
try!(writeln!(&mut output,
289289
"[{}] *** Quits: {} ({}) ({})",
290-
time.with_format(&context.timezone, TIME_FORMAT),
290+
time.with_format(&context.timezone_out, TIME_FORMAT),
291291
nick,
292292
mask.as_ref().expect("Mask not present, but required."),
293293
reason.as_ref().expect("Reason not present, but required.")))
294294
}
295295
&Event { ty: Type::TopicChange { ref nick, ref new_topic }, ref time, .. } => {
296296
try!(writeln!(&mut output,
297297
"[{}] *** {} changes topic to '{}'",
298-
time.with_format(&context.timezone, TIME_FORMAT),
298+
time.with_format(&context.timezone_out, TIME_FORMAT),
299299
nick.as_ref().expect("Nick not present, but required."),
300300
new_topic))
301301
}

formats/weechat/src/lib.rs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ impl<'a> Iterator for Iter<'a> {
2727
type Item = ilc_base::Result<Event<'a>>;
2828
fn next(&mut self) -> Option<ilc_base::Result<Event<'a>>> {
2929
fn parse_time(c: &Context, date: &str, time: &str) -> Time {
30-
Time::from_format(&c.timezone, &format!("{} {}", date, time), TIME_DATE_FORMAT)
30+
Time::from_format(&c.timezone_in,
31+
&format!("{} {}", date, time),
32+
TIME_DATE_FORMAT)
3133
}
3234

3335
loop {
@@ -181,29 +183,36 @@ impl Encode for Weechat {
181183
&Event { ty: Type::Msg { ref from, ref content, .. }, ref time, .. } => {
182184
try!(writeln!(&mut output,
183185
"{}\t{}\t{}",
184-
time.with_format(&context.timezone, TIME_DATE_FORMAT),
186+
time.with_format(&context.timezone_out, TIME_DATE_FORMAT),
185187
from,
186188
content))
187189
}
188190
&Event { ty: Type::Action { ref from, ref content, .. }, ref time, .. } => {
189191
try!(writeln!(&mut output,
190192
"{}\t *\t{} {}",
191-
time.with_format(&context.timezone, TIME_DATE_FORMAT),
193+
time.with_format(&context.timezone_out, TIME_DATE_FORMAT),
192194
from,
193195
content))
194196
}
195197
&Event { ty: Type::Join { ref nick, ref mask, .. }, ref channel, ref time } => {
196198
try!(writeln!(&mut output,
197199
"{}\t-->\t{} ({}) has joined {}",
198-
time.with_format(&context.timezone, TIME_DATE_FORMAT),
200+
time.with_format(&context.timezone_out, TIME_DATE_FORMAT),
199201
nick,
200202
mask.as_ref().expect("Hostmask not present, but required."),
201203
channel.as_ref().expect("Channel not present, but required.")))
202204
}
205+
&Event { ty: Type::Nick { ref old_nick, ref new_nick, .. }, ref time, .. } => {
206+
try!(writeln!(&mut output,
207+
"{}\t--\t{} is now known as {}",
208+
time.with_format(&context.timezone_out, TIME_DATE_FORMAT),
209+
old_nick,
210+
new_nick))
211+
}
203212
&Event { ty: Type::Part { ref nick, ref mask, ref reason }, ref channel, ref time } => {
204213
try!(write!(&mut output,
205214
"{}\t<--\t{} ({}) has left {}",
206-
time.with_format(&context.timezone, TIME_DATE_FORMAT),
215+
time.with_format(&context.timezone_out, TIME_DATE_FORMAT),
207216
nick,
208217
mask.as_ref().expect("Hostmask not present, but required."),
209218
channel.as_ref().expect("Channel not present, but required.")));
@@ -215,7 +224,7 @@ impl Encode for Weechat {
215224
&Event { ty: Type::Quit { ref nick, ref mask, ref reason }, ref time, .. } => {
216225
try!(write!(&mut output,
217226
"{}\t<--\t{} ({}) has quit",
218-
time.with_format(&context.timezone, TIME_DATE_FORMAT),
227+
time.with_format(&context.timezone_out, TIME_DATE_FORMAT),
219228
nick,
220229
mask.as_ref().expect("Hostmask not present, but required.")));
221230
if reason.is_some() && reason.as_ref().unwrap().len() > 0 {
@@ -226,12 +235,12 @@ impl Encode for Weechat {
226235
&Event { ty: Type::Disconnect, ref time, .. } => {
227236
try!(writeln!(&mut output,
228237
"{}\t--\tirc: disconnected from server",
229-
time.with_format(&context.timezone, TIME_DATE_FORMAT)))
238+
time.with_format(&context.timezone_out, TIME_DATE_FORMAT)))
230239
}
231240
&Event { ty: Type::Notice { ref from, ref content }, ref time, .. } => {
232241
try!(writeln!(&mut output,
233242
"{}\t--\tNotice({}): {}",
234-
time.with_format(&context.timezone, TIME_DATE_FORMAT),
243+
time.with_format(&context.timezone_out, TIME_DATE_FORMAT),
235244
from,
236245
content))
237246
}

0 commit comments

Comments
 (0)