Skip to content

GregorianCalendarHelper, suspicious % operator #78627

Closed

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

  1. ghost added
    untriaged
    on Nov 21, 2022
  2. self-assigned this
    on Nov 22, 2022
  3. ghost added
    in-pr
    on Nov 22, 2022
  4. ghost removed
    in-pr
    on Nov 24, 2022
  5. ghost removed
    untriaged
    on Nov 24, 2022
  6. ghost locked as resolved and limited conversation to collaborators on Dec 24, 2022
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