Skip to content

GregorianCalendarHelper, suspicious % operator #78627

Description

@VasilievSerg

Link to the sources

public int ToFourDigitYear(int year, int twoDigitYearMax)
{
    if (year < 0)
    {
        throw new ArgumentOutOfRangeException(nameof(year),
            SR.ArgumentOutOfRange_NeedPosNum);
    }

    if (year < 100)
    {
        int y = year % 100; // <=
        return (twoDigitYearMax / 100 - (y > twoDigitYearMax % 100 ? 1 : 0)) * 100 + y;
    }
    ....
}

The y and year variables are always equal.
Since year's value is in range [0, 99], the result of the year % 100 expression is always equal to year.

I'm not sure whether the marked statement is redundant or it is an error.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions