Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
relibc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
redox-os
relibc
Commits
07147578
Commit
07147578
authored
4 years ago
by
Peter Limkilde Svendsen
Browse files
Options
Downloads
Patches
Plain Diff
Simplify day-of-year calculation, correct comment
parent
2ed55a92
No related branches found
No related tags found
1 merge request
!311
Simplify gmtime_r() day-of-year calculation, correct comment
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/header/time/mod.rs
+7
-9
7 additions, 9 deletions
src/header/time/mod.rs
with
7 additions
and
9 deletions
src/header/time/mod.rs
+
7
−
9
View file @
07147578
...
...
@@ -250,15 +250,13 @@ pub unsafe extern "C" fn gmtime_r(clock: *const time_t, result: *mut tm) -> *mut
* 1900) */
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-
* year in the transformed calendar. For January and
* February, that value is sensitive to whether the previous
* year is a leap year. Therefore, we use the already
* computed date for those two months. */
let
yday
:
c_int
=
match
month
{
0
=>
mday
-
1
,
// January
1
=>
31
+
mday
-
1
,
// February
_
=>
day_of_year_transformed
+
if
is_leap_year
{
60
}
else
{
59
},
/* For dates in January or February, we use the fact that
* January 1 is always 306 days after March 1 in the
* previous year. */
let
yday
:
c_int
=
if
month
<
2
{
day_of_year_transformed
-
306
}
else
{
day_of_year_transformed
+
if
is_leap_year
{
60
}
else
{
59
}
};
let
hour
:
c_int
=
(
secs_of_day
/
(
60
*
60
))
.try_into
()
.unwrap
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment