Compare commits

...

4 Commits

Author SHA1 Message Date
Savanni D'Gerinel 449d46479c Remove som old dependencies from ifc 2023-07-28 23:14:35 -04:00
Savanni D'Gerinel 4c2ec9e24e Convert from IFC back to Gregorian 2023-01-01 10:18:06 -05:00
Savanni D'Gerinel 97efdc9ae6 add conversion from Gregorian 2022-12-31 19:15:41 -05:00
Savanni D'Gerinel f5a7894662 Totally rebuild the IFC data structure
Wish I understood what I was thinking and what my thoughts were about with respect to the API.
2022-12-31 14:17:30 -05:00
4 changed files with 836 additions and 901 deletions

View File

@ -1,12 +1,15 @@
{ {
"nodes": { "nodes": {
"flake-utils": { "flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": { "locked": {
"lastModified": 1659877975, "lastModified": 1681202837,
"narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=", "narHash": "sha256-H+Rh19JDwRtpVPAWp64F+rlEtxUWBAQW28eAi3SRSzg=",
"owner": "numtide", "owner": "numtide",
"repo": "flake-utils", "repo": "flake-utils",
"rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0", "rev": "cfacdce06f30d2b68473a46042957675eebb3401",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -17,11 +20,11 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1672335022, "lastModified": 1685573264,
"narHash": "sha256-417aTRDZpob/UNsA4A0ilBUBQ0H8u+Wx9+OJAAygufQ=", "narHash": "sha256-Zffu01pONhs/pqH07cjlF10NnMDLok8ix5Uk4rhOnZQ=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "88eaf4a29b5b87a5f83fab413caba24cb13633f0", "rev": "380be19fbd2d9079f677978361792cb25e8a3635",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -32,11 +35,11 @@
}, },
"nixpkgs_2": { "nixpkgs_2": {
"locked": { "locked": {
"lastModified": 1665296151, "lastModified": 1681358109,
"narHash": "sha256-uOB0oxqxN9K7XGF1hcnY+PQnlQJ+3bP2vCn/+Ru/bbc=", "narHash": "sha256-eKyxW4OohHQx9Urxi7TQlFBTDWII+F+x2hklDOQPB50=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "14ccaaedd95a488dd7ae142757884d8e125b3363", "rev": "96ba1c52e54e74c3197f4d43026b3f3d92e83ff9",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -52,7 +55,7 @@
"nixpkgs": "nixpkgs_2" "nixpkgs": "nixpkgs_2"
}, },
"locked": { "locked": {
"narHash": "sha256-ruR2xo30Vn7kY2hAgg2Z2xrCvNePxck6mgR5a8u+zow=", "narHash": "sha256-SWqxUiEP9O2gvlWtR4Ku6rIMGM7PuNZreAPrU2yAjsk=",
"type": "tarball", "type": "tarball",
"url": "https://github.com/oxalica/rust-overlay/archive/master.tar.gz" "url": "https://github.com/oxalica/rust-overlay/archive/master.tar.gz"
}, },
@ -66,6 +69,21 @@
"nixpkgs": "nixpkgs", "nixpkgs": "nixpkgs",
"oxalica": "oxalica" "oxalica": "oxalica"
} }
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
} }
}, },
"root": "root", "root": "root",

1134
ifc/Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -8,18 +8,14 @@ keywords = ["date", "time", "calendar"]
categories = ["date-and-time"] categories = ["date-and-time"]
[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]] # [[bin]]
name = "ifc-today" # name = "ifc-today"
path = "src/today.rs" # path = "src/today.rs"
[[bin]] # [[bin]]
name = "ifc-web" # name = "ifc-web"
path = "src/web.rs" # path = "src/web.rs"

View File

@ -1,7 +1,13 @@
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 {
@ -92,6 +98,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,
@ -99,12 +242,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) {
@ -126,7 +266,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,
@ -143,7 +294,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())
@ -166,7 +319,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
@ -264,6 +419,7 @@ impl Datelike for IFC {
}) })
} }
} }
*/
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
@ -271,6 +427,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!(
@ -379,6 +876,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!(
@ -651,20 +1151,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)
} }
*/
} }