Compare commits

..

5 Commits

Author SHA1 Message Date
Savanni D'Gerinel e0a97878e8 Remove build targets 2023-07-28 23:23:25 -04:00
Savanni D'Gerinel 9ba402d54f Remove some old dependencies from ifc 2023-07-28 23:21:58 -04:00
Savanni D'Gerinel 58d9a12e9f Convert from IFC back to Gregorian 2023-07-28 23:17:14 -04:00
Savanni D'Gerinel 08029a2afd add conversion from Gregorian 2023-07-28 23:17:14 -04:00
Savanni D'Gerinel d4fc937613 Totally rebuild the IFC data structure
Wish I understood what I was thinking and what my thoughts were about with respect to the API.
2023-07-28 23:17:12 -04:00
4 changed files with 814 additions and 905 deletions

View File

@ -51,11 +51,11 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1681932375, "lastModified": 1688392541,
"narHash": "sha256-tSXbYmpnKSSWpzOrs27ie8X3I0yqKA6AuCzCYNtwbCU=", "narHash": "sha256-lHrKvEkCPTUO+7tPfjIcb7Trk6k31rz18vkyqmkeJfY=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "3d302c67ab8647327dba84fbdb443cdbf0e82744", "rev": "ea4c80b39be4c09702b0cb3b42eab59e2ba4f24b",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -103,11 +103,11 @@
"rust-overlay": "rust-overlay" "rust-overlay": "rust-overlay"
}, },
"locked": { "locked": {
"lastModified": 1655189312, "lastModified": 1682891040,
"narHash": "sha256-gpJ57OgIebUpO+7F00VltxSEy6dz2x6HeJ5BcRM8rDA=", "narHash": "sha256-hjajsi7lq24uYitUh4o04UJi1g0Qe6ruPL0s5DgPQMY=",
"owner": "cargo2nix", "owner": "cargo2nix",
"repo": "cargo2nix", "repo": "cargo2nix",
"rev": "c149357cc3d17f2849c73eb7a09d07a307cdcfe8", "rev": "0167b39f198d72acdf009265634504fd6f5ace15",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -170,11 +170,11 @@
"nixpkgs": "nixpkgs_3" "nixpkgs": "nixpkgs_3"
}, },
"locked": { "locked": {
"lastModified": 1683230849, "lastModified": 1690502632,
"narHash": "sha256-PjIKxX1xIALyWD8NyDeoIZMMfsS4/w/AweAcYOcsLNs=", "narHash": "sha256-+k81RrxfphDUD5kekWbQ4xuZIHBEAQf67uivaQ34Afs=",
"owner": "1Password", "owner": "1Password",
"repo": "typeshare", "repo": "typeshare",
"rev": "2687f8d86ef38c07819715a2f31a21ffc25504e4", "rev": "9f74772af53759aee2f53e64478523e53083719e",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -185,11 +185,11 @@
}, },
"unstable": { "unstable": {
"locked": { "locked": {
"lastModified": 1681920287, "lastModified": 1690367991,
"narHash": "sha256-+/d6XQQfhhXVfqfLROJoqj3TuG38CAeoT6jO1g9r1k0=", "narHash": "sha256-2VwOn1l8y6+cu7zjNE8MgeGJNNz1eat1HwHrINeogFA=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "645bc49f34fa8eff95479f0345ff57e55b53437e", "rev": "c9cf0708f00fbe553319258e48ca89ff9a413703",
"type": "github" "type": "github"
}, },
"original": { "original": {

1134
ifc/Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -10,18 +10,6 @@ license = "GPL-3.0-only"
license-file = "../COPYING" license-file = "../COPYING"
[dependencies] [dependencies]
chrono = "0.4" chrono = { version = "0.4" }
chrono-tz = "0.6"
iron = "0.6.1"
mustache = "0.9.0"
params = "*"
router = "*"
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
thiserror = { version = "1" }
[[bin]]
name = "ifc-today"
path = "src/today.rs"
[[bin]]
name = "ifc-web"
path = "src/web.rs"

View File

@ -10,10 +10,16 @@ Luminescent Dreams Tools is distributed in the hope that it will be useful, but
You should have received a copy of the GNU General Public License along with Lumeto. If not, see <https://www.gnu.org/licenses/>. You should have received a copy of the GNU General Public License along with Lumeto. If not, see <https://www.gnu.org/licenses/>.
*/ */
extern crate chrono;
extern crate chrono_tz;
use chrono::{Datelike, NaiveDate}; use chrono::{Datelike, NaiveDate};
use serde::{Deserialize, Serialize};
use std::convert::TryInto;
use thiserror::Error;
#[derive(Clone, Debug, Error, PartialEq)]
pub enum Error {
#[error("invalid date")]
InvalidDate,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)] #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub enum DayOfWeek { pub enum DayOfWeek {
@ -104,6 +110,143 @@ impl From<Month> for String {
} }
} }
fn is_leap_year(year: i32) -> bool {
NaiveDate::from_ymd_opt(year, 12, 31).unwrap().ordinal() == 366
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub enum IFC {
LeapDay(i32),
YearDay(i32),
Day(Day),
}
impl IFC {
pub fn leap_day(year: i32) -> Result<Self, Error> {
if is_leap_year(year) {
Ok(Self::LeapDay(year))
} else {
Err(Error::InvalidDate)
}
}
pub fn year_day(year: i32) -> Self {
Self::YearDay(year)
}
pub fn ymd(year: i32, month: u8, day: u8) -> Result<Self, Error> {
if month < 1 || month > 13 {
Err(Error::InvalidDate)
} else if day < 1 || day > 28 {
Err(Error::InvalidDate)
} else {
Ok(Self::Day(Day { year, month, day }))
}
}
pub fn year(&self) -> i32 {
match *self {
IFC::LeapDay(year) => year,
IFC::YearDay(year) => year,
IFC::Day(Day { year, .. }) => year,
}
}
pub fn day_of_week(&self) -> DayOfWeek {
match *self {
IFC::LeapDay(_) => DayOfWeek::LeapDay,
IFC::YearDay(_) => DayOfWeek::YearDay,
IFC::Day(Day { day, .. }) => match (day - 1) % 7 {
0 => DayOfWeek::Sunday,
1 => DayOfWeek::Monday,
2 => DayOfWeek::Tuesday,
3 => DayOfWeek::Wednesday,
4 => DayOfWeek::Thursday,
5 => DayOfWeek::Friday,
6 => DayOfWeek::Saturday,
_ => panic!("impossible calculation"),
},
}
}
pub fn day_ordinal(&self) -> u32 {
self.day_ordinal0() + 1
}
pub fn day_ordinal0(&self) -> u32 {
match *self {
IFC::LeapDay(_) => 168,
IFC::YearDay(year) => {
if is_leap_year(year) {
365
} else {
364
}
}
IFC::Day(Day { year, month, day }) => {
u32::from(month - 1) * 28
+ u32::from(day - 1)
+ if is_leap_year(year) && month > 6 {
1
} else {
0
}
}
}
}
pub fn week_ordinal(&self) -> u32 {
self.week_ordinal0() + 1
}
pub fn week_ordinal0(&self) -> u32 {
match *self {
IFC::LeapDay(_) => 0,
IFC::YearDay(_) => 0,
IFC::Day(Day { month, day, .. }) => u32::from(month - 1) * 4 + (u32::from(day - 1) / 7),
}
}
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct Day {
year: i32,
month: u8,
day: u8,
}
impl From<chrono::NaiveDate> for IFC {
fn from(date: chrono::NaiveDate) -> Self {
if date.month() == 12 && date.day() == 31 {
Self::YearDay(date.year())
} else if is_leap_year(date.year()) && date.month() == 6 && date.day() == 17 {
Self::LeapDay(date.year())
} else {
let mut days = date.ordinal();
if is_leap_year(date.year())
&& date > NaiveDate::from_ymd_opt(date.year(), 6, 17).unwrap()
{
days = days - 1;
}
let month: u8 = (days / 28).try_into().unwrap();
let day: u8 = (days % 28).try_into().unwrap();
Self::Day(Day {
year: date.year(),
month: month + 1,
day,
})
}
}
}
impl From<IFC> for chrono::NaiveDate {
fn from(ifc: IFC) -> Self {
Self::from_ymd_opt(ifc.year(), 1, 1).unwrap()
+ chrono::naive::Days::new(ifc.day_ordinal0().into())
}
}
/*
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)] #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub struct IFC { pub struct IFC {
year: u32, year: u32,
@ -111,12 +254,9 @@ pub struct IFC {
leap_year: bool, leap_year: bool,
} }
fn is_leap_year(year: i32) -> bool {
NaiveDate::from_ymd(year, 12, 31).ordinal() == 366
}
impl IFC { impl IFC {
pub fn ymd(year: u32, month: u8, day: u8) -> IFC { pub fn ymd(year: u32, month: u8, day: u8) -> Self {
let leap_year = is_leap_year(year as i32 - 10000); let leap_year = is_leap_year(year as i32 - 10000);
let ordinal = if is_leap_year(year as i32 - 10000) { let ordinal = if is_leap_year(year as i32 - 10000) {
@ -138,7 +278,18 @@ impl IFC {
} }
} }
pub fn weekday_ifc(&self) -> DayOfWeek { pub fn year_day(year: u32) -> Self {
Self {
year,
ordinal: if is_leap_year(year) { 366 } else { 365 }
}
}
pub fn leap_day(year: u32) -> Result<IFC, Error> {
}
pub fn weekday(&self) -> DayOfWeek {
// if self.day.ordinal ==
match self.day() % 7 { match self.day() % 7 {
0 => DayOfWeek::Saturday, 0 => DayOfWeek::Saturday,
1 => DayOfWeek::Sunday, 1 => DayOfWeek::Sunday,
@ -155,7 +306,9 @@ impl IFC {
Month::from(self.month()) Month::from(self.month())
} }
} }
*/
/*
impl From<chrono::Date<chrono::Utc>> for IFC { impl From<chrono::Date<chrono::Utc>> for IFC {
fn from(d: chrono::Date<chrono::Utc>) -> IFC { fn from(d: chrono::Date<chrono::Utc>) -> IFC {
IFC::from(d.naive_utc()) IFC::from(d.naive_utc())
@ -178,7 +331,9 @@ impl From<chrono::NaiveDate> for IFC {
} }
} }
} }
*/
/*
impl Datelike for IFC { impl Datelike for IFC {
fn year(&self) -> i32 { fn year(&self) -> i32 {
self.year as i32 self.year as i32
@ -276,6 +431,7 @@ impl Datelike for IFC {
}) })
} }
} }
*/
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
@ -283,6 +439,347 @@ mod tests {
use chrono::NaiveDate; use chrono::NaiveDate;
#[test]
fn creates_a_day() {
assert_eq!(IFC::leap_day(12020), Ok(IFC::LeapDay(12020)));
assert_eq!(IFC::year_day(12020), IFC::YearDay(12020));
assert_eq!(
IFC::ymd(12022, 13, 28),
Ok(IFC::Day(Day {
year: 12022,
month: 13,
day: 28
}))
);
}
#[test]
fn rejects_invalid_dates() {
assert_eq!(IFC::leap_day(12022), Err(Error::InvalidDate));
assert_eq!(IFC::ymd(12022, 13, 0), Err(Error::InvalidDate));
assert_eq!(IFC::ymd(12022, 14, 1), Err(Error::InvalidDate));
}
#[test]
fn it_expresses_day_of_week() {
assert_eq!(
IFC::leap_day(12020).unwrap().day_of_week(),
DayOfWeek::LeapDay
);
assert_eq!(IFC::year_day(12022).day_of_week(), DayOfWeek::YearDay);
assert_eq!(
IFC::ymd(12022, 1, 1).unwrap().day_of_week(),
DayOfWeek::Sunday
);
assert_eq!(
IFC::ymd(12022, 1, 2).unwrap().day_of_week(),
DayOfWeek::Monday
);
assert_eq!(
IFC::ymd(12022, 1, 3).unwrap().day_of_week(),
DayOfWeek::Tuesday
);
assert_eq!(
IFC::ymd(12022, 1, 4).unwrap().day_of_week(),
DayOfWeek::Wednesday
);
assert_eq!(
IFC::ymd(12022, 1, 5).unwrap().day_of_week(),
DayOfWeek::Thursday
);
assert_eq!(
IFC::ymd(12022, 1, 6).unwrap().day_of_week(),
DayOfWeek::Friday
);
assert_eq!(
IFC::ymd(12022, 1, 7).unwrap().day_of_week(),
DayOfWeek::Saturday
);
assert_eq!(
IFC::ymd(12022, 1, 8).unwrap().day_of_week(),
DayOfWeek::Sunday
);
}
#[test]
fn it_reports_ordinal_days() {
assert_eq!(IFC::ymd(12022, 1, 1).unwrap().day_ordinal(), 1);
assert_eq!(IFC::ymd(12022, 1, 1).unwrap().day_ordinal0(), 0);
assert_eq!(IFC::ymd(12022, 1, 28).unwrap().day_ordinal(), 28);
assert_eq!(IFC::ymd(12022, 1, 28).unwrap().day_ordinal0(), 27);
assert_eq!(IFC::ymd(12022, 2, 1).unwrap().day_ordinal(), 29);
assert_eq!(IFC::ymd(12022, 2, 1).unwrap().day_ordinal0(), 28);
assert_eq!(IFC::ymd(12022, 3, 1).unwrap().day_ordinal(), 57);
assert_eq!(IFC::ymd(12022, 3, 1).unwrap().day_ordinal0(), 56);
assert_eq!(IFC::ymd(12022, 4, 1).unwrap().day_ordinal(), 85);
assert_eq!(IFC::ymd(12022, 4, 1).unwrap().day_ordinal0(), 84);
assert_eq!(IFC::ymd(12022, 5, 1).unwrap().day_ordinal(), 113);
assert_eq!(IFC::ymd(12022, 5, 1).unwrap().day_ordinal0(), 112);
assert_eq!(IFC::ymd(12022, 6, 1).unwrap().day_ordinal(), 141);
assert_eq!(IFC::ymd(12022, 6, 1).unwrap().day_ordinal0(), 140);
assert_eq!(IFC::ymd(12022, 7, 1).unwrap().day_ordinal(), 169);
assert_eq!(IFC::ymd(12022, 7, 1).unwrap().day_ordinal0(), 168);
assert_eq!(IFC::ymd(12022, 8, 1).unwrap().day_ordinal(), 197);
assert_eq!(IFC::ymd(12022, 8, 1).unwrap().day_ordinal0(), 196);
assert_eq!(IFC::ymd(12022, 9, 1).unwrap().day_ordinal(), 225);
assert_eq!(IFC::ymd(12022, 9, 1).unwrap().day_ordinal0(), 224);
assert_eq!(IFC::ymd(12022, 10, 1).unwrap().day_ordinal(), 253);
assert_eq!(IFC::ymd(12022, 10, 1).unwrap().day_ordinal0(), 252);
assert_eq!(IFC::ymd(12022, 11, 1).unwrap().day_ordinal(), 281);
assert_eq!(IFC::ymd(12022, 11, 1).unwrap().day_ordinal0(), 280);
assert_eq!(IFC::ymd(12022, 12, 1).unwrap().day_ordinal(), 309);
assert_eq!(IFC::ymd(12022, 12, 1).unwrap().day_ordinal0(), 308);
assert_eq!(IFC::ymd(12022, 13, 1).unwrap().day_ordinal(), 337);
assert_eq!(IFC::ymd(12022, 13, 1).unwrap().day_ordinal0(), 336);
assert_eq!(IFC::ymd(12022, 13, 28).unwrap().day_ordinal(), 364);
assert_eq!(IFC::ymd(12022, 13, 28).unwrap().day_ordinal0(), 363);
assert_eq!(IFC::year_day(12022).day_ordinal(), 365);
}
#[test]
fn it_reports_ordinal_days_on_leap_year() {
assert_eq!(IFC::ymd(12020, 1, 1).unwrap().day_ordinal(), 1);
assert_eq!(IFC::ymd(12020, 1, 1).unwrap().day_ordinal0(), 0);
assert_eq!(IFC::ymd(12020, 1, 28).unwrap().day_ordinal(), 28);
assert_eq!(IFC::ymd(12020, 1, 28).unwrap().day_ordinal0(), 27);
assert_eq!(IFC::ymd(12020, 2, 1).unwrap().day_ordinal(), 29);
assert_eq!(IFC::ymd(12020, 2, 1).unwrap().day_ordinal0(), 28);
assert_eq!(IFC::ymd(12020, 3, 1).unwrap().day_ordinal(), 57);
assert_eq!(IFC::ymd(12020, 3, 1).unwrap().day_ordinal0(), 56);
assert_eq!(IFC::ymd(12020, 4, 1).unwrap().day_ordinal(), 85);
assert_eq!(IFC::ymd(12020, 4, 1).unwrap().day_ordinal0(), 84);
assert_eq!(IFC::ymd(12020, 5, 1).unwrap().day_ordinal(), 113);
assert_eq!(IFC::ymd(12020, 5, 1).unwrap().day_ordinal0(), 112);
assert_eq!(IFC::ymd(12020, 6, 1).unwrap().day_ordinal(), 141);
assert_eq!(IFC::ymd(12020, 6, 1).unwrap().day_ordinal0(), 140);
assert_eq!(IFC::leap_day(12020).unwrap().day_ordinal(), 169);
assert_eq!(IFC::leap_day(12020).unwrap().day_ordinal0(), 168);
assert_eq!(IFC::ymd(12020, 7, 1).unwrap().day_ordinal(), 170);
assert_eq!(IFC::ymd(12020, 7, 1).unwrap().day_ordinal0(), 169);
assert_eq!(IFC::ymd(12020, 8, 1).unwrap().day_ordinal(), 198);
assert_eq!(IFC::ymd(12020, 8, 1).unwrap().day_ordinal0(), 197);
assert_eq!(IFC::ymd(12020, 9, 1).unwrap().day_ordinal(), 226);
assert_eq!(IFC::ymd(12020, 9, 1).unwrap().day_ordinal0(), 225);
assert_eq!(IFC::ymd(12020, 10, 1).unwrap().day_ordinal(), 254);
assert_eq!(IFC::ymd(12020, 10, 1).unwrap().day_ordinal0(), 253);
assert_eq!(IFC::ymd(12020, 11, 1).unwrap().day_ordinal(), 282);
assert_eq!(IFC::ymd(12020, 11, 1).unwrap().day_ordinal0(), 281);
assert_eq!(IFC::ymd(12020, 12, 1).unwrap().day_ordinal(), 310);
assert_eq!(IFC::ymd(12020, 12, 1).unwrap().day_ordinal0(), 309);
assert_eq!(IFC::ymd(12020, 13, 1).unwrap().day_ordinal(), 338);
assert_eq!(IFC::ymd(12020, 13, 1).unwrap().day_ordinal0(), 337);
assert_eq!(IFC::ymd(12020, 13, 28).unwrap().day_ordinal(), 365);
assert_eq!(IFC::ymd(12020, 13, 28).unwrap().day_ordinal0(), 364);
assert_eq!(IFC::year_day(12020).day_ordinal(), 366);
}
#[test]
fn it_reports_ordinal_weeks() {
assert_eq!(IFC::ymd(12022, 1, 1).unwrap().week_ordinal(), 1);
assert_eq!(IFC::ymd(12022, 1, 1).unwrap().week_ordinal0(), 0);
assert_eq!(IFC::ymd(12022, 1, 4).unwrap().week_ordinal(), 1);
assert_eq!(IFC::ymd(12022, 1, 4).unwrap().week_ordinal0(), 0);
assert_eq!(IFC::ymd(12022, 1, 7).unwrap().week_ordinal(), 1);
assert_eq!(IFC::ymd(12022, 1, 7).unwrap().week_ordinal0(), 0);
assert_eq!(IFC::ymd(12022, 1, 8).unwrap().week_ordinal(), 2);
assert_eq!(IFC::ymd(12022, 1, 8).unwrap().week_ordinal0(), 1);
assert_eq!(IFC::ymd(12022, 2, 1).unwrap().week_ordinal(), 5);
assert_eq!(IFC::ymd(12022, 2, 1).unwrap().week_ordinal0(), 4);
assert_eq!(IFC::ymd(12022, 13, 28).unwrap().week_ordinal(), 52);
assert_eq!(IFC::ymd(12022, 13, 28).unwrap().week_ordinal0(), 51);
}
#[test]
fn it_converts_from_gregorian() {
assert_eq!(
IFC::from(NaiveDate::from_ymd_opt(12022, 1, 1).unwrap()),
IFC::ymd(12022, 1, 1).unwrap()
);
assert_eq!(
IFC::from(NaiveDate::from_ymd_opt(12022, 1, 29).unwrap()),
IFC::ymd(12022, 2, 1).unwrap()
);
assert_eq!(
IFC::from(NaiveDate::from_ymd_opt(12022, 2, 26).unwrap()),
IFC::ymd(12022, 3, 1).unwrap()
);
assert_eq!(
IFC::from(NaiveDate::from_ymd_opt(12022, 3, 26).unwrap()),
IFC::ymd(12022, 4, 1).unwrap()
);
assert_eq!(
IFC::from(NaiveDate::from_ymd_opt(12022, 4, 23).unwrap()),
IFC::ymd(12022, 5, 1).unwrap()
);
assert_eq!(
IFC::from(NaiveDate::from_ymd_opt(12022, 5, 21).unwrap()),
IFC::ymd(12022, 6, 1).unwrap()
);
assert_eq!(
IFC::from(NaiveDate::from_ymd_opt(12022, 6, 18).unwrap()),
IFC::ymd(12022, 7, 1).unwrap()
);
assert_eq!(
IFC::from(NaiveDate::from_ymd_opt(12022, 7, 16).unwrap()),
IFC::ymd(12022, 8, 1).unwrap()
);
assert_eq!(
IFC::from(NaiveDate::from_ymd_opt(12022, 8, 13).unwrap()),
IFC::ymd(12022, 9, 1).unwrap()
);
assert_eq!(
IFC::from(NaiveDate::from_ymd_opt(12022, 9, 10).unwrap()),
IFC::ymd(12022, 10, 1).unwrap()
);
assert_eq!(
IFC::from(NaiveDate::from_ymd_opt(12022, 10, 8).unwrap()),
IFC::ymd(12022, 11, 1).unwrap()
);
assert_eq!(
IFC::from(NaiveDate::from_ymd_opt(12022, 11, 5).unwrap()),
IFC::ymd(12022, 12, 1).unwrap()
);
assert_eq!(
IFC::from(NaiveDate::from_ymd_opt(12022, 12, 3).unwrap()),
IFC::ymd(12022, 13, 1).unwrap()
);
assert_eq!(
IFC::from(NaiveDate::from_ymd_opt(12022, 12, 31).unwrap()),
IFC::YearDay(12022)
);
}
#[test]
fn it_converts_from_gregorian_on_leap_year() {
assert_eq!(
IFC::from(NaiveDate::from_ymd_opt(12020, 1, 1).unwrap()),
IFC::ymd(12020, 1, 1).unwrap()
);
assert_eq!(
IFC::from(NaiveDate::from_ymd_opt(12020, 1, 29).unwrap()),
IFC::ymd(12020, 2, 1).unwrap()
);
assert_eq!(
IFC::from(NaiveDate::from_ymd_opt(12020, 2, 26).unwrap()),
IFC::ymd(12020, 3, 1).unwrap()
);
assert_eq!(
IFC::from(NaiveDate::from_ymd_opt(12020, 2, 28).unwrap()),
IFC::ymd(12020, 3, 3).unwrap()
);
assert_eq!(
IFC::from(NaiveDate::from_ymd_opt(12020, 2, 29).unwrap()),
IFC::ymd(12020, 3, 4).unwrap()
);
assert_eq!(
IFC::from(NaiveDate::from_ymd_opt(12020, 3, 1).unwrap()),
IFC::ymd(12020, 3, 5).unwrap()
);
assert_eq!(
IFC::from(NaiveDate::from_ymd_opt(12020, 3, 25).unwrap()),
IFC::ymd(12020, 4, 1).unwrap()
);
assert_eq!(
IFC::from(NaiveDate::from_ymd_opt(12020, 4, 22).unwrap()),
IFC::ymd(12020, 5, 1).unwrap()
);
assert_eq!(
IFC::from(NaiveDate::from_ymd_opt(12020, 5, 20).unwrap()),
IFC::ymd(12020, 6, 1).unwrap()
);
assert_eq!(
IFC::from(NaiveDate::from_ymd_opt(12020, 6, 17).unwrap()),
IFC::LeapDay(12020)
);
assert_eq!(
IFC::from(NaiveDate::from_ymd_opt(12020, 6, 18).unwrap()),
IFC::ymd(12020, 7, 1).unwrap()
);
assert_eq!(
IFC::from(NaiveDate::from_ymd_opt(12020, 7, 16).unwrap()),
IFC::ymd(12020, 8, 1).unwrap()
);
assert_eq!(
IFC::from(NaiveDate::from_ymd_opt(12020, 8, 13).unwrap()),
IFC::ymd(12020, 9, 1).unwrap()
);
assert_eq!(
IFC::from(NaiveDate::from_ymd_opt(12020, 9, 10).unwrap()),
IFC::ymd(12020, 10, 1).unwrap()
);
assert_eq!(
IFC::from(NaiveDate::from_ymd_opt(12020, 10, 8).unwrap()),
IFC::ymd(12020, 11, 1).unwrap()
);
assert_eq!(
IFC::from(NaiveDate::from_ymd_opt(12020, 11, 5).unwrap()),
IFC::ymd(12020, 12, 1).unwrap()
);
assert_eq!(
IFC::from(NaiveDate::from_ymd_opt(12020, 12, 3).unwrap()),
IFC::ymd(12020, 13, 1).unwrap()
);
assert_eq!(
IFC::from(NaiveDate::from_ymd_opt(12020, 12, 31).unwrap()),
IFC::YearDay(12020)
);
}
#[test]
fn it_converts_to_gregorian() {
assert_eq!(
NaiveDate::from(IFC::ymd(12020, 1, 1).unwrap()),
NaiveDate::from_ymd_opt(12020, 1, 1).unwrap()
);
assert_eq!(
NaiveDate::from(IFC::leap_day(12020).unwrap()),
NaiveDate::from_ymd_opt(12020, 6, 17).unwrap()
);
assert_eq!(
NaiveDate::from(IFC::ymd(12020, 3, 4).unwrap()),
NaiveDate::from_ymd_opt(12020, 2, 29).unwrap()
);
assert_eq!(
NaiveDate::from(IFC::year_day(12020)),
NaiveDate::from_ymd_opt(12020, 12, 31).unwrap()
);
}
/*
#[test] #[test]
fn check_start_of_month() { fn check_start_of_month() {
assert_eq!( assert_eq!(
@ -391,6 +888,9 @@ mod tests {
); );
} }
#[test]
fn report_leap_day() {}
#[test] #[test]
fn check_start_of_month_leap_year() { fn check_start_of_month_leap_year() {
assert_eq!( assert_eq!(
@ -663,20 +1163,25 @@ mod tests {
assert_eq!(IFC::ymd(12019, 13, 29).day(), 29); assert_eq!(IFC::ymd(12019, 13, 29).day(), 29);
assert_eq!(IFC::ymd(12019, 13, 29).day0(), 28); assert_eq!(IFC::ymd(12019, 13, 29).day0(), 28);
} }
*/
/*
#[test] #[test]
fn it_reports_correct_day_of_week() { fn it_reports_correct_day_of_week() {
assert_eq!(IFC::ymd(12019, 1, 1).weekday(), chrono::Weekday::Sun); assert_eq!(IFC::ymd(12019, 1, 1).weekday(), DayOfWeek::Sunday);
assert_eq!(IFC::ymd(12019, 6, 1).weekday(), chrono::Weekday::Sun); assert_eq!(IFC::ymd(12019, 6, 1).weekday(), DayOfWeek::Sunday);
assert_eq!(IFC::ymd(12019, 6, 28).weekday(), chrono::Weekday::Sat); assert_eq!(IFC::ymd(12019, 6, 28).weekday(), DayOfWeek::Saturday);
assert_eq!(IFC::ymd(12019, 7, 1).weekday(), chrono::Weekday::Sun); assert_eq!(IFC::ymd(12019, 7, 1).weekday(), DayOfWeek::Sunday);
assert_eq!(IFC::ymd(12019, 13, 28).weekday(), chrono::Weekday::Sat); assert_eq!(IFC::ymd(12019, 13, 28).weekday(), DayOfWeek::Saturday);
assert_eq!(IFC::ymd(12019, 13, 29).weekday(), chrono::Weekday::Sat); assert_eq!(IFC::ymd(12019, 13, 29).weekday(), DayOfWeek::Saturday);
assert_eq!(IFC::ymd(12020, 6, 28).weekday(), chrono::Weekday::Sat); assert_eq!(IFC::ymd(12020, 6, 28).weekday(), DayOfWeek::Saturday);
assert_eq!(IFC::ymd(12020, 6, 29).weekday(), chrono::Weekday::Sat); assert_eq!(IFC::ymd(12020, 6, 29).weekday(), DayOfWeek::Saturday);
assert_eq!(IFC::ymd(12020, 7, 1).weekday(), chrono::Weekday::Sun); assert_eq!(IFC::ymd(12020, 7, 1).weekday(), DayOfWeek::Sunday);
assert_eq!(IFC::ymd(12020, 13, 28).weekday(), chrono::Weekday::Sat); assert_eq!(IFC::ymd(12020, 13, 28).weekday(), DayOfWeek::Saturday);
assert_eq!(IFC::ymd(12020, 13, 29).weekday(), chrono::Weekday::Sat); assert_eq!(IFC::ymd(12020, 13, 29).weekday(), DayOfWeek::Saturday);
assert_eq!(IFC::ymd(12022, 13, 31)
} }
*/
} }