summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordfhoughton <dfhoughton@gmail.com>2019-01-05 12:35:29 -0500
committerdfhoughton <dfhoughton@gmail.com>2019-01-05 12:35:29 -0500
commit8981b2d10268ac934b1251c6a1c91bf756ba7818 (patch)
tree77c2f37da00a8ba2e1bf450b9d24bf0d384bf7d0
parent8235e2be69d41b1f477a4adc1ac3fbb2c4a16533 (diff)
downloadtwo-timer-8981b2d10268ac934b1251c6a1c91bf756ba7818.zip
converted from utc to naive; added 'weekend'
-rw-r--r--CHANGES.md3
-rw-r--r--Cargo.lock2
-rw-r--r--Cargo.toml2
-rw-r--r--src/lib.rs128
-rw-r--r--tests/tests.rs427
5 files changed, 357 insertions, 205 deletions
diff --git a/CHANGES.md b/CHANGES.md
new file mode 100644
index 0000000..df61a65
--- /dev/null
+++ b/CHANGES.md
@@ -0,0 +1,3 @@
+# 1.0.0
+* convert `Date<Utc>` and `DateTime<Utc>` everywhere to `NaiveDate` and `NaiveDateTime`
+* added "weekend" for the expressions "this weekend", "last weekend", etc. \ No newline at end of file
diff --git a/Cargo.lock b/Cargo.lock
index 1b2b82a..b79a3e5 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -108,7 +108,7 @@ dependencies = [
[[package]]
name = "two_timer"
-version = "0.1.0"
+version = "1.0.0"
dependencies = [
"chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
diff --git a/Cargo.toml b/Cargo.toml
index 3259c9e..0a2cfa8 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "two_timer"
-version = "0.1.0"
+version = "1.0.0"
authors = ["dfhoughton <dfhoughton@gmail.com>"]
description="parser for English time expressions"
homepage="https://github.com/dfhoughton/two-timer"
diff --git a/src/lib.rs b/src/lib.rs
index 552bb21..6b87938 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -18,7 +18,7 @@ or "until".
extern crate two_timer;
use two_timer::{parse, Config};
extern crate chrono;
-use chrono::{Date, TimeZone, Utc};
+use chrono::naive::NaiveDate;
pub fn main() {
let phrases = [
@@ -44,7 +44,7 @@ pub fn main() {
Err(e) => println!("{:?}", e),
}
}
- let now = Utc.ymd_opt(1066, 10, 14).unwrap().and_hms(12, 30, 15);
+ let now = NaiveDate::from_ymd_opt(1066, 10, 14).unwrap().and_hms(12, 30, 15);
println!("\nlet \"now\" be some moment during the Battle of Hastings, specifically {}\n", now);
let conf = Config::new().now(now);
for phrase in phrases.iter() {
@@ -181,8 +181,8 @@ extern crate pidgin;
#[macro_use]
extern crate lazy_static;
extern crate chrono;
-use chrono::offset::LocalResult;
-use chrono::{Date, DateTime, Datelike, Duration, TimeZone, Timelike, Utc, Weekday};
+use chrono::naive::{NaiveDate, NaiveDateTime};
+use chrono::{Date, DateTime, Datelike, Duration, Local, TimeZone, Timelike, Weekday};
use pidgin::{Match, Matcher};
use regex::Regex;
@@ -207,7 +207,7 @@ lazy_static! {
named_period => <a_day> | <a_month>
modified_period -> <modifier> <modifiable_period>
modifier => [["this", "last", "next"]]
- modifiable_period => [["week", "month", "year", "pay period", "pp"]] | <a_month> | <a_day>
+ modifiable_period => [["week", "month", "year", "pay period", "pp", "weekend"]] | <a_month> | <a_day>
moment -> <at_time_on>? <some_day> <at_time>? | <specific_time> | <time>
specific_time => <first_time> | <last_time>
some_day => <specific_day> | <relative_day>
@@ -320,18 +320,18 @@ lazy_static! {
/// of time expressions.
#[derive(Debug, Clone)]
pub struct Config {
- now: DateTime<Utc>,
+ now: NaiveDateTime,
monday_starts_week: bool,
period: Period,
pay_period_length: u32,
- pay_period_start: Option<Date<Utc>>,
+ pay_period_start: Option<NaiveDate>,
}
impl Config {
/// Constructs an expression with the default parameters.
pub fn new() -> Config {
Config {
- now: Utc::now(),
+ now: Local::now().naive_local(),
monday_starts_week: true,
period: Period::Minute,
pay_period_length: 7,
@@ -340,7 +340,7 @@ impl Config {
}
/// Returns a copy of the configuration parameters with the "now" moment
/// set to the parameter supplied.
- pub fn now(&self, n: DateTime<Utc>) -> Config {
+ pub fn now(&self, n: NaiveDateTime) -> Config {
let mut c = self.clone();
c.now = n;
c
@@ -371,7 +371,7 @@ impl Config {
/// date for a pay period set to the parameter supplied. By default this date
/// is undefined. Unless it is defined, expressions containing the phrase "pay period"
/// or "pp" cannot be interpreted.
- pub fn pay_period_start(&self, pay_period_start: Option<Date<Utc>>) -> Config {
+ pub fn pay_period_start(&self, pay_period_start: Option<NaiveDate>) -> Config {
let mut c = self.clone();
c.pay_period_start = pay_period_start;
c
@@ -400,7 +400,7 @@ pub enum TimeError {
/// Converts a time expression into a pair or timestamps and a boolean indicating whether
/// the expression was literally a range, such as "9 to 11", as opposed to "9 AM", say.
-///
+///
/// The second parameter is an optional `Config` object. In general you will not need to
/// use this except in testing or in the interpretation of pay periods.
///
@@ -416,7 +416,7 @@ pub enum TimeError {
pub fn parse(
phrase: &str,
config: Option<Config>,
-) -> Result<(DateTime<Utc>, DateTime<Utc>, bool), TimeError> {
+) -> Result<(NaiveDateTime, NaiveDateTime, bool), TimeError> {
let parse = MATCHER.parse(phrase);
if parse.is_none() {
return Err(TimeError::Parse(format!(
@@ -490,7 +490,7 @@ pub fn parse(
// for the end time, if the span is less than a day, use the first, otherwise use the second
// e.g., Monday through Friday at 3 PM should end at 3 PM, but Monday through Friday should end at the end of Friday
-fn pick_terminus(d1: DateTime<Utc>, d2: DateTime<Utc>, through: bool) -> DateTime<Utc> {
+fn pick_terminus(d1: NaiveDateTime, d2: NaiveDateTime, through: bool) -> NaiveDateTime {
if d1.day() == d2.day() && d1.month() == d2.month() && d1.year() == d2.year() {
d1
} else if through {
@@ -509,8 +509,8 @@ fn pick_terminus(d1: DateTime<Utc>, d2: DateTime<Utc>, through: bool) -> DateTim
/// # use two_timer::first_moment;
/// println!("{}", first_moment()); // -262144-01-01 00:00:00 UTC
/// ```
-pub fn first_moment() -> DateTime<Utc> {
- chrono::MIN_DATE.and_hms_milli(0, 0, 0, 0)
+pub fn first_moment() -> NaiveDateTime {
+ chrono::naive::MIN_DATE.and_hms_milli(0, 0, 0, 0)
}
/// The moment regarded as the end of time.
@@ -522,8 +522,8 @@ pub fn first_moment() -> DateTime<Utc> {
/// # use two_timer::last_moment;
/// println!("{}", last_moment()); // +262143-12-31 23:59:59.999 UTC
/// ```
-pub fn last_moment() -> DateTime<Utc> {
- chrono::MAX_DATE.and_hms_milli(23, 59, 59, 999)
+pub fn last_moment() -> NaiveDateTime {
+ chrono::naive::MAX_DATE.and_hms_milli(23, 59, 59, 999)
}
fn specific(m: &Match) -> bool {
@@ -533,7 +533,7 @@ fn specific(m: &Match) -> bool {
fn handle_specific_day(
m: &Match,
config: &Config,
-) -> Result<(DateTime<Utc>, DateTime<Utc>), TimeError> {
+) -> Result<(NaiveDateTime, NaiveDateTime), TimeError> {
let now = config.now.clone();
let mut times = m.all_names("time");
if times.len() > 1 {
@@ -574,33 +574,32 @@ fn handle_specific_day(
let year = year(date, &now);
let month = n_month(date);
let day = n_day(date);
- let d_opt = Utc.ymd_opt(year, month, day);
+ let d_opt = NaiveDate::from_ymd_opt(year, month, day);
return match d_opt {
- LocalResult::None => Err(TimeError::ImpossibleDate(format!(
+ None => Err(TimeError::ImpossibleDate(format!(
"cannot construct UTC date with year {}, month {}, and day {}",
year, month, day
))),
- LocalResult::Single(d1) => {
+ Some(d1) => {
let d1 = d1.and_hms(0, 0, 0);
Ok(moment_and_time(
&Config::new().now(d1).period(Period::Day),
time,
))
}
- LocalResult::Ambiguous(_, _) => unreachable!(),
};
}
if let Some(date) = date.name("a_date") {
let year = year(date, &now);
let month = a_month(date);
let day = n_day(date);
- let d_opt = Utc.ymd_opt(year, month, day);
+ let d_opt = NaiveDate::from_ymd_opt(year, month, day);
return match d_opt {
- LocalResult::None => Err(TimeError::ImpossibleDate(format!(
+ None => Err(TimeError::ImpossibleDate(format!(
"cannot construct UTC date with year {}, month {}, and day {}",
year, month, day
))),
- LocalResult::Single(d1) => {
+ Some(d1) => {
if let Some(wd) = date.name("a_day") {
let wd = weekday(wd.as_str());
if wd == d1.weekday() {
@@ -626,7 +625,6 @@ fn handle_specific_day(
))
}
}
- LocalResult::Ambiguous(_, _) => unreachable!(),
};
}
unreachable!();
@@ -637,20 +635,19 @@ fn handle_specific_day(
fn handle_specific_period(
moment: &Match,
config: &Config,
-) -> Result<(DateTime<Utc>, DateTime<Utc>), TimeError> {
+) -> Result<(NaiveDateTime, NaiveDateTime), TimeError> {
if let Some(moment) = moment.name("month_and_year") {
let y = year(moment, &config.now);
let m = a_month(moment);
- return match Utc.ymd_opt(y, m, 1) {
- LocalResult::None => unreachable!(),
- LocalResult::Single(d1) => {
+ return match NaiveDate::from_ymd_opt(y, m, 1) {
+ None => unreachable!(),
+ Some(d1) => {
let d1 = d1.and_hms(0, 0, 0);
Ok(moment_and_time(
&Config::new().now(d1).period(Period::Month),
None,
))
}
- LocalResult::Ambiguous(_, _) => unreachable!(),
};
}
if let Some(moment) = moment.name("modified_period") {
@@ -687,6 +684,17 @@ fn handle_specific_period(
};
Ok(moment_to_period(d, &Period::Week, config))
}
+ ModifiablePeriod::Weekend => {
+ let (_, d2) =
+ moment_to_period(config.now, &Period::Week, &config.monday_starts_week(true));
+ let d2 = match modifier {
+ PeriodModifier::Next => d2 + Duration::days(7),
+ PeriodModifier::Last => d2 - Duration::days(7),
+ PeriodModifier::This => d2,
+ };
+ let d1 = d2 - Duration::days(2);
+ Ok((d1, d2))
+ }
ModifiablePeriod::Month => {
let (d, _) = moment_to_period(config.now, &Period::Month, config);
let d = match modifier {
@@ -742,12 +750,19 @@ enum ModifiablePeriod {
Month,
Year,
PayPeriod,
+ Weekend,
}
impl ModifiablePeriod {
fn from_match(m: &Match) -> ModifiablePeriod {
match m.as_str().chars().nth(0).expect("unreachable") {
- 'w' | 'W' => ModifiablePeriod::Week,
+ 'w' | 'W' => {
+ if m.as_str().len() == 4 {
+ ModifiablePeriod::Week
+ } else {
+ ModifiablePeriod::Weekend
+ }
+ }
'm' | 'M' => ModifiablePeriod::Month,
'y' | 'Y' => ModifiablePeriod::Year,
'p' | 'P' => ModifiablePeriod::PayPeriod,
@@ -776,7 +791,7 @@ impl PeriodModifier {
fn handle_specific_time(
moment: &Match,
config: &Config,
-) -> Result<(DateTime<Utc>, DateTime<Utc>), TimeError> {
+) -> Result<(NaiveDateTime, NaiveDateTime), TimeError> {
return if moment.has("first_time") {
Ok(moment_to_period(first_moment(), &config.period, config))
} else {
@@ -787,7 +802,7 @@ fn handle_specific_time(
fn handle_one_time(
moment: &Match,
config: &Config,
-) -> Result<(DateTime<Utc>, DateTime<Utc>, bool), TimeError> {
+) -> Result<(NaiveDateTime, NaiveDateTime, bool), TimeError> {
let r = if moment.has("specific_day") {
handle_specific_day(moment, config)
} else if let Some(moment) = moment.name("specific_period") {
@@ -804,7 +819,7 @@ fn handle_one_time(
}
// add time to a date
-fn moment_and_time(config: &Config, daytime: Option<&Match>) -> (DateTime<Utc>, DateTime<Utc>) {
+fn moment_and_time(config: &Config, daytime: Option<&Match>) -> (NaiveDateTime, NaiveDateTime) {
if let Some(daytime) = daytime {
let (hour, minute, second) = time(daytime);
let period = if second.is_some() {
@@ -831,9 +846,9 @@ fn moment_and_time(config: &Config, daytime: Option<&Match>) -> (DateTime<Utc>,
fn relative_moment(
m: &Match,
config: &Config,
- other_time: &DateTime<Utc>,
+ other_time: &NaiveDateTime,
before: bool,
-) -> (DateTime<Utc>, DateTime<Utc>) {
+) -> (NaiveDateTime, NaiveDateTime) {
if let Some(day) = m.name("a_day") {
let wd = weekday(day.as_str());
let mut delta =
@@ -888,7 +903,7 @@ fn relative_moment(
other_time.year()
}
};
- let d = Utc.ymd(year, month, 1).and_hms(0, 0, 0);
+ let d = NaiveDate::from_ymd(year, month, 1).and_hms(0, 0, 0);
let (d1, d2) = moment_to_period(d, &Period::Month, config);
if before && d1 >= *other_time {
return moment_to_period(d1.with_year(d1.year() - 1).unwrap(), &Period::Month, config);
@@ -903,7 +918,7 @@ fn relative_moment(
fn specific_moment(
m: &Match,
config: &Config,
-) -> Result<(DateTime<Utc>, DateTime<Utc>), TimeError> {
+) -> Result<(NaiveDateTime, NaiveDateTime), TimeError> {
if let Some(m) = m.name("specific_day") {
return handle_specific_day(m, config);
}
@@ -975,7 +990,7 @@ fn n_month(m: &Match) -> u32 {
cap[1].parse::<u32>().unwrap()
}
-fn year(m: &Match, now: &DateTime<Utc>) -> i32 {
+fn year(m: &Match, now: &NaiveDateTime) -> i32 {
let year = m.name("year").unwrap();
if let Some(sy) = year.name("short_year") {
let y = s_to_n(sy.as_str()) as i32;
@@ -1015,22 +1030,22 @@ fn n_day(m: &Match) -> u32 {
/// expand a moment to the period containing it
fn moment_to_period(
- now: DateTime<Utc>,
+ now: NaiveDateTime,
period: &Period,
config: &Config,
-) -> (DateTime<Utc>, DateTime<Utc>) {
+) -> (NaiveDateTime, NaiveDateTime) {
match period {
Period::Year => {
- let d1 = Utc.ymd(now.year(), 1, 1).and_hms(0, 0, 0);
- let d2 = Utc.ymd(now.year() + 1, 1, 1).and_hms(0, 0, 0);
+ let d1 = NaiveDate::from_ymd(now.year(), 1, 1).and_hms(0, 0, 0);
+ let d2 = NaiveDate::from_ymd(now.year() + 1, 1, 1).and_hms(0, 0, 0);
(d1, d2)
}
Period::Month => {
- let d1 = Utc.ymd(now.year(), now.month(), 1).and_hms(0, 0, 0);
+ let d1 = NaiveDate::from_ymd(now.year(), now.month(), 1).and_hms(0, 0, 0);
let d2 = if now.month() == 12 {
- Utc.ymd(now.year() + 1, 1, 1)
+ NaiveDate::from_ymd(now.year() + 1, 1, 1)
} else {
- Utc.ymd(now.year(), now.month() + 1, 1)
+ NaiveDate::from_ymd(now.year(), now.month() + 1, 1)
}
.and_hms(0, 0, 0);
(d1, d2)
@@ -1041,28 +1056,29 @@ fn moment_to_period(
} else {
now.weekday().num_days_from_sunday()
};
- let d1 = Utc.ymd(now.year(), now.month(), now.day()).and_hms(0, 0, 0)
+ let d1 = NaiveDate::from_ymd(now.year(), now.month(), now.day()).and_hms(0, 0, 0)
- Duration::days(offset as i64);
(d1, d1 + Duration::days(7))
}
Period::Day => {
- let d1 = Utc.ymd(now.year(), now.month(), now.day()).and_hms(0, 0, 0);
+ let d1 = NaiveDate::from_ymd(now.year(), now.month(), now.day()).and_hms(0, 0, 0);
(d1, d1 + Duration::days(1))
}
Period::Hour => {
- let d1 = Utc
- .ymd(now.year(), now.month(), now.day())
- .and_hms(now.hour(), 0, 0);
+ let d1 =
+ NaiveDate::from_ymd(now.year(), now.month(), now.day()).and_hms(now.hour(), 0, 0);
(d1, d1 + Duration::hours(1))
}
Period::Minute => {
- let d1 =
- Utc.ymd(now.year(), now.month(), now.day())
- .and_hms(now.hour(), now.minute(), 0);
+ let d1 = NaiveDate::from_ymd(now.year(), now.month(), now.day()).and_hms(
+ now.hour(),
+ now.minute(),
+ 0,
+ );
(d1, d1 + Duration::minutes(1))
}
Period::Second => {
- let d1 = Utc.ymd(now.year(), now.month(), now.day()).and_hms(
+ let d1 = NaiveDate::from_ymd(now.year(), now.month(), now.day()).and_hms(
now.hour(),
now.minute(),
now.second(),
diff --git a/tests/tests.rs b/tests/tests.rs
index ae607cf..f4460b2 100644
--- a/tests/tests.rs
+++ b/tests/tests.rs
@@ -2,12 +2,13 @@
extern crate two_timer;
use two_timer::{parse, Config};
extern crate chrono;
-use chrono::{Duration, TimeZone, Utc};
+use chrono::naive::NaiveDate;
+use chrono::{Duration, Local, TimeZone, Utc};
#[test]
fn always() {
- let alpha = chrono::MIN_DATE.and_hms_milli(0, 0, 0, 0);
- let omega = chrono::MAX_DATE.and_hms_milli(23, 59, 59, 999);
+ let alpha = chrono::naive::MIN_DATE.and_hms_milli(0, 0, 0, 0);
+ let omega = chrono::naive::MAX_DATE.and_hms_milli(23, 59, 59, 999);
for phrase in [
"always",
"ever",
@@ -26,7 +27,7 @@ fn always() {
#[test]
fn yesterday() {
- let now = Utc::now();
+ let now = Local::now().naive_local();
let (start, end, _) = parse("yesterday", Some(Config::new().now(now))).unwrap();
assert!(start < now);
assert!(end < now);
@@ -39,7 +40,7 @@ fn yesterday() {
#[test]
fn tomorrow() {
- let now = Utc::now();
+ let now = Local::now().naive_local();
let (start, end, _) = parse("tomorrow", Some(Config::new().now(now))).unwrap();
assert!(start > now);
assert!(end > now);
@@ -52,7 +53,7 @@ fn tomorrow() {
#[test]
fn today() {
- let now = Utc::now();
+ let now = Local::now().naive_local();
let (start, end, _) = parse("today", Some(Config::new().now(now))).unwrap();
assert!(start < now);
assert!(end > now);
@@ -66,7 +67,7 @@ fn today() {
#[test]
fn day_5_6_69_at_3_30_pm() {
- let then = Utc.ymd(1969, 5, 6).and_hms(15, 30, 0);
+ let then = NaiveDate::from_ymd(1969, 5, 6).and_hms(15, 30, 0);
for phrase in [
"at 3:30 PM on 5-6-69",
"3:30 p.m. on 5-6-69",
@@ -83,7 +84,7 @@ fn day_5_6_69_at_3_30_pm() {
#[test]
fn day_5_6_69_at_3_pm() {
- let then = Utc.ymd(1969, 5, 6).and_hms(15, 0, 0);
+ let then = NaiveDate::from_ymd(1969, 5, 6).and_hms(15, 0, 0);
for phrase in [
"at 3 PM on 5-6-69",
"3 p.m. on 5-6-69",
@@ -100,7 +101,7 @@ fn day_5_6_69_at_3_pm() {
#[test]
fn day_5_6_69_at_3_30_00_pm() {
- let then = Utc.ymd(1969, 5, 6).and_hms(15, 30, 0);
+ let then = NaiveDate::from_ymd(1969, 5, 6).and_hms(15, 30, 0);
for phrase in [
"at 3:30:00 PM on 5-6-69",
"3:30:00 p.m. on 5-6-69",
@@ -117,7 +118,7 @@ fn day_5_6_69_at_3_30_00_pm() {
#[test]
fn day_5_6_69_at_3_30_01_pm() {
- let then = Utc.ymd(1969, 5, 6).and_hms(15, 30, 1);
+ let then = NaiveDate::from_ymd(1969, 5, 6).and_hms(15, 30, 1);
for phrase in [
"at 3:30:01 PM on 5-6-69",
"3:30:01 p.m. on 5-6-69",
@@ -134,7 +135,7 @@ fn day_5_6_69_at_3_30_01_pm() {
#[test]
fn day_5_6_69_at_3_30_01_am() {
- let then = Utc.ymd(1969, 5, 6).and_hms(3, 30, 1);
+ let then = NaiveDate::from_ymd(1969, 5, 6).and_hms(3, 30, 1);
for phrase in [
"at 3:30:01 AM on 5-6-69",
"3:30:01 a.m. on 5-6-69",
@@ -151,8 +152,8 @@ fn day_5_6_69_at_3_30_01_am() {
#[test]
fn at_3_pm() {
- let now = Utc.ymd(1969, 5, 6).and_hms(16, 0, 0);
- let then = Utc.ymd(1969, 5, 6).and_hms(15, 0, 0);
+ let now = NaiveDate::from_ymd(1969, 5, 6).and_hms(16, 0, 0);
+ let then = NaiveDate::from_ymd(1969, 5, 6).and_hms(15, 0, 0);
for phrase in ["3 PM", "3 pm", "15"].iter() {
let (start, end, _) = parse(phrase, Some(Config::new().now(now))).unwrap();
assert_eq!(then, start);
@@ -162,8 +163,8 @@ fn at_3_pm() {
#[test]
fn at_3_00_pm() {
- let now = Utc.ymd(1969, 5, 6).and_hms(16, 0, 0);
- let then = Utc.ymd(1969, 5, 6).and_hms(15, 0, 0);
+ let now = NaiveDate::from_ymd(1969, 5, 6).and_hms(16, 0, 0);
+ let then = NaiveDate::from_ymd(1969, 5, 6).and_hms(15, 0, 0);
for phrase in ["3:00 PM", "3:00 pm", "15:00"].iter() {
let (start, end, _) = parse(phrase, Some(Config::new().now(now))).unwrap();
assert_eq!(then, start);
@@ -173,8 +174,8 @@ fn at_3_00_pm() {
#[test]
fn at_3_00_00_pm() {
- let now = Utc.ymd(1969, 5, 6).and_hms(16, 0, 0);
- let then = Utc.ymd(1969, 5, 6).and_hms(15, 0, 0);
+ let now = NaiveDate::from_ymd(1969, 5, 6).and_hms(16, 0, 0);
+ let then = NaiveDate::from_ymd(1969, 5, 6).and_hms(15, 0, 0);
for phrase in ["3:00:00 PM", "3:00:00 pm", "15:00:00"].iter() {
let (start, end, _) = parse(phrase, Some(Config::new().now(now))).unwrap();
assert_eq!(then, start);
@@ -184,8 +185,8 @@ fn at_3_00_00_pm() {
#[test]
fn at_3_pm_yesterday() {
- let now = Utc.ymd(1969, 5, 6).and_hms(14, 0, 0);
- let then = Utc.ymd(1969, 5, 5).and_hms(15, 0, 0);
+ let now = NaiveDate::from_ymd(1969, 5, 6).and_hms(14, 0, 0);
+ let then = NaiveDate::from_ymd(1969, 5, 5).and_hms(15, 0, 0);
for phrase in ["3 PM yesterday", "3 pm yesterday", "15 yesterday"].iter() {
let (start, end, _) = parse(phrase, Some(Config::new().now(now))).unwrap();
assert_eq!(then, start);
@@ -195,7 +196,7 @@ fn at_3_pm_yesterday() {
#[test]
fn alphabetic_5_6_69() {
- let then = Utc.ymd(1969, 5, 6).and_hms(0, 0, 0);
+ let then = NaiveDate::from_ymd(1969, 5, 6).and_hms(0, 0, 0);
for phrase in [
"May 6, 1969",
"May 6, '69",
@@ -238,7 +239,7 @@ fn alphabetic_5_6_69() {
#[test]
fn ymd_5_31_69() {
- let then = Utc.ymd(1969, 5, 31).and_hms(0, 0, 0);
+ let then = NaiveDate::from_ymd(1969, 5, 31).and_hms(0, 0, 0);
for phrase in [
"5-31-69",
"5/31/69",
@@ -331,8 +332,8 @@ fn leap_day() {
#[test]
fn may_1969() {
- let m1 = Utc.ymd(1969, 5, 1).and_hms(0, 0, 0);
- let m2 = Utc.ymd(1969, 6, 1).and_hms(0, 0, 0);
+ let m1 = NaiveDate::from_ymd(1969, 5, 1).and_hms(0, 0, 0);
+ let m2 = NaiveDate::from_ymd(1969, 6, 1).and_hms(0, 0, 0);
for phrase in ["May 1969", "May '69"].iter() {
let (start, end, _) = parse(phrase, None).unwrap();
assert_eq!(m1, start);
@@ -342,9 +343,9 @@ fn may_1969() {
#[test]
fn this_month() {
- let now = Utc.ymd(1969, 5, 6).and_hms(0, 0, 0);
- let d1 = Utc.ymd(1969, 5, 1).and_hms(0, 0, 0);
- let d2 = Utc.ymd(1969, 6, 1).and_hms(0, 0, 0);
+ let now = NaiveDate::from_ymd(1969, 5, 6).and_hms(0, 0, 0);
+ let d1 = NaiveDate::from_ymd(1969, 5, 1).and_hms(0, 0, 0);
+ let d2 = NaiveDate::from_ymd(1969, 6, 1).and_hms(0, 0, 0);
let (start, end, _) = parse("this month", Some(Config::new().now(now))).unwrap();
assert_eq!(d1, start);
assert_eq!(d2, end);
@@ -352,9 +353,9 @@ fn this_month() {
#[test]
fn next_month() {
- let now = Utc.ymd(1969, 5, 6).and_hms(0, 0, 0);
- let d1 = Utc.ymd(1969, 6, 1).and_hms(0, 0, 0);
- let d2 = Utc.ymd(1969, 7, 1).and_hms(0, 0, 0);
+ let now = NaiveDate::from_ymd(1969, 5, 6).and_hms(0, 0, 0);
+ let d1 = NaiveDate::from_ymd(1969, 6, 1).and_hms(0, 0, 0);
+ let d2 = NaiveDate::from_ymd(1969, 7, 1).and_hms(0, 0, 0);
let (start, end, _) = parse("next month", Some(Config::new().now(now))).unwrap();
assert_eq!(d1, start);
assert_eq!(d2, end);
@@ -362,9 +363,9 @@ fn next_month() {
#[test]
fn last_month() {
- let now = Utc.ymd(1969, 5, 6).and_hms(0, 0, 0);
- let d1 = Utc.ymd(1969, 4, 1).and_hms(0, 0, 0);
- let d2 = Utc.ymd(1969, 5, 1).and_hms(0, 0, 0);
+ let now = NaiveDate::from_ymd(1969, 5, 6).and_hms(0, 0, 0);
+ let d1 = NaiveDate::from_ymd(1969, 4, 1).and_hms(0, 0, 0);
+ let d2 = NaiveDate::from_ymd(1969, 5, 1).and_hms(0, 0, 0);
let (start, end, _) = parse("last month", Some(Config::new().now(now))).unwrap();
assert_eq!(d1, start);
assert_eq!(d2, end);
@@ -372,9 +373,9 @@ fn last_month() {
#[test]
fn this_year() {
- let now = Utc.ymd(1969, 5, 6).and_hms(0, 0, 0);
- let d1 = Utc.ymd(1969, 1, 1).and_hms(0, 0, 0);
- let d2 = Utc.ymd(1970, 1, 1).and_hms(0, 0, 0);
+ let now = NaiveDate::from_ymd(1969, 5, 6).and_hms(0, 0, 0);
+ let d1 = NaiveDate::from_ymd(1969, 1, 1).and_hms(0, 0, 0);
+ let d2 = NaiveDate::from_ymd(1970, 1, 1).and_hms(0, 0, 0);
let (start, end, _) = parse("this year", Some(Config::new().now(now))).unwrap();
assert_eq!(d1, start);
assert_eq!(d2, end);
@@ -382,9 +383,9 @@ fn this_year() {
#[test]
fn next_year() {
- let now = Utc.ymd(1969, 5, 6).and_hms(0, 0, 0);
- let d1 = Utc.ymd(1970, 1, 1).and_hms(0, 0, 0);
- let d2 = Utc.ymd(1971, 1, 1).and_hms(0, 0, 0);
+ let now = NaiveDate::from_ymd(1969, 5, 6).and_hms(0, 0, 0);
+ let d1 = NaiveDate::from_ymd(1970, 1, 1).and_hms(0, 0, 0);
+ let d2 = NaiveDate::from_ymd(1971, 1, 1).and_hms(0, 0, 0);
let (start, end, _) = parse("next year", Some(Config::new().now(now))).unwrap();
assert_eq!(d1, start);
assert_eq!(d2, end);
@@ -392,9 +393,9 @@ fn next_year() {
#[test]
fn last_year() {
- let now = Utc.ymd(1969, 5, 6).and_hms(0, 0, 0);
- let d1 = Utc.ymd(1968, 1, 1).and_hms(0, 0, 0);
- let d2 = Utc.ymd(1969, 1, 1).and_hms(0, 0, 0);
+ let now = NaiveDate::from_ymd(1969, 5, 6).and_hms(0, 0, 0);
+ let d1 = NaiveDate::from_ymd(1968, 1, 1).and_hms(0, 0, 0);
+ let d2 = NaiveDate::from_ymd(1969, 1, 1).and_hms(0, 0, 0);
let (start, end, _) = parse("last year", Some(Config::new().now(now))).unwrap();
assert_eq!(d1, start);
assert_eq!(d2, end);
@@ -402,9 +403,9 @@ fn last_year() {
#[test]
fn this_week() {
- let now = Utc.ymd(1969, 5, 6).and_hms(0, 0, 0);
- let d1 = Utc.ymd(1969, 5, 5).and_hms(0, 0, 0);
- let d2 = Utc.ymd(1969, 5, 12).and_hms(0, 0, 0);
+ let now = NaiveDate::from_ymd(1969, 5, 6).and_hms(0, 0, 0);
+ let d1 = NaiveDate::from_ymd(1969, 5, 5).and_hms(0, 0, 0);
+ let d2 = NaiveDate::from_ymd(1969, 5, 12).and_hms(0, 0, 0);
let (start, end, _) = parse("this week", Some(Config::new().now(now))).unwrap();
assert_eq!(d1, start);
assert_eq!(d2, end);
@@ -412,9 +413,9 @@ fn this_week() {
#[test]
fn next_week() {
- let now = Utc.ymd(1969, 5, 6).and_hms(0, 0, 0);
- let d1 = Utc.ymd(1969, 5, 12).and_hms(0, 0, 0);
- let d2 = Utc.ymd(1969, 5, 19).and_hms(0, 0, 0);
+ let now = NaiveDate::from_ymd(1969, 5, 6).and_hms(0, 0, 0);
+ let d1 = NaiveDate::from_ymd(1969, 5, 12).and_hms(0, 0, 0);
+ let d2 = NaiveDate::from_ymd(1969, 5, 19).and_hms(0, 0, 0);
let (start, end, _) = parse("next week", Some(Config::new().now(now))).unwrap();
assert_eq!(d1, start);
assert_eq!(d2, end);
@@ -422,9 +423,9 @@ fn next_week() {
#[test]
fn last_week() {
- let now = Utc.ymd(1969, 5, 6).and_hms(0, 0, 0);
- let d1 = Utc.ymd(1969, 4, 28).and_hms(0, 0, 0);
- let d2 = Utc.ymd(1969, 5, 5).and_hms(0, 0, 0);
+ let now = NaiveDate::from_ymd(1969, 5, 6).and_hms(0, 0, 0);
+ let d1 = NaiveDate::from_ymd(1969, 4, 28).and_hms(0, 0, 0);
+ let d2 = NaiveDate::from_ymd(1969, 5, 5).and_hms(0, 0, 0);
let (start, end, _) = parse("last week", Some(Config::new().now(now))).unwrap();
assert_eq!(d1, start);
assert_eq!(d2, end);
@@ -432,9 +433,9 @@ fn last_week() {
#[test]
fn this_week_sunday_starts() {
- let now = Utc.ymd(1969, 5, 6).and_hms(0, 0, 0);
- let d1 = Utc.ymd(1969, 5, 4).and_hms(0, 0, 0);
- let d2 = Utc.ymd(1969, 5, 11).and_hms(0, 0, 0);
+ let now = NaiveDate::from_ymd(1969, 5, 6).and_hms(0, 0, 0);
+ let d1 = NaiveDate::from_ymd(1969, 5, 4).and_hms(0, 0, 0);
+ let d2 = NaiveDate::from_ymd(1969, 5, 11).and_hms(0, 0, 0);
let (start, end, _) = parse(
"this week",
Some(Config::new().now(now).monday_starts_week(false)),
@@ -446,9 +447,9 @@ fn this_week_sunday_starts() {
#[test]
fn next_week_sunday_starts() {
- let now = Utc.ymd(1969, 5, 6).and_hms(0, 0, 0);
- let d1 = Utc.ymd(1969, 5, 11).and_hms(0, 0, 0);
- let d2 = Utc.ymd(1969, 5, 18).and_hms(0, 0, 0);
+ let now = NaiveDate::from_ymd(1969, 5, 6).and_hms(0, 0, 0);
+ let d1 = NaiveDate::from_ymd(1969, 5, 11).and_hms(0, 0, 0);
+ let d2 = NaiveDate::from_ymd(1969, 5, 18).and_hms(0, 0, 0);
let (start, end, _) = parse(
"next week",
Some(Config::new().now(now).monday_starts_week(false)),
@@ -460,9 +461,9 @@ fn next_week_sunday_starts() {
#[test]
fn last_week_sunday_starts() {
- let now = Utc.ymd(1969, 5, 6).and_hms(0, 0, 0);
- let d1 = Utc.ymd(1969, 4, 27).and_hms(0, 0, 0);
- let d2 = Utc.ymd(1969, 5, 4).and_hms(0, 0, 0);
+ let now = NaiveDate::from_ymd(1969, 5, 6).and_hms(0, 0, 0);
+ let d1 = NaiveDate::from_ymd(1969, 4, 27).and_hms(0, 0, 0);
+ let d2 = NaiveDate::from_ymd(1969, 5, 4).and_hms(0, 0, 0);
let (start, end, _) = parse(
"last week",
Some(Config::new().now(now).monday_starts_week(false)),
@@ -474,14 +475,14 @@ fn last_week_sunday_starts() {
#[test]
fn this_pay_period() {
- let now = Utc.ymd(1969, 5, 6).and_hms(0, 0, 0);
+ let now = NaiveDate::from_ymd(1969, 5, 6).and_hms(0, 0, 0);
// two-week pay period beginning about a year before "now" on a Sunday
let config = Config::new()
- .pay_period_start(Some(Utc.ymd(1968, 5, 5)))
+ .pay_period_start(Some(NaiveDate::from_ymd(1968, 5, 5)))
.pay_period_length(14)
.now(now);
- let d1 = Utc.ymd(1969, 5, 4).and_hms(0, 0, 0);
- let d2 = Utc.ymd(1969, 5, 18).and_hms(0, 0, 0);
+ let d1 = NaiveDate::from_ymd(1969, 5, 4).and_hms(0, 0, 0);
+ let d2 = NaiveDate::from_ymd(1969, 5, 18).and_hms(0, 0, 0);
let (start, end, _) = parse("this pay period", Some(config)).unwrap();
assert_eq!(d1, start);
assert_eq!(d2, end);
@@ -489,14 +490,14 @@ fn this_pay_period() {
#[test]
fn next_pay_period() {
- let now = Utc.ymd(1969, 5, 6).and_hms(0, 0, 0);
+ let now = NaiveDate::from_ymd(1969, 5, 6).and_hms(0, 0, 0);
// two-week pay period beginning about a year before "now" on a Sunday
let config = Config::new()
- .pay_period_start(Some(Utc.ymd(1968, 5, 5)))
+ .pay_period_start(Some(NaiveDate::from_ymd(1968, 5, 5)))
.pay_period_length(14)
.now(now);
- let d1 = Utc.ymd(1969, 5, 18).and_hms(0, 0, 0);
- let d2 = Utc.ymd(1969, 6, 1).and_hms(0, 0, 0);
+ let d1 = NaiveDate::from_ymd(1969, 5, 18).and_hms(0, 0, 0);
+ let d2 = NaiveDate::from_ymd(1969, 6, 1).and_hms(0, 0, 0);
let (start, end, _) = parse("next pay period", Some(config)).unwrap();
assert_eq!(d1, start);
assert_eq!(d2, end);
@@ -504,14 +505,14 @@ fn next_pay_period() {
#[test]
fn last_pay_period() {
- let now = Utc.ymd(1969, 5, 6).and_hms(0, 0, 0);
+ let now = NaiveDate::from_ymd(1969, 5, 6).and_hms(0, 0, 0);
// two-week pay period beginning about a year before "now" on a Sunday
let config = Config::new()
- .pay_period_start(Some(Utc.ymd(1968, 5, 5)))
+ .pay_period_start(Some(NaiveDate::from_ymd(1968, 5, 5)))
.pay_period_length(14)
.now(now);
- let d1 = Utc.ymd(1969, 4, 20).and_hms(0, 0, 0);
- let d2 = Utc.ymd(1969, 5, 4).and_hms(0, 0, 0);
+ let d1 = NaiveDate::from_ymd(1969, 4, 20).and_hms(0, 0, 0);
+ let d2 = NaiveDate::from_ymd(1969, 5, 4).and_hms(0, 0, 0);
let (start, end, _) = parse("last pay period", Some(config)).unwrap();
assert_eq!(d1, start);
assert_eq!(d2, end);
@@ -519,14 +520,14 @@ fn last_pay_period() {
#[test]
fn this_pay_period_weird() {
- let now = Utc.ymd(1969, 5, 6).and_hms(0, 0, 0);
+ let now = NaiveDate::from_ymd(1969, 5, 6).and_hms(0, 0, 0);
// two-week pay period beginning about a year *after* "now" on a Sunday
let config = Config::new()
- .pay_period_start(Some(Utc.ymd(1970, 4, 5)))
+ .pay_period_start(Some(NaiveDate::from_ymd(1970, 4, 5)))
.pay_period_length(14)
.now(now);
- let d1 = Utc.ymd(1969, 5, 4).and_hms(0, 0, 0);
- let d2 = Utc.ymd(1969, 5, 18).and_hms(0, 0, 0);
+ let d1 = NaiveDate::from_ymd(1969, 5, 4).and_hms(0, 0, 0);
+ let d2 = NaiveDate::from_ymd(1969, 5, 18).and_hms(0, 0, 0);
let (start, end, _) = parse("this pay period", Some(config)).unwrap();
assert_eq!(d1, start);
assert_eq!(d2, end);
@@ -534,14 +535,14 @@ fn this_pay_period_weird() {
#[test]
fn next_pay_period_weird() {
- let now = Utc.ymd(1969, 5, 6).and_hms(0, 0, 0);
+ let now = NaiveDate::from_ymd(1969, 5, 6).and_hms(0, 0, 0);
// two-week pay period beginning about a year *after* "now" on a Sunday
let config = Config::new()
- .pay_period_start(Some(Utc.ymd(1970, 4, 5)))
+ .pay_period_start(Some(NaiveDate::from_ymd(1970, 4, 5)))
.pay_period_length(14)
.now(now);
- let d1 = Utc.ymd(1969, 5, 18).and_hms(0, 0, 0);
- let d2 = Utc.ymd(1969, 6, 1).and_hms(0, 0, 0);
+ let d1 = NaiveDate::from_ymd(1969, 5, 18).and_hms(0, 0, 0);
+ let d2 = NaiveDate::from_ymd(1969, 6, 1).and_hms(0, 0, 0);
let (start, end, _) = parse("next pay period", Some(config)).unwrap();
assert_eq!(d1, start);
assert_eq!(d2, end);
@@ -549,14 +550,14 @@ fn next_pay_period_weird() {
#[test]
fn last_pay_period_weird() {
- let now = Utc.ymd(1969, 5, 6).and_hms(0, 0, 0);
+ let now = NaiveDate::from_ymd(1969, 5, 6).and_hms(0, 0, 0);
// two-week pay period beginning about a year *after* "now" on a Sunday
let config = Config::new()
- .pay_period_start(Some(Utc.ymd(1970, 4, 5)))
+ .pay_period_start(Some(NaiveDate::from_ymd(1970, 4, 5)))
.pay_period_length(14)
.now(now);
- let d1 = Utc.ymd(1969, 4, 20).and_hms(0, 0, 0);
- let d2 = Utc.ymd(1969, 5, 4).and_hms(0, 0, 0);
+ let d1 = NaiveDate::from_ymd(1969, 4, 20).and_hms(0, 0, 0);
+ let d2 = NaiveDate::from_ymd(1969, 5, 4).and_hms(0, 0, 0);
let (start, end, _) = parse("last pay period", Some(config)).unwrap();
assert_eq!(d1, start);
assert_eq!(d2, end);
@@ -564,9 +565,9 @@ fn last_pay_period_weird() {
#[test]
fn this_april() {
- let now = Utc.ymd(1969, 5, 6).and_hms(0, 0, 0);
- let d1 = Utc.ymd(1969, 4, 1).and_hms(0, 0, 0);
- let d2 = Utc.ymd(1969, 5, 1).and_hms(0, 0, 0);
+ let now = NaiveDate::from_ymd(1969, 5, 6).and_hms(0, 0, 0);
+ let d1 = NaiveDate::from_ymd(1969, 4, 1).and_hms(0, 0, 0);
+ let d2 = NaiveDate::from_ymd(1969, 5, 1).and_hms(0, 0, 0);
let (start, end, _) = parse("this april", Some(Config::new().now(now))).unwrap();
assert_eq!(d1, start);
assert_eq!(d2, end);
@@ -574,9 +575,9 @@ fn this_april() {
#[test]
fn next_april() {
- let now = Utc.ymd(1969, 5, 6).and_hms(0, 0, 0);
- let d1 = Utc.ymd(1970, 4, 1).and_hms(0, 0, 0);
- let d2 = Utc.ymd(1970, 5, 1).and_hms(0, 0, 0);
+ let now = NaiveDate::from_ymd(1969, 5, 6).and_hms(0, 0, 0);
+ let d1 = NaiveDate::from_ymd(1970, 4, 1).and_hms(0, 0, 0);
+ let d2 = NaiveDate::from_ymd(1970, 5, 1).and_hms(0, 0, 0);
let (start, end, _) = parse("next april", Some(Config::new().now(now))).unwrap();
assert_eq!(d1, start);
assert_eq!(d2, end);
@@ -584,9 +585,9 @@ fn next_april() {
#[test]
fn last_april() {
- let now = Utc.ymd(1969, 5, 6).and_hms(0, 0, 0);
- let d1 = Utc.ymd(1968, 4, 1).and_hms(0, 0, 0);
- let d2 = Utc.ymd(1968, 5, 1).and_hms(0, 0, 0);
+ let now = NaiveDate::from_ymd(1969, 5, 6).and_hms(0, 0, 0);
+ let d1 = NaiveDate::from_ymd(1968, 4, 1).and_hms(0, 0, 0);
+ let d2 = NaiveDate::from_ymd(1968, 5, 1).and_hms(0, 0, 0);
let (start, end, _) = parse("last april", Some(Config::new().now(now))).unwrap();
assert_eq!(d1, start);
assert_eq!(d2, end);
@@ -594,9 +595,9 @@ fn last_april() {
#[test]
fn this_friday() {
- let now = Utc.ymd(1969, 5, 6).and_hms(0, 0, 0);
- let d1 = Utc.ymd(1969, 5, 9).and_hms(0, 0, 0);
- let d2 = Utc.ymd(1969, 5, 10).and_hms(0, 0, 0);
+ let now = NaiveDate::from_ymd(1969, 5, 6).and_hms(0, 0, 0);
+ let d1 = NaiveDate::from_ymd(1969, 5, 9).and_hms(0, 0, 0);
+ let d2 = NaiveDate::from_ymd(1969, 5, 10).and_hms(0, 0, 0);
let (start, end, _) = parse("this friday", Some(Config::new().now(now))).unwrap();
assert_eq!(d1, start);
assert_eq!(d2, end);
@@ -604,9 +605,9 @@ fn this_friday() {
#[test]
fn next_friday() {
- let now = Utc.ymd(1969, 5, 6).and_hms(0, 0, 0);
- let d1 = Utc.ymd(1969, 5, 16).and_hms(0, 0, 0);
- let d2 = Utc.ymd(1969, 5, 17).and_hms(0, 0, 0);
+ let now = NaiveDate::from_ymd(1969, 5, 6).and_hms(0, 0, 0);
+ let d1 = NaiveDate::from_ymd(1969, 5, 16).and_hms(0, 0, 0);
+ let d2 = NaiveDate::from_ymd(1969, 5, 17).and_hms(0, 0, 0);
let (start, end, _) = parse("next friday", Some(Config::new().now(now))).unwrap();
assert_eq!(d1, start);
assert_eq!(d2, end);
@@ -614,9 +615,9 @@ fn next_friday() {
#[test]
fn last_friday() {
- let now = Utc.ymd(1969, 5, 6).and_hms(0, 0, 0);
- let d1 = Utc.ymd(1969, 5, 2).and_hms(0, 0, 0);
- let d2 = Utc.ymd(1969, 5, 3).and_hms(0, 0, 0);
+ let now = NaiveDate::from_ymd(1969, 5, 6).and_hms(0, 0, 0);
+ let d1 = NaiveDate::from_ymd(1969, 5, 2).and_hms(0, 0, 0);
+ let d2 = NaiveDate::from_ymd(1969, 5, 3).and_hms(0, 0, 0);
let (start, end, _) = parse("last friday", Some(Config::new().now(now))).unwrap();
assert_eq!(d1, start);
assert_eq!(d2, end);
@@ -624,9 +625,9 @@ fn last_friday() {
#[test]
fn this_monday() {
- let now = Utc.ymd(1969, 5, 6).and_hms(0, 0, 0);
- let d1 = Utc.ymd(1969, 5, 5).and_hms(0, 0, 0);
- let d2 = Utc.ymd(1969, 5, 6).and_hms(0, 0, 0);
+ let now = NaiveDate::from_ymd(1969, 5, 6).and_hms(0, 0, 0);
+ let d1 = NaiveDate::from_ymd(1969, 5, 5).and_hms(0, 0, 0);
+ let d2 = NaiveDate::from_ymd(1969, 5, 6).and_hms(0, 0, 0);
let (start, end, _) = parse("this monday", Some(Config::new().now(now))).unwrap();
assert_eq!(d1, start);
assert_eq!(d2, end);
@@ -634,9 +635,9 @@ fn this_monday() {
#[test]
fn next_monday() {
- let now = Utc.ymd(1969, 5, 6).and_hms(0, 0, 0);
- let d1 = Utc.ymd(1969, 5, 12).and_hms(0, 0, 0);
- let d2 = Utc.ymd(1969, 5, 13).and_hms(0, 0, 0);
+ let now = NaiveDate::from_ymd(1969, 5, 6).and_hms(0, 0, 0);
+ let d1 = NaiveDate::from_ymd(1969, 5, 12).and_hms(0, 0, 0);
+ let d2 = NaiveDate::from_ymd(1969, 5, 13).and_hms(0, 0, 0);
let (start, end, _) = parse("next monday", Some(Config::new().now(now))).unwrap();
assert_eq!(d1, start);
assert_eq!(d2, end);
@@ -644,9 +645,9 @@ fn next_monday() {
#[test]
fn last_monday() {
- let now = Utc.ymd(1969, 5, 6).and_hms(0, 0, 0);
- let d1 = Utc.ymd(1969, 4, 28).and_hms(0, 0, 0);
- let d2 = Utc.ymd(1969, 4, 29).and_hms(0, 0, 0);
+ let now = NaiveDate::from_ymd(1969, 5, 6).and_hms(0, 0, 0);
+ let d1 = NaiveDate::from_ymd(1969, 4, 28).and_hms(0, 0, 0);
+ let d2 = NaiveDate::from_ymd(1969, 4, 29).and_hms(0, 0, 0);
let (start, end, _) = parse("last monday", Some(Config::new().now(now))).unwrap();
assert_eq!(d1, start);
assert_eq!(d2, end);
@@ -654,7 +655,7 @@ fn last_monday() {
#[test]
fn dawn_of_time() {
- let then = chrono::MIN_DATE.and_hms_milli(0, 0, 0, 0);
+ let then = chrono::naive::MIN_DATE.and_hms_milli(0, 0, 0, 0);
for phrase in [
"the beginning",
"the beginning of time",
@@ -676,7 +677,7 @@ fn dawn_of_time() {
#[test]
fn the_crack_of_doom() {
- let then = chrono::MAX_DATE.and_hms_milli(23, 59, 59, 999);
+ let then = chrono::naive::MAX_DATE.and_hms_milli(23, 59, 59, 999);
for phrase in [
"the end",
"the end of time",
@@ -706,8 +707,8 @@ fn the_crack_of_doom() {
#[test]
fn friday() {
- let now = Utc.ymd(1969, 5, 6).and_hms(0, 0, 0);
- let then = Utc.ymd(1969, 5, 2).and_hms(0, 0, 0);
+ let now = NaiveDate::from_ymd(1969, 5, 6).and_hms(0, 0, 0);
+ let then = NaiveDate::from_ymd(1969, 5, 2).and_hms(0, 0, 0);
let (start, end, _) = parse("Friday", Some(Config::new().now(now))).unwrap();
assert_eq!(then, start);
assert_eq!(then + Duration::days(1), end);
@@ -715,8 +716,8 @@ fn friday() {
#[test]
fn tuesday() {
- let now = Utc.ymd(1969, 5, 6).and_hms(0, 0, 0);
- let then = Utc.ymd(1969, 4, 29).and_hms(0, 0, 0);
+ let now = NaiveDate::from_ymd(1969, 5, 6).and_hms(0, 0, 0);
+ let then = NaiveDate::from_ymd(1969, 4, 29).and_hms(0, 0, 0);
let (start, end, _) = parse("Tuesday", Some(Config::new().now(now))).unwrap();
assert_eq!(then, start);
assert_eq!(then + Duration::days(1), end);
@@ -724,8 +725,8 @@ fn tuesday() {
#[test]
fn monday() {
- let now = Utc.ymd(1969, 5, 6).and_hms(0, 0, 0);
- let then = Utc.ymd(1969, 5, 5).and_hms(0, 0, 0);
+ let now = NaiveDate::from_ymd(1969, 5, 6).and_hms(0, 0, 0);
+ let then = NaiveDate::from_ymd(1969, 5, 5).and_hms(0, 0, 0);
let (start, end, _) = parse("Monday", Some(Config::new().now(now))).unwrap();
assert_eq!(then, start);
assert_eq!(then + Duration::days(1), end);
@@ -733,8 +734,8 @@ fn monday() {
#[test]
fn friday_at_3_pm() {
- let now = Utc.ymd(1969, 5, 6).and_hms(0, 0, 0);
- let then = Utc.ymd(1969, 5, 2).and_hms(15, 0, 0);
+ let now = NaiveDate::from_ymd(1969, 5, 6).and_hms(0, 0, 0);
+ let then = NaiveDate::from_ymd(1969, 5, 2).and_hms(15, 0, 0);
let (start, end, _) = parse("Friday at 3 pm", Some(Config::new().now(now))).unwrap();
assert_eq!(then, start);
assert_eq!(then + Duration::hours(1), end);
@@ -742,8 +743,8 @@ fn friday_at_3_pm() {
#[test]
fn tuesday_at_3_pm() {
- let now = Utc.ymd(1969, 5, 6).and_hms(0, 0, 0);
- let then = Utc.ymd(1969, 4, 29).and_hms(15, 0, 0);
+ let now = NaiveDate::from_ymd(1969, 5, 6).and_hms(0, 0, 0);
+ let then = NaiveDate::from_ymd(1969, 4, 29).and_hms(15, 0, 0);
let (start, end, _) = parse("Tuesday at 3 pm", Some(Config::new().now(now))).unwrap();
assert_eq!(then, start);
assert_eq!(then + Duration::hours(1), end);
@@ -751,8 +752,8 @@ fn tuesday_at_3_pm() {
#[test]
fn monday_at_3_pm() {
- let now = Utc.ymd(1969, 5, 6).and_hms(0, 0, 0);
- let then = Utc.ymd(1969, 5, 5).and_hms(15, 0, 0);
+ let now = NaiveDate::from_ymd(1969, 5, 6).and_hms(0, 0, 0);
+ let then = NaiveDate::from_ymd(1969, 5, 5).and_hms(15, 0, 0);
let (start, end, _) = parse("Monday at 3 pm", Some(Config::new().now(now))).unwrap();
assert_eq!(then, start);
assert_eq!(then + Duration::hours(1), end);
@@ -760,9 +761,9 @@ fn monday_at_3_pm() {
#[test]
fn just_may() {
- let now = Utc.ymd(1969, 5, 6).and_hms(0, 0, 0);
- let d1 = Utc.ymd(1969, 5, 1).and_hms(0, 0, 0);
- let d2 = Utc.ymd(1969, 6, 1).and_hms(0, 0, 0);
+ let now = NaiveDate::from_ymd(1969, 5, 6).and_hms(0, 0, 0);
+ let d1 = NaiveDate::from_ymd(1969, 5, 1).and_hms(0, 0, 0);
+ let d2 = NaiveDate::from_ymd(1969, 6, 1).and_hms(0, 0, 0);
let (start, end, _) = parse("May", Some(Config::new().now(now))).unwrap();
assert_eq!(d1, start);
assert_eq!(d2, end);
@@ -770,9 +771,9 @@ fn just_may() {
#[test]
fn just_april() {
- let now = Utc.ymd(1969, 5, 6).and_hms(0, 0, 0);
- let d1 = Utc.ymd(1969, 4, 1).and_hms(0, 0, 0);
- let d2 = Utc.ymd(1969, 5, 1).and_hms(0, 0, 0);
+ let now = NaiveDate::from_ymd(1969, 5, 6).and_hms(0, 0, 0);
+ let d1 = NaiveDate::from_ymd(1969, 4, 1).and_hms(0, 0, 0);
+ let d2 = NaiveDate::from_ymd(1969, 5, 1).and_hms(0, 0, 0);
let (start, end, _) = parse("April", Some(Config::new().now(now))).unwrap();
assert_eq!(d1, start);
assert_eq!(d2, end);
@@ -780,9 +781,9 @@ fn just_april() {
#[test]
fn just_june() {
- let now = Utc.ymd(1969, 5, 6).and_hms(0, 0, 0);
- let d1 = Utc.ymd(1968, 6, 1).and_hms(0, 0, 0);
- let d2 = Utc.ymd(1968, 7, 1).and_hms(0, 0, 0);
+ let now = NaiveDate::from_ymd(1969, 5, 6).and_hms(0, 0, 0);
+ let d1 = NaiveDate::from_ymd(1968, 6, 1).and_hms(0, 0, 0);
+ let d2 = NaiveDate::from_ymd(1968, 7, 1).and_hms(0, 0, 0);
let (start, end, _) = parse("June", Some(Config::new().now(now))).unwrap();
assert_eq!(d1, start);
assert_eq!(d2, end);
@@ -790,9 +791,9 @@ fn just_june() {
#[test]
fn monday_through_friday() {
- let now = Utc.ymd(1969, 5, 6).and_hms(0, 0, 0);
- let d1 = Utc.ymd(1969, 5, 5).and_hms(0, 0, 0);
- let d2 = Utc.ymd(1969, 5, 10).and_hms(0, 0, 0);
+ let now = NaiveDate::from_ymd(1969, 5, 6).and_hms(0, 0, 0);
+ let d1 = NaiveDate::from_ymd(1969, 5, 5).and_hms(0, 0, 0);
+ let d2 = NaiveDate::from_ymd(1969, 5, 10).and_hms(0, 0, 0);
let (start, end, _) = parse("Monday through Friday", Some(Config::new().now(now))).unwrap();
assert_eq!(d1, start);
assert_eq!(d2, end);
@@ -800,9 +801,9 @@ fn monday_through_friday() {
#[test]
fn tuesday_through_friday() {
- let now = Utc.ymd(1969, 5, 6).and_hms(0, 0, 0);
- let d1 = Utc.ymd(1969, 4, 29).and_hms(0, 0, 0);
- let d2 = Utc.ymd(1969, 5, 3).and_hms(0, 0, 0);
+ let now = NaiveDate::from_ymd(1969, 5, 6).and_hms(0, 0, 0);
+ let d1 = NaiveDate::from_ymd(1969, 4, 29).and_hms(0, 0, 0);
+ let d2 = NaiveDate::from_ymd(1969, 5, 3).and_hms(0, 0, 0);
let (start, end, _) = parse("Tuesday through Friday", Some(Config::new().now(now))).unwrap();
assert_eq!(d1, start);
assert_eq!(d2, end);
@@ -810,9 +811,9 @@ fn tuesday_through_friday() {
#[test]
fn tuesday_through_3_pm_on_friday() {
- let now = Utc.ymd(1969, 5, 6).and_hms(0, 0, 0);
- let d1 = Utc.ymd(1969, 4, 29).and_hms(0, 0, 0);
- let d2 = Utc.ymd(1969, 5, 2).and_hms(15, 0, 0);
+ let now = NaiveDate::from_ymd(1969, 5, 6).and_hms(0, 0, 0);
+ let d1 = NaiveDate::from_ymd(1969, 4, 29).and_hms(0, 0, 0);
+ let d2 = NaiveDate::from_ymd(1969, 5, 2).and_hms(15, 0, 0);
let (start, end, _) = parse(
"Tuesday through 3 PM on Friday",
Some(Config::new().now(now)),
@@ -824,9 +825,9 @@ fn tuesday_through_3_pm_on_friday() {
#[test]
fn this_year_through_today() {
- let now = Utc.ymd(1969, 5, 6).and_hms(0, 0, 0);
- let d1 = Utc.ymd(1969, 1, 1).and_hms(0, 0, 0);
- let d2 = Utc.ymd(1969, 5, 7).and_hms(0, 0, 0);
+ let now = NaiveDate::from_ymd(1969, 5, 6).and_hms(0, 0, 0);
+ let d1 = NaiveDate::from_ymd(1969, 1, 1).and_hms(0, 0, 0);
+ let d2 = NaiveDate::from_ymd(1969, 5, 7).and_hms(0, 0, 0);
let (start, end, _) = parse("this year through today", Some(Config::new().now(now))).unwrap();
assert_eq!(d1, start);
assert_eq!(d2, end);
@@ -834,7 +835,7 @@ fn this_year_through_today() {
#[test]
fn april_3_25_bc() {
- let d1 = Utc.ymd(-24, 4, 3).and_hms(0, 0, 0);
+ let d1 = NaiveDate::from_ymd(-24, 4, 3).and_hms(0, 0, 0);
let d2 = d1 + Duration::days(1);
let (start, end, _) = parse("April 3, 25 BC", None).unwrap();
assert_eq!(d1, start);
@@ -843,9 +844,141 @@ fn april_3_25_bc() {
#[test]
fn april_3_25_ad() {
- let d1 = Utc.ymd(25, 4, 3).and_hms(0, 0, 0);
+ let d1 = NaiveDate::from_ymd(25, 4, 3).and_hms(0, 0, 0);
let d2 = d1 + Duration::days(1);
let (start, end, _) = parse("April 3, 25 AD", None).unwrap();
assert_eq!(d1, start);
assert_eq!(d2, end);
}
+
+#[test]
+fn this_weekend() {
+ let now = NaiveDate::from_ymd(1969, 5, 6).and_hms(0, 0, 0);
+ let d1 = NaiveDate::from_ymd(1969, 5, 10).and_hms(0, 0, 0);
+ let d2 = NaiveDate::from_ymd(1969, 5, 12).and_hms(0, 0, 0);
+ let (start, end, _) = parse("this weekend", Some(Config::new().now(now))).unwrap();
+ assert_eq!(d1, start);
+ assert_eq!(d2, end);
+}
+
+#[test]
+fn last_weekend() {
+ let now = NaiveDate::from_ymd(1969, 5, 6).and_hms(0, 0, 0);
+ let d1 = NaiveDate::from_ymd(1969, 5, 3).and_hms(0, 0, 0);
+ let d2 = NaiveDate::from_ymd(1969, 5, 5).and_hms(0, 0, 0);
+ let (start, end, _) = parse("last weekend", Some(Config::new().now(now))).unwrap();
+ assert_eq!(d1, start);
+ assert_eq!(d2, end);
+}
+
+#[test]
+fn next_weekend() {
+ let now = NaiveDate::from_ymd(1969, 5, 6).and_hms(0, 0, 0);
+ let d1 = NaiveDate::from_ymd(1969, 5, 17).and_hms(0, 0, 0);
+ let d2 = NaiveDate::from_ymd(1969, 5, 19).and_hms(0, 0, 0);
+ let (start, end, _) = parse("next weekend", Some(Config::new().now(now))).unwrap();
+ assert_eq!(d1, start);
+ assert_eq!(d2, end);
+}
+
+#[test]
+fn this_weekend_on_saturday() {
+ let now = NaiveDate::from_ymd(1969, 5, 10).and_hms(0, 0, 0);
+ let d1 = NaiveDate::from_ymd(1969, 5, 10).and_hms(0, 0, 0);
+ let d2 = NaiveDate::from_ymd(1969, 5, 12).and_hms(0, 0, 0);
+ let (start, end, _) = parse("this weekend", Some(Config::new().now(now))).unwrap();
+ assert_eq!(d1, start);
+ assert_eq!(d2, end);
+}
+
+#[test]
+fn last_weekend_on_saturday() {
+ let now = NaiveDate::from_ymd(1969, 5, 10).and_hms(0, 0, 0);
+ let d1 = NaiveDate::from_ymd(1969, 5, 3).and_hms(0, 0, 0);
+ let d2 = NaiveDate::from_ymd(1969, 5, 5).and_hms(0, 0, 0);
+ let (start, end, _) = parse("last weekend", Some(Config::new().now(now))).unwrap();
+ assert_eq!(d1, start);
+ assert_eq!(d2, end);
+}
+
+#[test]
+fn next_weekend_on_saturday() {
+ let now = NaiveDate::from_ymd(1969, 5, 10).and_hms(0, 0, 0);
+ let d1 = NaiveDate::from_ymd(1969, 5, 17).and_hms(0, 0, 0);
+ let d2 = NaiveDate::from_ymd(1969, 5, 19).and_hms(0, 0, 0);
+ let (start, end, _) = parse("next weekend", Some(Config::new().now(now))).unwrap();
+ assert_eq!(d1, start);
+ assert_eq!(d2, end);
+}
+
+#[test]
+fn this_weekend_on_sunday() {
+ let now = NaiveDate::from_ymd(1969, 5, 11).and_hms(0, 0, 0);
+ let d1 = NaiveDate::from_ymd(1969, 5, 10).and_hms(0, 0, 0);
+ let d2 = NaiveDate::from_ymd(1969, 5, 12).and_hms(0, 0, 0);
+ let (start, end, _) = parse("this weekend", Some(Config::new().now(now))).unwrap();
+ assert_eq!(d1, start);
+ assert_eq!(d2, end);
+}
+
+#[test]
+fn last_weekend_on_sunday() {
+ let now = NaiveDate::from_ymd(1969, 5, 11).and_hms(0, 0, 0);
+ let d1 = NaiveDate::from_ymd(1969, 5, 3).and_hms(0, 0, 0);
+ let d2 = NaiveDate::from_ymd(1969, 5, 5).and_hms(0, 0, 0);
+ let (start, end, _) = parse("last weekend", Some(Config::new().now(now))).unwrap();
+ assert_eq!(d1, start);
+ assert_eq!(d2, end);
+}
+
+#[test]
+fn next_weekend_on_sunday() {
+ let now = NaiveDate::from_ymd(1969, 5, 11).and_hms(0, 0, 0);
+ let d1 = NaiveDate::from_ymd(1969, 5, 17).and_hms(0, 0, 0);
+ let d2 = NaiveDate::from_ymd(1969, 5, 19).and_hms(0, 0, 0);
+ let (start, end, _) = parse("next weekend", Some(Config::new().now(now))).unwrap();
+ assert_eq!(d1, start);
+ assert_eq!(d2, end);
+}
+
+#[test]
+fn this_weekend_on_sunday_when_sunday_starts_week() {
+ let now = NaiveDate::from_ymd(1969, 5, 11).and_hms(0, 0, 0);
+ let d1 = NaiveDate::from_ymd(1969, 5, 10).and_hms(0, 0, 0);
+ let d2 = NaiveDate::from_ymd(1969, 5, 12).and_hms(0, 0, 0);
+ let (start, end, _) = parse(
+ "this weekend",
+ Some(Config::new().now(now).monday_starts_week(false)),
+ )
+ .unwrap();
+ assert_eq!(d1, start);
+ assert_eq!(d2, end);
+}
+
+#[test]
+fn last_weekend_on_sunday_when_sunday_starts_week() {
+ let now = NaiveDate::from_ymd(1969, 5, 11).and_hms(0, 0, 0);
+ let d1 = NaiveDate::from_ymd(1969, 5, 3).and_hms(0, 0, 0);
+ let d2 = NaiveDate::from_ymd(1969, 5, 5).and_hms(0, 0, 0);
+ let (start, end, _) = parse(
+ "last weekend",
+ Some(Config::new().now(now).monday_starts_week(false)),
+ )
+ .unwrap();
+ assert_eq!(d1, start);
+ assert_eq!(d2, end);
+}
+
+#[test]
+fn next_weekend_on_sunday_when_sunday_starts_week() {
+ let now = NaiveDate::from_ymd(1969, 5, 11).and_hms(0, 0, 0);
+ let d1 = NaiveDate::from_ymd(1969, 5, 17).and_hms(0, 0, 0);
+ let d2 = NaiveDate::from_ymd(1969, 5, 19).and_hms(0, 0, 0);
+ let (start, end, _) = parse(
+ "next weekend",
+ Some(Config::new().now(now).monday_starts_week(false)),
+ )
+ .unwrap();
+ assert_eq!(d1, start);
+ assert_eq!(d2, end);
+}