Skip to content
Snippets Groups Projects
Commit 075fd5be authored by Jeremy Soller's avatar Jeremy Soller
Browse files

Merge branch 'gmtime-yday-fix' into 'master'

Simplify gmtime_r() day-of-year calculation, correct comment

See merge request redox-os/relibc!311
parents 88cda09c 07147578
No related branches found
No related tags found
No related merge requests found
Pipeline #9225 failed
...@@ -301,15 +301,13 @@ pub unsafe extern "C" fn gmtime_r(clock: *const time_t, result: *mut tm) -> *mut ...@@ -301,15 +301,13 @@ pub unsafe extern "C" fn gmtime_r(clock: *const time_t, result: *mut tm) -> *mut
* 1900) */ * 1900) */
let is_leap_year: bool = year % 4 == 0 && (year % 100 != 0 || year % 400 == 0); let is_leap_year: bool = year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
/* For dates that are March 1 or later, we can use day-of- /* For dates in January or February, we use the fact that
* year in the transformed calendar. For January and * January 1 is always 306 days after March 1 in the
* February, that value is sensitive to whether the previous * previous year. */
* year is a leap year. Therefore, we use the already let yday: c_int = if month < 2 {
* computed date for those two months. */ day_of_year_transformed - 306
let yday: c_int = match month { } else {
0 => mday - 1, // January day_of_year_transformed + if is_leap_year { 60 } else { 59 }
1 => 31 + mday - 1, // February
_ => day_of_year_transformed + if is_leap_year { 60 } else { 59 },
}; };
let hour: c_int = (secs_of_day / (60 * 60)).try_into().unwrap(); let hour: c_int = (secs_of_day / (60 * 60)).try_into().unwrap();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment