Skip to content

Commit

Permalink
Expanding the coverage of the time zone test
Browse files Browse the repository at this point in the history
  • Loading branch information
xavetar committed Mar 26, 2024
1 parent b6aa4a6 commit f0f36da
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ mod tests {
let max_year_to_test: u64 = 2_500_u64;

for (day_seconds, timezone) in [
(25_u128, Zone { sign: Sign::Signed, hours: 3_u8, minutes: 0_u8, seconds: 0_u8 }),
(83599_u128, Zone { sign: Sign::Signed, hours: 3_u8, minutes: 0_u8, seconds: 0_u8 }),
(55_u128, Zone { sign: Sign::Signed, hours: 23_u8, minutes: 59_u8, seconds: 59_u8 }),
(45_u128, Zone { sign: Sign::Unsigned, hours: 6_u8, minutes: 0_u8, seconds: 0_u8 }),
(55_u128, Zone { sign: Sign::Unsigned, hours: 23_u8, minutes: 59_u8, seconds: 59_u8 })
Expand All @@ -139,7 +139,7 @@ mod tests {

if month.index() == Months::January.index() {
if year == UNIX_EPOCH_GREGORIAN_START_YEAR as u64 {
if date.unix_time < tz_seconds - day_seconds {
if date.unix_time + day_seconds < tz_seconds {
continue;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ mod tests {
let max_year_to_test: u64 = 2_500_u64;

for (day_seconds, timezone) in [
(25_u128, Zone { sign: Sign::Signed, hours: 5_u8, minutes: 30_u8, seconds: 0_u8 }),
(83599_u128, Zone { sign: Sign::Signed, hours: 5_u8, minutes: 30_u8, seconds: 0_u8 }),
(55_u128, Zone { sign: Sign::Signed, hours: 23_u8, minutes: 59_u8, seconds: 59_u8 }),
(45_u128, Zone { sign: Sign::Unsigned, hours: 9_u8, minutes: 30_u8, seconds: 0_u8 }),
(55_u128, Zone { sign: Sign::Unsigned, hours: 23_u8, minutes: 59_u8, seconds: 59_u8 })
Expand All @@ -155,7 +155,7 @@ mod tests {

if month.index() == Months::December.index() {
if year == UNIX_EPOCH_JULIAN_START_YEAR as u64 {
if date.unix_time < tz_seconds - day_seconds {
if date.unix_time + day_seconds < tz_seconds {
continue;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ mod tests {
let max_year_to_test: u64 = 2_500_u64;

for (day_seconds, timezone) in [
(25_u128, Zone { sign: Sign::Signed, hours: 4_u8, minutes: 30_u8, seconds: 0_u8 }),
(83599_u128, Zone { sign: Sign::Signed, hours: 4_u8, minutes: 30_u8, seconds: 0_u8 }),
(55_u128, Zone { sign: Sign::Signed, hours: 23_u8, minutes: 59_u8, seconds: 59_u8 }),
(45_u128, Zone { sign: Sign::Unsigned, hours: 8_u8, minutes: 0_u8, seconds: 0_u8 }),
(55_u128, Zone { sign: Sign::Unsigned, hours: 23_u8, minutes: 59_u8, seconds: 59_u8 })
Expand All @@ -139,7 +139,7 @@ mod tests {

if month.index() == Months::January.index() {
if year == UNIX_EPOCH_SOLAR_START_YEAR as u64 {
if date.unix_time < tz_seconds - day_seconds {
if date.unix_time + day_seconds < tz_seconds {
continue;
}
}
Expand Down
10 changes: 8 additions & 2 deletions api/src/types/planets/earth/calendar/traits/converter/tz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,16 @@ use crate::types::{

pub fn zone_recalc(timezone: Zone, unix_time: &mut u128, day_seconds: u128, era_days: &mut u128) {
let tz_sec: u128 = timezone.to_seconds() as u128;

if timezone.sign == Sign::Signed && (*unix_time + day_seconds) < tz_sec {
panic!("[OVERFLOW]: Signed timezone overflow unix_time or also can be that unix time in selected calendar system start from another date!")
panic!(
"[OVERFLOW]: Signed timezone will overflow unix_time type: unix time - time zone < zero.\n
Also can be that unix time in selected calendar system start from another date!"
)
} else if timezone.sign == Sign::Unsigned && *unix_time > u128::MAX - (tz_sec + day_seconds) {
panic!("[OVERFLOW]: Unsigned time zone will overflow unix time type: unix time + time zone > type unix time!")
} else {
if timezone.sign == Sign::Signed && tz_sec > 0 {
if timezone.sign == Sign::Signed {
if day_seconds >= tz_sec {
*unix_time += day_seconds;
*unix_time -= tz_sec;
Expand Down

0 comments on commit f0f36da

Please sign in to comment.