System.Globalization.GregorianCalendarHelper.ToFourDigitYear C# (CSharp) Method

ToFourDigitYear() public method

public ToFourDigitYear ( int year, int twoDigitYearMax ) : int
year int
twoDigitYearMax int
return int
        public int ToFourDigitYear(int year, int twoDigitYearMax) {
            if (year < 0) {
                throw new ArgumentOutOfRangeException("year",
                    Environment.GetResourceString("ArgumentOutOfRange_NeedPosNum"));                
            }
            
            if (year < 100) {
                int y = year % 100;
                return ((twoDigitYearMax/100 - ( y > twoDigitYearMax % 100 ? 1 : 0))*100 + y);
            }
            
            if (year < m_minYear || year > m_maxYear) {
                throw new ArgumentOutOfRangeException(
                            "year",
                            String.Format(
                                CultureInfo.CurrentCulture,
                                Environment.GetResourceString("ArgumentOutOfRange_Range"), m_minYear, m_maxYear));
            }
            // If the year value is above 100, just return the year value.  Don't have to do
            // the TwoDigitYearMax comparison.
            return (year);
        }
    }        

Usage Example

        public override int ToFourDigitYear(int year) {
            if (year < 0) {
                throw new ArgumentOutOfRangeException("year",
                    Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
            }
            Contract.EndContractBlock();

            return (helper.ToFourDigitYear(year, this.TwoDigitYearMax));
        }
All Usage Examples Of System.Globalization.GregorianCalendarHelper::ToFourDigitYear