Skip to content

Commit

Permalink
[RELEASE] Update leap year function for Solar calendar
Browse files Browse the repository at this point in the history
Signed-off-by: XAVETAR <xavetar@proton.me>
  • Loading branch information
xavetar committed Mar 16, 2024
1 parent e366e18 commit 5e5f65b
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 25 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ resolver="2"
[workspace.package]
authors = ["Stanislav Mikhailov <xavetar@proton.me>"]
edition = "2021"
version = "1.8.0"
version = "1.8.1"
rust-version = "1.67.0"
license = "MIT AND Apache-2.0"
license-file = "LICENSE-Anti-Virus"
Expand All @@ -33,7 +33,7 @@ exclude = ["res/", "compact/", ".*", ".DS_Store", "debug/", "target/", "Cargo.lo

# Dependencies
[workspace.dependencies]
PHASEXave = { version = "=1.8.0", path = "api/", default-features = false }
PHASEXave = { version = "=1.8.1", path = "api/", default-features = false }

# Profiles
[profile.dev]
Expand Down
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
<a href="https://nowpayments.io/donation?api_key=NRH28QG-ABRM7CC-J7NVGXN-F8FTRS1&source=lk_donation&medium=referral" target="_blank">
<img src="https://nowpayments.io/images/embeds/donation-button-black.svg" alt="Crypto donation button by NOWPayments" style="height: 60px !important; width: 217px !important;">
</a>
<a href="https://www.buymeacoffee.com/xavetar" target="_blank">
<img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" style="height: 60px !important; width: 217px !important;">
</a>
</div>

## About
Expand Down
9 changes: 6 additions & 3 deletions api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,19 @@
<a href="https://nowpayments.io/donation?api_key=NRH28QG-ABRM7CC-J7NVGXN-F8FTRS1&source=lk_donation&medium=referral" target="_blank">
<img src="https://nowpayments.io/images/embeds/donation-button-black.svg" alt="Crypto donation button by NOWPayments" style="height: 60px !important; width: 217px !important;">
</a>
<a href="https://www.buymeacoffee.com/xavetar" target="_blank">
<img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" style="height: 60px !important; width: 217px !important;">
</a>
</div>

## Validity of Calendars

- The Gregorian calendar advances every year by 0.000031 days in absolute values, relative to the point of the vernal equinox. Between 3225~3232 the divergence will reach about 2 days from the Vernal Equinox.
- The Solar calendar solves all the leap year problems of the Gregorian and Julian calendar, but it is a bit slower than the others because of more complex computational operations.

## Validity of Leap Year Algorithms

- Julian year: u128 - 2^128
- Gregorian year: u128 - 2^128
- Solar year: u128 / 24219 = 14050223664104152254980577539608085 ~ 2^113

## Features

Add feature to Cargo.toml to use local timezone, absolute time functions:
Expand Down
20 changes: 10 additions & 10 deletions compact/converter/to_presentation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,14 @@ fn to_presentation(date: &mut Date, to: CalendarView) {
// Equivalent to: 365.2425 * last_year
// Equivalent to: ((365.25 * last_year)) - 0.0075 * last_year
date.view = CalendarView::Gregorian;
date.era_days = (((last_year * 365.0_f64) + (last_year * 25.0_f64) / 100.0_f64)) - last_year * 75.0_f64 / 10000.0_f64;
date.era_days = (((last_year * 365.0_f64) + (last_year * 25.0_f64) / 100.0_f64)) - ((last_year * 75.0_f64) / 10000.0_f64);
date.era_days += days_from(&date);
},
(CalendarView::Julian, CalendarView::Solar) => {
// Equivalent to: 365.24219 * last_year
// Equivalent to: ((365.25 * last_year)) - 0.00781 * last_year
date.view = CalendarView::Julian;
date.era_days = (((last_year * 365.0_f64) + (last_year * 25.0_f64) / 100.0_f64)) - last_year * 781.0_f64 / 100000.0_f64;
date.era_days = (((last_year * 365.0_f64) + (last_year * 25.0_f64) / 100.0_f64)) - ((last_year * 781.0_f64) / 100000.0_f64);
date.era_days += days_from(&date);
},
(CalendarView::Gregorian, CalendarView::Gregorian) => {
Expand All @@ -108,14 +108,14 @@ fn to_presentation(date: &mut Date, to: CalendarView) {
// Equivalent to: (365.25 * last_year) - 2
// Equivalent to: ((365.2425 * last_year) + 0.0075 * last_year) - 2
date.view = CalendarView::Julian;
date.era_days = (((last_year * 365.0_f64) + (last_year * 2425.0_f64) / 10000.0_f64) + last_year * 75.0_f64 / 10000.0_f64) - JULIAN_BCE_DAYS_FIRST_YEAR as f64;
date.era_days = (((last_year * 365.0_f64) + (last_year * 2425.0_f64) / 10000.0_f64) + ((last_year * 75.0_f64) / 10000.0_f64)) - JULIAN_BCE_DAYS_FIRST_YEAR as f64;
date.era_days += days_from(&date);
},
(CalendarView::Gregorian, CalendarView::Solar) => {
// Equivalent to: 365.24219 * last_year
// Equivalent to: (365.2425 * last_year) - 0.00031 * last_year
date.view = CalendarView::Solar;
date.era_days = ((last_year * 365.0_f64) + (last_year * 2425.0_f64) / 10000.0_f64) - last_year * 31.0_f64 / 100000.0_f64;
date.era_days = ((last_year * 365.0_f64) + (last_year * 2425.0_f64) / 10000.0_f64) - ((last_year * 31.0_f64) / 100000.0_f64);
date.era_days += days_from(&date);
},
(CalendarView::Solar, CalendarView::Solar) => {
Expand All @@ -125,17 +125,17 @@ fn to_presentation(date: &mut Date, to: CalendarView) {
date.era_days += days_from(&date);
},
(CalendarView::Solar, CalendarView::Julian) => {
// Equivalent to: 365.24219 * last_year
// Equivalent to: 365.25 * last_year
// Equivalent to: ((365.24219 * last_year) + 0.00781 * last_year) - 2
date.view = CalendarView::Julian;
date.era_days = (((last_year * 365.0_f64) + (last_year * 24219.0_f64) / 100000.0_f64) + last_year * 781.0_f64 / 100000.0_f64) - JULIAN_BCE_DAYS_FIRST_YEAR as f64;
date.era_days = (((last_year * 365.0_f64) + (last_year * 24219.0_f64) / 100000.0_f64) + ((last_year * 781.0_f64) / 100000.0_f64)) - JULIAN_BCE_DAYS_FIRST_YEAR as f64;
date.era_days += days_from(&date);
},
(CalendarView::Solar, CalendarView::Gregorian) => {
// Equivalent to: 365.24219 * last_year
// Equivalent to: 365.2425 * last_year
// Equivalent to: ((365.24219 * last_year) + 0.00031 * last_year)
date.view = CalendarView::Gregorian;
date.era_days = ((last_year * 365.0_f64) + (last_year * 24219.0_f64) / 100000.0_f64) + last_year * 31.0_f64 / 100000.0_f64;
date.era_days = ((last_year * 365.0_f64) + (last_year * 24219.0_f64) / 100000.0_f64) + ((last_year * 31.0_f64) / 100000.0_f64);
date.era_days += days_from(&date);
},
_ => panic!("[ERROR]: Unknown conversion method (to_presentation)!")
Expand All @@ -159,7 +159,7 @@ fn days_from(date: &Date) -> f64 {

if !check_date(&date) { panic!("[ERROR]: Invalid input date, or is not leap in this calendar: {:?}.", date.view); };

let (mut days, leap_year): (f64, bool) = (date.day as f64, is_leap_year(date.view, date.year));
let mut days: f64 = date.day as f64;

if date.month > 1_u8 && date.month < 13_u8 {
for m in 1_u8..date.month {
Expand Down Expand Up @@ -195,7 +195,7 @@ fn main() {
view: CalendarView::Gregorian
};

to_presentation(&mut date, CalendarView::Julian);
to_presentation(&mut date, CalendarView::Solar);

println!("Date: {:?}", date);
}
8 changes: 4 additions & 4 deletions tools/date-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
name = "date-cli"
authors = ["Stanislav Mikhailov <xavetar@proton.me>"]
publish = true
version = "1.0.1"
version = "1.0.2"
edition.workspace = true
license.workspace = true
license-file.workspace = true
Expand All @@ -28,10 +28,10 @@ default = []
[dependencies]

[target.'cfg(target_vendor = "apple")'.dependencies]
PHASEXave = { version = "1.8.0", features = ["platform_specific_functions_darwin"] }
PHASEXave = { version = "1.8.1", features = ["platform_specific_functions_darwin"] }

[target.'cfg(all(not(target_vendor = "apple"), target_family = "unix"))'.dependencies]
PHASEXave = { version = "1.8.0", features = ["platform_specific_functions_unix"] }
PHASEXave = { version = "1.8.1", features = ["platform_specific_functions_unix"] }

[target.'cfg(target_family = "windows")'.dependencies]
PHASEXave = { version = "1.8.0", features = ["platform_specific_functions_windows"] }
PHASEXave = { version = "1.8.1", features = ["platform_specific_functions_windows"] }
3 changes: 0 additions & 3 deletions tools/date-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
<a href="https://nowpayments.io/donation?api_key=NRH28QG-ABRM7CC-J7NVGXN-F8FTRS1&source=lk_donation&medium=referral" target="_blank">
<img src="https://nowpayments.io/images/embeds/donation-button-black.svg" alt="Crypto donation button by NOWPayments" style="height: 60px !important; width: 217px !important;">
</a>
<a href="https://www.buymeacoffee.com/xavetar" target="_blank">
<img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" style="height: 60px !important; width: 217px !important;">
</a>
</div>

## Command-Line Options
Expand Down

0 comments on commit 5e5f65b

Please sign in to comment.