Skip to content

Commit 3dc9d76

Browse files
committed
Run only most recent day by default
1 parent 97e6425 commit 3dc9d76

File tree

3 files changed

+60
-6
lines changed

3 files changed

+60
-6
lines changed

Cargo.lock

Lines changed: 43 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ bench = ["criterion"]
1515

1616
[dependencies]
1717
attohttpc = { version = "0.16.0", default_features = false, features = ["tls"] }
18+
chrono = "0.4"
1819
clap = { version = "3.0.0-beta.2", default_features = false, features = ["std"] }
1920
colored = "2.0.0"
2021
dirs = "3.0.1"

src/lib.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ pub mod parse;
33
pub mod utils;
44

55
// Reexport some crates for the generated main
6+
pub use chrono;
67
pub use clap;
78
pub use colored;
89

@@ -45,6 +46,7 @@ pub fn args(year: u16) -> App<'static> {
4546
.long("bench")
4647
.about("Run criterion benchmarks"),
4748
)
49+
.arg(Arg::new("all").long("all").about("Run all days"))
4850
}
4951

5052
#[macro_export]
@@ -54,16 +56,22 @@ macro_rules! base_main {
5456
use std::io::Read;
5557
use std::time::Instant;
5658

59+
use $crate::chrono::{prelude::*, FixedOffset, TimeZone};
60+
5761
use $crate::{bench_day, extract_day, parse, run_day};
5862

5963
const YEAR: u16 = $year;
6064

6165
fn main() {
6266
let mut opt = $crate::args(YEAR).get_matches();
6367

68+
6469
if opt.is_present("bench") {
6570
bench();
6671
} else {
72+
let est = FixedOffset::west(5 * 3600).from_utc_datetime(&Utc::now().naive_utc());
73+
let today = est.day().to_string();
74+
6775
let days: Vec<_> = {
6876
if let Some(opt_days) = opt.values_of("days") {
6977
let opt_days: Vec<_> = opt_days.collect();
@@ -84,10 +92,14 @@ macro_rules! base_main {
8492
.filter(|day| days.contains(&format!("day{}", day).as_str()))
8593
.collect()
8694
} else {
87-
parse!(extract_day {}; $( $tail )*)
88-
.iter()
89-
.map(|s| &s[3..])
90-
.collect()
95+
if !opt.is_present("all") && est.year() == YEAR as i32 && est.month() == 12 && est.day() <= 25 {
96+
vec![&today]
97+
} else {
98+
parse!(extract_day {}; $( $tail )*)
99+
.iter()
100+
.map(|s| &s[3..])
101+
.collect()
102+
}
91103
}
92104
};
93105

0 commit comments

Comments
 (0)