Compare commits
No commits in common. "e0a97878e874e7c9ebe13b761f1dc20c92b2891f" and "9130aa5c77bc68fbdb7ffdbcb2730129fdd9df11" have entirely different histories.
e0a97878e8
...
9130aa5c77
24
flake.lock
24
flake.lock
|
@ -51,11 +51,11 @@
|
|||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1688392541,
|
||||
"narHash": "sha256-lHrKvEkCPTUO+7tPfjIcb7Trk6k31rz18vkyqmkeJfY=",
|
||||
"lastModified": 1681932375,
|
||||
"narHash": "sha256-tSXbYmpnKSSWpzOrs27ie8X3I0yqKA6AuCzCYNtwbCU=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "ea4c80b39be4c09702b0cb3b42eab59e2ba4f24b",
|
||||
"rev": "3d302c67ab8647327dba84fbdb443cdbf0e82744",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -103,11 +103,11 @@
|
|||
"rust-overlay": "rust-overlay"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1682891040,
|
||||
"narHash": "sha256-hjajsi7lq24uYitUh4o04UJi1g0Qe6ruPL0s5DgPQMY=",
|
||||
"lastModified": 1655189312,
|
||||
"narHash": "sha256-gpJ57OgIebUpO+7F00VltxSEy6dz2x6HeJ5BcRM8rDA=",
|
||||
"owner": "cargo2nix",
|
||||
"repo": "cargo2nix",
|
||||
"rev": "0167b39f198d72acdf009265634504fd6f5ace15",
|
||||
"rev": "c149357cc3d17f2849c73eb7a09d07a307cdcfe8",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -170,11 +170,11 @@
|
|||
"nixpkgs": "nixpkgs_3"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1690502632,
|
||||
"narHash": "sha256-+k81RrxfphDUD5kekWbQ4xuZIHBEAQf67uivaQ34Afs=",
|
||||
"lastModified": 1683230849,
|
||||
"narHash": "sha256-PjIKxX1xIALyWD8NyDeoIZMMfsS4/w/AweAcYOcsLNs=",
|
||||
"owner": "1Password",
|
||||
"repo": "typeshare",
|
||||
"rev": "9f74772af53759aee2f53e64478523e53083719e",
|
||||
"rev": "2687f8d86ef38c07819715a2f31a21ffc25504e4",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -185,11 +185,11 @@
|
|||
},
|
||||
"unstable": {
|
||||
"locked": {
|
||||
"lastModified": 1690367991,
|
||||
"narHash": "sha256-2VwOn1l8y6+cu7zjNE8MgeGJNNz1eat1HwHrINeogFA=",
|
||||
"lastModified": 1681920287,
|
||||
"narHash": "sha256-+/d6XQQfhhXVfqfLROJoqj3TuG38CAeoT6jO1g9r1k0=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "c9cf0708f00fbe553319258e48ca89ff9a413703",
|
||||
"rev": "645bc49f34fa8eff95479f0345ff57e55b53437e",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -10,6 +10,18 @@ license = "GPL-3.0-only"
|
|||
license-file = "../COPYING"
|
||||
|
||||
[dependencies]
|
||||
chrono = { version = "0.4" }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
thiserror = { version = "1" }
|
||||
chrono = "0.4"
|
||||
chrono-tz = "0.6"
|
||||
iron = "0.6.1"
|
||||
mustache = "0.9.0"
|
||||
params = "*"
|
||||
router = "*"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
|
||||
[[bin]]
|
||||
name = "ifc-today"
|
||||
path = "src/today.rs"
|
||||
|
||||
[[bin]]
|
||||
name = "ifc-web"
|
||||
path = "src/web.rs"
|
||||
|
|
543
ifc/src/lib.rs
543
ifc/src/lib.rs
|
@ -10,16 +10,10 @@ 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/>.
|
||||
*/
|
||||
|
||||
use chrono::{Datelike, NaiveDate};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::convert::TryInto;
|
||||
use thiserror::Error;
|
||||
extern crate chrono;
|
||||
extern crate chrono_tz;
|
||||
|
||||
#[derive(Clone, Debug, Error, PartialEq)]
|
||||
pub enum Error {
|
||||
#[error("invalid date")]
|
||||
InvalidDate,
|
||||
}
|
||||
use chrono::{Datelike, NaiveDate};
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub enum DayOfWeek {
|
||||
|
@ -110,143 +104,6 @@ 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)]
|
||||
pub struct IFC {
|
||||
year: u32,
|
||||
|
@ -254,9 +111,12 @@ pub struct IFC {
|
|||
leap_year: bool,
|
||||
}
|
||||
|
||||
fn is_leap_year(year: i32) -> bool {
|
||||
NaiveDate::from_ymd(year, 12, 31).ordinal() == 366
|
||||
}
|
||||
|
||||
impl IFC {
|
||||
pub fn ymd(year: u32, month: u8, day: u8) -> Self {
|
||||
pub fn ymd(year: u32, month: u8, day: u8) -> IFC {
|
||||
let leap_year = is_leap_year(year as i32 - 10000);
|
||||
|
||||
let ordinal = if is_leap_year(year as i32 - 10000) {
|
||||
|
@ -278,18 +138,7 @@ impl IFC {
|
|||
}
|
||||
}
|
||||
|
||||
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 ==
|
||||
pub fn weekday_ifc(&self) -> DayOfWeek {
|
||||
match self.day() % 7 {
|
||||
0 => DayOfWeek::Saturday,
|
||||
1 => DayOfWeek::Sunday,
|
||||
|
@ -306,9 +155,7 @@ impl IFC {
|
|||
Month::from(self.month())
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
impl From<chrono::Date<chrono::Utc>> for IFC {
|
||||
fn from(d: chrono::Date<chrono::Utc>) -> IFC {
|
||||
IFC::from(d.naive_utc())
|
||||
|
@ -331,9 +178,7 @@ impl From<chrono::NaiveDate> for IFC {
|
|||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
impl Datelike for IFC {
|
||||
fn year(&self) -> i32 {
|
||||
self.year as i32
|
||||
|
@ -431,7 +276,6 @@ impl Datelike for IFC {
|
|||
})
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
@ -439,347 +283,6 @@ mod tests {
|
|||
|
||||
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]
|
||||
fn check_start_of_month() {
|
||||
assert_eq!(
|
||||
|
@ -888,9 +391,6 @@ mod tests {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn report_leap_day() {}
|
||||
|
||||
#[test]
|
||||
fn check_start_of_month_leap_year() {
|
||||
assert_eq!(
|
||||
|
@ -1163,25 +663,20 @@ mod tests {
|
|||
assert_eq!(IFC::ymd(12019, 13, 29).day(), 29);
|
||||
assert_eq!(IFC::ymd(12019, 13, 29).day0(), 28);
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
#[test]
|
||||
fn it_reports_correct_day_of_week() {
|
||||
assert_eq!(IFC::ymd(12019, 1, 1).weekday(), DayOfWeek::Sunday);
|
||||
assert_eq!(IFC::ymd(12019, 6, 1).weekday(), DayOfWeek::Sunday);
|
||||
assert_eq!(IFC::ymd(12019, 6, 28).weekday(), DayOfWeek::Saturday);
|
||||
assert_eq!(IFC::ymd(12019, 7, 1).weekday(), DayOfWeek::Sunday);
|
||||
assert_eq!(IFC::ymd(12019, 13, 28).weekday(), DayOfWeek::Saturday);
|
||||
assert_eq!(IFC::ymd(12019, 13, 29).weekday(), DayOfWeek::Saturday);
|
||||
assert_eq!(IFC::ymd(12019, 1, 1).weekday(), chrono::Weekday::Sun);
|
||||
assert_eq!(IFC::ymd(12019, 6, 1).weekday(), chrono::Weekday::Sun);
|
||||
assert_eq!(IFC::ymd(12019, 6, 28).weekday(), chrono::Weekday::Sat);
|
||||
assert_eq!(IFC::ymd(12019, 7, 1).weekday(), chrono::Weekday::Sun);
|
||||
assert_eq!(IFC::ymd(12019, 13, 28).weekday(), chrono::Weekday::Sat);
|
||||
assert_eq!(IFC::ymd(12019, 13, 29).weekday(), chrono::Weekday::Sat);
|
||||
|
||||
assert_eq!(IFC::ymd(12020, 6, 28).weekday(), DayOfWeek::Saturday);
|
||||
assert_eq!(IFC::ymd(12020, 6, 29).weekday(), DayOfWeek::Saturday);
|
||||
assert_eq!(IFC::ymd(12020, 7, 1).weekday(), DayOfWeek::Sunday);
|
||||
assert_eq!(IFC::ymd(12020, 13, 28).weekday(), DayOfWeek::Saturday);
|
||||
assert_eq!(IFC::ymd(12020, 13, 29).weekday(), DayOfWeek::Saturday);
|
||||
|
||||
assert_eq!(IFC::ymd(12022, 13, 31)
|
||||
assert_eq!(IFC::ymd(12020, 6, 28).weekday(), chrono::Weekday::Sat);
|
||||
assert_eq!(IFC::ymd(12020, 6, 29).weekday(), chrono::Weekday::Sat);
|
||||
assert_eq!(IFC::ymd(12020, 7, 1).weekday(), chrono::Weekday::Sun);
|
||||
assert_eq!(IFC::ymd(12020, 13, 28).weekday(), chrono::Weekday::Sat);
|
||||
assert_eq!(IFC::ymd(12020, 13, 29).weekday(), chrono::Weekday::Sat);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue