Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Is leap year calculation omitted?

Open
#446 0 comments 2 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
48/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
c
Domain
backend

Research direction

Start with plugins/sudoers/getdate.c and trace how Convert computes the Julian day from EPOCH through the requested year. Compare that loop with the leap year check already used for DaysInMonth, then inspect or run the date parsing tests mentioned by the project. Done means leap days are handled consistently across century years and the relevant tests pass.

Written by the indexing model from the issue text.

Description

Hi,all
in plugins/sudoers/getdate.c

static time_t
Convert(time_t Month, time_t Day, time_t Year, time_t Hours, time_t Minutes,
    time_t Seconds, MERIDIAN Meridian, DSTMODE DSTmode)
{
    static int DaysInMonth[12] = {
	31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
    };
    struct tm	tm;
    time_t	tod;
    time_t	Julian;
    int		i;

    if (Year < 0)
	Year = -Year;
    if (Year < 69)
	Year += 2000;
    else if (Year < 100) {
	Year += 1900;
	if (Year < EPOCH)
		Year += 100;
    }
    DaysInMonth[1] = Year % 4 == 0 && (Year % 100 != 0 || Year % 400 == 0)
		    ? 29 : 28;
    /* 32-bit time_t cannot represent years past 2038 */
    if (Year < EPOCH || (sizeof(time_t) == sizeof(int) && Year > 2038)
     || Month < 1 || Month > 12
     /* Lint fluff:  "conversion from long may lose accuracy" */
     || Day < 1 || Day > DaysInMonth[--Month])
	return -1;

    for (Julian = Day - 1, i = 0; i < Month; i++)
	Julian += DaysInMonth[i];
    for (i = EPOCH; i < Year; i++)
	Julian += 365 + (i % 4 == 0);
    Julian *= SECSPERDAY;
    Julian += yyTimezone * 60L;
    if ((tod = ToSeconds(Hours, Minutes, Seconds, Meridian)) < 0)
	return -1;
    Julian += tod;
    if (DSTmode == DSTon
     || (DSTmode == DSTmaybe && localtime_r(&Julian, &tm) && tm.tm_isdst))
	Julian -= 60 * 60;
    return Julian;

for (i = EPOCH; i < Year; i++)
Julian += 365 + (i % 4 == 0); //Only %4 was calculated. %100 and %400 were not calculated

Should it be Julian += 365 + (i % 4 == 0 && (i % 100 != 0 || i % 400 == 0)); ?

Dominant language
C
Stars
1.7k
Forks
306
Avg merge
1d 2h
Merged PRs (30d)
22

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from sudo-project/sudo

All issues in sudo-project/sudo

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.