Crates.io | PHASEXave |
lib.rs | PHASEXave |
version | 1.8.2 |
source | src |
created_at | 2023-10-26 10:38:14.199527 |
updated_at | 2024-03-26 21:34:26.814935 |
description | Fast, clear and simple interface for calculating date, week day and time in Solar, Julian, Gregorian calendar. |
homepage | |
repository | https://github.com/xavetar/PHASEXave |
max_upload_size | |
id | 1014298 |
size | 250,714 |
Why 2^64? u128 * 366 (upper limit of days in a year) overflows era days and seconds after unix epoch, because of this the temporary is u64, in the next version this type will be u128 again or more.
Add feature to Cargo.toml to use local time zone, absolute time functions:
[dependencies]
PHASEXave = { version = "*", features = ["platform_specific_functions_darwin"] }
[dependencies]
PHASEXave = { version = "*", features = ["platform_specific_functions_unix"] }
[dependencies]
PHASEXave = { version = "*", features = ["platform_specific_functions_windows"] }
Get UTC time:
use PHASEXave::{Time};
fn main() {
let time: Time = Time::utc();
println!("{hours}:{minutes}:{seconds}", hours = time.hours, minutes = time.minutes, seconds = time.seconds);
}
Get current time with any time zone:
use PHASEXave::{Time, Sign, Zone};
fn main() {
let time_zone: Zone = Zone { sign: Sign::Signed, hours: 4, minutes: 30, seconds: 0 };
let time: Time = Time::now(zone);
println!("{hours}:{minutes}:{seconds}", hours = time.hours, minutes = time.minutes, seconds = time.seconds);
}
Get current time with local time zone:
use PHASEXave::{Time};
fn main() {
let time: Time = Time::local();
println!("{hours}:{minutes}:{seconds}", hours = time.hours, minutes = time.minutes, seconds = time.seconds);
}
use PHASEXave::{Time, Uptime};
fn main() {
let time: Uptime = Time::absolute();
println!("{hours}:{minutes}:{seconds}", hours = time.hours, minutes = time.minutes, seconds = time.seconds);
}
Get UTC date for Solar calendar:
use PHASEXave::{CalendarView, Date};
fn main() {
let date: Date = Date::utc(CalendarView::Solar);
println!("{yyyy}/{mm}/{dd}", yyyy = date.year, mm = date.month, dd = date.day);
}
Get UTC date for Julian calendar:
use PHASEXave::{CalendarView, Date};
fn main() {
let date: Date = Date::utc(CalendarView::Julian);
println!("{yyyy}/{mm}/{dd}", yyyy = date.year, mm = date.month, dd = date.day);
}
Get UTC date for Gregorian calendar:
use PHASEXave::{CalendarView, Date};
fn main() {
let date: Date = Date::utc(CalendarView::Gregorian);
println!("{yyyy}/{mm}/{dd}", yyyy = date.year, mm = date.month, dd = date.day);
}
Get current date with any time zone for Solar calendar:
use PHASEXave::{CalendarView, Date, Zone, Sign};
fn main() {
let time_zone: Zone = Zone { sign: Sign::Unsigned, hours: 0, minutes: 0, seconds: 0 };
let date: Date = Date::now(CalendarView::Solar, time_zone);
println!("{yyyy}/{mm}/{dd}", yyyy = date.year, mm = date.month, dd = date.day);
}
Get current date with any time zone for Julian calendar:
use PHASEXave::{CalendarView, Date, Zone, Sign};
fn main() {
let time_zone: Zone = Zone { sign: Sign::Unsigned, hours: 0, minutes: 0, seconds: 0 };
let date: Date = Date::now(CalendarView::Julian, time_zone);
println!("{yyyy}/{mm}/{dd}", yyyy = date.year, mm = date.month, dd = date.day);
}
Get current date with any time zone for Gregorian calendar:
use PHASEXave::{CalendarView, Date, Zone, Sign};
fn main() {
let time_zone: Zone = Zone { sign: Sign::Unsigned, hours: 0, minutes: 0, seconds: 0 };
let date: Date = Date::now(CalendarView::Gregorian, time_zone);
println!("{yyyy}/{mm}/{dd}", yyyy = date.year, mm = date.month, dd = date.day);
}
Get current date with local time zone for Solar calendar:
use PHASEXave::{CalendarView, Date};
fn main() {
let date: Date = Date::local(CalendarView::Solar);
println!("{yyyy}/{mm}/{dd}", yyyy = date.year, mm = date.month, dd = date.day);
}
Get current date with local time zone for Julian calendar:
use PHASEXave::{CalendarView, Date};
fn main() {
let date: Date = Date::local(CalendarView::Julian);
println!("{yyyy}/{mm}/{dd}", yyyy = date.year, mm = date.month, dd = date.day);
}
Get current date with local time zone for Gregorian calendar:
use PHASEXave::{CalendarView, Date};
fn main() {
let date: Date = Date::local(CalendarView::Gregorian);
println!("{yyyy}/{mm}/{dd}", yyyy = date.year, mm = date.month, dd = date.day);
}
Convert any* date representation between different calendars:
use PHASEXave::{CalendarView, Date, Sign, Zone, Julian, Gregorian, Solar};
fn main() {
let mut date: Date = Date {
day: 27,
month: 2,
year: 3226,
time_zone: Zone { sign: Sign::Unsigned, hours: 0, minutes: 0, seconds: 0 },
unix_time: 0,
era_days: 0,
view: CalendarView::Solar
};
<Date as Julian>::to_presentation(&mut date, true);
println!("JL: {yyyy}/{mm}/{dd}:{era_days}:{unix_time}", yyyy = date.year, mm = date.month, dd = date.day, era_days = date.era_days, unix_time = date.unix_time);
<Date as Gregorian>::to_presentation(&mut date, true);
println!("GR: {yyyy}/{mm}/{dd}:{era_days}:{unix_time}", yyyy = date.year, mm = date.month, dd = date.day, era_days = date.era_days, unix_time = date.unix_time);
<Date as Solar>::to_presentation(&mut date, true);
println!("SL: {yyyy}/{mm}/{dd}:{era_days}:{unix_time}", yyyy = date.year, mm = date.month, dd = date.day, era_days = date.era_days, unix_time = date.unix_time);
}
Output:
JL: 3226/2/27:1177987:39642393600
GR: 3226/2/27:1177965:39640492800
SL: 3226/2/27:1177964:39640406400
* - any, but except first BCE days in Julian Calendar,
Convert any Solar date to Julian date:
use PHASEXave::{Date, Sign, Zone, Julian, CalendarView};
fn main() {
let mut date: Date = Date {
day: 27,
month: 2,
year: 3226,
time_zone: Zone { sign: Sign::Unsigned, hours: 0, minutes: 0, seconds: 0 },
unix_time: 0,
era_days: 0,
view: CalendarView::Solar
};
<Date as Julian>::to_date(&mut date, false);
println!("JL: {yyyy}/{mm}/{dd}:{era_days}:{unix_time}", yyyy = date.year, mm = date.month, dd = date.day, era_days = date.era_days, unix_time = date.unix_time);
}
Output:
JL: 3226/2/4:1177964:39640406400
Convert any Solar date to Gregorian date:
use PHASEXave::{Date, Sign, Zone, Gregorian, CalendarView};
fn main() {
let mut date: Date = Date {
day: 1,
month: 3,
year: 3226,
time_zone: Zone { sign: Sign::Unsigned, hours: 0, minutes: 0, seconds: 0 },
unix_time: 0,
era_days: 0,
view: CalendarView::Solar
};
<Date as Gregorian>::to_date(&mut date, false);
println!("GR: {yyyy}/{mm}/{dd}:{era_days}:{unix_time}", yyyy = date.year, mm = date.month, dd = date.day, era_days = date.era_days, unix_time = date.unix_time);
}
Output:
GR: 3226/2/28:1177966:39640579200
Convert *any Julian date to Solar date:
use PHASEXave::{Date, Sign, Zone, Solar, CalendarView};
fn main() {
let mut date: Date = Date {
day: 5,
month: 2,
year: 3226,
time_zone: Zone { sign: Sign::Unsigned, hours: 0, minutes: 0, seconds: 0 },
unix_time: 0,
era_days: 0,
view: CalendarView::Julian
};
<Date as Solar>::to_date(&mut date, false);
println!("SL: {yyyy}/{mm}/{dd}:{era_days}:{unix_time}", yyyy = date.year, mm = date.month, dd = date.day, era_days = date.era_days, unix_time = date.unix_time);
}
Output:
SL: 3226/2/28:1177965:39640492800
Convert *any Julian date to Gregorian date:
use PHASEXave::{Date, Sign, Zone, Gregorian, CalendarView};
fn main() {
let mut date: Date = Date {
day: 30,
month: 10,
year: 2023,
time_zone: Zone { sign: Sign::Unsigned, hours: 0, minutes: 0, seconds: 0 },
unix_time: 0,
era_days: 0,
view: CalendarView::Julian
};
<Date as Gregorian>::to_date(&mut date, false);
println!("GR: {yyyy}/{mm}/{dd}:{era_days}:{unix_time}", yyyy = date.year, mm = date.month, dd = date.day, era_days = date.era_days, unix_time = date.unix_time);
}
Output:
GR: 2023/11/12:738836:1699747200
* - any, but except first two days, that missing in Gregorian calendar
Convert any Gregorian date to Solar date:
use PHASEXave::{Date, Sign, Zone, Solar, CalendarView};
fn main() {
let mut date: Date = Date {
day: 28,
month: 2,
year: 3226,
time_zone: Zone { sign: Sign::Unsigned, hours: 0, minutes: 0, seconds: 0 },
unix_time: 0,
era_days: 0,
view: CalendarView::Gregorian
};
<Date as Solar>::to_date(&mut date, false);
println!("SL: {yyyy}/{mm}/{dd}:{era_days}:{unix_time}", yyyy = date.year, mm = date.month, dd = date.day, era_days = date.era_days, unix_time = date.unix_time);
}
Output:
SL: 3226/3/1:1177966:39640579200
Convert any Gregorian date to Julian date:
use PHASEXave::{Date, Sign, Zone, Julian, CalendarView};
fn main() {
let mut date: Date = Date {
day: 12,
month: 11,
year: 2023,
time_zone: Zone { sign: Sign::Unsigned, hours: 0, minutes: 0, seconds: 0 },
unix_time: 0,
era_days: 0,
view: CalendarView::Gregorian
};
<Date as Julian>::to_date(&mut date, false);
println!("JL: {yyyy}/{mm}/{dd}:{era_days}:{unix_time}", yyyy = date.year, mm = date.month, dd = date.day, era_days = date.era_days, unix_time = date.unix_time);
}
Output:
JL: 2023/10/30:738836:1699747200
Convert any Gregorian to Julian and Julian to Gregorian:
use PHASEXave::{CalendarView, Date, Julian, Gregorian, Solar, Sign, Zone};
fn main() {
let time_zone: Zone = Zone { sign: Sign::Unsigned, hours: 0, minutes: 0, seconds: 0 };
let mut date: Date = Date::now(CalendarView::Gregorian, time_zone);
<Date as Solar>::to_date(&mut date, true);
<Date as Julian>::to_date(&mut date, true);
<Date as Gregorian>::to_date(&mut date, true);
println!("GR: {yyyy}/{mm}/{dd}:{era_days}:{unix_time}", yyyy = date.year, mm = date.month, dd = date.day, era_days = date.era_days, unix_time = date.unix_time);
}
Output:
GR: 2024/3/4:738949:1709574752
Get week day from Solar, Julian and Gregorian calendar:
Get week day from Date:
use PHASEXave::{CalendarView, Date, RataDie, Xavetar, Sakamoto, Sign, Zone};
fn main() {
let time_zone: Zone = Zone { sign: Sign::Unsigned, hours: 8, minutes: 0, seconds: 0 };
let date: Date = Date::now(CalendarView::Solar, time_zone);
println!(
"Solar Week day:\n\nRata Die: {rata_die}\nXavetar: {xavetar}\nSakamoto: {sakamoto}\n",
rata_die = <Date as RataDie>::week_day(&date).name(),
xavetar = <Date as Xavetar>::week_day(&date).name(),
sakamoto = <Date as Sakamoto>::week_day(&date).name(),
);
println!("Date: {yyyy}/{mm}/{dd}", yyyy = date.year, mm = date.month, dd = date.day);
}
Output:
Solar Week day:
Rata Die: Tuesday
Xavetar: Tuesday
Sakamoto: Tuesday
Date: 2024/3/6
Get week day from any date:
use PHASEXave::{CalendarView, Date, RataDie, Sakamoto, Xavetar};
fn main() {
let (yyyy, mm, dd): (u64, u8, u8) = (1582, 10, 5);
println!(
"Solar Week day:\n\nRata Die: {rata_die}\nXavetar: {xavetar}\nSakamoto: {sakamoto}\n",
rata_die = <Date as RataDie>::from(CalendarView::Solar, yyyy, mm, dd).name(),
xavetar = <Date as Xavetar>::from(CalendarView::Solar, yyyy, mm, dd).name(),
sakamoto = <Date as Sakamoto>::from(CalendarView::Solar, yyyy, mm, dd).name(),
);
println!("Date: {yyyy}/{mm}/{dd}", yyyy = yyyy, mm = mm, dd = dd);
}
Output:
Solar Week day:
Rata Die: Tuesday
Xavetar: Tuesday
Sakamoto: Tuesday
Date: 1582/10/5
Get week day from Date:
use PHASEXave::{CalendarView, Date, RataDie, Xavetar, Sakamoto, Sign, Zone};
fn main() {
let time_zone: Zone = Zone { sign: Sign::Unsigned, hours: 8, minutes: 0, seconds: 0 };
let date: Date = Date::now(CalendarView::Julian, time_zone);
println!(
"Julian Week day:\n\nRata Die: {rata_die}\nXavetar: {xavetar}\nSakamoto: {sakamoto}\n",
rata_die = <Date as RataDie>::week_day(&date).name(),
xavetar = <Date as Xavetar>::week_day(&date).name(),
sakamoto = <Date as Sakamoto>::week_day(&date).name(),
);
println!("Date: {yyyy}/{mm}/{dd}", yyyy = date.year, mm = date.month, dd = date.day);
}
Output:
Julian Week day:
Rata Die: Tuesday
Xavetar: Tuesday
Sakamoto: Tuesday
Date: 2024/2/21
Get week day from any date:
use PHASEXave::{CalendarView, Date, RataDie, Xavetar, Sakamoto};
fn main() {
let (yyyy, mm, dd): (u64, u8, u8) = (1582, 10, 5);
println!(
"Julian Week day:\n\nRata Die: {rata_die}\nXavetar: {xavetar}\nSakamoto: {sakamoto}\n",
rata_die = <Date as RataDie>::from(CalendarView::Julian, yyyy, mm, dd).name(),
xavetar = <Date as Xavetar>::from(CalendarView::Julian, yyyy, mm, dd).name(),
sakamoto = <Date as Sakamoto>::from(CalendarView::Julian, yyyy, mm, dd).name(),
);
println!("Date: {yyyy}/{mm}/{dd}", yyyy = yyyy, mm = mm, dd = dd);
}
Output:
Julian Week day:
Rata Die: Friday
Xavetar: Friday
Sakamoto: Friday
Date: 1582/10/5
Get week day from Date:
use PHASEXave::{CalendarView, Date, RataDie, Xavetar, Sakamoto, Sign, Zone};
fn main() {
let time_zone: Zone = Zone { sign: Sign::Unsigned, hours: 8, minutes: 0, seconds: 0 };
let date: Date = Date::now(CalendarView::Gregorian, time_zone);
println!(
"Gregorian Week day:\n\nRata Die: {rata_die}\nSakamoto: {sakamoto}\nXavetar: {xavetar}\n",
rata_die = <Date as RataDie>::week_day(&date).name(),
xavetar = <Date as Xavetar>::week_day(&date).name(),
sakamoto = <Date as Sakamoto>::week_day(&date).name(),
);
println!("Date: {yyyy}/{mm}/{dd}", yyyy = date.year, mm = date.month, dd = date.day);
}
Output:
Gregorian Week day:
Rata Die: Tuesday
Sakamoto: Tuesday
Xavetar: Tuesday
Date: 2024/3/5
Get week day from any date:
use PHASEXave::{CalendarView, Date, RataDie, Xavetar, Sakamoto};
fn main() {
let (yyyy, mm, dd): (u64, u8, u8) = (1582, 10, 5);
println!(
"Gregorian Week day:\n\nRata Die: {rata_die}\nXavetar: {xavetar}\nSakamoto: {sakamoto}\n",
rata_die = <Date as RataDie>::from(CalendarView::Gregorian, yyyy, mm, dd).name(),
xavetar = <Date as Xavetar>::from(CalendarView::Gregorian, yyyy, mm, dd).name(),
sakamoto = <Date as Sakamoto>::from(CalendarView::Gregorian, yyyy, mm, dd).name(),
);
println!("Date: {yyyy}/{mm}/{dd}", yyyy = yyyy, mm = mm, dd = dd);
}
Output:
Gregorian Week day:
Rata Die: Tuesday
Xavetar: Tuesday
Sakamoto: Tuesday
Date: 1582/10/5
PHASEXave is primarily distributed under the terms of three the Anti-Virus license and MIT license and the Apache License (Version 2.0)
See LICENSE-ANTI-VIRUS and LICENSE-APACHE and LICENSE-MIT for details.