June 2018 Update

This commit is contained in:
Ingy döt Net 2018-06-22 20:57:24 +00:00
parent ba8067c3b7
commit 22f33d4004
5278 changed files with 84726 additions and 14379 deletions

View file

@ -1,20 +1,18 @@
# v0.6.0
using Dates
using Base.Dates
function discordiandate(year::Integer, month::Integer, day::Integer)
const DISCORDIANSEASONS = ["Chaos", "Discord", "Confusion", "Bureaucracy", "The Aftermath"]
const HOLIDAYS = Dict(
"Chaos 5" => "Mungday",
"Chaos 50" => "Chaoflux",
"Discord 5" => "Mojoday",
"Discord 50" => "Discoflux",
"Confusion 5" => "Syaday",
"Confusion 50" => "Confuflux",
"Bureaucracy 5" => "Zaraday",
"Bureaucracy 50" => "Bureflux",
"The Aftermath 5" => "Maladay",
"The Aftermath 50" => "Afflux",
)
discordianseasons = ["Chaos", "Discord", "Confusion", "Bureaucracy", "The Aftermath"]
holidays = Dict(
"Chaos 5" => "Mungday",
"Chaos 50" => "Chaoflux",
"Discord 5" => "Mojoday",
"Discord 50" => "Discoflux",
"Confusion 5" => "Syaday",
"Confusion 50" => "Confuflux",
"Bureaucracy 5" => "Zaraday",
"Bureaucracy 50" => "Bureflux",
"The Aftermath 5" => "Maladay",
"The Aftermath 50" => "Afflux")
today = Date(year, month, day)
isleap = isleapyear(year)
if isleap && month == 2 && day == 29
@ -24,12 +22,11 @@ function discordiandate(year::Integer, month::Integer, day::Integer)
if isleap && dy >= 60
dy -= 1
end
dday = string(DISCORDIANSEASONS[div(dy, 73) + 1], " ", rem(dy, 73))
if haskey(HOLIDAYS, dday)
rst = dday * " ($(HOLIDAYS[dday])), YOLD $(year + 1166)"
else
rst = dday * ", YOLD $(year + 1166)"
rst = string(discordianseasons[div(dy, 73) + 1], " ", rem(dy, 73)) # day
if haskey(holidays, rst)
rst *= " ($(holidays[rst]))" # if holiday
end
rst *= ", YOLD $(year + 1166)" # year
end
return rst
end

View file

@ -0,0 +1,71 @@
extern crate chrono;
use chrono::NaiveDate;
use std::str::FromStr;
fn main() {
let date = std::env::args().nth(1).expect("Please provide a YYYY-MM-DD date.");
println!("{} is {}", date, NaiveDate::from_str(&date).unwrap().to_poee());
}
// The necessary constants for the seasons, weekdays, and holydays.
const APOSTLES: [&str; 5] = ["Mungday", "Mojoday", "Syaday", "Zaraday", "Maladay"];
const HOLYDAYS: [&str; 5] = ["Chaoflux", "Discoflux", "Confuflux", "Bureflux", "Afflux"];
const SEASONS: [&str; 5] = ["Chaos", "Discord", "Confusion", "Bureaucracy", "The Aftermath"];
const WEEKDAYS: [&str; 5] = ["Sweetmorn", "Boomtime", "Pungenday", "Prickle-Prickle", "Setting Orange"];
// The necessary constants for the conversion.
const APOSTLE_HOLYDAY: usize = 5;
const CURSE_OF_GREYFACE: i32 = 1166;
const SEASON_DAYS: usize = 73;
const SEASON_HOLYDAY: usize = 50;
const ST_TIBS_DAY: usize = 59;
const WEEK_DAYS: usize = 5;
// This extends the `Datelike` trait of Rust's Chrono crate with a method that
// prints any Datelike type as a String.
impl<T: Datelike> DiscordianDate for T {}
pub trait DiscordianDate: Datelike {
fn to_poee(&self) -> String {
let day = self.ordinal0() as usize;
let leap = self.year() % 4 == 0 && self.year() % 100 != 0 || self.year() % 400 == 0;
let year = self.year() + CURSE_OF_GREYFACE;
if leap && day == ST_TIBS_DAY { return format!("St. Tib's Day, in the YOLD {}", year); }
let day_offset = if leap && day > ST_TIBS_DAY { day - 1 } else { day };
let day_of_season = day_offset % SEASON_DAYS + 1;
let season = SEASONS[day_offset / SEASON_DAYS];
let weekday = WEEKDAYS[day_offset % WEEK_DAYS];
let holiday = if day_of_season == APOSTLE_HOLYDAY {
format!("\nCelebrate {}", APOSTLES[day_offset / SEASON_DAYS])
} else if day_of_season == SEASON_HOLYDAY {
format!("\nCelebrate {}", HOLYDAYS[day_offset / SEASON_DAYS])
} else {
String::with_capacity(0)
};
format!("{}, the {} day of {} in the YOLD {}{}",
weekday, ordinalize(day_of_season), season, year, holiday)
}
}
/// A helper function to ordinalize a numeral.
fn ordinalize(num: usize) -> String {
let s = format!("{}", num);
let suffix = if s.ends_with('1') && !s.ends_with("11") {
"st"
} else if s.ends_with('2') && !s.ends_with("12") {
"nd"
} else if s.ends_with('3') && !s.ends_with("13") {
"rd"
} else {
"th"
};
format!("{}{}", s, suffix)
}