GetDayOfYear() публичный Метод

public GetDayOfYear ( System.DateTime time ) : int
time System.DateTime
Результат int
Пример #1
0
 public void PosTest3()
 {
     System.Globalization.Calendar kC = new KoreanCalendar();
     System.Globalization.Calendar gC = new GregorianCalendar();
     DateTime dateTime = gC.ToDateTime(2000, 2, 29, 0, 0, 0, 0);
     int expectedValue = gC.GetDayOfYear(dateTime);
     int actualValue;
     actualValue = kC.GetDayOfYear(dateTime);
     Assert.Equal(expectedValue, actualValue);
 }
Пример #2
0
 public void PosTest4()
 {
     System.Globalization.Calendar kC = new KoreanCalendar();
     System.Globalization.Calendar gC = new GregorianCalendar();
     DateTime dateTime = new DateTime(TestLibrary.Generator.GetInt64(-55) % (DateTime.MaxValue.Ticks + 1));
     dateTime = gC.ToDateTime(dateTime.Year, dateTime.Month, dateTime.Day, 0, 0, 0, 0);
     int expectedValue = gC.GetDayOfYear(dateTime);
     int actualValue;
     actualValue = kC.GetDayOfYear(dateTime);
     Assert.Equal(expectedValue, actualValue);
 }
        internal int GetWeekOfYearFullDays(DateTime time, CalendarWeekRule rule, int firstDayOfWeek, int fullDays)
        {
            int dayForJan1;
            int offset;
            int day;
            System.Globalization.Calendar gc = new GregorianCalendar();
            int dayOfYear = gc.GetDayOfYear(time) - 1; // Make the day of year to be 0-based, so that 1/1 is day 0.
                                                       //
                                                       // Calculate the number of days between the first day of year (1/1) and the first day of the week.
                                                       // This value will be a positive value from 0 ~ 6.  We call this value as "offset".
                                                       //
                                                       // If offset is 0, it means that the 1/1 is the start of the first week.
                                                       //     Assume the first day of the week is Monday, it will look like this:
                                                       //     Sun      Mon     Tue     Wed     Thu     Fri     Sat
                                                       //     12/31    1/1     1/2     1/3     1/4     1/5     1/6
                                                       //              +--> First week starts here.
                                                       //
                                                       // If offset is 1, it means that the first day of the week is 1 day ahead of 1/1.
                                                       //     Assume the first day of the week is Monday, it will look like this:
                                                       //     Sun      Mon     Tue     Wed     Thu     Fri     Sat
                                                       //     1/1      1/2     1/3     1/4     1/5     1/6     1/7
                                                       //              +--> First week starts here.
                                                       //
                                                       // If offset is 2, it means that the first day of the week is 2 days ahead of 1/1.
                                                       //     Assume the first day of the week is Monday, it will look like this:
                                                       //     Sat      Sun     Mon     Tue     Wed     Thu     Fri     Sat
                                                       //     1/1      1/2     1/3     1/4     1/5     1/6     1/7     1/8
                                                       //                      +--> First week starts here.



            // Day of week is 0-based.
            // Get the day of week for 1/1.  This can be derived from the day of week of the target day.
            // Note that we can get a negative value.  It's ok since we are going to make it a positive value when calculating the offset.
            dayForJan1 = (int)gc.GetDayOfWeek(time) - (dayOfYear % 7);

            // Now, calucalte the offset.  Substract the first day of week from the dayForJan1.  And make it a positive value.
            offset = (firstDayOfWeek - dayForJan1 + 14) % 7;
            if (offset != 0 && offset >= fullDays)
            {
                //
                // If the offset is greater than the value of fullDays, it means that
                // the first week of the year starts on the week where Jan/1 falls on.
                //
                offset -= 7;
            }
            //
            // Calculate the day of year for specified time by taking offset into account.
            //
            day = dayOfYear - offset;
            if (day >= 0)
            {
                //
                // If the day of year value is greater than zero, get the week of year.
                //
                return (day / 7 + 1);
            }
            //
            // Otherwise, the specified time falls on the week of previous year.
            // Call this method again by passing the last day of previous year.
            //
            return (GetWeekOfYearFullDays(time.AddDays(-(dayOfYear + 1)), rule, firstDayOfWeek, fullDays));
        }
 internal int GetFirstDayWeekOfYear(DateTime time, int firstDayOfWeek)
 {
     System.Globalization.Calendar gc = new GregorianCalendar();
     int dayOfYear = gc.GetDayOfYear(time) - 1;   // Make the day of year to be 0-based, so that 1/1 is day 0.
                                                  // Calculate the day of week for the first day of the year.
                                                  // dayOfWeek - (dayOfYear % 7) is the day of week for the first day of this year.  Note that
                                                  // this value can be less than 0.  It's fine since we are making it positive again in calculating offset.
     int dayForJan1 = (int)gc.GetDayOfWeek(time) - (dayOfYear % 7);
     int offset = (dayForJan1 - firstDayOfWeek + 14) % 7;
     //BCLDebug.Assert(offset >= 0, "Calendar.GetFirstDayWeekOfYear(): offset >= 0");
     return ((dayOfYear + offset) / 7 + 1);
 }