Skip to content

Commit

Permalink
Switches from UTC times to local times to prevent issues with using t…
Browse files Browse the repository at this point in the history
…he --today option in timezones other than GMT.
  • Loading branch information
Charlie Saunders committed Feb 22, 2018
1 parent b40979e commit bbf5027
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
12 changes: 6 additions & 6 deletions src/calculate.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use inputs::Inputs;
use chrono::{Date, Duration, Utc};
use chrono::{Date, Duration, Local};
use DateFormat;

struct Range {
start: Date<Utc>,
end: Date<Utc>,
current: Date<Utc>,
start: Date<Local>,
end: Date<Local>,
current: Date<Local>,
}

impl Range {
fn new(start: Date<Utc>, end: Date<Utc>) -> Range {
fn new(start: Date<Local>, end: Date<Local>) -> Range {
Range {
start,
end,
Expand All @@ -23,7 +23,7 @@ impl Range {
}

impl Iterator for Range {
type Item = Date<Utc>;
type Item = Date<Local>;
fn next(&mut self) -> Option<Self::Item> {
let start = self.start;
let end = self.end;
Expand Down
16 changes: 8 additions & 8 deletions src/inputs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ extern crate regex;
mod date_string_parser;

use clap::ArgMatches;
use chrono::{Date, TimeZone, Utc};
use chrono::{Date, TimeZone, Local};
use DateFormat;

pub struct Inputs {
pub start: Option<Date<Utc>>,
pub end: Option<Date<Utc>>,
pub start: Option<Date<Local>>,
pub end: Option<Date<Local>>,
pub offset: Option<i64>,
pub format_type: DateFormat,
pub list_output: bool,
Expand All @@ -21,19 +21,19 @@ impl Inputs {
pub fn new(args: ArgMatches) -> Result<Inputs, &'static str> {
let mut input_format_type = DateFormat::Dashes;

let mut start: Option<Date<Utc>> = match args.value_of("start") {
let mut start: Option<Date<Local>> = match args.value_of("start") {
Some(value) => {
let parsed_value = date_string_parser::ParsedDateString::new(value)?;
input_format_type = parsed_value.format_type;
Some(Utc.ymd(parsed_value.year, parsed_value.month, parsed_value.day))
Some(Local.ymd(parsed_value.year, parsed_value.month, parsed_value.day))
}
None => None,
};

let mut end: Option<Date<Utc>> = match args.value_of("end") {
let mut end: Option<Date<Local>> = match args.value_of("end") {
Some(value) => {
let parsed_value = date_string_parser::ParsedDateString::new(value)?;
Some(Utc.ymd(parsed_value.year, parsed_value.month, parsed_value.day))
Some(Local.ymd(parsed_value.year, parsed_value.month, parsed_value.day))
}
None => None,
};
Expand All @@ -52,7 +52,7 @@ impl Inputs {
};

let today = if args.is_present("today") {
Some(Utc::today())
Some(Local::today())
} else {
None
};
Expand Down

0 comments on commit bbf5027

Please sign in to comment.